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

Commit 2cfe9651 authored by Nate Myren's avatar Nate Myren
Browse files

Have zygote mount appcompat system properties

If needed, the zygote should mount
/dev/__properties__/appcompat_override in place of /dev/__properties__,
and reload system properties (and any constants derived from them)

Bug: 291814949
Test: atest AppcompatOverrideSystemPropertiesDeclarationTest

Change-Id: Ifd364f5d9463e88b2ee928c1f71a6b96b8c29f45
parent 0be58372
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -730,13 +730,14 @@ public class Process {
                                                   whitelistedDataInfoMap,
                                           boolean bindMountAppsData,
                                           boolean bindMountAppStorageDirs,
                                           boolean bindMountSystemOverrides,
                                           @Nullable String[] zygoteArgs) {
        return ZYGOTE_PROCESS.start(processClass, niceName, uid, gid, gids,
                    runtimeFlags, mountExternal, targetSdkVersion, seInfo,
                    abi, instructionSet, appDataDir, invokeWith, packageName,
                    zygotePolicyFlags, isTopApp, disabledCompatChanges,
                    pkgDataInfoMap, whitelistedDataInfoMap, bindMountAppsData,
                    bindMountAppStorageDirs, zygoteArgs);
                    bindMountAppStorageDirs, bindMountSystemOverrides, zygoteArgs);
    }

    /** @hide */
