系统启动流程
Loader
从Boot ROM内存区域读取程序 Boot Loader
拉起Linux系统内核
Kernel
kernel,起来后加载驱动,设置缓存等等,然后拉起系统OS,找init.rc脚本
C++ Framework Native
init(pid=1) 拉起孵化器
Zygote Android Runtime
孵化器,用于复制自己孵化进程
JavaFramework
SystemServer,系统服务,拉起AMS
Apps
Launcher等系统应用拉起
Zygote进程启动
init.rc脚本
解析init.zygote.rc脚本
启动main类型服务,do_class_start()
启动zygote服务,start()
创建Zygote进程,fork()
运行app_main.cpp的main()
首先查看init.rc
先引入其他脚本
SystemServer进程启动
运行app_main.cpp的main()
AndroidRuntime.start() Android环境启动
startVm()
startReg()
ZygoteInit.main()
registerZygoteSocket()
preload()
startSystemServer()
runSelectLoop()
/**
* The main entry point from zygote.
*/
public static void main(String[] args) {
new SystemServer().run();
}
// Start services.
try {
t.traceBegin("StartServices");
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
}
AMS
startBootstrapServices
// TODO: Might need to move after migration to WM.
ActivityTaskManagerService atm = mSystemServiceManager.startService(
ActivityTaskManagerService.Lifecycle.class).getService();
mActivityManagerService = ActivityManagerService.Lifecycle.startService(
mSystemServiceManager, atm);
mActivityManagerService.setSystemServiceManager(mSystemServiceManager);
mActivityManagerService.setInstaller(installer);
SystemServiceManager.startService(string)
SystemServiceManager.startService(Class
constructor.newInstance
SystemServiceManager.starService(SystemService)
添加到mServices
SystemService.onStart
Lifecycle.getService