Android拥有不同的权限组和权限。每个权限组代表特定的权限。但是我找不到每个组所拥有的权限列表。它在任何地方发布?Android权限组的内容
例如, android.permission.ACCOUNT_MANAGER与权限组ACCOUNTS关联。 我需要这种关联的列表。
Android拥有不同的权限组和权限。每个权限组代表特定的权限。但是我找不到每个组所拥有的权限列表。它在任何地方发布?Android权限组的内容
例如, android.permission.ACCOUNT_MANAGER与权限组ACCOUNTS关联。 我需要这种关联的列表。
可以使用PackageManager getAllPermissionGroups()和queryPermissionsByGroup() 来枚举整个Android权限层次结构。下面的代码在5.1.1(SDK 22)设备的末尾生成了输出结果。标记为“个人”的组具有groupInfo.flags == 1,并且看起来与在棉花糖中被称为“危险”的权限组相对应。
由于SDK级别的差异以及应用程序可以定义自定义权限的事实,您将在不同设备上获得不同的权限层次结构。
/**
* Uses PackageManager getAllPermissionGroups() and queryPermissionsByGroup()
* to enumerate the Android permission hierarchy.
*/
private void showPermissionTree()
{
final PackageManager pm = m_context.getPackageManager();
if (pm == null)
return;
/*
* Get a list of all permission groups and sort them alphabetically.
* Then add to the end of the list the special case of a null group name. There can be
* numerous permissions that are not listed under a group name.
*/
List<PermissionGroupInfo> groupInfoList = pm.getAllPermissionGroups(0);
if (groupInfoList == null)
return;
ArrayList<String> groupNameList = new ArrayList<>();
for (PermissionGroupInfo groupInfo : groupInfoList) {
String groupName = groupInfo.name;
if (groupName != null) {
if (Build.VERSION.SDK_INT >= 17) {
/*
* SDK 17 added the flags field. If non-zero, the permission group contains
* permissions that control access to user personal data.
* N.B. These are the permissions groups that are called "dangerous" in
* Marshmallow.
*/
if (groupInfo.flags != 0) {
groupName += " (personal)";
}
}
groupNameList.add(groupName);
}
}
Collections.sort(groupNameList);
groupNameList.add(null);
/*
* Loop though each permission group, adding to the StringBuilder the group name and
* the list of all permissions under that group.
*/
StringBuilder sb = new StringBuilder(10000);
final String INDENT = " ";
for (String groupName : groupNameList) {
if (groupName == null)
groupName = "null";
sb.append("* ").append(groupName).append("\n");
ArrayList<String> permissionNameList = getPermissionsForGroup(groupName);
if (permissionNameList.size() > 0) {
for (String permission : permissionNameList) {
sb.append(INDENT).append(permission).append("\n");
}
} else {
sb.append(INDENT).append("no permissions under group\n");
}
sb.append("\n");
}
m_textView.setText(sb.toString());
}
/*
* Gets and returns a list of all permission under the specified group, sorted alphabetically.
*
* N.B. groupName can be null. The docs for PackageManager.queryPermissionsByGroup() say
* "Use null to find all of the permissions not associated with a group."
*/
private ArrayList<String> getPermissionsForGroup(String groupName)
{
final PackageManager pm = m_context.getPackageManager();
final ArrayList<String> permissionNameList = new ArrayList<>();
try {
List<PermissionInfo> permissionInfoList =
pm.queryPermissionsByGroup(groupName, PackageManager.GET_META_DATA);
if (permissionInfoList != null) {
for (PermissionInfo permInfo : permissionInfoList) {
String permName = permInfo.name;
if (permName == null) {
permName = "null";
} else if (permName.isEmpty()) {
permName = "empty";
}
permissionNameList.add(permName);
}
}
}
catch (PackageManager.NameNotFoundException e) {
// e.printStackTrace();
Log.d(TAG, "permissions not found for group = " + groupName);
}
Collections.sort(permissionNameList);
return permissionNameList;
}
Android权限列表here和权限组here。然后还可以看看PemissionInfo()。
我需要哪个权限与哪些权限组相关联。我已经看到了这些链接。 –
使用'PermissionInfo()'并在结果struct中得到'public String group':http://developer.android.com/reference/android/content/pm/PermissionInfo.html#group –
是的,但我需要编写一个应用程序来遍历权限并获取关联的组。我问,是否有这样的协会发布在任何地方? –
我同意,这似乎是谷歌应该保持的记录在其网站上信息的列表。与每个权限的保护级别一起。 –