SMA

2021-08-20  本文已影响0人  细雨么么

1.首先
执行SystemServer的Main函数

  /**
     * The main entry point from zygote.

【参考】https://www.jianshu.com/p/eca67eddb333
     */
    public static void main(String[] args) {
        new SystemServer().run();
    }
      run函数中先生成系统的进程的context【  createSystemContext()】,利用系统context反射生成SystemServerManager对象,启动引导服务、核心服务、及其他服务
    mSystemServiceManager = new SystemServiceManager(mSystemContext);
        LocalServices.addService(SystemServiceManager.class, mSystemServiceManager);

        // Start services.
        try {
            startBootstrapServices();
            startCoreServices();
            startOtherServices();
        } catch (Throwable ex) {
            Slog.e("System", "******************************************");
            Slog.e("System", "************ Failure starting system services", ex);
            throw ex;
        }
    启动引导服务中生成ActivityManagerService,
   mInstaller = mSystemServiceManager.startService(Installer.class);

        // Activity manager runs the show.
        mActivityManagerService = mSystemServiceManager.startService(
                ActivityManagerService.Lifecycle.class).getService();
        mActivityManagerService.setSystemServiceManager(mSystemServiceManager);

        // Power manager needs to be started early because other services need it.
        // Native daemons may be watching for it to be registered so it must be ready
        // to handle incoming binder calls immediately (including being able to verify
        // the permissions for those calls).
        mPowerManagerService = mSystemServiceManager.startService(PowerManagerService.class);

        // Now that the power manager has been started, let the activity manager
        // initialize power management features.
        mActivityManagerService.initPowerManagement();

        // Display manager is needed to provide display metrics before package manager
        // starts up.
        mDisplayManagerService = mSystemServiceManager.startService(DisplayManagerService.class);

        // We need the default display before we can initialize the package manager.
        mSystemServiceManager.startBootPhase(SystemService.PHASE_WAIT_FOR_DEFAULT_DISPLAY);

ActivityManagerService#LifeCycle生成ActivityManageServie对象
ActivityManagerService()

/**
*哈哈 ActivityThread  ServiceThread  ActivityService
*
*/
  mSystemThread = ActivityThread.currentActivityThread();

        Slog.i(TAG, "Memory class: " + ActivityManager.staticGetMemoryClass());

        mHandlerThread = new ServiceThread(TAG,
                android.os.Process.THREAD_PRIORITY_FOREGROUND, false /*allowIo*/);
        mHandlerThread.start();
        mHandler = new MainHandler(mHandlerThread.getLooper());

        mFgBroadcastQueue = new BroadcastQueue(this, mHandler,
                "foreground", BROADCAST_FG_TIMEOUT, false);
        mBgBroadcastQueue = new BroadcastQueue(this, mHandler,
                "background", BROADCAST_BG_TIMEOUT, true);
        mBroadcastQueues[0] = mFgBroadcastQueue;
        mBroadcastQueues[1] = mBgBroadcastQueue;

        mServices = new ActiveServices(this);

Activity 启动流程:
参考:、、https://blog.csdn.net/qq_35540562/article/details/104826151

startActivity 执行的都是StartActivityforResult,调用到Instrumentation 内部execStartActivity,通过Aidl 调用系统进程的Activitymanagerservice(Activitytaskmanagerservice)ActivityTaskManagerService#startActivity 实际调用的是 startActivityAsUser。startActivityAsUser使用 ActivityStarter的 execute。其中execute()中的res = executeRequest(mRequest); 特别重要,内部又调用startAcitivityUnchecked startactivityInner ActvityStack#startActivityLocked
之后调用 mRootWindowContainer.resumeFocusedStacksTopActivities( mTargetStack, mStartActivity, mOptions); 一路到ActivityStack#resumeTopActivityUncheckedLocked resumeTopActivityInnerLocked

上一篇 下一篇

猜你喜欢

热点阅读