0

Background

  • We build and control the hardware devices on which the app will run.
  • (EDIT)We will build a custom version of the Android OS soon as well.
  • We're building an app which we expect to be "always-on."
  • We want the app to be able to self-update, independent of the market. Hence, we are hosting a service which the client app will periodically poll for updates, download the apk, and then install it. Therein lies...

The problem

I want the UpdateService to install the downloaded app update without giving the user the usual permission and update prompts - after all, we control the hardware and the software. To do that, I think I need to give my app superuser permissions (tho, if there is some other way, then my question becomes something completely different). But I can't figure out how to do that.

I have read about a superuser app that can be installed - but this seems like a user solution for users who want to root their own phones. Or a solution for devs who want to distribute an app that needs superuser, but they don't control the device on which their users will install it.

Is there a file somewhere in the android OS that lists apps or users which should have su? If so, it's no problem; we control everything.

Eric J Turley
  • 350
  • 1
  • 5
  • 20
  • installing superuser.apk does not in and of itself root a phone. It is a helper application that can be installed on rooted phones which alerts the user when an application tries to use a command that requires su permission. – FoamyGuy Apr 08 '13 at 21:15
  • You don't control everything, since you don't control Android. The only way to do this is to build your own version of Android and install a custom ROM on your users device. Imagine the security problems, rooted or not, if apps could do this? – Simon Apr 08 '13 at 21:38
  • @Simon Turns out, we will actually control that as well - see (EDIT). Regardless, still looking for an answer. – Eric J Turley Apr 09 '13 at 03:07
  • @FoamyGuy Thanks for the clarification on superuser. – Eric J Turley Apr 09 '13 at 03:08
  • @EricTurley If you are rooted (and maybe have busybox, i'm not certain?) you can install a package via cmd process. See this question: http://stackoverflow.com/questions/14398543/android-install-apk-silently-by-busybox-command-line – FoamyGuy Apr 09 '13 at 13:41
  • @FoamyGuy OK. I explored that link and the ones branching from it. After changing the command line to point to the busybox binary on our device (it's at /system/bin/busybox), I ran it. It fails, however. Neither "am", "pm", nor "install" are listed as "Currently defined functions" when I print out the help for BusyBox v1.11.3 on our device. – Eric J Turley Apr 09 '13 at 15:07
  • @EricTurley where did your BusyBox binary come from? – FoamyGuy Apr 09 '13 at 15:31
  • @FoamyGuy I don't know. See, another company makes the device for us. At present, I don't know how busybox gets on it. I'm trying to find out... – Eric J Turley Apr 09 '13 at 20:36
  • @FoamyGuy I've updated to the latest busybox (1.21), and it **also** does not contain the functions "am" or "pm." However, those are included in Android (as /system/bin) as far as I can tell. You pointed me to the above SO question, in which the asker specifically called `/system/bin/busybox pm install`, I assume, suggesting that could solve my problem. Here's what I don't understand, tho. How does an invocation to `busybox pm` even work? Some kind of alias? Or is there some busybox version out there which includes those functions? – Eric J Turley Apr 24 '13 at 15:00
  • If the app comes with the ROM, it shouldn't need superuser permissions. I think... – Yaroslav Mytkalyk Jun 19 '14 at 16:30

2 Answers2

1

first I download and then I run the uninstall and install ( the system is rooted)

private void uninstall() {

        try {
            Process p = Runtime.getRuntime().exec("su");
            InputStream es = p.getErrorStream();
            DataOutputStream os = new DataOutputStream(p.getOutputStream());

            os.writeBytes("pm uninstall  com.example.app\n");

            os.writeBytes("exit\n");
            os.flush();
            int read;
            byte[] buffer = new byte[4096];
            String output = new String();
            while ((read = es.read(buffer)) > 0) {
                output += new String(buffer, 0, read);
            }
            p.waitFor();
        } catch (Exception e) {
        }
    }

    private void install() {
        try {
            // Do the magic
            Process p = Runtime.getRuntime().exec("su");
            InputStream es = p.getErrorStream();
            DataOutputStream os = new DataOutputStream(p.getOutputStream());

            os.writeBytes("pm install /mnt/sdcard/exampple/app.apk\n");

            os.writeBytes("exit\n");
            os.flush();
            int read;
            byte[] buffer = new byte[4096];
            String output = new String();
            while ((read = es.read(buffer)) > 0) {
                output += new String(buffer, 0, read);
            }
            p.waitFor();

        } catch (IOException e) {
            Log.d("catch silant", "1");
        } catch (InterruptedException e) {
            Log.d("catch silant", "2");
        }
    }
Steve Czetty
  • 6,147
  • 9
  • 39
  • 48
user1361207
  • 101
  • 1
  • 1
  • 7
0

look of this : https://code.google.com/p/auto-update-apk-client/downloads/detail?name=auto-update-apk-client_2012-10-04.tgz&can=2&q=

I think it can help you, I am also trying to do it now if you are success pleas write because I have an hard time with doing it.

user1361207
  • 101
  • 1
  • 1
  • 7
  • Thanks, but I've already looked at that. If you look at the source, you'll see it's just running an "su" command - which, on my device, even rooted, returns an error: "permission denied." That's exactly what I'm trying to work around. Here's the source to which I'm referring: https://code.google.com/p/auto-update-apk-client/source/browse/src/com/lazydroid/autoupdateapk/SilentAutoUpdate.java However, I'm totally open to someone telling me how to get this method to work... – Eric J Turley Apr 10 '13 at 14:50
  • I have exactly the same issue if you resolve it please update – user1361207 Apr 10 '13 at 17:58