標籤: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 傳統型程式啟動分析