grant system permissions to an app in the android emulator

14,545

Solution 1

If you want a signatureOrSystem permission, you just need to be placed on the system image; you don't need to be signed with any special cert. You can do this as a one-off (until you exit the emulator) like this:

> adb root
> adb remount
> adb push /path/to/My.apk /system/app/My.apk

Once you have done that, you can use the normal process to install further updates on the data partition ("adb install -r /path/to/My.apk" which is what the developer tools do when you run from Eclipse). When installing this way, the app retains any signatureOrSystem permissions it had requested from the original version on the system image, but can not gain any new such permissions.

If you need pure signature permissions, you need to sign your app with the same cert as whatever is declaring those permissions (typically the core framework, but the media system is a separate cert etc). If you are requesting signature permissions you don't need to be installed on the system image, you can just install it as a normal app and it can still get the permissions because of the signing.

Solution 2

As far as I can tell, you need to:

  • download the Android source and build an emulator firmware image.
  • sign your application with the keys in the Android source tree at /build/target/product/security/.
  • add android:sharedUserId="android.uid.system" to your application's manifest.
  • run your application on an emulator using the image built in step 1.

The reason for having to build your own firmware image is so that you can get at the keys. Now, it might be possible that the keys for the standard emulator image are available somewhere, which will save you the long and exceedingly tedious process of building your own Android, but I'm afraid I have no idea where these might be.

Disclaimer: never tried this myself.

Share:
14,545

Related videos on Youtube

Ben
Author by

Ben

i'm a coder who likes to make stuff.

Updated on June 25, 2022

Comments

  • Ben
    Ben almost 2 years

    I am building an app that will be bundled on an android device as a system app. The manufacturer is a ways out on delivering the device to us, so in the meantime I'd like to grant my app system level permissions in the emulator so I can work on an auto update feature that will do silent installs of APKs without any interactions from the user. From what I've read, its my understanding that the only way to be able to do silent installs on android is if your app is signed with the same cert as the OS. So how can I simulate this in the emulator?

  • Ben
    Ben about 12 years
    that's what i was afraid of... any idea of where to look to find the keys for the existing emulators?
  • David Given
    David Given about 12 years
    Absolutely none. Building a firmware image isn't that hard; an hour or so for the massive download, and then about four for the build... and if you're shipping in a manufacturer ROM, you probably want to be getting a source release from them anyway for integration testing.
  • zapl
    zapl about 12 years
    you could try if the keys from android git work. E.g.: github.com/android/platform_build/tree/master/target/product‌​/… It's the "platform" key that you need to use for signing iirc
  • David Given
    David Given about 12 years
    Worth a try --- it depends whether the emulator image is built with BUILD_SECURE or not.
  • MindWire
    MindWire about 12 years
    Can anyone validate that this works? Lots of bumps, but no pretty green checkmark?!
  • hackbod
    hackbod about 12 years
    What permissions are you trying to retrieve. There is no doubt this works -- what signatureOrSystem means is that an app in /system/app can get the permission, and this is used for a number of core parts of the platform.
  • Ben
    Ben over 11 years
    this is how it works on the real device, so I don't see why this wouldn't work on the emulator. Thankfully, now that the prototype device is built, we no longer need the emulator. here's the device btw: youtube.com/watch?v=LyV0sWEJXP4
  • domen
    domen over 10 years
    Thank you for the clarification on upgrading.
  • davidgyoung
    davidgyoung almost 10 years
    Does this really work on a real device? I'm not seeing that all system permissions get granted when my app is installed in /system/app. See: stackoverflow.com/questions/24296286/…