Android9.0给系统应用添加默认权限的方法

软件平台:Android9.0

硬件平台:Mtk6771

        近来做产品需求开发,发现首次起机或者恢复出厂设置之后,app首次启动的时候,会触发权限申请的提示弹窗,用户可以选择授权或者拒绝,会给用户造成不良体验,于是琢磨了一套Framework层默认给app授权的机制,具体操作如下:

diff --git a/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java b/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java
index 1c40347f..a1b37a1a 100644
--- a/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java
+++ b/services/core/java/com/android/server/pm/permission/DefaultPermissionGrantPolicy.java
@@ -359,6 +359,25 @@ public final class DefaultPermissionGrantPolicy {
         String[] calendarSyncAdapterPackages = (syncAdapterPackagesProvider != null) ?
                 syncAdapterPackagesProvider.getPackages(CalendarContract.AUTHORITY, userId) : null;
 
+        // IflyIME
+        final String iflyimePackageName = "com.iflytek.inputmethod";
+        PackageParser.Package iflyimePackage = getSystemPackage(iflyimePackageName);
+        if (iflyimePackage != null
+                && doesPackageSupportRuntimePermissions(iflyimePackage)) {
+            grantRuntimePermissions(iflyimePackage, STORAGE_PERMISSIONS, true, userId);
+            grantRuntimePermissions(iflyimePackage, MICROPHONE_PERMISSIONS, true, userId);
+        }
+
+        // IflyOCR
+        final String iflytekOcrPackageName = "com.iflytek.ocr";
+        PackageParser.Package iflyOcrPackage = getSystemPackage(iflytekOcrPackageName);
+        if (iflyOcrPackage != null
+                && doesPackageSupportRuntimePermissions(iflyOcrPackage)) {
+            grantRuntimePermissions(iflyOcrPackage, STORAGE_PERMISSIONS, true, userId);
+            grantRuntimePermissions(iflyOcrPackage, CAMERA_PERMISSIONS, true, userId);
+            grantRuntimePermissions(iflyOcrPackage, PHONE_PERMISSIONS, true, userId);
+        }
+

         // Installer
         final String installerPackageName = mServiceInternal.getKnownPackageName(
                 PackageManagerInternal.PACKAGE_INSTALLER, userId);

 

做如上修改,即可给相应的app添加默认授权~

MARK 一下。

 

 

 

 

 

 

 

 

 

 

 

 

 

你可能感兴趣的:(android)