step1: ZygoteInit.java/startSystemServer
call pid = Zygote.forkSystemServer(
parsedArgs.uid, parsedArgs.gid,
parsedArgs.gids, debugFlags, null,
parsedArgs.permittedCapabilities,
parsedArgs.effectiveCapabilities) fork出system进程, call handleSystemServerProcess(parsedArgs)处理执行System进程。
step2: ZygoteInit.java/handleSystemServerProcess
call closeServerSocket()关掉socket,call RuntimeInit.zygoteInit(parsedArgs.remainingArgs)处理后续启动。
step3: RuntimeInit.java/zygoteInit
call commonInit()初始化键盘,call zygoteInitNative()启动binder线程池,call invokeStaticMain(startClass, startArgs)处理。
step4: RuntimeInit.java/invokeStaticMain()
call Class.forName(className)加载systemserver.java, call throw new ZygoteInit.MethodAndArgsCaller(m, argv)抛出一个异常进入systemserver中的main方法。
step5: SystemServer.java/main()
call init1(args)进入com_android_server_SystemServer.cpp中的android_server_SystemServer_init1()进行第一级初始化.
step6: System_init.cpp/system_init()
call SurfaceFlinger::instantiate()启动SurfaceFlinger, call SensorService::instantiate();启动传感器, call runtime->callStatic("com/android/server/SystemServer", "init2") call SystemServer.java中init2(),最后把主线程加入binder线程池中.
step7:SystemServer.java/init2()
call Thread thr = new ServerThread()启动一个线程来注册关键Services.
step8: SystemServer.java/run()
call Looper.prepare()来创建一个消息队列, call ServiceManager.addService()启动需要的service,最后call Looper.loop()进入消息循环中等待队列的事件。