一、修改ActivityManagerService.java的startHomeActivityLocked方法
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;
}
//mtk 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("android".equals(info.activityInfo.packageName)){ //if there is a default Launcher?
ComponentName DefaultLauncher=new ComponentName("com.android.launcher3","com.android.launcher3.Launcher"); //here set the package name and class name of default launcher.
ArrayList<ResolveInfo> homeActivities = new ArrayList<ResolveInfo>();
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<ComponentName>Activities=new ArrayList();
mPm.replacePreferredActivity(mHomeFilter, IntentFilter.MATCH_CATEGORY_EMPTY,mHomeComponentSet, DefaultLauncher);
}
//mtk add end
Intent intent = getHomeIntent();
ActivityInfo aInfo =
resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
......