目录
重拾Android-【吃透源码系列】之Android系统启动(六)SystemServer的启动

源码来自Android 11.0

系统服务入口函数:

/**
* The main entry point from zygote.
*/
public static void main(String[] args) {
new SystemServer().run();
}

private void run() {
TimingsTraceAndSlog t = new TimingsTraceAndSlog();
try {
... 代码省略

// Create the system service manager.
// 创建系统的服务管理者
mSystemServiceManager = new SystemServiceManager(mSystemContext);

... 代码省略
} finally {
t.traceEnd(); // InitBeforeStartServices
}

... 代码省略

// Start services.
try {
// 启动引导服务
startBootstrapServices(t);
// 启动核心服务
startCoreServices(t);
// 启动其他服务
startOtherServices(t);
} catch (Throwable ex) {
Slog.e("System", "******************************************");
Slog.e("System", "************ Failure starting system services", ex);
throw ex;
} finally {
t.traceEnd(); // StartServices
}

... 代码省略

// Loop forever.
Looper.loop();
throw new RuntimeException("Main thread loop unexpectedly exited");
}

SystemServer进程启动服务示意图.png

上述百十种服务启动完成之后,系统就开始通知AMS系统启动完毕可以开始执行桌面系统,也就是Launcher应用。


// 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(() -> {
... 代码省略
}

下一章介绍ActivityManagerService,详细介绍Launcher应用的启动流程。

打赏
  • 微信
  • 支付宝

评论