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;}

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. C语言在屏幕上显示内容
  2. .NET Core2.0小技巧之MemoryCache问题修
  3. .NET CORE如何动态调用泛型解决方法
  4. C#中委托和匿名委托的具体介绍
  5. asp.net mvc如何动态编译生成Controller
  6. C#中关于匿名委托和Lambda表达式的使用详
  7. web.config 配置文件示例详解
  8. ASP.NET Core中的多语言支持的图文详解
  9. C#中关于逆变和协变的详解
  10. MemoryCache问题修复的解决方法