// line 796-797privatevoidrun(){TimingsTraceAndSlogt=newTimingsTraceAndSlog();//...// line 984-994 调用 startOtherServices 方法try{t.traceBegin("StartServices");startBootstrapServices(t);startCoreServices(t);startOtherServices(t);startApexServices(t);// Only update the timeout after starting all the services so that we use// the default timeout to start system server.updateWatchdogTimeout(t);CriticalEventLog.getInstance().logSystemServerStarted();}catch(Throwableex){
// line 1513-1518/** * Starts a miscellaneous grab bag of stuff that has yet to be refactored and organized. */privatevoidstartOtherServices(@NonNullTimingsTraceAndSlogt){t.traceBegin("startOtherServices");mSystemServiceManager.updateOtherServicesStartIndex();//...// line 3217-3223 调用 mActivityManagerService.systemReady// 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(()->{Slog.i(TAG,"Making services ready");
// line 8970-8975/** * Ready. Set. Go! */publicvoidsystemReady(finalRunnablegoingCallback,@NonNullTimingsTraceAndSlogt){t.traceBegin("PhaseActivityManagerReady");mSystemServiceManager.preSystemReady();//...// line 9129-9139 调用 mAtmInternal.startHomeOnAllDisplaysbooleanisBootingSystemUser=currentUserId==UserHandle.USER_SYSTEM;// Some systems - like automotive - will explicitly unlock system user then switch// to a secondary user.// TODO(b/266158156): this workaround shouldn't be necessary once we move// the headless-user start logic to UserManager-land.if(isBootingSystemUser&&!UserManager.isHeadlessSystemUserMode()){t.traceBegin("startHomeOnAllDisplays");mAtmInternal.startHomeOnAllDisplays(currentUserId,"systemReady");t.traceEnd();}
// line 6038finalclassLocalServiceextendsActivityTaskManagerInternal{// line 6636-6641@OverridepublicbooleanstartHomeOnAllDisplays(intuserId,Stringreason){synchronized(mGlobalLock){returnmRootWindowContainer.startHomeOnAllDisplays(userId,reason);}}
// line 1296-1303booleanstartHomeOnAllDisplays(intuserId,Stringreason){booleanhomeStarted=false;for(inti=getChildCount()-1;i>=0;i--){finalintdisplayId=getChildAt(i).mDisplayId;homeStarted|=startHomeOnDisplay(userId,reason,displayId);}returnhomeStarted;}// line 1315-1321booleanstartHomeOnDisplay(intuserId,Stringreason,intdisplayId){returnstartHomeOnDisplay(userId,reason,displayId,false/* allowInstrumenting */,false/* fromHomeKey */);}booleanstartHomeOnDisplay(intuserId,Stringreason,intdisplayId,booleanallowInstrumenting,booleanfromHomeKey){// line 1328-1333finalDisplayContentdisplay=getDisplayContentOrCreate(displayId);returndisplay.reduceOnAllTaskDisplayAreas((taskDisplayArea,result)->result|startHomeOnTaskDisplayArea(userId,reason,taskDisplayArea,allowInstrumenting,fromHomeKey),false/* initValue */);}// line 1346-1347booleanstartHomeOnTaskDisplayArea(intuserId,Stringreason,TaskDisplayAreataskDisplayArea,booleanallowInstrumenting,booleanfromHomeKey){// line 1402-1403mService.getActivityStartController().startHomeActivity(homeIntent,aInfo,myReason,taskDisplayArea);
// line 1346-1347booleanstartHomeOnTaskDisplayArea(intuserId,Stringreason,TaskDisplayAreataskDisplayArea,booleanallowInstrumenting,booleanfromHomeKey){// line 1363-1370IntenthomeIntent=null;ActivityInfoaInfo=null;if(taskDisplayArea==getDefaultTaskDisplayArea()||mWmService.shouldPlacePrimaryHomeOnDisplay(taskDisplayArea.getDisplayId(),userId)){homeIntent=mService.getHomeIntent();aInfo=resolveHomeActivity(userId,homeIntent);}elseif(shouldPlaceSecondaryHomeOnDisplayArea(taskDisplayArea)){
// line 564-567/** Used to control how we initialize the service. */ComponentNamemTopComponent;StringmTopAction=Intent.ACTION_MAIN;StringmTopData;// line 5609-5617IntentgetHomeIntent(){Intentintent=newIntent(mTopAction,mTopData!=null?Uri.parse(mTopData):null);intent.setComponent(mTopComponent);intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);if(mFactoryTest!=FactoryTest.FACTORY_TEST_LOW_LEVEL){intent.addCategory(Intent.CATEGORY_HOME);}returnintent;}
// line 1413-1443ActivityInforesolveHomeActivity(intuserId,IntenthomeIntent){finalintflags=ActivityManagerService.STOCK_PM_FLAGS;finalComponentNamecomp=homeIntent.getComponent();ActivityInfoaInfo=null;try{if(comp!=null){// Factory test.aInfo=AppGlobals.getPackageManager().getActivityInfo(comp,flags,userId);}else{finalStringresolvedType=homeIntent.resolveTypeIfNeeded(mService.mContext.getContentResolver());finalResolveInfoinfo=mTaskSupervisor.resolveIntent(homeIntent,resolvedType,userId,flags,Binder.getCallingUid(),Binder.getCallingPid());if(info!=null){aInfo=info.activityInfo;}}}catch(RemoteExceptione){// ignore}if(aInfo==null){Slogf.wtf(TAG,newException(),"No home screen found for %s and user %d",homeIntent,userId);returnnull;}aInfo=newActivityInfo(aInfo);aInfo.applicationInfo=mService.getAppInfoForUser(aInfo.applicationInfo,userId);returnaInfo;}aInfo=newActivityInfo(aInfo);aInfo.applicationInfo=mService.getAppInfoForUser(aInfo.applicationInfo,userId);returnaInfo;}
// line 1346-1347booleanstartHomeOnTaskDisplayArea(intuserId,Stringreason,TaskDisplayAreataskDisplayArea,booleanallowInstrumenting,booleanfromHomeKey){// line 1389-1403// Updates the home component of the intent.homeIntent.setComponent(newComponentName(aInfo.applicationInfo.packageName,aInfo.name));homeIntent.setFlags(homeIntent.getFlags()|FLAG_ACTIVITY_NEW_TASK);// Updates the extra information of the intent.if(fromHomeKey){homeIntent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY,true);}homeIntent.putExtra(WindowManagerPolicy.EXTRA_START_REASON,reason);// Update the reason for ANR debugging to verify if the user activity is the one that// actually launched.finalStringmyReason=reason+":"+userId+":"+UserHandle.getUserId(aInfo.applicationInfo.uid)+":"+taskDisplayArea.getDisplayId();mService.getActivityStartController().startHomeActivity(homeIntent,aInfo,myReason,taskDisplayArea);
// line 167-185voidstartHomeActivity(Intentintent,ActivityInfoaInfo,Stringreason,TaskDisplayAreataskDisplayArea){if(mHomeLaunchingTaskDisplayAreas.contains(taskDisplayArea)){Slog.e(TAG,"Abort starting home on "+taskDisplayArea+" recursively.");return;}finalActivityOptionsoptions=ActivityOptions.makeBasic();options.setLaunchWindowingMode(WINDOWING_MODE_FULLSCREEN);if(!ActivityRecord.isResolverActivity(aInfo.name)){// The resolver activity shouldn't be put in root home task because when the// foreground is standard type activity, the resolver activity should be put on the// top of current foreground instead of bring root home task to front.options.setLaunchActivityType(ACTIVITY_TYPE_HOME);}finalintdisplayId=taskDisplayArea.getDisplayId();options.setLaunchDisplayId(displayId);options.setLaunchTaskDisplayArea(taskDisplayArea.mRemoteToken.toWindowContainerToken());// The home activity will be started later, defer resuming to avoid unnecessary operations// (e.g. start home recursively) when creating root home task.mSupervisor.beginDeferResume();finalTaskrootHomeTask;try{// Make sure root home task exists on display area.rootHomeTask=taskDisplayArea.getOrCreateRootHomeTask(ON_TOP);}finally{mSupervisor.endDeferResume();}try{mHomeLaunchingTaskDisplayAreas.add(taskDisplayArea);mLastHomeActivityStartResult=obtainStarter(intent,"startHomeActivity: "+reason).setOutActivity(tmpOutRecord).setCallingUid(0).setActivityInfo(aInfo).setActivityOptions(options.toBundle(),Binder.getCallingPid(),Binder.getCallingUid()).execute();