}
return true;
}
注释1处的mFactoryTest代表系统的运行模式,系统的运行模式分为三种,分别是非工厂模式、低级工厂模式和高级工厂模式,mTopAction则用来描述第一个被启动Activity组件的Action,它的值为Intent.ACTION_MAIN。因此注释1的代码意思就是mFactoryTest为FactoryTest.FACTORY_TEST_LOW_LEVEL(低级工厂模式)并且mTopAction=null时,直接返回false。
注释2处的getHomeIntent函数如下所示。
ActivityManagerService#getHomeIntent()
Intent getHomeIntent() {
Intent intent = new Intent(mTopAction, mTopData != null ? Uri.parse(mTopData) : null); //1
intent.setComponent(mTopComponent);
intent.addFlags(Intent.FLAG_DEBUG_TRIAGED_MISSING);
if (mFactoryTest != FactoryTest.FACTORY_TEST_LOW_LEVEL) {
intent.addCategory(Intent.CATEGORY_HOME); //2
}
return intent;
}
注释1中创建了Intent,并将mTopAction和mTopData传入。mTopAction的值为Intent.ACTION_MAIN。
注释2如果系统运行模式不是低级工厂模式则将intent的Category设置为Intent.CATEGORY_HOME。之后被启动的应用程序就是Launcher,因为Launcher的Manifest文件中的intent-filter标签匹配了Action为Intent.ACTION_MAIN,Category为Intent.CATEGORY_HOME。Launcher的Manifest文件如下所示。
packages/apps/Launcher3/AndroidManifest.xml
…
<application
…
…
ActivityManagerService的startHomeActivityLocked()的注释3就是启动符合条件的应用程序,即Launcher。
frameworks/base/services/core/java/com/android/server/am/ActivityStarter.java
ActivityStarter#startHomeActivityLocked()
void startHomeActivityLocked(Intent intent, ActivityInfo aInfo, String reason) {
mSupervisor.moveHomeStackTaskToTop(HOME_ACTIVITY_TYPE, reason);
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