背景:这几天在处理关于工厂测试app的授权问题,按照之前的把权限添加到权限白名单方式,使用app时,依然会发现无法打开录音,照相机等功能,去setting查看app权限管理,发现这些权限没有授予。现在问题解决了
首先,前面我写了这个博客,Android 开机权限白名单默认授予系统app权限, 里面提到默认授权时
private void restorePermissionState(@NonNull AndroidPackage pkg, boolean replace,
@Nullable String packageOfInterest, @Nullable PermissionCallback callback)
{
...
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;
}
} else if (bp.isSignature()) {
// For all apps signature permissions are install time ones.
allowedSig = grantSignaturePermission(perm, pkg, ps, bp, origPermissions);
if (allowedSig) {
grant = GRANT_INSTALL;
}
}
...
}
这里仅会去授予SignaturePermission
,而对于RuntimePermission
,在android Q后,不会被授权了。
关于权限等级的说明:
Normal, Dangerous, Signature, SigatureOrS