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

Commit e51005da authored by Sudheer Shanka's avatar Sudheer Shanka
Browse files

Look for visible vols for a user under /mnt/user/<userId>/package/.

Currently, we pass down visisble volumes for a user to zygote so that
it can set up appropriate bind mounts after forking. This method has
atleast a couple of race conditions, so instead make zygote just
look under /mnt/user/<userId>/package for volumes that need to be
handled for a particular user.

Bug: 126069494
Test: manual
Test: atest cts/hostsidetests/appsecurity/src/android/appsecurity/cts/ExternalStorageHostTest.java
Test: atest cts/tests/app/src/android/app/cts/DownloadManagerTest.java
Test: atest cts/tests/tests/provider/src/android/provider/cts/MediaStore*
Change-Id: Iab47eb34d38a25dfda4a686db9b7203ad4885a93
parent da1cd642
Loading
Loading
Loading
Loading
+2 −5
Original line number Diff line number Diff line
@@ -505,7 +505,6 @@ public class Process {
     * @param invokeWith null-ok the command to invoke with.
     * @param packageName null-ok the name of the package this process belongs to.
     * @param packagesForUid null-ok all the packages with the same uid as this process.
     * @param visibleVols null-ok storage volumes that can be accessed by this process.
     * @param zygoteArgs Additional arguments to supply to the zygote process.
     * 
     * @return An object that describes the result of the attempt to start the process.
@@ -525,13 +524,12 @@ public class Process {
                                  @Nullable String invokeWith,
                                  @Nullable String packageName,
                                  @Nullable String[] packagesForUid,
                                  @Nullable String[] visibleVols,
                                  @Nullable String sandboxId,
                                  @Nullable String[] zygoteArgs) {
        return ZYGOTE_PROCESS.start(processClass, niceName, uid, gid, gids,
                    runtimeFlags, mountExternal, targetSdkVersion, seInfo,
                    abi, instructionSet, appDataDir, invokeWith, packageName,
                    packagesForUid, visibleVols, sandboxId, /*useBlastulaPool=*/ true, zygoteArgs);
                    packagesForUid, sandboxId, /*useBlastulaPool=*/ true, zygoteArgs);
    }

    /** @hide */
