热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

软件平台:Android9.0硬件平台:Mtk6771近来做产品需求开发,发现首次起机或者恢复出厂设置之后,app首次启动

软件平台: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 一下。








推荐阅读
author-avatar
眾于-晴
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有