Android-Framework 默认给安装的应用赋权限

一、环境

高通865 Android

二、情景

主动给安装的应用赋予权限,避免权限申请

注:这种方法对预制进系统的应用不生效

三、代码实现

frameworks/base/core/java/android/app/AppOpsManager.java
@@ -1802,7 +1802,7 @@ public class AppOpsManager {
             AppOpsManager.MODE_ALLOWED, // READ_ICC_SMS
             AppOpsManager.MODE_ALLOWED, // WRITE_ICC_SMS
             AppOpsManager.MODE_DEFAULT, // WRITE_SETTINGS
-            getSystemAlertWindowDefault(), // SYSTEM_ALERT_WINDOW
+            AppOpsManager.MODE_ALLOWED, //getSystemAlertWindowDefault(), // SYSTEM_ALERT_WINDOW
             AppOpsManager.MODE_ALLOWED, // ACCESS_NOTIFICATIONS
             AppOpsManager.MODE_ALLOWED, // CAMERA
             AppOpsManager.MODE_ALLOWED, // RECORD_AUDIO
packages/apps/PermissionController/src/com/android/packageinstaller/permission/ui/GrantPermissionsActivity.java
@@ -388,14 +388,14 @@ public class GrantPermissionsActivity extends Activity
                 }
             }
         }
-
+/*
         setContentView(mViewHandler.createView());
 
         Window window = getWindow();
         WindowManager.LayoutParams layoutParams = window.getAttributes();
         mViewHandler.updateWindowAttributes(layoutParams);
         window.setAttributes(layoutParams);
-
+*/
         // Restore UI state after lifecycle events. This has to be before
         // showNextPermissionGroupGrantRequest is called. showNextPermissionGroupGrantRequest might
         // update the UI and the UI behaves differently for updates and initial creations.
@@ -707,10 +707,17 @@ public class GrantPermissionsActivity extends Activity
 
                 // Set the permission message as the title so it can be announced.
                 setTitle(message);
-
+/*
                 mViewHandler.updateUi(groupState.mGroup.getName(), numGrantRequests, currentIndex,
                         icon, message, detailMessage, mButtonLabels);
-
+                        */
+                if (groupState.mGroup.getName() != null) {
+                   Log.d(LOG_TAG, "requestedPermission groupState.mGroup.getName() = " + groupState.mGroup.getName());
+                    try {
+                          onPermissionGrantResult(groupState.mGroup.getName(), GRANTED_ALWAYS);
+                        } catch (Exception e){}
+                    }
+                        
                 return true;
             }
 

注意:这种方案,清除应用用户数据的时候,权限也会被清理掉,相关处理方法,请查阅另一篇博客:

Android-Framework 清除应用用户数据,不清除权限-CSDN博客

猜你喜欢

转载自blog.csdn.net/banzhuantuqiang/article/details/133943149