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

Commit 9c8c9fac authored by Svet Ganov's avatar Svet Ganov
Browse files

Make storage a restricted permission - permission controller

This change makes storage a soft restricted permission. When the
permission is whitelisted for an app then hodlding it allows the
app to access the full SD card as on a P device. If howerver, the
permisison is not whitelisted for an app then holding it allows
accessing the visual/aural collections in media store while the
app would run in its own isolated storage sandbox.

This change also connects the opt in/out application attribute
to how external storage is mounted remocing temporary code. The
attribute was renamed to convey that opting in legacy mode is
not somethung that is desirable or would be available in the long
run.

White at this also fix the default state of app ops for restricted
permissions to avoid allowing ops for non requested restricted
permissions to every UID as component access could skip permission
checks by cannot skip app op checks.

bug:130327036

atest CtsPermission2TestCases
atest CtsPermissionTestCases
atest CtsAppOpsTestCases
atest atest CtsAppSecurityHostTestCases:android.appsecurity.cts.ExternalStorageHostTest
atest CtsAppSecurityHostTestCases:android.appsecurity.cts.PermissionsHostTest

Change-Id: I658191699f47236f958437cf65c2c557ab02fc9d
parent 9d73bc5a
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;