Building AOSP and adding a system app with runtime permission

随声附和 提交于 2020-01-07 08:40:58

问题


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.


回答1:


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



回答2:


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



来源:https://stackoverflow.com/questions/48743350/building-aosp-and-adding-a-system-app-with-runtime-permission

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!