我正在尝试创建一个小型应用程序,它需要对/system 文件夹进行读/写访问(它正在尝试删除一个文件,并创建一个新文件来代替它)。我可以使用 adb 毫无问题地重新挂载该文件夹,如果我这样做,我的应用程序肯定可以正常工作,直到重新启动。
我的设备已获得 root 权限(sgs3 和 stock 4.1.2)。我可以毫无问题地获得 root 访问权限 - 我在可以启用它的地方收到弹出消息。但在那之后它并没有真正响应命令。
我有这样的东西:
//at this point I get the popup to grant root access
Runtime.getRuntime().exec("su");
//no error messages - not on console, not in logcat
Runtime.getRuntime().exec("mount -w -o remount -t ext4 /dev/block/mmcblk0p9 /system");
//trying to do things in the system folder...
FileWriter fw=new FileWriter(file);
fw.write("a");
fw.close();
//trying to remount the folder as read only only once everything is done
Runtime.getRuntime().exec("mount -r -o remount -t ext4 /dev/block/mmcblk0p9 /system");
如果我从 adb shell 运行相同的重新安装命令,一切都会完美。如果我不运行它,而是尝试依赖该应用程序,当我尝试从文件系统写入/删除时,会收到以下错误消息(抛出 IOException):
open failed: EROFS (read-only file system)
一些附加信息:我正在使用 2.2 SDK,在我的 list 文件中具有 WRITE_EXTERNAL_STORAGE 权限(尽管我不确定是否需要它,因为我正在尝试使用内部存储)。
欢迎所有想法。
你的问题是你挂载的进程与你的 root 进程不同,尝试这样的事情:
Process suProcess;
DataOutputStream os;
thử{
//Get Root
suProcess = Runtime.getRuntime().exec("su");
os= new DataOutputStream(suProcess.getOutputStream());
//Remount writable FS within the root process
os.writeBytes("mount -w -o remount -t ext4 /dev/block/mmcblk0p9 /system\n");
os.flush();
//Do something here
os.writeBytes("rm /system/somefile\n");
os.flush();
//Do something there
os.writeBytes("touch /system/somefile\n");
os.flush();
//Remount Read-Only
os.writeBytes("mount -r -o remount -t ext4 /dev/block/mmcblk0p9 /system\n");
os.flush();
//End process
os.writeBytes("exit\n");
os.flush();
}
catch (IOException e) {
throw new RuntimeException(e);
}
Tôi là một lập trình viên xuất sắc, rất giỏi!