How to Compile Android Application with System Permissions

How to compile Android Application with system permissions

After having some search I found how to sign my application with system (platform) key.
System signatures are located in directory <root-of-android-source-tree>/build/target/product/security. You can use them to sign your application with system privileges.

Android runtime permissions for System app

At first, dump your package service and inspect the package has correct flag and permissions. If your app is privileged, privateFlags must have PRIVILEGED. If your app is privileged, all Runtime permissions are granted if it is requested in the manifest. However I'm not sure this is true on Android 6.0.

adb shell dumpsys package

Packages:
Package [com.android.systemui] (4dfb5a):
....
flags=[ SYSTEM HAS_CODE PERSISTENT ]
privateFlags=[ PRIVILEGED DEFAULT_TO_DEVICE_PROTECTED_STORAGE DIRECT_BOOT_AWARE RESIZEABLE_ACTIVITIES ]
dataDir=/data/user_de/0/com.android.systemui
....
pkgFlags=[ SYSTEM HAS_CODE PERSISTENT ]
declared permissions:
com.android.systemui.permission.SELF: prot=signature, INSTALLED
requested permissions:
android.permission.RECEIVE_BOOT_COMPLETED
android.permission.READ_EXTERNAL_STORAGE
....
install permissions:
android.permission.REAL_GET_TASKS: granted=true
android.permission.REMOTE_AUDIO_PLAYBACK: granted=true

And please have a look this answer

Get Android system permissions by putting app in /system/app?

As of Android 4.4, Privileged Apps must be put in /system/priv-app instead of /system/app. Once I moved my app there, it got the privilege as expected.

See here: AOSP Privileged vs System app

How to grant system permissions to my android app?

Far better than a silent uninstall is somehow bricking the app. There's a few ways that this could be done, but basically keep track of the first day they used it, and make the program not work. Alternatively, it could be set up to work until a certain day, after which it will no longer work. This question answers how to do this.

It is possible to compile with Api 23 (6.0) and to maintain the old permission system (install-time)?

Yes the old permission system will be used (even on Android 6.0) if targetSdkVersion is set <23. However an user on Android 6.0 can later manually disable individual permissions from Settings. Although Android 6.0 will warn the user when they try to do that but they can revoke anyway.

Now the question is will your app crash after user revokes permission?

When we call a function that requires a permission user revoked on
application with targetSdkVersion less than 23, no Exception will
be thrown. Instead it will just simply do nothing. For the function
that return value, it will return either null or 0 depends on the
case. Although application would not be crashed from calling a
function. It may still can crash from what that application does next
with those returned value.

grant system permissions to an app in the android emulator

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.



Related Topics



Leave a reply



Submit