Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e04014a3 authored by Svetoslav Ganov's avatar Svetoslav Ganov Committed by Android (Google) Code Review
Browse files

Merge "Make storage a restricted permission - permission controller" into qt-dev

parents e6d3e0c3 9c8c9fac
Loading
Loading
Loading
Loading
+27 −2
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ class RuntimePermissionsUpgradeController {
    private static final String LOG_TAG = RuntimePermissionsUpgradeController.class.getSimpleName();

    // The latest version of the runtime permissions database
    private static final int LATEST_VERSION = 2;
    private static final int LATEST_VERSION = 3;

    private RuntimePermissionsUpgradeController() {
        /* do nothing - hide constructor */
@@ -104,7 +104,7 @@ class RuntimePermissionsUpgradeController {
            currentVersion = 1;
        }

        if (currentVersion <= 1) {
        if (currentVersion == 1) {
            Log.i(LOG_TAG, "Expanding location permissions");

            for (int i = 0; i < appCount; i++) {
@@ -138,6 +138,31 @@ class RuntimePermissionsUpgradeController {
            currentVersion = 2;
        }

        if (currentVersion == 2) {
            Log.i(LOG_TAG, "Grandfathering Storage permissions");

            final List<String> storagePermissions = Utils.getPlatformPermissionNamesOfGroup(
                    Manifest.permission_group.STORAGE);

            for (int i = 0; i < appCount; i++) {
                final PackageInfo app = apps.get(i);
                if (app.requestedPermissions == null) {
                    continue;
                }

                // We don't want to allow modification of storage post install, so put it
                // on the internal system whitelist to prevent the installer changing it.
                for (String requestedPermission : app.requestedPermissions) {
                    if (storagePermissions.contains(requestedPermission)) {
                        context.getPackageManager().addWhitelistedRestrictedPermission(
                                app.packageName, requestedPermission,
                                PackageManager.FLAG_PERMISSION_WHITELIST_UPGRADE);
                    }
                }
            }
            currentVersion = 3;
        }

        // XXX: Add new upgrade steps above this point.

        return currentVersion;