I am trying to create a small application, that needs read/write access on the /system folder (it is trying to remove a file, and create a new one instead of it). I am able to remount the folder without a problem with adb, and if I do it, certainly my app works fine until the reboot.
My device is rooted (sgs3 with stock 4.1.2). I can acquire root access without a problem - i get the pop up message where i can enable it. But after that it does not really respond to commands.
I have something like this:
//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");
If I run the same remounting command from adb shell, everything is perfect. If I don't run it, but try to rely on the app, I get the following error message (IOException thrown) when I try to write/delete from the file system:
open failed: EROFS (read-only file system)
Some additional info: I am using 2.2 SDK, have WRITE_EXTERNAL_STORAGE permission in my manifest file (although I am not sure if I need it, since I am trying to use the internal storage).
All ideas are welcome.
Your problem is that you are mounting in a different process than the one you have root on, try something like this:
Process suProcess;
DataOutputStream os;
try{
//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);
}