Java Code Examples for android.content.pm.PackageManager#queryPermissionsByGroup()

The following examples show how to use android.content.pm.PackageManager#queryPermissionsByGroup() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AptoideUtils.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
public static List<ApkPermission> parsePermissions(Context context, List<String> permissionArray) {
    List<ApkPermission> list = new ArrayList<>();
    CharSequence csPermissionGroupLabel;
    CharSequence csPermissionLabel;
    PackageManager pm = context.getPackageManager();

    List<PermissionGroupInfo> lstGroups = pm.getAllPermissionGroups(PackageManager.PERMISSION_GRANTED);
    for (String permission : permissionArray) {

        for (PermissionGroupInfo pgi : lstGroups) {
            try {
                List<PermissionInfo> lstPermissions = pm.queryPermissionsByGroup(pgi.name, PackageManager.PERMISSION_GRANTED);
                for (PermissionInfo pi : lstPermissions) {
                    if (pi.name.equals(permission)) {
                        csPermissionLabel = pi.loadLabel(pm);
                        csPermissionGroupLabel = pgi.loadLabel(pm);
                        list.add(new ApkPermission(csPermissionGroupLabel.toString(), csPermissionLabel.toString()));
                    }
                }
            } catch (Exception e) {
                Logger.printException(e);
            }
        }
    }

    Collections.sort(list, new Comparator<ApkPermission>() {
        @Override
        public int compare(ApkPermission lhs, ApkPermission rhs) {
            return lhs.getName().compareTo(rhs.getName());
        }
    });

    return list;
}
 
Example 2
Source File: PermissionsActivity.java    From aptoide-client with GNU General Public License v2.0 5 votes vote down vote up
public static ArrayList<ApkPermission> permissions(Context context, ArrayList<String> permissionArray) {
    PackageManager pm = context.getPackageManager();

    CharSequence csPermissionGroupLabel;
    CharSequence csPermissionLabel;
    List<PermissionGroupInfo> lstGroups = pm.getAllPermissionGroups(0);
    ArrayList<ApkPermission> list = new ArrayList<>();

    if (permissionArray != null) {
        for (int i = 0; i != permissionArray.size(); i++) {
            String permission = permissionArray.get(i);

            for (PermissionGroupInfo pgi : lstGroups) {
                try {
                    List<PermissionInfo> lstPermissions = pm.queryPermissionsByGroup(pgi.name, 0);
                    for (PermissionInfo pi : lstPermissions) {
                        if (pi.name.equals(permission)) {
                            csPermissionLabel = pi.loadLabel(pm);
                            csPermissionGroupLabel = pgi.loadLabel(pm);
                            list.add(new ApkPermission(csPermissionGroupLabel.toString(), csPermissionLabel.toString()));
                        }
                    }
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
        }
        Collections.sort(list, new Comparator<ApkPermission>() {
            @Override
            public int compare(ApkPermission lhs, ApkPermission rhs) {
                return lhs.getName().compareTo(rhs.getName());
            }
        });
    }

    return list;
}
 
Example 3
Source File: AptoideUtils.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
public static List<ApkPermission> parsePermissions(Context context,
    List<String> permissionArray) {
  List<ApkPermission> list = new ArrayList<>();
  CharSequence csPermissionGroupLabel;
  CharSequence csPermissionLabel;
  PackageManager pm = context.getPackageManager();

  List<PermissionGroupInfo> lstGroups =
      pm.getAllPermissionGroups(PackageManager.PERMISSION_GRANTED);
  for (String permission : permissionArray) {

    for (PermissionGroupInfo pgi : lstGroups) {
      try {
        List<PermissionInfo> lstPermissions =
            pm.queryPermissionsByGroup(pgi.name, PackageManager.PERMISSION_GRANTED);
        for (PermissionInfo pi : lstPermissions) {
          if (pi.name.equals(permission)) {
            csPermissionLabel = pi.loadLabel(pm);
            csPermissionGroupLabel = pgi.loadLabel(pm);
            list.add(new ApkPermission(csPermissionGroupLabel.toString(),
                csPermissionLabel.toString()));
          }
        }
      } catch (Exception e) {
        Logger.getInstance()
            .e(TAG, e);
        throw new RuntimeException(e);
      }
    }
  }

  Collections.sort(list, (lhs, rhs) -> lhs.getName()
      .compareTo(rhs.getName()));

  return list;
}