android 9.0默认launcher

frameworks\base\services\core\java\com\android\server\am\ActivityManagerService.java

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;
    }
   //默认Launcher add start 
    final PackageManager mPm = mContext.getPackageManager();
    Intent homeIntent = new Intent();
    homeIntent.addCategory(Intent.CATEGORY_HOME);
    homeIntent.setAction(Intent.ACTION_MAIN);
    homeIntent.addCategory(Intent.CATEGORY_DEFAULT);
    ResolveInfo info = mPm.resolveActivity(homeIntent, PackageManager.MATCH_DEFAULT_ONLY);
    if ("com.google.android.setupwizard".equals(info.activityInfo.packageName) || "android".equals(info.activityInfo.packageName)) { //if there is a default Launcher?
        String defaultlauncherpckname="com.wyt.drpan";  //填写apk包名
        String defaultlauncherclsname="com.wyt.drpan.activity.MainActivity";  //填写apk类名
		//setHomeDefault("com.wyt.drpan","com.wyt.drpan.MainActivity");
        ComponentName DefaultLauncher = new ComponentName(defaultlauncherpckname, defaultlauncherclsname);
        ArrayList homeActivities = new ArrayList();
        ComponentName currentDefaultHome = mPm.getHomeActivities(homeActivities);
        ComponentName[] mHomeComponentSet = new ComponentName[homeActivities.size()];
        for (int i = 0; i < homeActivities.size(); i++) {
            final ResolveInfo candidate = homeActivities.get(i);
            Log.d(TAG, "homeActivitie: candidate = " + candidate);
            final ActivityInfo activityInfo = candidate.activityInfo;
            ComponentName activityName = new ComponentName(activityInfo.packageName, activityInfo.name);
            mHomeComponentSet[i] = activityName;
        }
        IntentFilter mHomeFilter = new IntentFilter(Intent.ACTION_MAIN);
        mHomeFilter.addCategory(Intent.CATEGORY_HOME);
        mHomeFilter.addCategory(Intent.CATEGORY_DEFAULT);
        List Activities = new ArrayList();
        mPm.replacePreferredActivity(mHomeFilter, IntentFilter.MATCH_CATEGORY_EMPTY, mHomeComponentSet, DefaultLauncher);
    }

//默认Launcher end
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() | 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;
mActivityStartController.startHomeActivity(intent, aInfo, myReason);
}
} else {
Slog.wtf(TAG, "No home screen found for " + intent, new Throwable());
}

    return true;
}

你可能感兴趣的:(android,9.0)