Android 5.1 ActivityManagerService启动

本文详细介绍了Android 5.1中ActivityManagerService的启动过程,包括其主要功能如启动或结束应用进程、管理Activity生命周期、Broadcast Receiver注册与分发等。在SystemServer启动时,ActivityManagerService逐步启动,具体步骤涵盖多个阶段,如发送ACTION_PRE_BOOT_COMPLETE广播、清理持久进程、读取Settings配置、启动SystemUI、启动persistent应用和home,并最终发送ACTION_BOOT_COMPLETE广播。
摘要由CSDN通过智能技术生成

ActivityManager主要功能有:

①启动或杀死应用程序进程。

②启动调度Activyty生命周期。

③注册Broadcast Receiver,接收分发Broadcast。

④启动发布Content Provocer。

⑤task相关。

⑥OOM。


ActivityManagerService是在SystemServer启动过程中启动的,代码如下。


private void startBootstrapServices() {
        // Wait for installd to finish starting up so that it has a chance to
        // create critical directories such as /data/user with the appropriate
        // permissions.  We need this to complete before we initialize other services.
        Installer installer = mSystemServiceManager.startService(Installer.class);

        // Activity manager runs the show.
        //①启动Liifcycle,进而启动ActivityManagerService
        mActivityManagerService = mSystemServiceManager.startService(
                ActivityManagerService.Lifecycle.class).getService();
        mActivityManagerService.setSystemServiceManager(mSystemServiceManager);
        mActivityManagerService.setInstaller(installer);
        ……
      // Set up the Application instance for the system process and get started.
        //②调用setSystemProcess()方法。
        mActivityManagerService.setSystemProcess();
        ……
        private void startOtherServices() {
            final Context context = mSystemContext;
            AccountManagerService accountManager = null;
            ContentService contentService = null;
            VibratorService vibrator = null;
             ……
            Slog.i(TAG, "System Content Providers");
            //③调用installSystemProviders方法。
            mActivityManagerService.installSystemProviders();
            ……
            //④调用systemReday方法
             mActivityManagerService.systemReady(new Runnable() {
            @Override
            public void run() {
                Slog.i(TAG, "Making services ready");
                mSystemServiceManager.startBootPhase(
                        SystemService.PHASE_ACTIVITY_MANAGER_READY);

                try {
                    mActivityManagerService.startObservingNativeCrashes();
                } catch (Throwable e) {
                    reportWtf("observing native crashes", e);
                }

                Slog.i(TAG, "WebViewFactory preparation");
                WebViewFactory.prepareWebViewInSystemServer();

                try {
                    startSystemUi(context);
                } catch (Throwable e) {
                    reportWtf("starting System UI", e);
                }
                try {
                    if (networkScoreF != null) networkScoreF.systemReady();
                } catch (Throwable e) {
                    reportWtf("making Network Score Service ready", e);
                }

下面详细分析每个步骤。

1.第一阶段,启动ActivityManagerService。

mActivityManagerService = mSystemServiceManager.startService(
                ActivityManagerService.Lifecycle.class).getService();
        //通过反射获取到会启动ActivityManagerService构造方法。
    }
 public ActivityManagerService(Context systemContext) {
        mContext = systemContext;
        mFactoryTest = FactoryTest.getMode();
        mSystemThread = ActivityThread.currentActivityThread();

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值