android 系统启动流程
- 加载BootLoader引导程序,启动init.cpp, 解析init.rc配置文件
- 启动zygote孵化器进程,
1、启动虚拟机和注册JNI方法
2、注册Socket服务端、预加载系统资源文件
3、执行runSleepLoop等待其他进程注册 - 启动SystemServer进程,通过Zygote孵化器进程fork出来,创建Biner线程池,执行main方法,创建系统上下文,启动三个系统服务(引导、核心、其他)
在startBootstrapServices中启动AMS、PMS等引导服务,其中PMS主要作用是系统中的APK的解析和安装;AMS主要用于四大组件的启动 和管理,因此LauncherActivity通过AMS启动,startOtherServices开启启动其他服务中启动Launcher的入口为AMS的systemReady方法,
/**
* Ready. Set. Go!
*/
public void systemReady(final Runnable goingCallback, @NonNull TimingsTraceAndSlog t) {
...
mAtmInternal.startHomeOnAllDisplays(currentUserId, "systemReady");
...
}
ActivityTaskManagerService.startHomeOnAllDisplays->RootWindowContainer.startHomeOnDisplay-> startHomeOnTaskDisplayArea->
boolean startHomeOnTaskDisplayArea(int userId, String reason, TaskDisplayArea taskDisplayArea,
boolean allowInstrumenting, boolean fromHomeKey) {
// Fallback to top focused display area if the provided one is invalid.
if (taskDisplayArea == null) {
final Task rootTask = getTopDisplayFocusedRootTask();
taskDisplayArea = rootTask != null ? rootTask.getDisplayArea()
: getDefaultTaskDisplayArea();
}
Intent homeIntent = null;
ActivityInfo aInfo = null;
if (taskDisplayArea == getDefaultTaskDisplayArea()) {
// 将会返回附带Intent.CATEGORY_HOME属性的Intent,方面后续从系统的AndroidManifest.xml中查找对应的Activity。
homeIntent = mService.getHomeIntent();
// resolveActivityInfo()这里将会查找出桌面Activity,然后返回ActivityInfo对象
aInfo = resolveHomeActivity(userId, homeIntent);
} else if (shouldPlaceSecondaryHomeOnDisplayArea(taskDisplayArea)) {
Pair<ActivityInfo, Intent> info = resolveSecondaryHomeActivity(userId, taskDisplayArea);
aInfo = info.first;
homeIntent = info.second;
}
if (aInfo == null || homeIntent == null) {
return false;
}
if (!canStartHomeOnDisplayArea(aInfo, taskDisplayArea, allowInstrumenting)) {
return false;
}
// Updates the home component of the intent.
homeIntent.setComponent(new ComponentName(aInfo.applicationInfo.packageName, aInfo.name));
homeIntent.