I can't change chmod to 777 in Android programmatically

2.9k Views Asked by At

I have a rooted device, and want to change the chmod permission of an apk(Prueba.apk) that is inside /system/app , so to achieve that I am using the RootTools library with BusyBox. And my code is:

        Command comando = new Command(0, "chmod 777 /system/app/Prueba.apk");
    try {
        RootTools.getShell(true).add(comando);
    } catch (IOException | RootDeniedException | TimeoutException ex) {
        ex.printStackTrace();
    }

But when I check, after running that code with a Root file explorer I see that the chmod permissions for Prueba.apk didn't change.

2

There are 2 best solutions below

0
On BEST ANSWER

The problem was that when I mounted the system partition as RW I did it like this:

        Command comando = new Command(0, "mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system/app";
    try {
        RootTools.getShell(true).add(comando);
    } catch (IOException | RootDeniedException | TimeoutException ex) {
        ex.printStackTrace();
    }

But the correct way is making ALL system partition RW instead of just /system/app folder, so I changed the code to:

        Command comando = new Command(0, "mount -o remount,rw -t yaffs2 /dev/block/mtdblock3 /system";
    try {
        RootTools.getShell(true).add(comando);
    } catch (IOException | RootDeniedException | TimeoutException ex) {
        ex.printStackTrace();
    }

And then I could execute chmod 777 command perfectly.

1
On

You should trying using su -c before running your code that requires root access.

/system/* is read-only and commands should be run by root, but first the /system partition needs to be mounted as read and write. There are a variety of ways to do this, but for my Nexus 5x this works:
mount -o rw,remount /system

However, this method may not work so try a different way to mount r/o here