Search code examples
javaandroidrootchmodroottools

I can't change chmod to 777 in Android programmatically


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.


Solution

  • 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.