List of usage examples for android.content.pm PermissionInfo loadLabel
public @NonNull CharSequence loadLabel(@NonNull PackageManager pm)
From source file:Main.java
public static void printAllPermission(Context context) { if (!debug) { return;//from w ww. j a va 2s .co m } PackageManager pm = context.getPackageManager(); CharSequence csPermissionGroupLabel; CharSequence csPermissionLabel; List<PermissionGroupInfo> lstGroups = pm.getAllPermissionGroups(PackageManager.GET_PERMISSIONS); for (PermissionGroupInfo pgi : lstGroups) { csPermissionGroupLabel = pgi.loadLabel(pm); Log.d("ldx", "PermissionGroup: " + pgi.name + " [" + csPermissionGroupLabel.toString() + "]"); try { List<PermissionInfo> lstPermissions = pm.queryPermissionsByGroup(pgi.name, 0); for (PermissionInfo pi : lstPermissions) { csPermissionLabel = pi.loadLabel(pm); Log.d("ldx", " PermissionChild" + pi.name + " [" + csPermissionLabel.toString() + "]"); } } catch (Exception ex) { ex.printStackTrace(); } } }
From source file:Main.java
private static String getPermissionLabel(Context context, String permission, String defValue) { try {/* w w w. j a v a2 s . c o m*/ final PackageManager pm = context.getPackageManager(); final PermissionInfo pi = pm.getPermissionInfo(permission, 0); final CharSequence label = pi.loadLabel(pm); if (label != null && !label.toString().equals(permission)) return label.toString(); } catch (NameNotFoundException e) { // om nom nom } return defValue; }
From source file:com.kaliturin.blacklist.utils.Permissions.java
/** * Returns information string about permission **///from w w w . j a va 2s. c o m @Nullable private static String getPermissionInfo(@NonNull Context context, @NonNull String permission) { context = context.getApplicationContext(); PackageManager pm = context.getPackageManager(); PermissionInfo info = null; try { info = pm.getPermissionInfo(permission, PackageManager.GET_META_DATA); } catch (PackageManager.NameNotFoundException ex) { Log.w(TAG, ex); } if (info != null) { CharSequence label = info.loadLabel(pm); if (label == null) { label = info.nonLocalizedLabel; } return label.toString(); } return null; }
From source file:org.microg.tools.selfcheck.PermissionCheckGroup.java
private void doPermissionCheck(Context context, ResultCollector collector, final String permission) { PackageManager pm = context.getPackageManager(); try {/*from www. j av a 2 s.c o m*/ PermissionInfo info = pm.getPermissionInfo(permission, 0); PermissionGroupInfo groupInfo = info.group != null ? pm.getPermissionGroupInfo(info.group, 0) : null; CharSequence permLabel = info.loadLabel(pm); CharSequence groupLabel = groupInfo != null ? groupInfo.loadLabel(pm) : permLabel; collector.addResult(context.getString(R.string.self_check_name_permission, permLabel), context.checkSelfPermission(permission) == PackageManager.PERMISSION_GRANTED ? Positive : Negative, context.getString(R.string.self_check_resolution_permission, groupLabel), new SelfCheckGroup.CheckResolver() { @Override public void tryResolve(Fragment fragment) { fragment.requestPermissions(new String[] { permission }, 0); } }); } catch (PackageManager.NameNotFoundException e) { Log.w(TAG, e); } }
From source file:com.github.michalbednarski.intentslab.PermissionInfoFragment.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setRetainInstance(true);//w w w .j a v a 2s .co m // Get system services mPm = getActivity().getApplicationContext().getPackageManager(); final String permissionName = getArguments().getString(ARG_PERMISSION_NAME); // Get information about permission itself FormattedTextBuilder headerText = new FormattedTextBuilder(); headerText.appendGlobalHeader(permissionName); try { final PermissionInfo permissionInfo = mPm.getPermissionInfo(permissionName, 0); headerText.appendGlobalHeader(String.valueOf(permissionInfo.loadLabel(mPm))); headerText.appendValue(getString(R.string.description), String.valueOf(permissionInfo.loadDescription(mPm))); try { if (permissionInfo.group != null) { headerText.appendValue(getString(R.string.permission_group_name), permissionInfo.group); final PermissionGroupInfo permissionGroupInfo = mPm.getPermissionGroupInfo(permissionInfo.group, 0); headerText.appendValueNoNewLine(getString(R.string.permission_group_label), String.valueOf(permissionGroupInfo.loadLabel(mPm))); headerText.appendValueNoNewLine(getString(R.string.permission_group_description), String.valueOf(permissionGroupInfo.loadDescription(mPm))); } } catch (PackageManager.NameNotFoundException ignored) { } headerText.appendValue(getString(R.string.permission_protection_level), protectionLevelToString(permissionInfo.protectionLevel)); mDefinedBy = mPm.getPackageInfo(permissionInfo.packageName, 0); } catch (PackageManager.NameNotFoundException e) { // Undeclared permission e.printStackTrace(); } mDetailsText = headerText.getText(); (new ScanUsingAppsTask()).execute(permissionName); }
From source file:com.github.michalbednarski.intentslab.browser.PermissionsFetcher.java
@Override Object getEntries(Context context) { PackageManager pm = context.getPackageManager(); List<PackageInfo> installedPackages = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS); ArrayList<Component> foundPermissions = new ArrayList<Component>(); final boolean grouped = mGrouped; // Avoid race conditions ArrayList<Category> apps = grouped ? new ArrayList<Category>() : null; for (PackageInfo aPackage : installedPackages) { if (aPackage.permissions == null || aPackage.permissions.length == 0) { continue; }/*from w ww . j ava2s. c o m*/ for (PermissionInfo permission : aPackage.permissions) { if (ComponentFetcher.checkProtectionLevel(permission, mProtectionFilter) && (mNameSubstring == null || permission.name.toLowerCase().contains(mNameSubstring.toLowerCase()))) { Component component = new Component(); component.title = permission.name; component.subtitle = String.valueOf(permission.loadLabel(pm)); component.componentInfo = permission; foundPermissions.add(component); } } if (grouped && !foundPermissions.isEmpty()) { Category category = new Category(); category.title = String.valueOf(aPackage.applicationInfo.loadLabel(pm)); category.subtitle = aPackage.packageName; category.components = foundPermissions.toArray(new Component[foundPermissions.size()]); apps.add(category); foundPermissions.clear(); } } return grouped ? apps.toArray(new Category[apps.size()]) : foundPermissions.toArray(new Component[foundPermissions.size()]); }