I have root privileges, and I'm testing out a new feature for my app that involves accesing and editing Android's system folder.
However my code doesnt seem to be changing anything. Im on 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");
}
The /system
mount point is mounted RO by default. Even with root level permissions, the only way to write to it would be to remount it as RW. Additionally, you may still run into some issues with SE Android (SE Linux for Android), which is present and in full enforcing mode since Lollipop. There could be SE Android security policy built into the platform which will restrict access to certain parts of the filesystem, even for root.