標籤:systemserver android systemserver android init android啟動流程 framework
#############################################
本文為極度寒冰原創,轉載請註明出處
#############################################
SystemServer也是系統的一個重要的守護進程,從SystemServer的進程中,我們看到了系統的各種關鍵的Service的啟動。
另外,根據前面的zygote的分析,我們知道了systemServer在android的啟動過程中是肯定要啟動的。
因為在init.rc裡面,已經指定了要start-system-server = true.
那麼在zygote中,我們看到了如下的code
if (startSystemServer) { // 如果startSystemServer為true的話,我們會啟動systemServer startSystemServer(abiList, socketName); } 我們看到執行了startSystemServer的函數,那麼我們來看一下這個函數的實現。
603 int pid;604605 try {606 parsedArgs = new ZygoteConnection.Arguments(args);607 ZygoteConnection.applyDebuggerSystemProperty(parsedArgs);608 ZygoteConnection.applyInvokeWithSystemProperty(parsedArgs);609610 /* Request to fork the system server process */611 pid = Zygote.forkSystemServer( // 從這邊我們可以看到,systemServer是由Zygote給孵化出來的一個子進程612 parsedArgs.uid, parsedArgs.gid,613 parsedArgs.gids,614 parsedArgs.debugFlags,615 null,616 parsedArgs.permittedCapabilities,617 parsedArgs.effectiveCapabilities);618 } catch (IllegalArgumentException ex) {619 throw new RuntimeException(ex);620 }621622 /* For child process */623 if (pid == 0) { // 在孵化出來的子進程裡面624 if (hasSecondZygote(abiList)) {625 waitForSecondaryZygote(socketName);626 }627628 handleSystemServerProcess(parsedArgs); // 會執行到handleSystemServerProcess的操作629 }通過上面的內容,我們可以很容易的知道,在system的啟動過程中,是由zygote分裂出來的一個子進程進行處理的。
然後在子進程裡面,執行handSystemServerProcess進行接下來的操作。
那麼,handSystemServerProcess是在做什麼呢?
這個過程我們用一個流程圖來代替吧
相信這個流程圖可以很清晰的表明system的啟動過程,在invokeStaticMain函數後,我們進入到了systemServer的main函數中。
169 public static void main(String[] args) {170 new SystemServer().run();171 }這邊就很簡單易懂了。
在run函數中,通過下面的一些方法,去啟動起來系統的其他關鍵進程。
252 // Start services.253 try {254 startBootstrapServices();255 startCoreServices();256 startOtherServices();257 } catch (Throwable ex) {258 Slog.e("System", "******************************************");259 Slog.e("System", "************ Failure starting system services", ex);260 throw ex;261 }而我們在接下來,會對系統framework中的各個關鍵進程進行詳細的分析。
Android啟動流程分析(十二) SystemServer