简体   繁体   中英

Building AOSP and adding a system app with runtime permission

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.

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);
  1. You can grant permissions manually by modifying DefaultPermissionGrantPolicy.java .

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".

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM