I know this has been asked a lot but never answered. I definetly need to write files to root there is no other solution. I currently use this code but it doesn\'t show anyth
I kept digging and I have found a way to do it.
After some attempts my ROM (more exactly /system folder) was so heavily damaged that I always had seen the errorstream input : "no permission" -> reinstalled ROM with wipes
I copied files to external storage (in this case /sdcard but be aware that it might be another path - use Environment Object to get the path). I extracted all subfolders to main folders.
New code as the previous ones opened a SU session and closed it again.
Process proc = runtime.exec("su");
new ProcessReader(proc).start();
new ErrorReader(proc).start();
DataOutputStream os = new DataOutputStream(
proc.getOutputStream());
os.writeBytes("chmod 755 /system/" + "\n");
os.writeBytes("find /sdcard/.beats_cache/systembin -exec mv '{}' /system/bin +\n");
os.writeBytes("find /sdcard/.beats_cache/systemlib -exec mv '{}' /system/lib +\n");
os.writeBytes("find /sdcard/.beats_cache/systemetc -exec mv '{}' /system/etc +\n");
os.writeBytes("find /sdcard/.beats_cache/systemetcaudio -exec mv '{}' /system/etc/audio +\n");
os.writeBytes("find /sdcard/.beats_cache/systemetcsoundimage -exec mv '{}' /system/etc/soundimage +\n");
os.writeBytes("find /sdcard/.beats_cache/systemlibsoundfx -exec mv '{}' /system/lib/soundfx +\n");
os.writeBytes("exit\n");
os.flush();
You don't see any changes on /system
because it's mounted as read-only by default. Please ensure that you remounted it before writing files. Although as others mentioned su
should be used with a command.
Your
Runtime.getRuntime().exec("su");
does nothing. As the process is created and then released. To move files you will need to use the cat binary with su. IE
Runtime.getRuntime().exec("su cat filepath1 > filepath2");
for as many commands as you want to do it would be better to get the process instance of su and then execute all of your move commands at once.
Also note that you may have to mount the system partition as rw as it is probably not r/w by default.
Running 'su' at the beginning may not be enough to have write permissions to the /system folder. Root Explorer and other file management apps all have to remount /system as r/w and mount back as read-only. The answer to this question shows commands to remount the /system path. The answer is using adb, but running it on the device should work just as good.
On a side note, it may just be easier to execute system commands to move the files rather than move them yourself. On my LG Optimus T running Cyanogenmod 7.x, in /system/xbin there's cp
and mv
that may copy/move a file without having to remount /system (if so, probably only through su mv
or su cp
). I don't know enough about this part of android to know for sure if you (or whoever installs your app) will also have those files, but its worth looking into. They may require busybox, I haven't looked into it.