Java Code Examples for android.content.pm.PackageManager#FLAG_PERMISSION_REVIEW_REQUIRED

The following examples show how to use android.content.pm.PackageManager#FLAG_PERMISSION_REVIEW_REQUIRED . 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: PermissionsState.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private boolean hasPermissionRequiringReview(int userId) {
    final int permissionCount = mPermissions.size();
    for (int i = 0; i < permissionCount; i++) {
        final PermissionData permission = mPermissions.valueAt(i);
        if ((permission.getFlags(userId)
                & PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED) != 0) {
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: PermissionManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void grantRequestedRuntimePermissionsForUser(PackageParser.Package pkg, int userId,
        String[] grantedPermissions, int callingUid, PermissionCallback callback) {
    PackageSetting ps = (PackageSetting) pkg.mExtras;
    if (ps == null) {
        return;
    }

    PermissionsState permissionsState = ps.getPermissionsState();

    final int immutableFlags = PackageManager.FLAG_PERMISSION_SYSTEM_FIXED
            | PackageManager.FLAG_PERMISSION_POLICY_FIXED;

    final boolean supportsRuntimePermissions = pkg.applicationInfo.targetSdkVersion
            >= Build.VERSION_CODES.M;

    final boolean instantApp = mPackageManagerInt.isInstantApp(pkg.packageName, userId);

    for (String permission : pkg.requestedPermissions) {
        final BasePermission bp;
        synchronized (mLock) {
            bp = mSettings.getPermissionLocked(permission);
        }
        if (bp != null && (bp.isRuntime() || bp.isDevelopment())
                && (!instantApp || bp.isInstant())
                && (supportsRuntimePermissions || !bp.isRuntimeOnly())
                && (grantedPermissions == null
                       || ArrayUtils.contains(grantedPermissions, permission))) {
            final int flags = permissionsState.getPermissionFlags(permission, userId);
            if (supportsRuntimePermissions) {
                // Installer cannot change immutable permissions.
                if ((flags & immutableFlags) == 0) {
                    grantRuntimePermission(permission, pkg.packageName, false, callingUid,
                            userId, callback);
                }
            } else if (mSettings.mPermissionReviewRequired) {
                // In permission review mode we clear the review flag when we
                // are asked to install the app with all permissions granted.
                if ((flags & PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED) != 0) {
                    updatePermissionFlags(permission, pkg.packageName,
                            PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED, 0, callingUid,
                            userId, callback);
                }
            }
        }
    }
}
 
Example 3
Source File: PermissionManagerService.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
private void updatePermissionFlags(String permName, String packageName, int flagMask,
        int flagValues, int callingUid, int userId, PermissionCallback callback) {
    if (!mUserManagerInt.exists(userId)) {
        return;
    }

    enforceGrantRevokeRuntimePermissionPermissions("updatePermissionFlags");

    enforceCrossUserPermission(callingUid, userId,
            true,  // requireFullPermission
            true,  // checkShell
            false, // requirePermissionWhenSameUser
            "updatePermissionFlags");

    // Only the system can change these flags and nothing else.
    if (callingUid != Process.SYSTEM_UID) {
        flagMask &= ~PackageManager.FLAG_PERMISSION_SYSTEM_FIXED;
        flagValues &= ~PackageManager.FLAG_PERMISSION_SYSTEM_FIXED;
        flagMask &= ~PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT;
        flagValues &= ~PackageManager.FLAG_PERMISSION_GRANTED_BY_DEFAULT;
        flagValues &= ~PackageManager.FLAG_PERMISSION_REVIEW_REQUIRED;
    }

    final PackageParser.Package pkg = mPackageManagerInt.getPackage(packageName);
    if (pkg == null || pkg.mExtras == null) {
        throw new IllegalArgumentException("Unknown package: " + packageName);
    }
    if (mPackageManagerInt.filterAppAccess(pkg, callingUid, userId)) {
        throw new IllegalArgumentException("Unknown package: " + packageName);
    }

    final BasePermission bp;
    synchronized (mLock) {
        bp = mSettings.getPermissionLocked(permName);
    }
    if (bp == null) {
        throw new IllegalArgumentException("Unknown permission: " + permName);
    }

    final PackageSetting ps = (PackageSetting) pkg.mExtras;
    final PermissionsState permissionsState = ps.getPermissionsState();
    final boolean hadState =
            permissionsState.getRuntimePermissionState(permName, userId) != null;
    final boolean permissionUpdated =
            permissionsState.updatePermissionFlags(bp, userId, flagMask, flagValues);
    if (permissionUpdated && callback != null) {
        // Install and runtime permissions are stored in different places,
        // so figure out what permission changed and persist the change.
        if (permissionsState.getInstallPermissionState(permName) != null) {
            callback.onInstallPermissionUpdated();
        } else if (permissionsState.getRuntimePermissionState(permName, userId) != null
                || hadState) {
            callback.onPermissionUpdated(new int[] { userId }, false);
        }
    }
}