Loading core/java/android/os/Process.java +39 −3 Original line number Diff line number Diff line Loading @@ -528,6 +528,40 @@ public class Process { */ private static int sPidFdSupported = PIDFD_UNKNOWN; /** * Value used to indicate that there is no special information about an application launch. App * launches with this policy will occur through the primary or secondary Zygote with no special * treatment. * * @hide */ public static final int ZYGOTE_POLICY_FLAG_EMPTY = 0; /** * Flag used to indicate that an application launch is user-visible and latency sensitive. Any * launch with this policy will use a Unspecialized App Process Pool if the target Zygote * supports it. * * @hide */ public static final int ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE = 1 << 0; /** * Flag used to indicate that the launch is one in a series of app launches that will be * performed in quick succession. For future use. * * @hide */ public static final int ZYGOTE_POLICY_FLAG_BATCH_LAUNCH = 1 << 1; /** * Flag used to indicate that the current launch event is for a system process. All system * processes are equally important, so none of them should be prioritized over the others. * * @hide */ public static final int ZYGOTE_POLICY_FLAG_SYSTEM_PROCESS = 1 << 2; /** * State associated with the zygote process. * @hide Loading Loading @@ -567,6 +601,7 @@ public class Process { * @param appDataDir null-ok the data directory of the app. * @param invokeWith null-ok the command to invoke with. * @param packageName null-ok the name of the package this process belongs to. * @param zygotePolicyFlags Flags used to determine how to launch the application * @param isTopApp whether the process starts for high priority application. * @param disabledCompatChanges null-ok list of disabled compat changes for the process being * started. Loading @@ -590,6 +625,7 @@ public class Process { @Nullable String appDataDir, @Nullable String invokeWith, @Nullable String packageName, int zygotePolicyFlags, boolean isTopApp, @Nullable long[] disabledCompatChanges, @Nullable Map<String, Pair<String, Long>> Loading @@ -598,7 +634,7 @@ public class Process { return ZYGOTE_PROCESS.start(processClass, niceName, uid, gid, gids, runtimeFlags, mountExternal, targetSdkVersion, seInfo, abi, instructionSet, appDataDir, invokeWith, packageName, /*useUsapPool=*/ true, isTopApp, disabledCompatChanges, zygotePolicyFlags, isTopApp, disabledCompatChanges, pkgDataInfoMap, zygoteArgs); } Loading @@ -622,8 +658,8 @@ public class Process { return WebViewZygote.getProcess().start(processClass, niceName, uid, gid, gids, runtimeFlags, mountExternal, targetSdkVersion, seInfo, abi, instructionSet, appDataDir, invokeWith, packageName, /*useUsapPool=*/ false, /*isTopApp=*/ false, disabledCompatChanges, /* pkgDataInfoMap */ null, zygoteArgs); /*zygotePolicyFlags=*/ ZYGOTE_POLICY_FLAG_EMPTY, /*isTopApp=*/ false, disabledCompatChanges, /* pkgDataInfoMap */ null, zygoteArgs); } /** Loading core/java/android/os/ZygoteProcess.java +73 −11 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ package android.os; import static android.os.Process.ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE; import static android.os.Process.ZYGOTE_POLICY_FLAG_SYSTEM_PROCESS; import android.annotation.NonNull; import android.annotation.Nullable; import android.compat.annotation.UnsupportedAppUsage; Loading Loading @@ -119,6 +122,10 @@ public class ZygoteProcess { mUsapPoolSecondarySocketAddress = new LocalSocketAddress(Zygote.USAP_POOL_SECONDARY_SOCKET_NAME, LocalSocketAddress.Namespace.RESERVED); // This constructor is used to create the primary and secondary Zygotes, which can support // Unspecialized App Process Pools. mUsapPoolSupported = true; } public ZygoteProcess(LocalSocketAddress primarySocketAddress, Loading @@ -128,6 +135,10 @@ public class ZygoteProcess { mUsapPoolSocketAddress = null; mUsapPoolSecondarySocketAddress = null; // This constructor is used to create the primary and secondary Zygotes, which CAN NOT // support Unspecialized App Process Pools. mUsapPoolSupported = false; } public LocalSocketAddress getPrimarySocketAddress() { Loading Loading @@ -266,6 +277,14 @@ public class ZygoteProcess { */ private ZygoteState secondaryZygoteState; /** * If this Zygote supports the creation and maintenance of a USAP pool. * * Currently only the primary and secondary Zygotes support USAP pools. Any * child Zygotes will be unable to create or use a USAP pool. */ private final boolean mUsapPoolSupported; /** * If the USAP pool should be created and used to start applications. * Loading Loading @@ -308,13 +327,14 @@ public class ZygoteProcess { * @param appDataDir null-ok the data directory of the app. * @param invokeWith null-ok the command to invoke with. * @param packageName null-ok the name of the package this process belongs to. * @param zygotePolicyFlags Flags used to determine how to launch the application. * @param isTopApp Whether the process starts for high priority application. * @param disabledCompatChanges null-ok list of disabled compat changes for the process being * started. * @param zygoteArgs Additional arguments to supply to the zygote process. * @param isTopApp Whether the process starts for high priority application. * @param pkgDataInfoMap Map from related package names to private data directory * volume UUID and inode number. * * @param zygoteArgs Additional arguments to supply to the Zygote process. * @return An object that describes the result of the attempt to start the process. * @throws RuntimeException on fatal start failure */ Loading @@ -329,7 +349,7 @@ public class ZygoteProcess { @Nullable String appDataDir, @Nullable String invokeWith, @Nullable String packageName, boolean useUsapPool, int zygotePolicyFlags, boolean isTopApp, @Nullable long[] disabledCompatChanges, @Nullable Map<String, Pair<String, Long>> Loading @@ -344,7 +364,7 @@ public class ZygoteProcess { return startViaZygote(processClass, niceName, uid, gid, gids, runtimeFlags, mountExternal, targetSdkVersion, seInfo, abi, instructionSet, appDataDir, invokeWith, /*startChildZygote=*/ false, packageName, useUsapPool, isTopApp, disabledCompatChanges, packageName, zygotePolicyFlags, isTopApp, disabledCompatChanges, pkgDataInfoMap, zygoteArgs); } catch (ZygoteStartFailedEx ex) { Log.e(LOG_TAG, Loading Loading @@ -391,7 +411,7 @@ public class ZygoteProcess { */ @GuardedBy("mLock") private Process.ProcessStartResult zygoteSendArgsAndGetResult( ZygoteState zygoteState, boolean useUsapPool, @NonNull ArrayList<String> args) ZygoteState zygoteState, int zygotePolicyFlags, @NonNull ArrayList<String> args) throws ZygoteStartFailedEx { // Throw early if any of the arguments are malformed. This means we can // avoid writing a partial response to the zygote. Loading @@ -417,7 +437,7 @@ public class ZygoteProcess { */ String msgStr = args.size() + "\n" + String.join("\n", args) + "\n"; if (useUsapPool && mUsapPoolEnabled && canAttemptUsap(args)) { if (shouldAttemptUsapLaunch(zygotePolicyFlags, args)) { try { return attemptUsapSendArgsAndGetResult(zygoteState, msgStr); } catch (IOException ex) { Loading Loading @@ -488,7 +508,43 @@ public class ZygoteProcess { } /** * Flags that may not be passed to a USAP. * Test various member properties and parameters to determine if a launch event should be * handled using an Unspecialized App Process Pool or not. * * @param zygotePolicyFlags Policy flags indicating special behavioral observations about the * Zygote command * @param args Arguments that will be passed to the Zygote * @return If the command should be sent to a USAP Pool member or an actual Zygote */ private boolean shouldAttemptUsapLaunch(int zygotePolicyFlags, ArrayList<String> args) { return mUsapPoolSupported && mUsapPoolEnabled && policySpecifiesUsapPoolLaunch(zygotePolicyFlags) && commandSupportedByUsap(args); } /** * Tests a Zygote policy flag set for various properties that determine if it is eligible for * being handled by an Unspecialized App Process Pool. * * @param zygotePolicyFlags Policy flags indicating special behavioral observations about the * Zygote command * @return If the policy allows for use of a USAP pool */ private static boolean policySpecifiesUsapPoolLaunch(int zygotePolicyFlags) { /* * Zygote USAP Pool Policy: Launch the new process from the USAP Pool iff the launch event * is latency sensitive but *NOT* a system process. All system processes are equally * important so we don't want to prioritize one over another. */ return (zygotePolicyFlags & (ZYGOTE_POLICY_FLAG_SYSTEM_PROCESS | ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE)) == ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE; } /** * Flags that may not be passed to a USAP. These may appear as prefixes to individual Zygote * arguments. */ private static final String[] INVALID_USAP_FLAGS = { "--query-abi-list", Loading @@ -505,10 +561,11 @@ public class ZygoteProcess { /** * Tests a command list to see if it is valid to send to a USAP. * * @param args Zygote/USAP command arguments * @return True if the command can be passed to a USAP; false otherwise */ private static boolean canAttemptUsap(ArrayList<String> args) { private static boolean commandSupportedByUsap(ArrayList<String> args) { for (String flag : args) { for (String badFlag : INVALID_USAP_FLAGS) { if (flag.startsWith(badFlag)) { Loading Loading @@ -544,6 +601,7 @@ public class ZygoteProcess { * @param startChildZygote Start a sub-zygote. This creates a new 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 zygotePolicyFlags Flags used to determine how to launch the application. * @param isTopApp Whether the process starts for high priority application. * @param disabledCompatChanges a list of disabled compat changes for the process being started. * @param pkgDataInfoMap Map from related package names to private data directory volume UUID Loading @@ -565,7 +623,7 @@ public class ZygoteProcess { @Nullable String invokeWith, boolean startChildZygote, @Nullable String packageName, boolean useUsapPool, int zygotePolicyFlags, boolean isTopApp, @Nullable long[] disabledCompatChanges, @Nullable Map<String, Pair<String, Long>> Loading Loading @@ -692,7 +750,7 @@ public class ZygoteProcess { // The USAP pool can not be used if the application will not use the systems graphics // driver. If that driver is requested use the Zygote application start path. return zygoteSendArgsAndGetResult(openZygoteSocketIfNeeded(abi), useUsapPool, zygotePolicyFlags, argsForZygote); } } Loading Loading @@ -722,6 +780,10 @@ public class ZygoteProcess { private long mLastPropCheckTimestamp = 0; private boolean fetchUsapPoolEnabledPropWithMinInterval() { // If this Zygote doesn't support USAPs there is no need to fetch any // properties. if (!mUsapPoolSupported) return false; final long currentTimestamp = SystemClock.elapsedRealtime(); if (mIsFirstPropCheck Loading Loading @@ -1219,7 +1281,7 @@ public class ZygoteProcess { gids, runtimeFlags, 0 /* mountExternal */, 0 /* targetSdkVersion */, seInfo, abi, instructionSet, null /* appDataDir */, null /* invokeWith */, true /* startChildZygote */, null /* packageName */, false /* useUsapPool */, false /* isTopApp */, ZYGOTE_POLICY_FLAG_SYSTEM_PROCESS /* zygotePolicyFlags */, false /* isTopApp */, null /* disabledCompatChanges */, null /* pkgDataInfoMap */, extraArgs); } catch (ZygoteStartFailedEx ex) { throw new RuntimeException("Starting child-zygote through Zygote failed", ex); Loading services/core/java/com/android/server/am/ActiveServices.java +4 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import static android.os.Process.NFC_UID; import static android.os.Process.ROOT_UID; import static android.os.Process.SHELL_UID; import static android.os.Process.SYSTEM_UID; import static android.os.Process.ZYGOTE_POLICY_FLAG_EMPTY; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_BACKGROUND_CHECK; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_FOREGROUND_SERVICE; Loading Loading @@ -2937,8 +2938,10 @@ public final class ActiveServices { // Not running -- get it started, and enqueue this service record // to be executed when the app comes up. if (app == null && !permissionsReviewRequired) { // TODO (chriswailes): Change the Zygote policy flags based on if the launch-for-service // was initiated from a notification tap or not. if ((app=mAm.startProcessLocked(procName, r.appInfo, true, intentFlags, hostingRecord, false, isolated, false)) == null) { hostingRecord, ZYGOTE_POLICY_FLAG_EMPTY, false, isolated, false)) == null) { String msg = "Unable to launch app " + r.appInfo.packageName + "/" + r.appInfo.uid + " for service " Loading services/core/java/com/android/server/am/ActivityManagerService.java +37 −22 Original line number Diff line number Diff line Loading @@ -65,6 +65,10 @@ import static android.os.Process.SHELL_UID; import static android.os.Process.SIGNAL_USR1; import static android.os.Process.SYSTEM_UID; import static android.os.Process.THREAD_PRIORITY_FOREGROUND; import static android.os.Process.ZYGOTE_POLICY_FLAG_BATCH_LAUNCH; import static android.os.Process.ZYGOTE_POLICY_FLAG_EMPTY; import static android.os.Process.ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE; import static android.os.Process.ZYGOTE_POLICY_FLAG_SYSTEM_PROCESS; import static android.os.Process.ZYGOTE_PROCESS; import static android.os.Process.getTotalMemory; import static android.os.Process.isThreadInProcess; Loading Loading @@ -3054,7 +3058,7 @@ public class ActivityManagerService extends IActivityManager.Stub info.targetSdkVersion = Build.VERSION.SDK_INT; ProcessRecord proc = mProcessList.startProcessLocked(processName, info /* info */, false /* knownToBeDead */, 0 /* intentFlags */, sNullHostingRecord /* hostingRecord */, sNullHostingRecord /* hostingRecord */, ZYGOTE_POLICY_FLAG_EMPTY, true /* allowWhileBooting */, true /* isolated */, uid, true /* keepIfLarge */, abiOverride, entryPoint, entryPointArgs, crashHandler); Loading @@ -3065,12 +3069,12 @@ public class ActivityManagerService extends IActivityManager.Stub @GuardedBy("this") final ProcessRecord startProcessLocked(String processName, ApplicationInfo info, boolean knownToBeDead, int intentFlags, HostingRecord hostingRecord, boolean allowWhileBooting, HostingRecord hostingRecord, int zygotePolicyFlags, boolean allowWhileBooting, boolean isolated, boolean keepIfLarge) { return mProcessList.startProcessLocked(processName, info, knownToBeDead, intentFlags, hostingRecord, allowWhileBooting, isolated, 0 /* isolatedUid */, keepIfLarge, null /* ABI override */, null /* entryPoint */, null /* entryPointArgs */, null /* crashHandler */); hostingRecord, zygotePolicyFlags, allowWhileBooting, isolated, 0 /* isolatedUid */, keepIfLarge, null /* ABI override */, null /* entryPoint */, null /* entryPointArgs */, null /* crashHandler */); } boolean isAllowedWhileBooting(ApplicationInfo ai) { Loading Loading @@ -4953,7 +4957,8 @@ public class ActivityManagerService extends IActivityManager.Stub } catch (RemoteException e) { app.resetPackageList(mProcessStats); mProcessList.startProcessLocked(app, new HostingRecord("link fail", processName)); new HostingRecord("link fail", processName), ZYGOTE_POLICY_FLAG_EMPTY); return false; } Loading Loading @@ -5372,7 +5377,9 @@ public class ActivityManagerService extends IActivityManager.Stub for (int ip=0; ip<NP; ip++) { if (DEBUG_PROCESSES) Slog.v(TAG_PROCESSES, "Starting process on hold: " + procs.get(ip)); mProcessList.startProcessLocked(procs.get(ip), new HostingRecord("on-hold")); mProcessList.startProcessLocked(procs.get(ip), new HostingRecord("on-hold"), ZYGOTE_POLICY_FLAG_BATCH_LAUNCH); } } if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL) { Loading Loading @@ -7225,7 +7232,8 @@ public class ActivityManagerService extends IActivityManager.Stub cpr.appInfo, false, 0, new HostingRecord("content provider", new ComponentName(cpi.applicationInfo.packageName, cpi.name)), false, false, false); cpi.name)), ZYGOTE_POLICY_FLAG_EMPTY, false, false, false); checkTime(startTime, "getContentProviderImpl: after start process"); if (proc == null) { Slog.w(TAG, "Unable to launch app " Loading Loading @@ -7785,7 +7793,8 @@ public class ActivityManagerService extends IActivityManager.Stub .getPersistentApplications(STOCK_PM_FLAGS | matchFlags).getList(); for (ApplicationInfo app : apps) { if (!"android".equals(app.packageName)) { addAppLocked(app, null, false, null /* ABI override */); addAppLocked(app, null, false, null /* ABI override */, ZYGOTE_POLICY_FLAG_BATCH_LAUNCH); } } } catch (RemoteException ex) { Loading Loading @@ -8056,23 +8065,25 @@ public class ActivityManagerService extends IActivityManager.Stub @GuardedBy("this") final ProcessRecord addAppLocked(ApplicationInfo info, String customProcess, boolean isolated, String abiOverride) { String abiOverride, int zygotePolicyFlags) { return addAppLocked(info, customProcess, isolated, false /* disableHiddenApiChecks */, false /* mountExtStorageFull */, abiOverride); false /* mountExtStorageFull */, abiOverride, zygotePolicyFlags); } @GuardedBy("this") final ProcessRecord addAppLocked(ApplicationInfo info, String customProcess, boolean isolated, boolean disableHiddenApiChecks, boolean mountExtStorageFull, String abiOverride) { boolean disableHiddenApiChecks, boolean mountExtStorageFull, String abiOverride, int zygotePolicyFlags) { return addAppLocked(info, customProcess, isolated, disableHiddenApiChecks, false /* disableTestApiChecks */, mountExtStorageFull, abiOverride); false /* disableTestApiChecks */, mountExtStorageFull, abiOverride, zygotePolicyFlags); } // TODO: Move to ProcessList? @GuardedBy("this") final ProcessRecord addAppLocked(ApplicationInfo info, String customProcess, boolean isolated, boolean disableHiddenApiChecks, boolean disableTestApiChecks, boolean mountExtStorageFull, String abiOverride) { boolean mountExtStorageFull, String abiOverride, int zygotePolicyFlags) { ProcessRecord app; if (!isolated) { app = getProcessRecordLocked(customProcess != null ? customProcess : info.processName, Loading Loading @@ -8107,7 +8118,8 @@ public class ActivityManagerService extends IActivityManager.Stub mPersistentStartingProcesses.add(app); mProcessList.startProcessLocked(app, new HostingRecord("added application", customProcess != null ? customProcess : app.processName), disableHiddenApiChecks, disableTestApiChecks, mountExtStorageFull, abiOverride); zygotePolicyFlags, disableHiddenApiChecks, disableTestApiChecks, mountExtStorageFull, abiOverride); } return app; Loading Loading @@ -14614,7 +14626,8 @@ public class ActivityManagerService extends IActivityManager.Stub mProcessList.addProcessNameLocked(app); app.pendingStart = false; mProcessList.startProcessLocked(app, new HostingRecord("restart", app.processName)); new HostingRecord("restart", app.processName), ZYGOTE_POLICY_FLAG_EMPTY); return true; } else if (app.pid > 0 && app.pid != MY_PID) { // Goodbye! Loading Loading @@ -14977,7 +14990,7 @@ public class ActivityManagerService extends IActivityManager.Stub ProcessRecord proc = startProcessLocked(app.processName, app, false, 0, new HostingRecord("backup", hostingName), false, false, false); ZYGOTE_POLICY_FLAG_SYSTEM_PROCESS, false, false, false); if (proc == null) { Slog.e(TAG, "Unable to start backup agent process " + r); return false; Loading Loading @@ -16616,7 +16629,8 @@ public class ActivityManagerService extends IActivityManager.Stub } ProcessRecord app = addAppLocked(ai, defProcess, false, disableHiddenApiChecks, disableTestApiChecks, mountExtStorageFull, abiOverride); disableTestApiChecks, mountExtStorageFull, abiOverride, ZYGOTE_POLICY_FLAG_EMPTY); app.setActiveInstrumentation(activeInstr); activeInstr.mFinished = false; activeInstr.mSourceUid = callingUid; Loading Loading @@ -18013,7 +18027,8 @@ public class ActivityManagerService extends IActivityManager.Stub mProcessList.mRemovedProcesses.remove(i); if (app.isPersistent()) { addAppLocked(app.info, null, false, null /* ABI override */); addAppLocked(app.info, null, false, null /* ABI override */, ZYGOTE_POLICY_FLAG_BATCH_LAUNCH); } } } Loading Loading @@ -19220,8 +19235,8 @@ public class ActivityManagerService extends IActivityManager.Stub // preempted by other processes before attaching the process of top app. startProcessLocked(processName, info, knownToBeDead, 0 /* intentFlags */, new HostingRecord(hostingType, hostingName, isTop), false /* allowWhileBooting */, false /* isolated */, true /* keepIfLarge */); ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE, false /* allowWhileBooting */, false /* isolated */, true /* keepIfLarge */); } } finally { Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER); services/core/java/com/android/server/am/BroadcastQueue.java +7 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ package com.android.server.am; import static android.os.Process.ZYGOTE_POLICY_FLAG_EMPTY; import static android.os.Process.ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE; import static com.android.server.am.ActivityManagerDebugConfig.*; import android.app.ActivityManager; Loading Loading @@ -1593,7 +1596,9 @@ public final class BroadcastQueue { + receiverUid); } if (brOptions != null && brOptions.getTemporaryAppWhitelistDuration() > 0) { final boolean isActivityCapable = (brOptions != null && brOptions.getTemporaryAppWhitelistDuration() > 0); if (isActivityCapable) { scheduleTempWhitelistLocked(receiverUid, brOptions.getTemporaryAppWhitelistDuration(), r); } Loading Loading @@ -1648,6 +1653,7 @@ public final class BroadcastQueue { info.activityInfo.applicationInfo, true, r.intent.getFlags() | Intent.FLAG_FROM_BACKGROUND, new HostingRecord("broadcast", r.curComponent), isActivityCapable ? ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE : ZYGOTE_POLICY_FLAG_EMPTY, (r.intent.getFlags()&Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0, false, false)) == null) { // Ah, this recipient is unavailable. Finish it if necessary, Loading Loading
core/java/android/os/Process.java +39 −3 Original line number Diff line number Diff line Loading @@ -528,6 +528,40 @@ public class Process { */ private static int sPidFdSupported = PIDFD_UNKNOWN; /** * Value used to indicate that there is no special information about an application launch. App * launches with this policy will occur through the primary or secondary Zygote with no special * treatment. * * @hide */ public static final int ZYGOTE_POLICY_FLAG_EMPTY = 0; /** * Flag used to indicate that an application launch is user-visible and latency sensitive. Any * launch with this policy will use a Unspecialized App Process Pool if the target Zygote * supports it. * * @hide */ public static final int ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE = 1 << 0; /** * Flag used to indicate that the launch is one in a series of app launches that will be * performed in quick succession. For future use. * * @hide */ public static final int ZYGOTE_POLICY_FLAG_BATCH_LAUNCH = 1 << 1; /** * Flag used to indicate that the current launch event is for a system process. All system * processes are equally important, so none of them should be prioritized over the others. * * @hide */ public static final int ZYGOTE_POLICY_FLAG_SYSTEM_PROCESS = 1 << 2; /** * State associated with the zygote process. * @hide Loading Loading @@ -567,6 +601,7 @@ public class Process { * @param appDataDir null-ok the data directory of the app. * @param invokeWith null-ok the command to invoke with. * @param packageName null-ok the name of the package this process belongs to. * @param zygotePolicyFlags Flags used to determine how to launch the application * @param isTopApp whether the process starts for high priority application. * @param disabledCompatChanges null-ok list of disabled compat changes for the process being * started. Loading @@ -590,6 +625,7 @@ public class Process { @Nullable String appDataDir, @Nullable String invokeWith, @Nullable String packageName, int zygotePolicyFlags, boolean isTopApp, @Nullable long[] disabledCompatChanges, @Nullable Map<String, Pair<String, Long>> Loading @@ -598,7 +634,7 @@ public class Process { return ZYGOTE_PROCESS.start(processClass, niceName, uid, gid, gids, runtimeFlags, mountExternal, targetSdkVersion, seInfo, abi, instructionSet, appDataDir, invokeWith, packageName, /*useUsapPool=*/ true, isTopApp, disabledCompatChanges, zygotePolicyFlags, isTopApp, disabledCompatChanges, pkgDataInfoMap, zygoteArgs); } Loading @@ -622,8 +658,8 @@ public class Process { return WebViewZygote.getProcess().start(processClass, niceName, uid, gid, gids, runtimeFlags, mountExternal, targetSdkVersion, seInfo, abi, instructionSet, appDataDir, invokeWith, packageName, /*useUsapPool=*/ false, /*isTopApp=*/ false, disabledCompatChanges, /* pkgDataInfoMap */ null, zygoteArgs); /*zygotePolicyFlags=*/ ZYGOTE_POLICY_FLAG_EMPTY, /*isTopApp=*/ false, disabledCompatChanges, /* pkgDataInfoMap */ null, zygoteArgs); } /** Loading
core/java/android/os/ZygoteProcess.java +73 −11 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ package android.os; import static android.os.Process.ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE; import static android.os.Process.ZYGOTE_POLICY_FLAG_SYSTEM_PROCESS; import android.annotation.NonNull; import android.annotation.Nullable; import android.compat.annotation.UnsupportedAppUsage; Loading Loading @@ -119,6 +122,10 @@ public class ZygoteProcess { mUsapPoolSecondarySocketAddress = new LocalSocketAddress(Zygote.USAP_POOL_SECONDARY_SOCKET_NAME, LocalSocketAddress.Namespace.RESERVED); // This constructor is used to create the primary and secondary Zygotes, which can support // Unspecialized App Process Pools. mUsapPoolSupported = true; } public ZygoteProcess(LocalSocketAddress primarySocketAddress, Loading @@ -128,6 +135,10 @@ public class ZygoteProcess { mUsapPoolSocketAddress = null; mUsapPoolSecondarySocketAddress = null; // This constructor is used to create the primary and secondary Zygotes, which CAN NOT // support Unspecialized App Process Pools. mUsapPoolSupported = false; } public LocalSocketAddress getPrimarySocketAddress() { Loading Loading @@ -266,6 +277,14 @@ public class ZygoteProcess { */ private ZygoteState secondaryZygoteState; /** * If this Zygote supports the creation and maintenance of a USAP pool. * * Currently only the primary and secondary Zygotes support USAP pools. Any * child Zygotes will be unable to create or use a USAP pool. */ private final boolean mUsapPoolSupported; /** * If the USAP pool should be created and used to start applications. * Loading Loading @@ -308,13 +327,14 @@ public class ZygoteProcess { * @param appDataDir null-ok the data directory of the app. * @param invokeWith null-ok the command to invoke with. * @param packageName null-ok the name of the package this process belongs to. * @param zygotePolicyFlags Flags used to determine how to launch the application. * @param isTopApp Whether the process starts for high priority application. * @param disabledCompatChanges null-ok list of disabled compat changes for the process being * started. * @param zygoteArgs Additional arguments to supply to the zygote process. * @param isTopApp Whether the process starts for high priority application. * @param pkgDataInfoMap Map from related package names to private data directory * volume UUID and inode number. * * @param zygoteArgs Additional arguments to supply to the Zygote process. * @return An object that describes the result of the attempt to start the process. * @throws RuntimeException on fatal start failure */ Loading @@ -329,7 +349,7 @@ public class ZygoteProcess { @Nullable String appDataDir, @Nullable String invokeWith, @Nullable String packageName, boolean useUsapPool, int zygotePolicyFlags, boolean isTopApp, @Nullable long[] disabledCompatChanges, @Nullable Map<String, Pair<String, Long>> Loading @@ -344,7 +364,7 @@ public class ZygoteProcess { return startViaZygote(processClass, niceName, uid, gid, gids, runtimeFlags, mountExternal, targetSdkVersion, seInfo, abi, instructionSet, appDataDir, invokeWith, /*startChildZygote=*/ false, packageName, useUsapPool, isTopApp, disabledCompatChanges, packageName, zygotePolicyFlags, isTopApp, disabledCompatChanges, pkgDataInfoMap, zygoteArgs); } catch (ZygoteStartFailedEx ex) { Log.e(LOG_TAG, Loading Loading @@ -391,7 +411,7 @@ public class ZygoteProcess { */ @GuardedBy("mLock") private Process.ProcessStartResult zygoteSendArgsAndGetResult( ZygoteState zygoteState, boolean useUsapPool, @NonNull ArrayList<String> args) ZygoteState zygoteState, int zygotePolicyFlags, @NonNull ArrayList<String> args) throws ZygoteStartFailedEx { // Throw early if any of the arguments are malformed. This means we can // avoid writing a partial response to the zygote. Loading @@ -417,7 +437,7 @@ public class ZygoteProcess { */ String msgStr = args.size() + "\n" + String.join("\n", args) + "\n"; if (useUsapPool && mUsapPoolEnabled && canAttemptUsap(args)) { if (shouldAttemptUsapLaunch(zygotePolicyFlags, args)) { try { return attemptUsapSendArgsAndGetResult(zygoteState, msgStr); } catch (IOException ex) { Loading Loading @@ -488,7 +508,43 @@ public class ZygoteProcess { } /** * Flags that may not be passed to a USAP. * Test various member properties and parameters to determine if a launch event should be * handled using an Unspecialized App Process Pool or not. * * @param zygotePolicyFlags Policy flags indicating special behavioral observations about the * Zygote command * @param args Arguments that will be passed to the Zygote * @return If the command should be sent to a USAP Pool member or an actual Zygote */ private boolean shouldAttemptUsapLaunch(int zygotePolicyFlags, ArrayList<String> args) { return mUsapPoolSupported && mUsapPoolEnabled && policySpecifiesUsapPoolLaunch(zygotePolicyFlags) && commandSupportedByUsap(args); } /** * Tests a Zygote policy flag set for various properties that determine if it is eligible for * being handled by an Unspecialized App Process Pool. * * @param zygotePolicyFlags Policy flags indicating special behavioral observations about the * Zygote command * @return If the policy allows for use of a USAP pool */ private static boolean policySpecifiesUsapPoolLaunch(int zygotePolicyFlags) { /* * Zygote USAP Pool Policy: Launch the new process from the USAP Pool iff the launch event * is latency sensitive but *NOT* a system process. All system processes are equally * important so we don't want to prioritize one over another. */ return (zygotePolicyFlags & (ZYGOTE_POLICY_FLAG_SYSTEM_PROCESS | ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE)) == ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE; } /** * Flags that may not be passed to a USAP. These may appear as prefixes to individual Zygote * arguments. */ private static final String[] INVALID_USAP_FLAGS = { "--query-abi-list", Loading @@ -505,10 +561,11 @@ public class ZygoteProcess { /** * Tests a command list to see if it is valid to send to a USAP. * * @param args Zygote/USAP command arguments * @return True if the command can be passed to a USAP; false otherwise */ private static boolean canAttemptUsap(ArrayList<String> args) { private static boolean commandSupportedByUsap(ArrayList<String> args) { for (String flag : args) { for (String badFlag : INVALID_USAP_FLAGS) { if (flag.startsWith(badFlag)) { Loading Loading @@ -544,6 +601,7 @@ public class ZygoteProcess { * @param startChildZygote Start a sub-zygote. This creates a new 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 zygotePolicyFlags Flags used to determine how to launch the application. * @param isTopApp Whether the process starts for high priority application. * @param disabledCompatChanges a list of disabled compat changes for the process being started. * @param pkgDataInfoMap Map from related package names to private data directory volume UUID Loading @@ -565,7 +623,7 @@ public class ZygoteProcess { @Nullable String invokeWith, boolean startChildZygote, @Nullable String packageName, boolean useUsapPool, int zygotePolicyFlags, boolean isTopApp, @Nullable long[] disabledCompatChanges, @Nullable Map<String, Pair<String, Long>> Loading Loading @@ -692,7 +750,7 @@ public class ZygoteProcess { // The USAP pool can not be used if the application will not use the systems graphics // driver. If that driver is requested use the Zygote application start path. return zygoteSendArgsAndGetResult(openZygoteSocketIfNeeded(abi), useUsapPool, zygotePolicyFlags, argsForZygote); } } Loading Loading @@ -722,6 +780,10 @@ public class ZygoteProcess { private long mLastPropCheckTimestamp = 0; private boolean fetchUsapPoolEnabledPropWithMinInterval() { // If this Zygote doesn't support USAPs there is no need to fetch any // properties. if (!mUsapPoolSupported) return false; final long currentTimestamp = SystemClock.elapsedRealtime(); if (mIsFirstPropCheck Loading Loading @@ -1219,7 +1281,7 @@ public class ZygoteProcess { gids, runtimeFlags, 0 /* mountExternal */, 0 /* targetSdkVersion */, seInfo, abi, instructionSet, null /* appDataDir */, null /* invokeWith */, true /* startChildZygote */, null /* packageName */, false /* useUsapPool */, false /* isTopApp */, ZYGOTE_POLICY_FLAG_SYSTEM_PROCESS /* zygotePolicyFlags */, false /* isTopApp */, null /* disabledCompatChanges */, null /* pkgDataInfoMap */, extraArgs); } catch (ZygoteStartFailedEx ex) { throw new RuntimeException("Starting child-zygote through Zygote failed", ex); Loading
services/core/java/com/android/server/am/ActiveServices.java +4 −1 Original line number Diff line number Diff line Loading @@ -24,6 +24,7 @@ import static android.os.Process.NFC_UID; import static android.os.Process.ROOT_UID; import static android.os.Process.SHELL_UID; import static android.os.Process.SYSTEM_UID; import static android.os.Process.ZYGOTE_POLICY_FLAG_EMPTY; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_BACKGROUND_CHECK; import static com.android.server.am.ActivityManagerDebugConfig.DEBUG_FOREGROUND_SERVICE; Loading Loading @@ -2937,8 +2938,10 @@ public final class ActiveServices { // Not running -- get it started, and enqueue this service record // to be executed when the app comes up. if (app == null && !permissionsReviewRequired) { // TODO (chriswailes): Change the Zygote policy flags based on if the launch-for-service // was initiated from a notification tap or not. if ((app=mAm.startProcessLocked(procName, r.appInfo, true, intentFlags, hostingRecord, false, isolated, false)) == null) { hostingRecord, ZYGOTE_POLICY_FLAG_EMPTY, false, isolated, false)) == null) { String msg = "Unable to launch app " + r.appInfo.packageName + "/" + r.appInfo.uid + " for service " Loading
services/core/java/com/android/server/am/ActivityManagerService.java +37 −22 Original line number Diff line number Diff line Loading @@ -65,6 +65,10 @@ import static android.os.Process.SHELL_UID; import static android.os.Process.SIGNAL_USR1; import static android.os.Process.SYSTEM_UID; import static android.os.Process.THREAD_PRIORITY_FOREGROUND; import static android.os.Process.ZYGOTE_POLICY_FLAG_BATCH_LAUNCH; import static android.os.Process.ZYGOTE_POLICY_FLAG_EMPTY; import static android.os.Process.ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE; import static android.os.Process.ZYGOTE_POLICY_FLAG_SYSTEM_PROCESS; import static android.os.Process.ZYGOTE_PROCESS; import static android.os.Process.getTotalMemory; import static android.os.Process.isThreadInProcess; Loading Loading @@ -3054,7 +3058,7 @@ public class ActivityManagerService extends IActivityManager.Stub info.targetSdkVersion = Build.VERSION.SDK_INT; ProcessRecord proc = mProcessList.startProcessLocked(processName, info /* info */, false /* knownToBeDead */, 0 /* intentFlags */, sNullHostingRecord /* hostingRecord */, sNullHostingRecord /* hostingRecord */, ZYGOTE_POLICY_FLAG_EMPTY, true /* allowWhileBooting */, true /* isolated */, uid, true /* keepIfLarge */, abiOverride, entryPoint, entryPointArgs, crashHandler); Loading @@ -3065,12 +3069,12 @@ public class ActivityManagerService extends IActivityManager.Stub @GuardedBy("this") final ProcessRecord startProcessLocked(String processName, ApplicationInfo info, boolean knownToBeDead, int intentFlags, HostingRecord hostingRecord, boolean allowWhileBooting, HostingRecord hostingRecord, int zygotePolicyFlags, boolean allowWhileBooting, boolean isolated, boolean keepIfLarge) { return mProcessList.startProcessLocked(processName, info, knownToBeDead, intentFlags, hostingRecord, allowWhileBooting, isolated, 0 /* isolatedUid */, keepIfLarge, null /* ABI override */, null /* entryPoint */, null /* entryPointArgs */, null /* crashHandler */); hostingRecord, zygotePolicyFlags, allowWhileBooting, isolated, 0 /* isolatedUid */, keepIfLarge, null /* ABI override */, null /* entryPoint */, null /* entryPointArgs */, null /* crashHandler */); } boolean isAllowedWhileBooting(ApplicationInfo ai) { Loading Loading @@ -4953,7 +4957,8 @@ public class ActivityManagerService extends IActivityManager.Stub } catch (RemoteException e) { app.resetPackageList(mProcessStats); mProcessList.startProcessLocked(app, new HostingRecord("link fail", processName)); new HostingRecord("link fail", processName), ZYGOTE_POLICY_FLAG_EMPTY); return false; } Loading Loading @@ -5372,7 +5377,9 @@ public class ActivityManagerService extends IActivityManager.Stub for (int ip=0; ip<NP; ip++) { if (DEBUG_PROCESSES) Slog.v(TAG_PROCESSES, "Starting process on hold: " + procs.get(ip)); mProcessList.startProcessLocked(procs.get(ip), new HostingRecord("on-hold")); mProcessList.startProcessLocked(procs.get(ip), new HostingRecord("on-hold"), ZYGOTE_POLICY_FLAG_BATCH_LAUNCH); } } if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL) { Loading Loading @@ -7225,7 +7232,8 @@ public class ActivityManagerService extends IActivityManager.Stub cpr.appInfo, false, 0, new HostingRecord("content provider", new ComponentName(cpi.applicationInfo.packageName, cpi.name)), false, false, false); cpi.name)), ZYGOTE_POLICY_FLAG_EMPTY, false, false, false); checkTime(startTime, "getContentProviderImpl: after start process"); if (proc == null) { Slog.w(TAG, "Unable to launch app " Loading Loading @@ -7785,7 +7793,8 @@ public class ActivityManagerService extends IActivityManager.Stub .getPersistentApplications(STOCK_PM_FLAGS | matchFlags).getList(); for (ApplicationInfo app : apps) { if (!"android".equals(app.packageName)) { addAppLocked(app, null, false, null /* ABI override */); addAppLocked(app, null, false, null /* ABI override */, ZYGOTE_POLICY_FLAG_BATCH_LAUNCH); } } } catch (RemoteException ex) { Loading Loading @@ -8056,23 +8065,25 @@ public class ActivityManagerService extends IActivityManager.Stub @GuardedBy("this") final ProcessRecord addAppLocked(ApplicationInfo info, String customProcess, boolean isolated, String abiOverride) { String abiOverride, int zygotePolicyFlags) { return addAppLocked(info, customProcess, isolated, false /* disableHiddenApiChecks */, false /* mountExtStorageFull */, abiOverride); false /* mountExtStorageFull */, abiOverride, zygotePolicyFlags); } @GuardedBy("this") final ProcessRecord addAppLocked(ApplicationInfo info, String customProcess, boolean isolated, boolean disableHiddenApiChecks, boolean mountExtStorageFull, String abiOverride) { boolean disableHiddenApiChecks, boolean mountExtStorageFull, String abiOverride, int zygotePolicyFlags) { return addAppLocked(info, customProcess, isolated, disableHiddenApiChecks, false /* disableTestApiChecks */, mountExtStorageFull, abiOverride); false /* disableTestApiChecks */, mountExtStorageFull, abiOverride, zygotePolicyFlags); } // TODO: Move to ProcessList? @GuardedBy("this") final ProcessRecord addAppLocked(ApplicationInfo info, String customProcess, boolean isolated, boolean disableHiddenApiChecks, boolean disableTestApiChecks, boolean mountExtStorageFull, String abiOverride) { boolean mountExtStorageFull, String abiOverride, int zygotePolicyFlags) { ProcessRecord app; if (!isolated) { app = getProcessRecordLocked(customProcess != null ? customProcess : info.processName, Loading Loading @@ -8107,7 +8118,8 @@ public class ActivityManagerService extends IActivityManager.Stub mPersistentStartingProcesses.add(app); mProcessList.startProcessLocked(app, new HostingRecord("added application", customProcess != null ? customProcess : app.processName), disableHiddenApiChecks, disableTestApiChecks, mountExtStorageFull, abiOverride); zygotePolicyFlags, disableHiddenApiChecks, disableTestApiChecks, mountExtStorageFull, abiOverride); } return app; Loading Loading @@ -14614,7 +14626,8 @@ public class ActivityManagerService extends IActivityManager.Stub mProcessList.addProcessNameLocked(app); app.pendingStart = false; mProcessList.startProcessLocked(app, new HostingRecord("restart", app.processName)); new HostingRecord("restart", app.processName), ZYGOTE_POLICY_FLAG_EMPTY); return true; } else if (app.pid > 0 && app.pid != MY_PID) { // Goodbye! Loading Loading @@ -14977,7 +14990,7 @@ public class ActivityManagerService extends IActivityManager.Stub ProcessRecord proc = startProcessLocked(app.processName, app, false, 0, new HostingRecord("backup", hostingName), false, false, false); ZYGOTE_POLICY_FLAG_SYSTEM_PROCESS, false, false, false); if (proc == null) { Slog.e(TAG, "Unable to start backup agent process " + r); return false; Loading Loading @@ -16616,7 +16629,8 @@ public class ActivityManagerService extends IActivityManager.Stub } ProcessRecord app = addAppLocked(ai, defProcess, false, disableHiddenApiChecks, disableTestApiChecks, mountExtStorageFull, abiOverride); disableTestApiChecks, mountExtStorageFull, abiOverride, ZYGOTE_POLICY_FLAG_EMPTY); app.setActiveInstrumentation(activeInstr); activeInstr.mFinished = false; activeInstr.mSourceUid = callingUid; Loading Loading @@ -18013,7 +18027,8 @@ public class ActivityManagerService extends IActivityManager.Stub mProcessList.mRemovedProcesses.remove(i); if (app.isPersistent()) { addAppLocked(app.info, null, false, null /* ABI override */); addAppLocked(app.info, null, false, null /* ABI override */, ZYGOTE_POLICY_FLAG_BATCH_LAUNCH); } } } Loading Loading @@ -19220,8 +19235,8 @@ public class ActivityManagerService extends IActivityManager.Stub // preempted by other processes before attaching the process of top app. startProcessLocked(processName, info, knownToBeDead, 0 /* intentFlags */, new HostingRecord(hostingType, hostingName, isTop), false /* allowWhileBooting */, false /* isolated */, true /* keepIfLarge */); ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE, false /* allowWhileBooting */, false /* isolated */, true /* keepIfLarge */); } } finally { Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
services/core/java/com/android/server/am/BroadcastQueue.java +7 −1 Original line number Diff line number Diff line Loading @@ -16,6 +16,9 @@ package com.android.server.am; import static android.os.Process.ZYGOTE_POLICY_FLAG_EMPTY; import static android.os.Process.ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE; import static com.android.server.am.ActivityManagerDebugConfig.*; import android.app.ActivityManager; Loading Loading @@ -1593,7 +1596,9 @@ public final class BroadcastQueue { + receiverUid); } if (brOptions != null && brOptions.getTemporaryAppWhitelistDuration() > 0) { final boolean isActivityCapable = (brOptions != null && brOptions.getTemporaryAppWhitelistDuration() > 0); if (isActivityCapable) { scheduleTempWhitelistLocked(receiverUid, brOptions.getTemporaryAppWhitelistDuration(), r); } Loading Loading @@ -1648,6 +1653,7 @@ public final class BroadcastQueue { info.activityInfo.applicationInfo, true, r.intent.getFlags() | Intent.FLAG_FROM_BACKGROUND, new HostingRecord("broadcast", r.curComponent), isActivityCapable ? ZYGOTE_POLICY_FLAG_LATENCY_SENSITIVE : ZYGOTE_POLICY_FLAG_EMPTY, (r.intent.getFlags()&Intent.FLAG_RECEIVER_BOOT_UPGRADE) != 0, false, false)) == null) { // Ah, this recipient is unavailable. Finish it if necessary, Loading