ActivityManagerService.java : switchUser(final int userId)
{
boolean homeInFront = mStackSupervisor.switchUserLocked(userId,uss);
if(homeInFront)
{
startHomeActivityLocked(userId);
}
}
boolean startHomeActivityLocked( int userId) {
Intent intent = getHomeIntent();
...
mStackSupervisor.startHomeActivity(intent,aInfo);
}
Intent getHomeIntent(){
Intent intent = new Intent(mTopAction, mTopData != null ? Uri.parse(mTopData:null));
intent.setComponent()mTopComponent;
...
return intent;
}
设置默认launcher 在 defaultActivity.java
Intent intent = new Intent();
intent.setAction(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.addCategory(Intent.CATEGORY_DEFAULT);
List<ResolveInfo> list = pm.queryIntentActivities(intent,PackageManager.GET_INTENT_FILTERS);
ComponentName[] components = new ComponentName[list.size()];
int defApk = -1;
for(int i = 0; i<list.size(); ++i)
{
ActivityInfo info = list.get(i).activityInfo;
if(info.packageName.equals("com.example.launcher")&&info.name.equals("xxxx"))
{
defApk = i ;
}
components[i] = new ComponentName(info.packageName,info.name);
}
if(defApk != -1){
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_MAIN);
filter.addCategory(Intent.CATEGORY_HOME);
filter.addCategory(Intent.CATEGORY_DEFAULT);
pm.addPreferedActivity(filter, IntentFilter.MATCH_CATEGORY_EMPTY, components, components[defApk] );
}