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

Commit 0b6da536 authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Create a new MOUNT_EXTERNAL_LEGACY storage mode.

Apps that are already installed on the device before isolated_storage
feature is enabled will be granted MOUNT_EXTERNAL_LEGACY mode. In this
mode, /mnt/runtime/write will be mounted at /storage giving them same
level of access as in P.

A new mount directory /mnt/runtime/full is also created which will be
used for mounting at /storage for apps started with MOUNT_EXTERNAL_FULL
mode. This will allow apps with WRITE_MEDIA_STORAGE permission to
read/write anywhere on the secondary devices without needing to bypass
sdcardfs.

Bug: 121277410
Test: manual
Test: atest android.appsecurity.cts.ExternalStorageHostTest
Change-Id: I4ec73276d7c586ae4afc482580d1eb8ee03d5be1
parent 2aa0d126
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -402,6 +402,8 @@ public class ZygoteProcess {
            argsForZygote.add("--mount-external-full");
        } else if (mountExternal == Zygote.MOUNT_EXTERNAL_INSTALLER) {
            argsForZygote.add("--mount-external-installer");
        } else if (mountExternal == Zygote.MOUNT_EXTERNAL_LEGACY) {
            argsForZygote.add("--mount-external-legacy");
        }

        argsForZygote.add("--target-sdk-version=" + targetSdkVersion);
+5 −0
Original line number Diff line number Diff line
@@ -81,6 +81,11 @@ public final class Zygote {
    public static final int MOUNT_EXTERNAL_READ = IVold.REMOUNT_MODE_READ;
    /** Read-write external storage should be mounted. */
    public static final int MOUNT_EXTERNAL_WRITE = IVold.REMOUNT_MODE_WRITE;
    /**
     * Mount mode for apps that are already installed on the device before the isolated_storage
     * feature is enabled.
     */
    public static final int MOUNT_EXTERNAL_LEGACY = IVold.REMOUNT_MODE_LEGACY;
    /**
     * Mount mode for package installers which should give them access to
     * all obb dirs in addition to their package sandboxes
+3 −1
Original line number Diff line number Diff line
@@ -690,6 +690,8 @@ class ZygoteConnection {
                    mountExternal = Zygote.MOUNT_EXTERNAL_FULL;
                } else if (arg.equals("--mount-external-installer")) {
                    mountExternal = Zygote.MOUNT_EXTERNAL_INSTALLER;
                } else if (arg.equals("--mount-external-legacy")) {
                    mountExternal = Zygote.MOUNT_EXTERNAL_LEGACY;
                } else if (arg.equals("--query-abi-list")) {
                    abiListQuery = true;
                } else if (arg.equals("--get-pid")) {
+6 −4
Original line number Diff line number Diff line
@@ -109,8 +109,9 @@ enum MountExternalKind {
  MOUNT_EXTERNAL_DEFAULT = 1,
  MOUNT_EXTERNAL_READ = 2,
  MOUNT_EXTERNAL_WRITE = 3,
  MOUNT_EXTERNAL_INSTALLER = 4,
  MOUNT_EXTERNAL_FULL = 5,
  MOUNT_EXTERNAL_LEGACY = 4,
  MOUNT_EXTERNAL_INSTALLER = 5,
  MOUNT_EXTERNAL_FULL = 6,
};

// Must match values in com.android.internal.os.Zygote.
@@ -548,8 +549,9 @@ static bool MountEmulatedStorage(uid_t uid, jint mount_mode,
    }

    if (GetBoolProperty(kIsolatedStorageSnapshot, GetBoolProperty(kIsolatedStorage, false))) {
        if (mount_mode == MOUNT_EXTERNAL_FULL) {
            storageSource = "/mnt/runtime/write";
        if (mount_mode == MOUNT_EXTERNAL_FULL || mount_mode == MOUNT_EXTERNAL_LEGACY) {
            storageSource = (mount_mode == MOUNT_EXTERNAL_FULL)
                    ? "/mnt/runtime/full" : "/mnt/runtime/write";
            if (TEMP_FAILURE_RETRY(mount(storageSource.string(), "/storage",
                    NULL, MS_BIND | MS_REC | MS_SLAVE, NULL)) == -1) {
                *error_msg = CREATE_ERROR("Failed to mount %s to /storage: %s",
+3 −3
Original line number Diff line number Diff line
@@ -3288,7 +3288,8 @@ class StorageManagerService extends IStorageManager.Stub
        }

        final int mountMode = mAmInternal.getStorageMountMode(pid, uid);
        if (mountMode == Zygote.MOUNT_EXTERNAL_FULL) {
        if (mountMode == Zygote.MOUNT_EXTERNAL_FULL
                || mountMode == Zygote.MOUNT_EXTERNAL_LEGACY) {
            return path;
        }

@@ -3663,8 +3664,7 @@ class StorageManagerService extends IStorageManager.Stub
                return Zygote.MOUNT_EXTERNAL_FULL;
            } else if (mIAppOpsService.checkOperation(OP_LEGACY_STORAGE, uid,
                    packageName) == MODE_ALLOWED) {
                // TODO: define a specific "legacy" mount mode
                return Zygote.MOUNT_EXTERNAL_FULL;
                return Zygote.MOUNT_EXTERNAL_LEGACY;
            } else if (mIPackageManager.checkUidPermission(INSTALL_PACKAGES, uid)
                    == PERMISSION_GRANTED || mIAppOpsService.checkOperation(
                            OP_REQUEST_INSTALL_PACKAGES, uid, packageName) == MODE_ALLOWED) {
Loading