// We now tell the activity manager it is okay to run third party // code. It will call back into us once it has gotten to the state // where third party code can really run (but before it has actually // started launching the initial applications), for us to complete our // initialization. mActivityManagerService.systemReady(newRunnable() { @Override publicvoidrun() { .... try { startSystemUi(context); } catch (Throwable e) { reportWtf("starting System UI", e); } ... }); }
publicvoidsystemReady(final Runnable goingCallback) { synchronized(this) { //第一次为false不会进入 if (mSystemReady) { // If we're done calling all the receivers, run the next "boot phase" passed in // by the SystemServer if (goingCallback != null) { goingCallback.run(); } return; }
.... mSystemReady = true; }
...
synchronized(this) { // Make sure we have no pre-ready processes sitting around.
if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL) { .... } }
... //执行传入的Runnable对象 if (goingCallback != null) goingCallback.run();
...
synchronized (this) { // Only start up encryption-aware persistent apps; once user is // unlocked we'll come back around and start unaware apps startPersistentApps(PackageManager.MATCH_DIRECT_BOOT_AWARE);
// Start up initial activity. mBooting = true; // Enable home activity for system user, so that the system can always boot ... //启动Lanucher的主Activity startHomeActivityLocked(currentUserId, "systemReady");
booleanstartHomeActivityLocked(int userId, String reason) { if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL && mTopAction == null) { // We are running in factory test mode, but unable to find // the factory test app, so just sit around displaying the // error message and don't try to start anything. returnfalse; } //构建启动Lanucher主Activity的Intent对象 Intentintent= getHomeIntent(); ActivityInfoaInfo= resolveActivityInfo(intent, STOCK_PM_FLAGS, userId); if (aInfo != null) { intent.setComponent(newComponentName(aInfo.applicationInfo.packageName, aInfo.name)); // Don't do this if the home app is currently being // instrumented. aInfo = newActivityInfo(aInfo); aInfo.applicationInfo = getAppInfoForUser(aInfo.applicationInfo, userId); ProcessRecordapp= getProcessRecordLocked(aInfo.processName, aInfo.applicationInfo.uid, true); if (app == null || app.instrumentationClass == null) { intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK); //启动Lanucher主Activity mActivityStarter.startHomeActivityLocked(intent, aInfo, reason); } } else { Slog.wtf(TAG, "No home screen found for " + intent, newThrowable()); }