Reputation: 81
I work on Android 6 AOSP. I am able to build add the application as a system app but now I want to add runtime permission by default on this system app. Like that the app can start without asking the user to validate the permission.
Do you know how I can do that?
Thanks for you help.
Upvotes: 4
Views: 5017
Reputation: 33
You can grant runtime permissions to system apps by modifying the DefaultPermissionsGrantPolicy.java
class.
In the grantDefaultSystemHandlerPermissions(int userId)
method, add this code:
PackageParser.Package yourPackage = getSystemPackageLPr("YOUR_APP_PACKAGE_NAME");
if (yourPackage != null
&& doesPackageSupportRuntimePermissions(yourPackage)) {
grantRuntimePermissionsLPw(yourPackage, CONTACTS_PERMISSIONS, userId);
grantRuntimePermissionsLPw(yourPackage, CALENDAR_PERMISSIONS, userId);
}
Make sure you add the code above this line:
mService.mSettings.onDefaultRuntimePermissionsGrantedLPr(userId);
Upvotes: 1
Reputation: 2815
If your app is privileged, all Runtime permissions are granted if requested in manifest.
To make your app privileged:
in Android.mk
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true
If this does not solve your problem:
1. You can grant Runtime permissions to your app in Runtime. App must have android.Manifest.permission.GRANT_RUNTIME_PERMISSIONS. Pm.java
IPackageManager pm = IPackageManager.Stub.asInterface(ServiceManager.getService("package"));
pm.grantRuntimePermission(pkgname, perm, UserHandle.USER_OWNER);
pm.updatePermissionFlags(perm, pkgname, PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT,
PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT, UserHandle.USER_OWNER);
Additionally, if app use shared user id with system. Any permission is granted even though it is not requested in manifest.
android:sharedUserId="android.uid.system".
Upvotes: 7