Java Code Examples for android.content.pm.PackageInfo#REQUESTED_PERMISSION_GRANTED

The following examples show how to use android.content.pm.PackageInfo#REQUESTED_PERMISSION_GRANTED . 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: AppSecurityPermissions.java    From fdroidclient with GNU General Public License v3.0 6 votes vote down vote up
@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 2
Source File: AppSecurityPermissions.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private boolean isDisplayablePermission(PermissionInfo pInfo, int newReqFlags,
        int existingReqFlags) {
    final int base = pInfo.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE;
    final boolean isNormal = (base == PermissionInfo.PROTECTION_NORMAL);

    // We do not show normal permissions in the UI.
    if (isNormal) {
        return false;
    }

    final boolean isDangerous = (base == PermissionInfo.PROTECTION_DANGEROUS)
            || ((pInfo.protectionLevel&PermissionInfo.PROTECTION_FLAG_PRE23) != 0);
    final boolean isRequired =
            ((newReqFlags&PackageInfo.REQUESTED_PERMISSION_REQUIRED) != 0);
    final boolean isDevelopment =
            ((pInfo.protectionLevel&PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0);
    final boolean wasGranted =
            ((existingReqFlags&PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0);
    final boolean isGranted =
            ((newReqFlags&PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0);

    // Dangerous and normal permissions are always shown to the user if the permission
    // is required, or it was previously granted
    if (isDangerous && (isRequired || wasGranted || isGranted)) {
        return true;
    }

    // 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.
    if (isDevelopment && wasGranted) {
        if (localLOGV) Log.i(TAG, "Special perm " + pInfo.name
                + ": protlevel=0x" + Integer.toHexString(pInfo.protectionLevel));
        return true;
    }
    return false;
}
 
Example 3
Source File: DataProvider.java    From android-permission-checker-app with Apache License 2.0 5 votes vote down vote up
private AppDetails fetchDetail(String packageName) {
  PackageManager packageManager = context.getPackageManager();
  AppDetails appDetails = new AppDetails();
  try {
    PackageInfo packageInfo = packageManager.getPackageInfo(packageName,
        PackageManager.GET_META_DATA | PackageManager.GET_PERMISSIONS);
    appDetails.name = packageInfo.applicationInfo.loadLabel(packageManager).toString();
    appDetails.icon = packageInfo.applicationInfo.loadIcon(packageManager);
    appDetails.packageName = packageName;
    appDetails.publicSrcDir = packageInfo.applicationInfo.publicSourceDir;
    if (packageInfo.requestedPermissions != null) {
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        for (int index = 0; index < packageInfo.requestedPermissions.length; index++) {
          if ((packageInfo.requestedPermissionsFlags[index]
              & PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0) {
            appDetails.grantedPermissionList.add(packageInfo.requestedPermissions[index]);
          } else {
            appDetails.deniedPermissionList.add(packageInfo.requestedPermissions[index]);
          }
        }
      } else {
        appDetails.grantedPermissionList =
            new ArrayList<>(Arrays.asList(packageInfo.requestedPermissions));
      }
    }
  } catch (PackageManager.NameNotFoundException e) {
    e.printStackTrace();
  }
  return appDetails;
}
 
Example 4
Source File: CondomPackageManager.java    From condom with Apache License 2.0 5 votes vote down vote up
@Override public PackageInfo getPackageInfo(final String pkg, final int flags) throws NameNotFoundException {
	final PackageInfo info = mCondom.proceed(OutboundType.GET_PACKAGE_INFO, pkg, null, new CondomCore.WrappedValueProcedureThrows<PackageInfo, NameNotFoundException>() {
		@Override public PackageInfo proceed() throws NameNotFoundException {
			return CondomPackageManager.super.getPackageInfo(pkg, flags);
		}
	});
	if (info == null) throw new NameNotFoundException(pkg);
	if ((flags & PackageManager.GET_PERMISSIONS) != 0 && ! mCondom.getSpoofPermissions().isEmpty() && mCondom.getPackageName().equals(pkg)) {
		final List<String> requested_permissions = info.requestedPermissions == null ? new ArrayList<String>()
				: new ArrayList<>(Arrays.asList(info.requestedPermissions));
		final List<String> missing_permissions = new ArrayList<>(mCondom.getSpoofPermissions());
		missing_permissions.removeAll(requested_permissions);
		if (! missing_permissions.isEmpty()) {
			requested_permissions.addAll(missing_permissions);
			info.requestedPermissions = requested_permissions.toArray(new String[requested_permissions.size()]);
		}    // Even if all permissions to spoof are already requested, the permission granted state still requires amending.

		if (SDK_INT >= JELLY_BEAN) {
			final int[] req_permissions_flags = info.requestedPermissionsFlags == null ? new int[requested_permissions.size()]
					: Arrays.copyOf(info.requestedPermissionsFlags, requested_permissions.size());
			for (int i = 0; i < info.requestedPermissions.length; i++)
				if (mCondom.shouldSpoofPermission(info.requestedPermissions[i]))
					req_permissions_flags[i] = PackageInfo.REQUESTED_PERMISSION_GRANTED;
			info.requestedPermissionsFlags = req_permissions_flags;
		}
	}
	return info;
}
 
Example 5
Source File: PermissiveTestRule.java    From permissive with Apache License 2.0 5 votes vote down vote up
private void grantAllPermissions() {
  Context context = InstrumentationRegistry.getTargetContext();
  try {
    PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), PackageManager.GET_PERMISSIONS);
    UiAutomation uiAutomation = InstrumentationRegistry.getInstrumentation().getUiAutomation();
    for (int i = 0; i < packageInfo.requestedPermissions.length; ++i) {
      if ((packageInfo.requestedPermissionsFlags[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) == 0) {
        grantReal(uiAutomation, packageInfo.requestedPermissions[i]);
      }
    }
  } catch (PackageManager.NameNotFoundException e) {
    Log.w(TAG, "packageInfo not found for: " + context.getPackageName());
  }
}
 
Example 6
Source File: AppSecurityPermissions.java    From fdroidclient with GNU General Public License v3.0 5 votes vote down vote up
/**
 * A permission is a "new permission" if the app is already installed and
 * doesn't currently hold this permission. On older devices that don't support
 * this concept, permissions are never "new permissions".
 */
@TargetApi(16)
private static boolean isNewPermission(PackageInfo installedPkgInfo, int existingFlags) {
    if (installedPkgInfo == null || Build.VERSION.SDK_INT < 16) {
        return false;
    }

    return (existingFlags & PackageInfo.REQUESTED_PERMISSION_GRANTED) == 0;
}