PackageManagerクラスのgetPermissionInfo()メソッドを使用して、特定の権限のPermissionInfoオブジェクトを取得できます。PermissionInfoオブジェクトには、任意のアクセス許可の保護レベルを確認するために使用できるプロパティProtection Lavelがあります PROTECTION_FLAG_SYSTEM
。
次のコードのように:
for (PermissionInfo permission : packageInfo.permissions) {
// Dump permission info
String protectionLevel;
switch(permission.protectionLevel) {
case PermissionInfo.PROTECTION_NORMAL : protectionLevel = "normal"; break;
case PermissionInfo.PROTECTION_DANGEROUS : protectionLevel = "dangerous"; break;
case PermissionInfo.PROTECTION_SIGNATURE : protectionLevel = "signature"; break;
case PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM : protectionLevel = "signatureOrSystem"; break;
default : protectionLevel = "<unknown>"; break;
}
Log.i("PermissionCheck", permission.name + " " + protectionLevel);
}
更新:
の保護レベルを取得するにはrequestedPermissions
:
String[] reqp = info.requestedPermissions;
String perm = reqp[i];
if (perm.contains("android.permission.")) {
try {
PermissionInfo pi = getPackageManager().getPermissionInfo(perm, PackageManager.GET_META_DATA);
String protctionLevel = "unknown";
switch(pi.protectionLevel) {
case PermissionInfo.PROTECTION_NORMAL : protctionLevel = "normal"; break;
case PermissionInfo.PROTECTION_DANGEROUS : protctionLevel = "dangerous"; break;
case PermissionInfo.PROTECTION_SIGNATURE : protctionLevel = "signature"; break;
case PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM : protctionLevel = "signatureOrSystem"; break;
case PermissionInfo.PROTECTION_FLAG_SYSTEM : protctionLevel = "system"; break;
default : protctionLevel = "<unknown>"; break;
}
list_permission.add(perm + " "+protctionLevel);
} catch (NameNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
list_permission.add(perm);
}
次の行は、API レベル 16 以上でのみ機能します。
case PermissionInfo.PROTECTION_FLAG_SYSTEM : protctionLevel = "system"; break;