开机第一次启动

SystemServer进程是zygote孵化进程fork出的第一个进程。

SystemServer的main函数首先做一些虚拟机相关的初始化工作,然后调用初始化函数,该函数首先创建一个线程,启动各种服务线程,包括:电源管理,ams,wms,震动,蓝牙,网络,定位等服务,其中ams:

ams启动过程:

  1. public void setSystemProcess()
  2. public final void installSystemProviders()
  3. public void systemReady(final Runnable goingCallback)

ams的systemReader最后有:
mStackSupervisor.resumeFocusedStackTopActivityLocked();
由于系统刚启动时,队列中中无任何activity对象,那么将调用ActivityStack的:

 private boolean resumeTopActivityInnerLocked(ActivityRecord prev, ActivityOptions options)
// Find the first activity that is not finishing.
        final ActivityRecord next = topRunningActivityLocked();
if (next == null) {
           ...
            // Let's just start up the Launcher...
            ActivityOptions.abort(options);
            if (DEBUG_STATES) Slog.d(TAG_STATES,
                    "resumeTopActivityLocked: No more activities go home");
            if (DEBUG_STACK) mStackSupervisor.validateTopActivitiesLocked();
            // Only resume home if on home display
            return isOnHomeDisplay() &&
                    mStackSupervisor.resumeHomeStackTask(returnTaskType, prev, reason);
        }
boolean resumeHomeStackTask(int homeStackTaskType, ActivityRecord prev, String reason) {
        if (!mService.mBooting && !mService.mBooted) {
            // Not ready yet!
            return false;
        }

        if (homeStackTaskType == RECENTS_ACTIVITY_TYPE) {
            mWindowManager.showRecentApps(false /* fromHome */);
            return false;
        }

        if (prev != null) {
            prev.task.setTaskToReturnTo(APPLICATION_ACTIVITY_TYPE);
        }

        mHomeStack.moveHomeStackTaskToTop(homeStackTaskType);
        ActivityRecord r = getHomeActivity();
        final String myReason = reason + " resumeHomeStackTask";

        // Only resume home activity if isn't finishing.
        if (r != null && !r.finishing) {
            mService.setFocusedActivityLocked(r, myReason);
            return resumeFocusedStackTopActivityLocked(mHomeStack, prev, null);
        }
        return mService.startHomeActivityLocked(mCurrentUser, myReason);
    }

然后,在startHomeActivtyLocked()中,发intent:

intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
        if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
            intent.addCategory(Intent.CATEGORY_HOME);
        }

无论哪个应用程序,只要声明自己能够响应该intent,就会被认为是home程序。

你可能感兴趣的:(开机第一次启动)