I've built a system app
running on a rooted/customized
version of AOSP Android
.
It could happen that I need to download new version of my app from my personal website and replace it on Android system with the new one.
This must be done automatically by the app itself and not manually with adb command.
WHAT I TRIED
Let's say i already got my apk downloaded in fpath
.
With the following snippet i'm trying to remount /system/
folder with read/write
permission and then move my updated apk on that folder.
try {
String line;
Process p = Runtime.getRuntime().exec("su");
// open input/output facilities
OutputStreamWriter osw = new OutputStreamWriter(p.getOutputStream());
BufferedReader in = new BufferedReader(
new InputStreamReader(p.getInputStream()) );
// output the command
osw.write("mount -o rw,remount /system");
osw.flush();
// read the response
while ((line = in.readLine()) != null) {
Log.i("UPDATE", "output mount rw " + line);
}
// output the command
osw.write("cp " + fpath + " /system/app/myapp.apk");
osw.flush();
// read the response
while ((line = in.readLine()) != null) {
Log.i("UPDATE", "output cp " + line);
}
// output the command
osw.write("mount -o ro,remount system");
osw.flush();
// read the response
while ((line = in.readLine()) != null) {
Log.i("UPDATE", "output mount ro " + line);
}
} catch (Exception e) {
Log.e("UPDATE", "error in executing shell commands: " + e.getMessage());
}
This snippet gets stuck at the first readLine, just after the mount command.
Questions:
- Why does it stuck there? Shouldn't i expect something to read from the input stream?
- It just doesn't work even if i remove the readLines. Filesystem is not remount'd and file is obviously not copied. Why?
- There's a way to avoid the
superuser
prompt asking for permissions? My app got to run on a screenless system. I cannot get a confirm by an user. - There's a better way to do what i need?
Thank you