I am trying to write a file, generated by my app, onto the system partition. As I can not create an FileOutputStream inside my app I create the file in the data directory of my app, correct the permissions and then move it to the system partition.
At the moment the code below misses the writable remount of /system - for testing purposes I have performed this step successfully via adb remount
- therefore this should not be the problem.
The app also gets successfully root permissions.
But the code below does not work. It only creates the file but does not move it to the system partition. What's my mistake?
FileOutputStream out = openFileOutput("myfile.test", MODE_WORLD_READABLE);
File f = getFileStreamPath("myfile.test");
writeDataToOutputStream(out);
out.close();
String filename = f.getAbsolutePath();
Runtime r = Runtime.getRuntime();
r.exec("su");
// Waiting here some seconds does not make any difference
r.exec(new String[] { "chown", "root.root", filename });
r.exec(new String[] { "chmod", "644", filename });
r.exec(new String[] { "mv", filename, "/system/myfile.test" });