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

Commit 3bc4ab48 authored by Sudheer Shanka's avatar Sudheer Shanka Committed by Android (Google) Code Review
Browse files

Merge "Bind mount pkg specific dirs in the zygote child namespaces."

parents 627f2714 3f0645ba
Loading
Loading
Loading
Loading
+10 −2
Original line number Original line Diff line number Diff line
@@ -483,6 +483,8 @@ public class Process {
     * @param appDataDir null-ok the data directory of the app.
     * @param appDataDir null-ok the data directory of the app.
     * @param invokeWith null-ok the command to invoke with.
     * @param invokeWith null-ok the command to invoke with.
     * @param packageName null-ok the name of the package this process belongs to.
     * @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.
     * @param zygoteArgs Additional arguments to supply to the zygote process.
     * 
     * 
     * @return An object that describes the result of the attempt to start the process.
     * @return An object that describes the result of the attempt to start the process.
@@ -501,10 +503,13 @@ public class Process {
                                  @Nullable String appDataDir,
                                  @Nullable String appDataDir,
                                  @Nullable String invokeWith,
                                  @Nullable String invokeWith,
                                  @Nullable String packageName,
                                  @Nullable String packageName,
                                  @Nullable String[] packagesForUid,
                                  @Nullable String[] visibleVols,
                                  @Nullable String[] zygoteArgs) {
                                  @Nullable String[] zygoteArgs) {
        return zygoteProcess.start(processClass, niceName, uid, gid, gids,
        return zygoteProcess.start(processClass, niceName, uid, gid, gids,
                    runtimeFlags, mountExternal, targetSdkVersion, seInfo,
                    runtimeFlags, mountExternal, targetSdkVersion, seInfo,
                    abi, instructionSet, appDataDir, invokeWith, packageName, zygoteArgs);
                    abi, instructionSet, appDataDir, invokeWith, packageName,
                    packagesForUid, visibleVols, zygoteArgs);
    }
    }


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


    /**
    /**
+37 −2
Original line number Original line Diff line number Diff line
@@ -215,6 +215,8 @@ public class ZygoteProcess {
     * @param appDataDir null-ok the data directory of the app.
     * @param appDataDir null-ok the data directory of the app.
     * @param invokeWith null-ok the command to invoke with.
     * @param invokeWith null-ok the command to invoke with.
     * @param packageName null-ok the name of the package this process belongs to.
     * @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.
     * @param zygoteArgs Additional arguments to supply to the zygote process.
     *
     *
     * @return An object that describes the result of the attempt to start the process.
     * @return An object that describes the result of the attempt to start the process.
@@ -231,12 +233,14 @@ public class ZygoteProcess {
                                                  @Nullable String appDataDir,
                                                  @Nullable String appDataDir,
                                                  @Nullable String invokeWith,
                                                  @Nullable String invokeWith,
                                                  @Nullable String packageName,
                                                  @Nullable String packageName,
                                                  @Nullable String[] packagesForUid,
                                                  @Nullable String[] visibleVols,
                                                  @Nullable String[] zygoteArgs) {
                                                  @Nullable String[] zygoteArgs) {
        try {
        try {
            return startViaZygote(processClass, niceName, uid, gid, gids,
            return startViaZygote(processClass, niceName, uid, gid, gids,
                    runtimeFlags, mountExternal, targetSdkVersion, seInfo,
                    runtimeFlags, mountExternal, targetSdkVersion, seInfo,
                    abi, instructionSet, appDataDir, invokeWith, false /* startChildZygote */,
                    abi, instructionSet, appDataDir, invokeWith, false /* startChildZygote */,
                    packageName, zygoteArgs);
                    packageName, packagesForUid, visibleVols, zygoteArgs);
        } catch (ZygoteStartFailedEx ex) {
        } catch (ZygoteStartFailedEx ex) {
            Log.e(LOG_TAG,
            Log.e(LOG_TAG,
                    "Starting VM process through Zygote failed");
                    "Starting VM process through Zygote failed");
@@ -355,6 +359,8 @@ public class ZygoteProcess {
     * @param startChildZygote Start a sub-zygote. This creates a new zygote process
     * @param startChildZygote Start a sub-zygote. This creates a new zygote process
     * that has its state cloned from this zygote process.
     * that has its state cloned from this zygote process.
     * @param packageName null-ok the name of the package this process belongs to.
     * @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.
     * @param extraArgs Additional arguments to supply to the zygote process.
     * @return An object that describes the result of the attempt to start the process.
     * @return An object that describes the result of the attempt to start the process.
     * @throws ZygoteStartFailedEx if process start failed for any reason
     * @throws ZygoteStartFailedEx if process start failed for any reason
@@ -372,6 +378,8 @@ public class ZygoteProcess {
                                                      @Nullable String invokeWith,
                                                      @Nullable String invokeWith,
                                                      boolean startChildZygote,
                                                      boolean startChildZygote,
                                                      @Nullable String packageName,
                                                      @Nullable String packageName,
                                                      @Nullable String[] packagesForUid,
                                                      @Nullable String[] visibleVols,
                                                      @Nullable String[] extraArgs)
                                                      @Nullable String[] extraArgs)
                                                      throws ZygoteStartFailedEx {
                                                      throws ZygoteStartFailedEx {
        ArrayList<String> argsForZygote = new ArrayList<String>();
        ArrayList<String> argsForZygote = new ArrayList<String>();
@@ -439,6 +447,32 @@ public class ZygoteProcess {
            argsForZygote.add("--package-name=" + packageName);
            argsForZygote.add("--package-name=" + packageName);
        }
        }


        if (packagesForUid != null && packagesForUid.length > 0) {
            final StringBuilder sb = new StringBuilder();
            sb.append("--packages-for-uid=");

            for (int i = 0; i < packagesForUid.length; ++i) {
                if (i != 0) {
                    sb.append(',');
                }
                sb.append(packagesForUid[i]);
            }
            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());
        }

        argsForZygote.add(processClass);
        argsForZygote.add(processClass);


        if (extraArgs != null) {
        if (extraArgs != null) {
@@ -746,7 +780,8 @@ public class ZygoteProcess {
            result = startViaZygote(processClass, niceName, uid, gid,
            result = startViaZygote(processClass, niceName, uid, gid,
                    gids, runtimeFlags, 0 /* mountExternal */, 0 /* targetSdkVersion */, seInfo,
                    gids, runtimeFlags, 0 /* mountExternal */, 0 /* targetSdkVersion */, seInfo,
                    abi, instructionSet, null /* appDataDir */, null /* invokeWith */,
                    abi, instructionSet, null /* appDataDir */, null /* invokeWith */,
                    true /* startChildZygote */, null /* packageName */, extraArgs);
                    true /* startChildZygote */, null /* packageName */,
                    null /* packagesForUid */, null /* visibleVolumes */, extraArgs);
        } catch (ZygoteStartFailedEx ex) {
        } catch (ZygoteStartFailedEx ex) {
            throw new RuntimeException("Starting child-zygote through Zygote failed", ex);
            throw new RuntimeException("Starting child-zygote through Zygote failed", ex);
        }
        }
+6 −1
Original line number Original line Diff line number Diff line
@@ -89,8 +89,13 @@ public abstract class StorageManagerInternal {
     * @param appId The appId for the given package.
     * @param appId The appId for the given package.
     * @param sharedUserId The sharedUserId for given package if it specified
     * @param sharedUserId The sharedUserId for given package if it specified
     *      {@code android:sharedUserId} in the manifest, otherwise {@code null}
     *      {@code android:sharedUserId} in the manifest, otherwise {@code null}
     * @param userId
     * @param userId The userId in which the storage needs to be mounted.
     */
     */
    public abstract void mountExternalStorageForApp(String packageName, int appId,
    public abstract void mountExternalStorageForApp(String packageName, int appId,
            String sharedUserId, int userId);
            String sharedUserId, int userId);

    /**
     * @return Labels of storage volumes that are visible to the given userId.
     */
    public abstract String[] getVisibleVolumesForUser(int userId);
}
}
+1 −1
Original line number Original line Diff line number Diff line
@@ -157,7 +157,7 @@ public class VolumeInfo implements Parcelable {
    public final DiskInfo disk;
    public final DiskInfo disk;
    public final String partGuid;
    public final String partGuid;
    public int mountFlags = 0;
    public int mountFlags = 0;
    public int mountUserId = -1;
    public int mountUserId = UserHandle.USER_NULL;
    @UnsupportedAppUsage
    @UnsupportedAppUsage
    public int state = STATE_UNMOUNTED;
    public int state = STATE_UNMOUNTED;
    public String fsType;
    public String fsType;
+8 −7
Original line number Original line Diff line number Diff line
@@ -135,13 +135,14 @@ public final class Zygote {
    public static int forkAndSpecialize(int uid, int gid, int[] gids, int runtimeFlags,
    public static int forkAndSpecialize(int uid, int gid, int[] gids, int runtimeFlags,
            int[][] rlimits, int mountExternal, String seInfo, String niceName, int[] fdsToClose,
            int[][] rlimits, int mountExternal, String seInfo, String niceName, int[] fdsToClose,
            int[] fdsToIgnore, boolean startChildZygote, String instructionSet, String appDataDir,
            int[] fdsToIgnore, boolean startChildZygote, String instructionSet, String appDataDir,
          String packageName) {
            String packageName, String[] packagesForUid, String[] visibleVolIds) {
        VM_HOOKS.preFork();
        VM_HOOKS.preFork();
        // Resets nice priority for zygote process.
        // Resets nice priority for zygote process.
        resetNicePriority();
        resetNicePriority();
        int pid = nativeForkAndSpecialize(
        int pid = nativeForkAndSpecialize(
                  uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName, fdsToClose,
                  uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName, fdsToClose,
                  fdsToIgnore, startChildZygote, instructionSet, appDataDir, packageName);
                  fdsToIgnore, startChildZygote, instructionSet, appDataDir, packageName,
                  packagesForUid, visibleVolIds);
        // Enable tracing as soon as possible for the child process.
        // Enable tracing as soon as possible for the child process.
        if (pid == 0) {
        if (pid == 0) {
            Trace.setTracingEnabled(true, runtimeFlags);
            Trace.setTracingEnabled(true, runtimeFlags);
@@ -156,7 +157,7 @@ public final class Zygote {
    native private static int nativeForkAndSpecialize(int uid, int gid, int[] gids,int runtimeFlags,
    native private static int nativeForkAndSpecialize(int uid, int gid, int[] gids,int runtimeFlags,
            int[][] rlimits, int mountExternal, String seInfo, String niceName, int[] fdsToClose,
            int[][] rlimits, int mountExternal, String seInfo, String niceName, int[] fdsToClose,
            int[] fdsToIgnore, boolean startChildZygote, String instructionSet, String appDataDir,
            int[] fdsToIgnore, boolean startChildZygote, String instructionSet, String appDataDir,
          String packageName);
            String packageName, String[] packagesForUid, String[] visibleVolIds);


    /**
    /**
     * Called to do any initialization before starting an application.
     * Called to do any initialization before starting an application.
Loading