@@ -547,13 +545,12 @@ public class Process {
                                  @Nullable String invokeWith,
                                  @Nullable String packageName,
                                  @Nullable String[] packagesForUid,
                                  @Nullable String[] visibleVols,
                                  @Nullable String sandboxId,
                                  @Nullable String[] zygoteArgs) {
        return WebViewZygote.getProcess().start(processClass, niceName, uid, gid, gids,
                    runtimeFlags, mountExternal, targetSdkVersion, seInfo,
                    abi, instructionSet, appDataDir, invokeWith, packageName,
                    packagesForUid, visibleVols, sandboxId, /*useBlastulaPool=*/ false, zygoteArgs);
                    packagesForUid, sandboxId, /*useBlastulaPool=*/ false, zygoteArgs);
    }

    /**
+2 −19
Original line number Diff line number Diff line
@@ -305,7 +305,6 @@ public class ZygoteProcess {
     * @param invokeWith null-ok the command to invoke with.
     * @param packageName null-ok the name of the package this process belongs to.
     * @param packagesForUid null-ok all the packages with the same uid as this process.
     * @param visibleVols null-ok storage volumes that can be accessed by this process.
     * @param zygoteArgs Additional arguments to supply to the zygote process.
     *
     * @return An object that describes the result of the attempt to start the process.
@@ -323,7 +322,6 @@ public class ZygoteProcess {
                                                  @Nullable String invokeWith,
                                                  @Nullable String packageName,
                                                  @Nullable String[] packagesForUid,
                                                  @Nullable String[] visibleVols,
                                                  @Nullable String sandboxId,
                                                  boolean useBlastulaPool,
                                                  @Nullable String[] zygoteArgs) {
@@ -339,7 +337,7 @@ public class ZygoteProcess {
            return startViaZygote(processClass, niceName, uid, gid, gids,
                    runtimeFlags, mountExternal, targetSdkVersion, seInfo,
                    abi, instructionSet, appDataDir, invokeWith, /*startChildZygote=*/false,
                    packageName, packagesForUid, visibleVols, sandboxId,
                    packageName, packagesForUid, sandboxId,
                    useBlastulaPool, zygoteArgs);
        } catch (ZygoteStartFailedEx ex) {
            Log.e(LOG_TAG,
@@ -531,7 +529,6 @@ public class ZygoteProcess {
     * that has its state cloned from this zygote process.
     * @param packageName null-ok the name of the package this process belongs to.
     * @param packagesForUid null-ok all the packages with the same uid as this process.
     * @param visibleVols null-ok storage volumes that can be accessed by this process.
     * @param extraArgs Additional arguments to supply to the zygote process.
     * @return An object that describes the result of the attempt to start the process.
     * @throws ZygoteStartFailedEx if process start failed for any reason
@@ -550,7 +547,6 @@ public class ZygoteProcess {
                                                      boolean startChildZygote,
                                                      @Nullable String packageName,
                                                      @Nullable String[] packagesForUid,
                                                      @Nullable String[] visibleVols,
                                                      @Nullable String sandboxId,
                                                      boolean useBlastulaPool,
                                                      @Nullable String[] extraArgs)
@@ -638,19 +634,6 @@ public class ZygoteProcess {
            argsForZygote.add(sb.toString());
        }

        if (visibleVols != null && visibleVols.length > 0) {
            final StringBuilder sb = new StringBuilder();
            sb.append("--visible-vols=");

            for (int i = 0; i < visibleVols.length; ++i) {
                if (i != 0) {
                    sb.append(',');
                }
                sb.append(visibleVols[i]);
            }
            argsForZygote.add(sb.toString());
        }

        if (sandboxId != null) {
            argsForZygote.add("--sandbox-id=" + sandboxId);
        }
@@ -1061,7 +1044,7 @@ public class ZygoteProcess {
                    gids, runtimeFlags, 0 /* mountExternal */, 0 /* targetSdkVersion */, seInfo,
                    abi, instructionSet, null /* appDataDir */, null /* invokeWith */,
                    true /* startChildZygote */, null /* packageName */,
                    null /* packagesForUid */, null /* visibleVolumes */, null /* sandboxId */,
                    null /* packagesForUid */, null /* sandboxId */,
                    false /* useBlastulaPool */, extraArgs);
        } catch (ZygoteStartFailedEx ex) {
            throw new RuntimeException("Starting child-zygote through Zygote failed", ex);
+0 −5
Original line number Diff line number Diff line
@@ -108,11 +108,6 @@ public abstract class StorageManagerInternal {
    public abstract void destroySandboxForApp(@NonNull String packageName,
            @Nullable String sharedUserId, int userId);

    /**
     * @return Labels of storage volumes that are visible to the given userId.
     */
    public abstract String[] getVisibleVolumesForUser(int userId);

    /**
     * A listener for reset events in the StorageManagerService.
     */
+7 −7
Original line number Diff line number Diff line
@@ -236,14 +236,14 @@ public final class Zygote {
    public static int forkAndSpecialize(int uid, int gid, int[] gids, int runtimeFlags,
            int[][] rlimits, int mountExternal, String seInfo, String niceName, int[] fdsToClose,
            int[] fdsToIgnore, boolean startChildZygote, String instructionSet, String appDataDir,
            String packageName, String[] packagesForUID, String[] visibleVolIDs, String sandboxId) {
            String packageName, String[] packagesForUID, String sandboxId) {
        ZygoteHooks.preFork();
        // Resets nice priority for zygote process.
        resetNicePriority();
        int pid = nativeForkAndSpecialize(
                uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName, fdsToClose,
                fdsToIgnore, startChildZygote, instructionSet, appDataDir, packageName,
                packagesForUID, visibleVolIDs, sandboxId);
                packagesForUID, sandboxId);
        // Enable tracing as soon as possible for the child process.
        if (pid == 0) {
            Trace.setTracingEnabled(true, runtimeFlags);
@@ -258,7 +258,7 @@ public final class Zygote {
    private static native int nativeForkAndSpecialize(int uid, int gid, int[] gids,
            int runtimeFlags, int[][] rlimits, int mountExternal, String seInfo, String niceName,
            int[] fdsToClose, int[] fdsToIgnore, boolean startChildZygote, String instructionSet,
            String appDataDir, String packageName, String[] packagesForUID, String[] visibleVolIDs,
            String appDataDir, String packageName, String[] packagesForUID,
            String sandboxId);

    /**
@@ -285,11 +285,11 @@ public final class Zygote {
    public static void specializeBlastula(int uid, int gid, int[] gids, int runtimeFlags,
            int[][] rlimits, int mountExternal, String seInfo, String niceName,
            boolean startChildZygote, String instructionSet, String appDataDir, String packageName,
            String[] packagesForUID, String[] visibleVolIDs, String sandboxId) {
            String[] packagesForUID, String sandboxId) {

        nativeSpecializeBlastula(uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo,
                                 niceName, startChildZygote, instructionSet, appDataDir,
                                 packageName, packagesForUID, visibleVolIDs, sandboxId);
                                 packageName, packagesForUID, sandboxId);

        // Enable tracing as soon as possible for the child process.
        Trace.setTracingEnabled(true, runtimeFlags);
@@ -309,7 +309,7 @@ public final class Zygote {
    private static native void nativeSpecializeBlastula(int uid, int gid, int[] gids,
            int runtimeFlags, int[][] rlimits, int mountExternal, String seInfo, String niceName,
            boolean startChildZygote, String instructionSet, String appDataDir, String packageName,
            String[] packagesForUID, String[] visibleVolIDs, String sandboxId);
            String[] packagesForUID, String sandboxId);

    /**
     * Called to do any initialization before starting an application.
@@ -600,7 +600,7 @@ public final class Zygote {
                           args.mRuntimeFlags, rlimits, args.mMountExternal,
                           args.mSeInfo, args.mNiceName, args.mStartChildZygote,
                           args.mInstructionSet, args.mAppDataDir, args.mPackageName,
                           args.mPackagesForUid, args.mVisibleVolIds, args.mSandboxId);
                           args.mPackagesForUid, args.mSandboxId);

        if (args.mNiceName != null) {
            Process.setArgV0(args.mNiceName);
+0 −5
Original line number Diff line number Diff line
@@ -116,9 +116,6 @@ class ZygoteArguments {
    /** from --packages-for-uid */
    String[] mPackagesForUid;

    /** from --visible-vols */
    String[] mVisibleVolIds;

    /** from --sandbox-id */
    String mSandboxId;

@@ -395,8 +392,6 @@ class ZygoteArguments {
                mPackageName = arg.substring(arg.indexOf('=') + 1);
            } else if (arg.startsWith("--packages-for-uid=")) {
                mPackagesForUid = arg.substring(arg.indexOf('=') + 1).split(",");
            } else if (arg.startsWith("--visible-vols=")) {
                mVisibleVolIds = arg.substring(arg.indexOf('=') + 1).split(",");
            } else if (arg.startsWith("--sandbox-id=")) {
                if (mSandboxId != null) {
                    throw new IllegalArgumentException("Duplicate arg specified");
Loading