Android启动流程分析(十二) SystemServer

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;
604
605        try {
606            parsedArgs = new ZygoteConnection.Arguments(args);
607            ZygoteConnection.applyDebuggerSystemProperty(parsedArgs);
608            ZygoteConnection.applyInvokeWithSystemProperty(parsedArgs);
609
610            /* 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        }
621
622        /* For child process */
623        if (pid == 0) {  // 在孵化出来的子进程里面
624            if (hasSecondZygote(abiList)) {
625                waitForSecondaryZygote(socketName);
626            }
627
628            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中的各个关键进程进行详细的分析。

 

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值