ActivityManagerService 启动
BootRoom -----> Boot
企业微信截图_16467247018996.png
AMS
- 管理四大组件的生命周期
AMS 启动
SystemServer 在zygote进程启动后,zygote直接fork一个进程,启动SystemServer, SystemServer进入main方法开始执行,在SystemServier的main方法中, 执行了SystemServer.run()方法。
public static void main(String[] args) {
new SystemServer().run();
}
SystemServer.run()
// Start services.
try {
startBootstrapServices(); //启动一些 boot进程 , 在这里第一次开启了ActivtyManagerService ,这里还会将当前进程设置为System进程
startCoreServices(); //启动一些核心进程
startOtherServices(); //启动其他服务
} catch (Throwable ex) {
Slog.e("System", "******************************************");
Slog.e("System", "************ Failure starting system services", ex);
throw ex;
}
Looper.loop(); //启动looper循环,保证当前线程不会停止
进入 startBootstrapService
private void startBootstrapServices() {
// Wait for installd to finish starting up so that it has a chance to
// create critical directories such as /data/user with the appropriate
// permissions. We need this to complete before we initialize other services.
Installer installer = mSystemServiceManager.startService(Installer.class);
// Activity manager runs the show.
mActivityManagerService = mSystemServiceManager.startService(
ActivityManagerService.Lifecycle.class).getService();
mActivityManagerService.setSystemServiceManager(mSystemServiceManager);
mActivityManagerService.setInstaller(installer);
在SystemServer.run中,最后所有service启动之后:
mActivityManagerService.systemReady(new Runnable() { //这里会执行一系列方法,通知其他服务,当前系统启动完成
mSystemServiceManager.startBootPhase(
SystemService.PHASE_ACTIVITY_MANAGER_READY);
try {
mActivityManagerService.startObservingNativeCrashes();
} catch (Throwable e) {
reportWtf("observing native crashes", e);
}
Slog.i(TAG, "WebViewFactory preparation");
WebViewFactory.prepareWebViewInSystemServer();
try {
startSystemUi(context);
} catch (Throwable e) {
reportWtf("starting System UI", e);
}
try {
if (networkScoreF != null) networkScoreF.systemReady();
} catch (Throwable e) {
reportWtf("making Network Score Service ready", e);
}
... //剩余的就不在进行表述
}
AMS.systemReady()
AMS.systemReady() 方法中,会调用startHomeActiivtyLocked.();
SystemServer中将当前服务准备完成之后,调用systemReady方法来启动Launcher
来看 startHomeActivityLocked
boolean startHomeActivityLocked(int userId, String reason) {
...
Intent intent = getHomeIntent(); //获取当前应用的HomeIntent
ActivityInfo aInfo =
resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
if (aInfo != null) {
intent.setComponent(new ComponentName(
aInfo.applicationInfo.packageName, aInfo.name));
// Don't do this if the home app is currently being
// instrumented.
aInfo = new ActivityInfo(aInfo);
aInfo.applicationInfo = getAppInfoForUser(aInfo.applicationInfo, userId);
ProcessRecord app = getProcessRecordLocked(aInfo.processName,
aInfo.applicationInfo.uid, true);
if (app == null || app.instrumentationClass == null) {
intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
mStackSupervisor.startHomeActivity(intent, aInfo, reason);
}
}
return true;
}
到这里就属于Activity的启动流程了
网友评论