我正在尝试将我的代码改编为Android Marshmallow。
我编写了一个函数来检查权限是否可撤消(PROTECTION_NORMAL
并PROTECTION_SIGNATURE
在安装时授予)。
在API-22上运行,Manifest.permission.READ_PHONE_STATE
返回值protectionLevel=PermissionInfo.PROTECTION_DANGEROUS
,这是我所期望的。
但是在API-22上Manifest.permission.INSTALL_SHORTCUT
也会返回protectionLevel=PermissionInfo.PROTECTION_DANGEROUS
,这从文档中是错误的。
这是怎么发生的?我的代码有什么问题:
final PermissionInfo permissionInfo = packageManager.getPermissionInfo(permission, 0);
switch (permissionInfo.protectionLevel) {
case PermissionInfo.PROTECTION_NORMAL:
case PermissionInfo.PROTECTION_SIGNATURE:
return false;
default:
return true;
}
Manifest.permission.INSTALL_SHORTCUT也返回protectionLevel = PermissionInfo.PROTECTION_DANGEROUS
如果您使用的是问题中显示的代码,则不会。充其量,您的代码将指示protectionLevel
isnormal
或signature
and并没有设置其他位。
这是怎么发生的?
protectionLevel
是一个位掩码。您没有正确比较位掩码。
int coreBits=info.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE;
coreBits
将是核心PROTECTION_
价值之一。protectionLevel
可能没有,因为可能设置了高阶位(例如PROTECTION_FLAG_PRE23
)。并且,在Android 6.0上,该coreBits
报告INSTALL_SHORTCUT
为normal
许可。
有关使用的演示,请参见此示例项目PermissionInfo.PROTECTION_MASK_BASE
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句