简体   繁体   English

我无法以编程方式在Android中将chmod更改为777

[英]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. 我有一个root用户设备,并且想要更改/ system / app内的apk(Prueba.apk)的chmod权限,因此要实现此目的,我将RootTools库与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. 但是当我检查时,使用根文件浏览器运行该代码后,我发现Prueba.apk的chmod权限没有更改。

You should trying using su -c before running your code that requires root access. 在运行需要root用户访问权限的代码之前,应尝试使用su -c

/system/* is read-only and commands should be run by root, but first the /system partition needs to be mounted as read and write. /system/*是只读的,命令应该由root用户运行,但是首先/system分区需要以读写方式挂载。 There are a variety of ways to do this, but for my Nexus 5x this works: 有多种方法可以执行此操作,但是对于我的Nexus 5x来说,它可以工作:
mount -o rw,remount /system

However, this method may not work so try a different way to mount r/o here 但是,此方法可能不起作用,因此请尝试使用其他方法在此处安装R / O

The problem was that when I mounted the system partition as RW I did it like this: 问题是当我将系统分区挂载为RW时,我这样做是这样的:

        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: 但是正确的方法是将所有系统分区改为RW,而不仅仅是/ system / app文件夹,因此我将代码更改为:

        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. 然后,我可以完美地执行chmod 777命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM