Android 源碼分析(七) Launcher 傳統型程式啟動分析

來源:互聯網
上載者:User

標籤:ica   通過   msu   tsp   started   開始   進程   pack   isp   

一.前言:

    init進程 –> Zygote進程 –> SystemServer進程 –> Launcher傳統型程式 -> 我們的App應用

    init進程:linux的根進程,android系統是基於linux系統的,因此可以算作是整個android作業系統的第一個進程;

    Zygote進程:android系統的根進程,主要作用:可以作用Zygote進程fork出SystemServer進程和各種應用進程;

    SystemService進程:主要是在這個進程中啟動系統的各項服務,比如ActivityManagerService,PackageManagerService,WindowManagerService服務等等;
    
    Launcher傳統型程式:就是我們平時看到的傳統型程式,它其實也是一個android應用程式,只不過這個應用程式是系統預設第一個啟動的應用程式.
   

  二. Launcher 傳統型程式啟動

        Launcher程式就是我們平時看到的傳統型程式,它其實也是一個android應用程式,只不過這個應用程式是系統預設第一個啟動的應用程式。

  前一篇文章我們知道在SystemServer進程的啟動過程中會調用其main靜態方法,開始執行整個SystemServer的啟動流程。在調用startOtherService方法中就會通過調用mActivityManagerService.systemReady()方法。

//SystemServer.javaprivate void startOtherServices() {    ......         // We now tell the activity manager it is okay to run third party        // code.  It will call back into us once it has gotten to the state        // where third party code can really run (but before it has actually        // started launching the initial applications), for us to complete our        // initialization.        mActivityManagerService.systemReady()    ......}
//ActivityManagerService.javapublic void systemReady(final Runnable goingCallback, BootTimingsTraceLog traceLog) {        ......    startHomeActivityLocked(currentUserId, "systemReady");        ......}boolean startHomeActivityLocked(int userId, String reason) {        if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL                && mTopAction == null) {            // We are running in factory test mode, but unable to find            // the factory test app, so just sit around displaying the            // error message and don‘t try to start anything.            return false;        }        Intent intent = getHomeIntent();        ActivityInfo aInfo = resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);        if (aInfo != null) {            intent.setComponent(new ComponentName(aInfo.applicationInfo.packageName, aInfo.name));            // Don‘t do this if the home app is currently being            // instrumented.            aInfo = new ActivityInfo(aInfo);            aInfo.applicationInfo = getAppInfoForUser(aInfo.applicationInfo, userId);            ProcessRecord app = getProcessRecordLocked(aInfo.processName,                    aInfo.applicationInfo.uid, true);            if (app == null || app.instr == null) {                intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);                final int resolvedUserId = UserHandle.getUserId(aInfo.applicationInfo.uid);                // For ANR debugging to verify if the user activity is the one that actually                // launched.                final String myReason = reason + ":" + userId + ":" + resolvedUserId;                mActivityStarter.startHomeActivityLocked(intent, aInfo, myReason);            }        } else {            Slog.wtf(TAG, "No home screen found for " + intent, new Throwable());        }        return true;    }     Intent getHomeIntent() {        Intent intent = new Intent(mTopAction, mTopData != null ? Uri.parse(mTopData) : null);        intent.setComponent(mTopComponent);        intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);        if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) {            intent.addCategory(Intent.CATEGORY_HOME);        }        return intent;    }
//ActivityStarter.java    void startHomeActivityLocked(Intent intent, ActivityInfo aInfo, String reason) {        mSupervisor.moveHomeStackTaskToTop(reason);        mLastHomeActivityStartResult = startActivityLocked(null /*caller*/, intent,                null /*ephemeralIntent*/, null /*resolvedType*/, aInfo, null /*rInfo*/,                null /*voiceSession*/, null /*voiceInteractor*/, null /*resultTo*/,                null /*resultWho*/, 0 /*requestCode*/, 0 /*callingPid*/, 0 /*callingUid*/,                null /*callingPackage*/, 0 /*realCallingPid*/, 0 /*realCallingUid*/,                0 /*startFlags*/, null /*options*/, false /*ignoreTargetSecurity*/,                false /*componentSpecified*/, mLastHomeActivityStartRecord /*outActivity*/,                null /*container*/, null /*inTask*/, "startHomeActivity: " + reason);        if (mSupervisor.inResumeTopActivity) {            // If we are in resume section already, home activity will be initialized, but not            // resumed (to avoid recursive resume) and will stay that way until something pokes it            // again. We need to schedule another resume.            mSupervisor.scheduleResumeTopActivities();        }    }

  後面就進入了Activity的啟動流程了。

Android 源碼分析(七) Launcher 傳統型程式啟動分析

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.