我拥有root权限,并且我正在为我的应用测试一项涉及访问和编辑Android系统文件夹的新功能。
但是我的代码似乎没有改变任何东西。我在Marshmallow CM 13.
Process p;
try {
// Preform su to get root privileges
p = Runtime.getRuntime().exec("su");
// Attempt to write a file to a root-only
DataOutputStream os = new DataOutputStream(p.getOutputStream());
os.writeBytes("echo \"Do I have root?\" >/system/etc/temporary.txt\n");
// Close the terminal
os.writeBytes("exit\n");
os.flush();
try {
p.waitFor();
if (p.exitValue() != 255) {
// TODO Code to run on success
toastMessage("root");
}
else {
// TODO Code to run on unsuccessful
toastMessage("not root");
}
} catch (InterruptedException e) {
// TODO Code to run in interrupted exception
toastMessage("not root");
}
} catch (IOException e) {
// TODO Code to run in input/output exception
toastMessage("not root");
}
答案 0 :(得分:2)
/system
安装点默认安装为RO。即使具有根级别权限,写入它的唯一方法是将其重新安装为RW。此外,您可能仍会遇到SE Android(SE Linux for Android)的一些问题,它存在并且自Lollipop以来处于完全执行模式。可能会在平台中内置SE Android安全策略,这将限制对文件系统某些部分的访问,即使对于root也是如此。