android.content.pm.PermissionInfo Java Examples
The following examples show how to use
android.content.pm.PermissionInfo.
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: PermissionCheckGroup.java From android_external_MicroGUiTools with Apache License 2.0 | 8 votes |
private void doPermissionCheck(Context context, ResultCollector collector, final String permission) { PackageManager pm = context.getPackageManager(); try { 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); } }
Example #2
Source File: BroadcastQueue.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
/** * Return true if all given permissions are signature-only perms. */ final boolean isSignaturePerm(String[] perms) { if (perms == null) { return false; } IPackageManager pm = AppGlobals.getPackageManager(); for (int i = perms.length-1; i >= 0; i--) { try { PermissionInfo pi = pm.getPermissionInfo(perms[i], "android", 0); if ((pi.protectionLevel & (PermissionInfo.PROTECTION_MASK_BASE | PermissionInfo.PROTECTION_FLAG_PRIVILEGED)) != PermissionInfo.PROTECTION_SIGNATURE) { // If this a signature permission and NOT allowed for privileged apps, it // is okay... otherwise, nope! return false; } } catch (RemoteException e) { return false; } } return true; }
Example #3
Source File: PermissionsHelperTest.java From android-testdpc with Apache License 2.0 | 6 votes |
@Test public void ensureRequiredPermissions_ifPermissionIsDangerousAndPermissionGrantStateIsAlreadySet_shouldReturnTrue() { addPermissionInfo(DANGEROUS_PERMISSION, PermissionInfo.PROTECTION_DANGEROUS); shadowOf(mDevicePolicyManager).setProfileOwner(TESTDPC_ADMIN); mDevicePolicyManager.setPermissionGrantState( TESTDPC_ADMIN, mContext.getPackageName(), DANGEROUS_PERMISSION, DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED); boolean requiredPermissionsGranted = PermissionsHelper .ensureRequiredPermissions(new String[]{DANGEROUS_PERMISSION}, TESTDPC_ADMIN, mContext); assertTrue(requiredPermissionsGranted); assertThat(mDevicePolicyManager .getPermissionGrantState(TESTDPC_ADMIN, mContext.getPackageName(), DANGEROUS_PERMISSION)) .isEqualTo(DevicePolicyManager.PERMISSION_GRANT_STATE_GRANTED); }
Example #4
Source File: ApplicationPackageManager.java From AndroidComponentPlugin with Apache License 2.0 | 6 votes |
@Override @SuppressWarnings("unchecked") public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) throws NameNotFoundException { try { ParceledListSlice<PermissionInfo> parceledList = mPM.queryPermissionsByGroup(group, flags); if (parceledList != null) { List<PermissionInfo> pi = parceledList.getList(); if (pi != null) { return pi; } } } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } throw new NameNotFoundException(group); }
Example #5
Source File: PermissionManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
private PermissionInfo getPermissionInfo(String permName, String packageName, int flags, int callingUid) { if (mPackageManagerInt.getInstantAppPackageName(callingUid) != null) { return null; } // reader synchronized (mLock) { final BasePermission bp = mSettings.getPermissionLocked(permName); if (bp == null) { return null; } final int adjustedProtectionLevel = adjustPermissionProtectionFlagsLocked( bp.getProtectionLevel(), packageName, callingUid); return bp.generatePermissionInfo(adjustedProtectionLevel, flags); } }
Example #6
Source File: BasePermission.java From android_9.0.0_r45 with Apache License 2.0 | 6 votes |
public void updateDynamicPermission(Collection<BasePermission> permissionTrees) { if (PackageManagerService.DEBUG_SETTINGS) Log.v(TAG, "Dynamic permission: name=" + getName() + " pkg=" + getSourcePackageName() + " info=" + pendingPermissionInfo); if (sourcePackageSetting == null && pendingPermissionInfo != null) { final BasePermission tree = findPermissionTree(permissionTrees, name); if (tree != null && tree.perm != null) { sourcePackageSetting = tree.sourcePackageSetting; perm = new PackageParser.Permission(tree.perm.owner, new PermissionInfo(pendingPermissionInfo)); perm.info.packageName = tree.perm.info.packageName; perm.info.name = name; uid = tree.uid; } } }
Example #7
Source File: Check.java From OneKeyPerm with MIT License | 6 votes |
static void hasDefinePermission(Context context) { try { String packName = context.getPackageName(); String perm = packName.concat(".permission.ONE_KEY_PERM"); PackageManager pm = context.getPackageManager(); PackageInfo pi = pm.getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS); if (pi.permissions == null) { log(packName); return; } for (PermissionInfo permission : pi.permissions) { if (perm.equals(permission.name) && permission.protectionLevel == PROTECTION_SIGNATURE && ContextCompat.checkSelfPermission(context, perm) == PackageManager.PERMISSION_GRANTED) { return; } } log(packName); } catch (Exception e) { e.printStackTrace(); } }
Example #8
Source File: AppSecurityPermissions.java From fdroidclient with GNU General Public License v3.0 | 6 votes |
@TargetApi(23) private boolean isDisplayablePermission(PermissionInfo pInfo, int existingReqFlags) { final int base = pInfo.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE; final boolean isNormal = base == PermissionInfo.PROTECTION_NORMAL; final boolean isDangerous = base == PermissionInfo.PROTECTION_DANGEROUS || ((pInfo.protectionLevel & PermissionInfo.PROTECTION_FLAG_PRE23) != 0); // Dangerous and normal permissions are always shown to the user // this is matches the permission list in AppDetailsActivity if (isNormal || isDangerous) { return true; } final boolean isDevelopment = (pInfo.protectionLevel & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0; final boolean wasGranted = (existingReqFlags & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0; // Development permissions are only shown to the user if they are already // granted to the app -- if we are installing an app and they are not // already granted, they will not be granted as part of the install. return isDevelopment && wasGranted; }
Example #9
Source File: IApkManagerImpl.java From letv with Apache License 2.0 | 6 votes |
public PermissionInfo getPermissionInfo(String name, int flags) throws RemoteException { waitForReadyInner(); try { enforcePluginFileExists(); if (shouldNotBlockOtherInfo()) { for (PluginPackageParser pluginPackageParser : this.mPluginCache.values()) { for (PermissionInfo permissionInfo : pluginPackageParser.getPermissions()) { if (TextUtils.equals(permissionInfo.name, name)) { return permissionInfo; } } } } List<String> pkgs = this.mActivityManagerService.getPackageNamesByPid(Binder.getCallingPid()); for (PluginPackageParser pluginPackageParser2 : this.mPluginCache.values()) { for (PermissionInfo permissionInfo2 : pluginPackageParser2.getPermissions()) { if (TextUtils.equals(permissionInfo2.name, name) && pkgs.contains(permissionInfo2.packageName)) { return permissionInfo2; } } } } catch (Exception e) { handleException(e); } return null; }
Example #10
Source File: ApplicationPackageManager.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
@Override public PermissionInfo getPermissionInfo(String name, int flags) throws NameNotFoundException { try { PermissionInfo pi = mPM.getPermissionInfo(name, flags); if (pi != null) { return pi; } } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } throw new NameNotFoundException(name); }
Example #11
Source File: PermissionManager.java From QuickDevFramework with Apache License 2.0 | 5 votes |
/** * 获取权限所属权限组的名称 * <p>在需要显示某个权限所属的一组权限的名称时使用</p> */ public static String getPermissionGroupName(Context context, String permission) { PackageManager packageManager = context.getPackageManager(); try { PermissionInfo permissionInfo = packageManager.getPermissionInfo(permission, 0); PermissionGroupInfo permissionGroupInfo = packageManager.getPermissionGroupInfo(permissionInfo.group, 0); return permissionGroupInfo.loadDescription(packageManager).toString(); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return permission; }
Example #12
Source File: DataImportActivity.java From trekarta with GNU General Public License v3.0 | 5 votes |
private void askForPermission(Runnable task) { mTask = task; if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { // Should we show an explanation? if (shouldShowRequestPermissionRationale(Manifest.permission.READ_EXTERNAL_STORAGE)) { String name; try { PackageManager pm = getPackageManager(); PermissionInfo permissionInfo = pm.getPermissionInfo(Manifest.permission.READ_EXTERNAL_STORAGE, PackageManager.GET_META_DATA); name = (String) permissionInfo.loadLabel(pm); } catch (PackageManager.NameNotFoundException e) { logger.error("Failed to obtain name for permission", e); name = "read external storage"; } new AlertDialog.Builder(this) .setMessage(getString(R.string.msgReadExternalStorageRationale, name)) .setPositiveButton(R.string.ok, (dialog, which) -> requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE)) .setNegativeButton(R.string.cancel, (dialog, which) -> finish()) .create() .show(); } else { requestPermissions(new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE); } } else { mDataImportFragment.startImport(mTask); } }
Example #13
Source File: ApkManager.java From letv with Apache License 2.0 | 5 votes |
public List<PermissionInfo> queryPermissionsByGroup(String group, int flags) throws RemoteException { try { if (!(this.mApkManager == null || group == null)) { return this.mApkManager.queryPermissionsByGroup(group, flags); } } catch (RemoteException e) { JLog.log("wuxinrong", "获取权限信息列表 失败 e=" + e.getMessage()); throw e; } catch (Exception e2) { JLog.log("wuxinrong", "获取权限信息列表 失败 e=" + e2.getMessage()); } return null; }
Example #14
Source File: Utils.java From Android-Applications-Info with Apache License 2.0 | 5 votes |
public static String getProtectionLevelString(int level) { String protLevel = "????"; switch (level & PermissionInfo.PROTECTION_MASK_BASE) { case PermissionInfo.PROTECTION_DANGEROUS: protLevel = "dangerous"; break; case PermissionInfo.PROTECTION_NORMAL: protLevel = "normal"; break; case PermissionInfo.PROTECTION_SIGNATURE: protLevel = "signature"; break; case PermissionInfo.PROTECTION_SIGNATURE_OR_SYSTEM: protLevel = "signatureOrSystem"; break; } if ((level & PermissionInfo.PROTECTION_FLAG_SYSTEM) != 0) { protLevel += "|system"; } if ((level & PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0) { protLevel += "|development"; } if ((level & PermissionInfo.PROTECTION_FLAG_APPOP) != 0) { protLevel += "|appop"; } return protLevel; }
Example #15
Source File: PermissionManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void enforcePermissionCapLocked(PermissionInfo info, BasePermission tree) { // We calculate the max size of permissions defined by this uid and throw // if that plus the size of 'info' would exceed our stated maximum. if (tree.getUid() != Process.SYSTEM_UID) { final int curTreeSize = calculateCurrentPermissionFootprintLocked(tree); if (curTreeSize + info.calculateFootprint() > MAX_PERMISSION_TREE_FOOTPRINT) { throw new SecurityException("Permission tree size cap exceeded"); } } }
Example #16
Source File: Helper.java From AppOpsX with MIT License | 5 votes |
public static List<OpEntryInfo> getLocalOpEntryInfos(Context context) { if (sOpEntryInfoList.isEmpty()) { int[] sOpToSwitch = FixCompat.sOpToSwitch(); String[] sOpNames = FixCompat.sOpNames(); String[] sOpPerms = FixCompat.sOpPerms(); int len = sOpPerms.length; PackageManager pm = context.getPackageManager(); for (int i = 0; i < len; i++) { OpEntry entry = new OpEntry(sOpToSwitch[i], AppOpsManager.MODE_ALLOWED, 0, 0, 0, 0, null); OpEntryInfo opEntryInfo = new OpEntryInfo(entry); opEntryInfo.opName = sOpNames[i]; try { PermissionInfo permissionInfo = pm.getPermissionInfo(sOpPerms[i], 0); opEntryInfo.opPermsLab = String.valueOf(permissionInfo.loadLabel(pm)); opEntryInfo.opPermsDesc = String.valueOf(permissionInfo.loadDescription(pm)); } catch (PackageManager.NameNotFoundException e) { //ignore Integer resId = sPermI18N.get(opEntryInfo.opName); if (resId != null) { opEntryInfo.opPermsLab = context.getString(resId); opEntryInfo.opPermsDesc = opEntryInfo.opName; } else { opEntryInfo.opPermsLab = opEntryInfo.opName; } } sOpEntryInfo.put(entry.getOp(), opEntryInfo); sAllOps.put(entry.getOp(), entry.getOp()); sOpEntryInfoList.add(opEntryInfo); } } return new ArrayList<OpEntryInfo>(sOpEntryInfoList); }
Example #17
Source File: Permissions.java From YalpStore with GNU General Public License v2.0 | 5 votes |
private void addPermissionWidgets() { PermissionsComparator comparator = new PermissionsComparator(activity); Set<String> newPermissions = new HashSet<>(); if (!comparator.isSame(app)) { newPermissions.addAll(comparator.getNewPermissions()); } Map<String, PermissionGroupInfo> groups = new HashMap<>(); Map<String, Set<PermissionInfo>> permissions = new HashMap<>(); for (String permissionName: app.getPermissions()) { PermissionInfo permissionInfo = getPermissionInfo(permissionName); if (null == permissionInfo) { continue; } PermissionGroupInfo permissionGroupInfo = getPermissionGroupInfo(permissionInfo); groups.put(permissionGroupInfo.name, permissionGroupInfo); if (!permissions.containsKey(permissionGroupInfo.name)) { permissions.put(permissionGroupInfo.name, new HashSet<PermissionInfo>()); } permissions.get(permissionGroupInfo.name).add(permissionInfo); } LinearLayout container = activity.findViewById(R.id.permissions_container_widgets); container.removeAllViews(); List<String> permissionGroupLabels = new ArrayList<>(groups.keySet()); Collections.sort(permissionGroupLabels); for (String permissionGroupLabel: permissionGroupLabels) { PermissionGroupInfo groupInfo = groups.get(permissionGroupLabel); PermissionGroup widget = new PermissionGroup(activity); widget.setPermissionGroupInfo(groupInfo); widget.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); widget.setNewPermissions(newPermissions); widget.setPermissions(permissions.get(groupInfo.name)); container.addView(widget); } activity.findViewById(R.id.permissions_none).setVisibility(permissionGroupLabels.isEmpty() ? View.VISIBLE : View.GONE); }
Example #18
Source File: VPackageManagerService.java From container with GNU General Public License v3.0 | 5 votes |
@Override public PermissionInfo getPermissionInfo(String name, int flags) { synchronized (mPackages) { PackageParser.Permission p = mPermissions.get(name); if (p != null) { return new PermissionInfo(p.info); } } return null; }
Example #19
Source File: PackageManagerWorker.java From GPT with Apache License 2.0 | 5 votes |
/** * addPermission * * @param info PermissionInfo * @return true or false */ public boolean addPermission(PermissionInfo info) { String packageName = info.packageName; if (isPlugin(packageName)) { // 给插件加,相当于给 host app 加 info.packageName = mPackageName; } return mTarget.addPermission(info); }
Example #20
Source File: PermissionsHelperTest.java From android-testdpc with Apache License 2.0 | 5 votes |
@Test public void ensureRequiredPermissions_ifAtLeastOnePermissionNotGranted_shouldReturnFalse() { addPermissionInfo(NORMAL_PERMISSION, PermissionInfo.PROTECTION_NORMAL); addPermissionInfo(DANGEROUS_PERMISSION, PermissionInfo.PROTECTION_DANGEROUS); shadowOf(mDevicePolicyManager).setProfileOwner(NON_TESTDPC_ADMIN); boolean requiredPermissionsGranted = PermissionsHelper .ensureRequiredPermissions(new String[]{NORMAL_PERMISSION, DANGEROUS_PERMISSION}, NON_TESTDPC_ADMIN, mContext); assertFalse(requiredPermissionsGranted); }
Example #21
Source File: PermissionManagerService.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private boolean addDynamicPermission( PermissionInfo info, int callingUid, PermissionCallback callback) { if (mPackageManagerInt.getInstantAppPackageName(callingUid) != null) { throw new SecurityException("Instant apps can't add permissions"); } if (info.labelRes == 0 && info.nonLocalizedLabel == null) { throw new SecurityException("Label must be specified in permission"); } final BasePermission tree = mSettings.enforcePermissionTree(info.name, callingUid); final boolean added; final boolean changed; synchronized (mLock) { BasePermission bp = mSettings.getPermissionLocked(info.name); added = bp == null; int fixedLevel = PermissionInfo.fixProtectionLevel(info.protectionLevel); if (added) { enforcePermissionCapLocked(info, tree); bp = new BasePermission(info.name, tree.getSourcePackageName(), BasePermission.TYPE_DYNAMIC); } else if (!bp.isDynamic()) { throw new SecurityException("Not allowed to modify non-dynamic permission " + info.name); } changed = bp.addToTree(fixedLevel, info, tree); if (added) { mSettings.putPermissionLocked(info.name, bp); } } if (changed && callback != null) { callback.onPermissionChanged(); } return added; }
Example #22
Source File: PermissionsActivity.java From aptoide-client with GNU General Public License v2.0 | 5 votes |
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 #23
Source File: BasePermission.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
public BasePermission(String _name, String _sourcePackageName, @PermissionType int _type) { name = _name; sourcePackageName = _sourcePackageName; type = _type; // Default to most conservative protection level. protectionLevel = PermissionInfo.PROTECTION_SIGNATURE; }
Example #24
Source File: PermissionManager.java From QuickDevFramework with Apache License 2.0 | 5 votes |
/** * 获取权限名称 * <p>在需要显示某个具体权限的名称时使用</p> */ public static String getPermissionName(Activity context, String permission) { PackageManager packageManager = context.getPackageManager(); try { PermissionInfo permissionInfo = packageManager.getPermissionInfo(permission, 0); return permissionInfo.loadLabel(packageManager).toString(); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } return permission; }
Example #25
Source File: ApplicationPackageManager.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
@Override public boolean addPermission(PermissionInfo info) { try { return mPM.addPermission(info); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } }
Example #26
Source File: ApplicationPackageManager.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
@Override public PermissionInfo getPermissionInfo(String name, int flags) throws NameNotFoundException { try { PermissionInfo pi = mPM.getPermissionInfo(name, flags); if (pi != null) { return pi; } } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } throw new NameNotFoundException(name); }
Example #27
Source File: ApplicationPackageManager.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public boolean addPermission(PermissionInfo info) { try { return mPM.addPermission(info); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } }
Example #28
Source File: GmailContract.java From retrowatch with Apache License 2.0 | 5 votes |
/** * Check if the installed Gmail app supports querying for label information. * * @param c an application Context * @return true if it's safe to make label API queries */ public static boolean canReadLabels(Context c) { boolean supported = false; try { final PackageInfo info = c.getPackageManager().getPackageInfo(PACKAGE, PackageManager.GET_PROVIDERS | PackageManager.GET_PERMISSIONS); boolean allowRead = false; if (info.permissions != null) { for (int i = 0, len = info.permissions.length; i < len; i++) { final PermissionInfo perm = info.permissions[i]; if (PERMISSION.equals(perm.name) && perm.protectionLevel < PermissionInfo.PROTECTION_SIGNATURE) { allowRead = true; break; } } } if (allowRead && info.providers != null) { for (int i = 0, len = info.providers.length; i < len; i++) { final ProviderInfo provider = info.providers[i]; if (AUTHORITY.equals(provider.authority) && TextUtils.equals(PERMISSION, provider.readPermission)) { supported = true; } } } } catch (NameNotFoundException e) { // Gmail app not found } return supported; }
Example #29
Source File: ApplicationPackageManager.java From AndroidComponentPlugin with Apache License 2.0 | 5 votes |
@Override public boolean addPermission(PermissionInfo info) { try { return mPM.addPermission(info); } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } }
Example #30
Source File: ApplicationPackageManager.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
@Override public PermissionInfo getPermissionInfo(String name, int flags) throws NameNotFoundException { try { PermissionInfo pi = mPM.getPermissionInfo(name, mContext.getOpPackageName(), flags); if (pi != null) { return pi; } } catch (RemoteException e) { throw e.rethrowFromSystemServer(); } throw new NameNotFoundException(name); }