系统启动后, 会查找并运行Launcher,
有源码的情况下,可以通过修改Intent-filter中的android:priorty="N" N >=1; 一般我会设置 N=100;
没有源码的情况下, 要将第三方Launcher默认启动, 则需要在些过程做点修改.
frameworks/base/services/java/com/android/server/am/ActivityManagerService.java
boolean startHomeActivityLocked(int userId) {
if (mHeadless) {
// Added because none of the other calls to ensureBootCompleted seem to fire
// when running headless.
ensureBootCompleted();
return false;
}
if (mFactoryTest == SystemServer.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;
}
Intent intent = new Intent(
mTopAction,
mTopData != null ? Uri.parse(mTopData) : null);
intent.setComponent(mTopComponent);
if (mFactoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
intent.addCategory(Intent.CATEGORY_HOME);
}
/** AnsonCode 2013.8.5 add Code**/
try{
final String specialPkg = "com.android.launcherX";
mContext.getPackageManager().getApplicationEnabledSetting(specialPkg);
intent.setPackage(specialPkg);
}catch(Exception e){
e.printStackTrace();
}
/** AnsonCode End **/
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);
if (app == null || app.instrumentationClass == null) {
intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
mMainStack.startActivityLocked(null, intent, null, aInfo,
null, null, 0, 0, 0, 0, null, false, null);
}
}
return true;
}
本文探讨了Android系统中Launcher的启动流程及如何通过修改代码来指定特定的Launcher为默认启动项。涉及修改源码中的Intent过滤器及在无源码情况下进行相应配置。
3289

被折叠的 条评论
为什么被折叠?



