Java Code Examples for android.content.pm.PackageManager.GET_PERMISSIONS

The following are Jave code examples for showing how to use GET_PERMISSIONS of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: condom   File: CondomPackageManager.java   View Source Code Vote up 5 votes
@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;
}