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博客