首页 > 安全资讯 >

android setupwizard launcher app启动优先级(未验证)

17-07-17

android setupwizard launcher app启动优先级(未验证),记录mainfest priority优先级决定app启动流程。

android setupwizard launcher  app启动优先级(未验证),记录mainfest priority优先级决定app启动流程。

<activity android:name="com.android.setupwizard.activity.DefaultMainActivity">
    <intent-filter android:priority="1">
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.HOME" />
        <category android:name="android.intent.category.LAUNCHER" />
    intent-filter>
activity>

app 启动为:

ActivityManagerService.java 
>>startHomeActivityLocked();

决定启动哪个app

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;
}
>>>   systemReady  
if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL) { ResolveInfo ri = mContext.getPackageManager() .resolveActivity(new Intent(Intent.ACTION_FACTORY_TEST), STOCK_PM_FLAGS); CharSequence errorMsg = null; if (ri != null) { ActivityInfo ai = ri.activityInfo; ApplicationInfo app = ai.applicationInfo; if ((app.flags&ApplicationInfo.FLAG_SYSTEM) != 0) { mTopAction = Intent.ACTION_FACTORY_TEST; mTopData = null; mTopComponent = new ComponentName(app.packageName, ai.name); } else { errorMsg = mContext.getResources().getText( com.android.internal.R.string.factorytest_not_system); } } 
>> 
mTopComponent >> 
mContext.getPackageManager() .resolveActivity
>>>ContextImpl.java
>>> resolveActivity
>>>  mPM.resolveIntent
PackageManagerService.java  resolveIntent
>>>chooseBestActivity 可以看到选择优先级的问题
private ResolveInfo chooseBestActivity(Intent intent, String resolvedType, int flags, List query, int userId) { if (query != null) { final int N = query.size(); if (N == 1) { return query.get(0); } else if (N > 1) { final boolean debug = ((intent.getFlags() & Intent.FLAG_DEBUG_LOG_RESOLUTION) != 0); // If there is more than one activity with the same priority,  // then let the user decide between them.  ResolveInfo r0 = query.get(0); ResolveInfo r1 = query.get(1); if (DEBUG_INTENT_MATCHING || debug) { Slog.v(TAG, r0.activityInfo.name + "=" + r0.priority + " vs "  + r1.activityInfo.name + "=" + r1.priority); } // If the first activity has a higher priority, or a different  // default, then it is always desirable to pick it.  if (r0.priority != r1.priority  || r0.preferredOrder != r1.preferredOrder  || r0.isDefault != r1.isDefault) { return query.get(0); } // If we have saved a preference for a preferred activity for  // this Intent, use that.  ResolveInfo ri = findPreferredActivity(intent, resolvedType, flags, query, r0.priority, true, false, debug, userId); if (ri != null) { return ri; } ri = new ResolveInfo(mResolveInfo); ri.activityInfo = new ActivityInfo(ri.activityInfo); ri.activityInfo.labelRes = ResolverActivity.getLabelRes(intent.getAction()); // If all of the options come from the same package, show the application's  // label and icon instead of the generic resolver's.  // Some calls like Intent.resolveActivityInfo query the ResolveInfo from here  // and then throw away the ResolveInfo itself, meaning that the caller loses  // the resolvePackageName. Therefore the activityInfo.labelRes above provides  // a fallback for this case; we only set the target package's resources on  // the ResolveInfo, not the ActivityInfo.  final String intentPackage = intent.getPackage(); if (!TextUtils.isEmpty(intentPackage) && allHavePackage(query, intentPackage)) { final ApplicationInfo appi = query.get(0).activityInfo.applicationInfo; ri.resolvePackageName = intentPackage; if (userNeedsBadging(userId)) { ri.noResourceId = true; } else { ri.icon = appi.icon; } ri.iconResourceId = appi.icon; ri.labelRes = appi.labelRes; } ri.activityInfo.applicationInfo = new ApplicationInfo( ri.activityInfo.applicationInfo); if (userId != 0) { ri.activityInfo.applicationInfo.uid = UserHandle.getUid(userId, UserHandle.getAppId(ri.activityInfo.applicationInfo.uid)); } // Make sure that the resolver is displayable in car mode  if (ri.activityInfo.metaData == null) ri.activityInfo.metaData = new Bundle(); ri.activityInfo.metaData.putBoolean(Intent.METADATA_DOCK_HOME, true); return ri; } } return null; }
相关文章
最新文章
热点推荐