Android 10 默认授权安装app运行时权限(去掉运行时全部权限授权弹窗)

[复制链接]
发表于 2025-12-25 23:34:48 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

×
 GRANT_INSTALL就是在安装apk时已经给予了全部申请权限,以是运行时给与权限改为安装时给予权限就可以了。
办理方案如下:
在PermissionManagerService.java文件中restorePermissionState方法中将应用权限设置为安装权限
/frameworks/base/services/core/java/com/android/server/pm/permission/PermissionManagerService.java
   final String perm = bp.getName();
                boolean allowedSig = false;
                int grant = GRANT_DENIED;
                  // Keep track of app op permissions.
                if (bp.isAppOp()) {
                    mSettings.addAppOpPackage(perm, pkg.packageName);
                }
  public class PermissionManagerService {
 if (bp.isNormal()) {
                    // For all apps normal permissions are install time ones.
                    grant = GRANT_INSTALL;
                } else if (bp.isRuntime()) {
                    if (origPermissions.hasInstallPermission(bp.getName())
                            || upgradedActivityRecognitionPermission != null) {
                        // Before Q we represented some runtime permissions as install permissions,
                        // in Q we cannot do this anymore. Hence upgrade them all.
                        grant = GRANT_UPGRADE;
                    } else {
                        // For modern apps keep runtime permissions unchanged.
+                        //grant = GRANT_RUNTIME;
+                         grant = GRANT_INSTALL;
                    }
                } else if (bp.isSignature()) {
                    // For all apps signature permissions are install time ones.
                         // Before Q we represented some runtime permissions as install permissions,
                         // in Q we cannot do this anymore. Hence upgrade them all.
-                        grant = GRANT_UPGRADE;
+                        grant = GRANT_INSTALL;
                     } else {
                         // For modern apps keep runtime permissions unchanged.
                         //grant = GRANT_RUNTIME;
@@ -1179,7 +1179,7 @@ public class PermissionManagerService {
                             // to the platform (note: need to only do this when
                             // updating the platform).
                             if (!isNewPlatformPermissionForPackage(perm, pkg)) {
-                                grant = GRANT_DENIED;
+                                grant = GRANT_INSTALL;
                             }
                         }
                     }
  别的,此修改方法只实用于安卓10,大概安卓11 R版本修改,也是行的通的。
请查阅下面的参考修改: 
Android R版本默认答应运行时安装权限-CSDN博客
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表