@@ -753,6 +754,7 @@ public class Process {
                                                  @Nullable String invokeWith,
                                                  @Nullable String packageName,
                                                  @Nullable long[] disabledCompatChanges,
                                                  boolean bindMountSyspropOverrides,
                                                  @Nullable String[] zygoteArgs) {
        // Webview zygote can't access app private data files, so doesn't need to know its data
        // info.
@@ -761,7 +763,8 @@ public class Process {
                    abi, instructionSet, appDataDir, invokeWith, packageName,
                    /*zygotePolicyFlags=*/ ZYGOTE_POLICY_FLAG_EMPTY, /*isTopApp=*/ false,
                disabledCompatChanges, /* pkgDataInfoMap */ null,
                /* whitelistedDataInfoMap */ null, false, false, zygoteArgs);
                /* whitelistedDataInfoMap */ null, /* bindMountAppsData */ false,
                /* bindMountAppStorageDirs */ false, bindMountSyspropOverrides, zygoteArgs);
    }

    /**
+9 −2
Original line number Diff line number Diff line
@@ -355,6 +355,7 @@ public class ZygoteProcess {
                                                          allowlistedDataInfoList,
                                                  boolean bindMountAppsData,
                                                  boolean bindMountAppStorageDirs,
                                                  boolean bindOverrideSysprops,
                                                  @Nullable String[] zygoteArgs) {
        // TODO (chriswailes): Is there a better place to check this value?
        if (fetchUsapPoolEnabledPropWithMinInterval()) {
@@ -367,7 +368,7 @@ public class ZygoteProcess {
                    abi, instructionSet, appDataDir, invokeWith, /*startChildZygote=*/ false,
                    packageName, zygotePolicyFlags, isTopApp, disabledCompatChanges,
                    pkgDataInfoMap, allowlistedDataInfoList, bindMountAppsData,
                    bindMountAppStorageDirs, zygoteArgs);
                    bindMountAppStorageDirs, bindOverrideSysprops, zygoteArgs);
        } catch (ZygoteStartFailedEx ex) {
            Log.e(LOG_TAG,
                    "Starting VM process through Zygote failed");
@@ -638,6 +639,7 @@ public class ZygoteProcess {
                                                              allowlistedDataInfoList,
                                                      boolean bindMountAppsData,
                                                      boolean bindMountAppStorageDirs,
                                                      boolean bindMountOverrideSysprops,
                                                      @Nullable String[] extraArgs)
                                                      throws ZygoteStartFailedEx {
        ArrayList<String> argsForZygote = new ArrayList<>();
@@ -753,6 +755,10 @@ public class ZygoteProcess {
            argsForZygote.add(Zygote.BIND_MOUNT_APP_DATA_DIRS);
        }

        if (bindMountOverrideSysprops) {
            argsForZygote.add(Zygote.BIND_MOUNT_SYSPROP_OVERRIDES);
        }

        if (disabledCompatChanges != null && disabledCompatChanges.length > 0) {
            StringBuilder sb = new StringBuilder();
            sb.append("--disabled-compat-changes=");
@@ -1306,7 +1312,8 @@ public class ZygoteProcess {
                    ZYGOTE_POLICY_FLAG_SYSTEM_PROCESS /* zygotePolicyFlags */, false /* isTopApp */,
                    null /* disabledCompatChanges */, null /* pkgDataInfoMap */,
                    null /* allowlistedDataInfoList */, true /* bindMountAppsData*/,
                    /* bindMountAppStorageDirs */ false, extraArgs);
                    /* bindMountAppStorageDirs */ false, /*bindMountOverrideSysprops */ false,
                    extraArgs);

        } catch (ZygoteStartFailedEx ex) {
            throw new RuntimeException("Starting child-zygote through Zygote failed", ex);
+18 −7
Original line number Diff line number Diff line
@@ -236,6 +236,9 @@ public final class Zygote {
    /** Bind mount app storage dirs to lower fs not via fuse */
    public static final String BIND_MOUNT_APP_DATA_DIRS = "--bind-mount-data-dirs";

    /** Bind the system properties to an alternate set, for appcompat reasons */
    public static final String BIND_MOUNT_SYSPROP_OVERRIDES = "--bind-mount-sysprop-overrides";

    /**
     * An extraArg passed when a zygote process is forking a child-zygote, specifying a name
     * in the abstract socket namespace. This socket name is what the new child zygote
@@ -353,6 +356,8 @@ public final class Zygote {
     * @param allowlistedDataInfoList Like pkgDataInfoList, but it's for allowlisted apps.
     * @param bindMountAppDataDirs  True if the zygote needs to mount data dirs.
     * @param bindMountAppStorageDirs  True if the zygote needs to mount storage dirs.
     * @param bindMountSyspropOverrides True if the zygote needs to mount the override system
     *                                  properties
     *
     * @return 0 if this is the child, pid of the child
     * if this is the parent, or -1 on error.
@@ -361,14 +366,15 @@ public final class Zygote {
            int[][] rlimits, int mountExternal, String seInfo, String niceName, int[] fdsToClose,
            int[] fdsToIgnore, boolean startChildZygote, String instructionSet, String appDataDir,
            boolean isTopApp, String[] pkgDataInfoList, String[] allowlistedDataInfoList,
            boolean bindMountAppDataDirs, boolean bindMountAppStorageDirs) {
            boolean bindMountAppDataDirs, boolean bindMountAppStorageDirs,
            boolean bindMountSyspropOverrides) {
        ZygoteHooks.preFork();

        int pid = nativeForkAndSpecialize(
                uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo, niceName, fdsToClose,
                fdsToIgnore, startChildZygote, instructionSet, appDataDir, isTopApp,
                pkgDataInfoList, allowlistedDataInfoList, bindMountAppDataDirs,
                bindMountAppStorageDirs);
                bindMountAppStorageDirs, bindMountSyspropOverrides);
        if (pid == 0) {
            // Note that this event ends at the end of handleChildProc,
            Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "PostFork");
@@ -391,7 +397,7 @@ public final class Zygote {
            int[] fdsToClose, int[] fdsToIgnore, boolean startChildZygote, String instructionSet,
            String appDataDir, boolean isTopApp, String[] pkgDataInfoList,
            String[] allowlistedDataInfoList, boolean bindMountAppDataDirs,
            boolean bindMountAppStorageDirs);
            boolean bindMountAppStorageDirs, boolean bindMountSyspropOverrides);

    /**
     * Specialize an unspecialized app process.  The current VM must have been started
@@ -421,16 +427,19 @@ public final class Zygote {
     * @param allowlistedDataInfoList Like pkgDataInfoList, but it's for allowlisted apps.
     * @param bindMountAppDataDirs  True if the zygote needs to mount data dirs.
     * @param bindMountAppStorageDirs  True if the zygote needs to mount storage dirs.
     * @param bindMountSyspropOverrides True if the zygote needs to mount the override system
     *                                  properties
     */
    private static void specializeAppProcess(int uid, int gid, int[] gids, int runtimeFlags,
            int[][] rlimits, int mountExternal, String seInfo, String niceName,
            boolean startChildZygote, String instructionSet, String appDataDir, boolean isTopApp,
            String[] pkgDataInfoList, String[] allowlistedDataInfoList,
            boolean bindMountAppDataDirs, boolean bindMountAppStorageDirs) {
            boolean bindMountAppDataDirs, boolean bindMountAppStorageDirs,
            boolean bindMountSyspropOverrides) {
        nativeSpecializeAppProcess(uid, gid, gids, runtimeFlags, rlimits, mountExternal, seInfo,
                niceName, startChildZygote, instructionSet, appDataDir, isTopApp,
                pkgDataInfoList, allowlistedDataInfoList,
                bindMountAppDataDirs, bindMountAppStorageDirs);
                bindMountAppDataDirs, bindMountAppStorageDirs, bindMountSyspropOverrides);

        // Note that this event ends at the end of handleChildProc.
        Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "PostFork");
@@ -455,7 +464,8 @@ public final class Zygote {
            int runtimeFlags, int[][] rlimits, int mountExternal, String seInfo, String niceName,
            boolean startChildZygote, String instructionSet, String appDataDir, boolean isTopApp,
            String[] pkgDataInfoList, String[] allowlistedDataInfoList,
            boolean bindMountAppDataDirs, boolean bindMountAppStorageDirs);
            boolean bindMountAppDataDirs, boolean bindMountAppStorageDirs,
            boolean bindMountSyspropOverrides);

    /**
     * Called to do any initialization before starting an application.
@@ -866,7 +876,8 @@ public final class Zygote {
                                 args.mSeInfo, args.mNiceName, args.mStartChildZygote,
                                 args.mInstructionSet, args.mAppDataDir, args.mIsTopApp,
                                 args.mPkgDataInfoList, args.mAllowlistedDataInfoList,
                                 args.mBindMountAppDataDirs, args.mBindMountAppStorageDirs);
                                 args.mBindMountAppDataDirs, args.mBindMountAppStorageDirs,
                                 args.mBindMountSyspropOverrides);

            // While `specializeAppProcess` sets the thread name on the process's main thread, this
            // is distinct from the app process name which appears in stack traces, as the latter is
+7 −0
Original line number Diff line number Diff line
@@ -242,6 +242,11 @@ class ZygoteArguments {
     */
    boolean mBindMountAppDataDirs;

    /**
     * @see Zygote#BIND_MOUNT_SYSPROP_OVERRIDES
     */
    boolean mBindMountSyspropOverrides;

    /**
     * Constructs instance and parses args
     *
@@ -481,6 +486,8 @@ class ZygoteArguments {
                mBindMountAppStorageDirs = true;
            } else if (arg.equals(Zygote.BIND_MOUNT_APP_DATA_DIRS)) {
                mBindMountAppDataDirs = true;
            } else if (arg.equals(Zygote.BIND_MOUNT_SYSPROP_OVERRIDES)) {
                mBindMountSyspropOverrides = true;
            } else {
                unprocessedArg = arg;
                break;
+2 −1
Original line number Diff line number Diff line
@@ -257,7 +257,8 @@ class ZygoteConnection {
                            parsedArgs.mInstructionSet, parsedArgs.mAppDataDir,
                            parsedArgs.mIsTopApp, parsedArgs.mPkgDataInfoList,
                            parsedArgs.mAllowlistedDataInfoList, parsedArgs.mBindMountAppDataDirs,
                            parsedArgs.mBindMountAppStorageDirs);
                            parsedArgs.mBindMountAppStorageDirs,
                            parsedArgs.mBindMountSyspropOverrides);

                    try {
                        if (pid == 0) {
Loading