0

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:

  1. Why does it stuck there? Shouldn't i expect something to read from the input stream?
  2. It just doesn't work even if i remove the readLines. Filesystem is not remount'd and file is obviously not copied. Why?
  3. 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.
  4. There's a better way to do what i need?

Thank you

Davide Berra
  • 6,387
  • 2
  • 29
  • 50

1 Answers1

0

There's a better way to do what i need?

Copying the APK will not install it. Use pm instead of cp.

There's a way to avoid the superuser prompt asking for permissions?

This is up to the su app, so if you need one that automatically grants permissions without asking or remembers the permissions.

m0skit0
  • 25,268
  • 11
  • 79
  • 127