frameworks/base/core/java/com/android/internal/app/ResolverActivity.java
java
+import android.os.SystemProperties;
protected void onCreate(Bundle savedInstanceState, Intent intent,
CharSequence title, int defaultTitleRes, Intent[] initialIntents,
List<ResolveInfo> rList, boolean supportsAlwaysUseOption) {
*******
+
+ if(mResolvingHome){
+ setDefaultLauncher();
+ finish();
+ return;
+ }
+
if (configureContentView()) {
return;
}
}
+
+ //add
+ private void setDefaultLauncher() {
+ try {
+ String defLauncher = SystemProperties.get("persist.sys.def_launcher", null);
+ if(defLauncher != null && defLauncher.length() > 0) {
+ Log.i("deflauncher", "---persist.sys.def_launcher=" + defLauncher);
+ String[] packConfig = defLauncher.split("/");
+ String default_pckname = packConfig[0];
+ String default_clsname = packConfig[1];
+ ComponentName preActivity = new ComponentName(default_pckname, default_clsname);
+ Log.i("deflauncher", "---default_pckname="+default_pckname);
+ Log.i("deflauncher", "---default_clsname="+default_clsname);
+
+ Intent homeIntent = new Intent();
+ homeIntent.setAction(Intent.ACTION_MAIN);
+ homeIntent.addCategory(Intent.CATEGORY_HOME);
+ homeIntent.addCategory(Intent.CATEGORY_DEFAULT);
+
+ List<ResolveInfo> list = new ArrayList<ResolveInfo>();
+ PackageManager pm = getPackageManager();
+ list = pm.queryIntentActivities(homeIntent, 0);
+ Log.i("deflauncher", "---queryIntentActivity list 1 size="+list.size());
+
+ ResolveInfo info = mPm.resolveActivity(homeIntent, 0);
+ if(info!=null) Log.i("deflauncher", "---queryIntentActivity packageName="+info.activityInfo.packageName);
+
+ ComponentName[] set = new ComponentName[list.size()];
+ int bestMatch = 0;
+ for (int i = 0; i < list.size(); i++) {
+ ResolveInfo r = list.get(i);
+ set[i] = new ComponentName(r.activityInfo.packageName,r.activityInfo.name);
+ Log.i("deflauncher", "---queryIntentActivity="+r.activityInfo.packageName);
+ if (r.match > bestMatch) bestMatch = r.match;
+ }
+
+ IntentFilter filter = new IntentFilter();
+ filter.addAction(Intent.ACTION_MAIN);
+ filter.addCategory(Intent.CATEGORY_HOME);
+ filter.addCategory(Intent.CATEGORY_DEFAULT);
+
+ pm.addPreferredActivity(filter, bestMatch, set, preActivity);
+ Log.i("deflauncher", "---set def_launcher end");
+
+ startDefaultLauncher();
+ }else{
+ Log.i("deflauncher", "---persist.sys.def_launcher is null");
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private boolean startDefaultLauncher(){
+ String defLauncher = SystemProperties.get("persist.sys.def_launcher", null);
+ if(defLauncher == null){
+ Log.i("deflauncher", "persist.sys.def_launcher not exists");
+ return false;
+ }
+ String[] packConfig = defLauncher.split("/");
+ String defPackageName = packConfig[0];
+ String defClassName = packConfig[1];
+
+ try {
+ Intent intent1 = new Intent(Intent.ACTION_MAIN);
+ intent1.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+ intent1.addCategory(Intent.CATEGORY_LAUNCHER);
+ intent1.setComponent(new ComponentName(defPackageName, defClassName));
+ startActivity(intent1);
+ return true;
+ }catch (Exception e){
+ Log.i("deflauncher", defPackageName + " start Fail");
+ return false;
+ }
+ }
+ // add end
frameworks/base/services/core/java/com/android/server/wm/RootWindowContainer.java
java
boolean startHomeOnTaskDisplayArea(int userId, String reason, TaskDisplayArea taskDisplayArea,
boolean allowInstrumenting, boolean fromHomeKey) {
......
// Updates the home component of the intent.
homeIntent.setComponent(new ComponentName(aInfo.applicationInfo.packageName, aInfo.name));
homeIntent.setFlags(homeIntent.getFlags() | FLAG_ACTIVITY_NEW_TASK);
// Updates the extra information of the intent.
if (fromHomeKey) {
homeIntent.putExtra(WindowManagerPolicy.EXTRA_FROM_HOME_KEY, true);
}
homeIntent.putExtra(WindowManagerPolicy.EXTRA_START_REASON, reason);
+ //add start
+ final PackageManager mPm = mService.mContext.getPackageManager();
+ Intent homeIntent1=new Intent();
+ homeIntent1.setAction(Intent.ACTION_MAIN);
+ homeIntent1.addCategory(Intent.CATEGORY_HOME);
+ homeIntent1.addCategory(Intent.CATEGORY_DEFAULT);
+
+ ResolveInfo info = mPm.resolveActivity(homeIntent1, PackageManager.MATCH_DEFAULT_ONLY);
+ if(info != null) Log.d("deflauncher","startHomeOnTaskDisplayArea currentPkg="+info.activityInfo.packageName);
+
+ //if there is a default Launcher?
+ String defLauncher = SystemProperties.get("persist.sys.def_launcher", null);
+ if(defLauncher != null && defLauncher.length() > 0){
+ Log.i("deflauncher", "startHomeOnTaskDisplayArea def_launcher="+defLauncher);
+ String[] packConfig = defLauncher.split("/");
+ String default_pckname = packConfig[0];
+ String default_clsname = packConfig[1];
+ ComponentName DefaultLauncher = new ComponentName(default_pckname, default_clsname);
+
+ 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 r = homeActivities.get(i);
+ final ActivityInfo activityInfo = r.activityInfo;
+ ComponentName activityName = new ComponentName(activityInfo.packageName, activityInfo.name);
+ mHomeComponentSet[i] = activityName;
+ Log.i("deflauncher", "startHomeOnTaskDisplayArea packageName="+activityInfo.packageName);
+ }
+ IntentFilter mHomeFilter = new IntentFilter(Intent.ACTION_MAIN);
+ mHomeFilter.addCategory(Intent.CATEGORY_HOME);
+ mHomeFilter.addCategory(Intent.CATEGORY_DEFAULT);
+
+ mPm.replacePreferredActivity(mHomeFilter,IntentFilter.MATCH_CATEGORY_EMPTY,
+ mHomeComponentSet, DefaultLauncher);
+ }
+ //add end
+
// Update the reason for ANR debugging to verify if the user activity is the one that
// actually launched.
final String myReason = reason + ":" + userId + ":" + UserHandle.getUserId(
aInfo.applicationInfo.uid) + ":" + taskDisplayArea.getDisplayId();
mService.getActivityStartController().startHomeActivity(homeIntent, aInfo, myReason,
taskDisplayArea);
return true;
}