从Android Q(10)开始,Google引入了一种新的机制,加快了app的启动时间,具体请看Android Framework | 一种新型的应用启动机制:USAP,本篇将会具体先容USAP 历程启动的流程。
从Activity启动流程 上篇(Android 10),我们得知在Activity启动过程中,我们会调用到\frameworks\base\core\java\android\os\ZygoteProcess.java的start方法,然后调用startViaZygote(),着实在调用startViaZygote()之前尚有一步:
public final Process.ProcessStartResult start(@NonNull final String processClass, final String niceName, int uid, int gid, @Nullable int[] gids, int runtimeFlags, int mountExternal, int targetSdkVersion, @Nullable String seInfo, @NonNull String abi, @Nullable String instructionSet, @Nullable String appDataDir, @Nullable String invokeWith, @Nullable String packageName, boolean useUsapPool, @Nullable String[] zygoteArgs) { // TODO (chriswailes): Is there a better place to check this value? //---------------------------- 就是这里 ---------------------------- if (fetchUsapPoolEnabledPropWithMinInterval()) { informZygotesOfUsapPoolStatus(); } try { return startViaZygote(processClass, niceName, uid, gid, gids, runtimeFlags, mountExternal, targetSdkVersion, seInfo, abi, instructionSet, appDataDir, invokeWith, /*startChildZygote=*/ false, packageName, useUsapPool, zygoteArgs); } catch (ZygoteStartFailedEx ex) { Log.e(LOG_TAG, "Starting VM process through Zygote failed"); throw new RuntimeException( "Starting VM process through Zygote failed", ex); } }从函数名称,我们可以得知,这里用fetchUsapPoolEnabledPropWithMinInterval判断体系是否开启了USAP功能,如果开启则调用informZygotesOfUsapPoolStatus(): |