To set Google Launcher2 as the default boot launcher, for example,
Its package name is Com.android.launcher
Launcher activity name is Com.android.launcher2.Launcher
1. Add the following code to the end of the Systemready function in Packagemanagerservice.java.
if (Isfirstboot ())
{
MTK ADD BEGIN
String examplepackagename = "Com.android.launcher"; Please modify the package name to be set
String exampleactivityname = "Com.android.launcher2.Launcher"; Please modify the launcher activity name to be set.
Intent intent=new Intent (Intent.action_main);
Intent.addcategory (Intent.category_home);
Final int callinguserid = Userhandle.getcallinguserid ();
list<resolveinfo> resolveinfolist = queryintentactivities (Intent,null, Packagemanager.get_meta_data, Callinguserid);
if (resolveinfolist! = null) {
int size = Resolveinfolist.size ();
for (int j=0;j<size;) {
Final ResolveInfo r = Resolveinfolist.get (j);
if (!r.activityinfo.packagename.equals (Examplepackagename)) {
Resolveinfolist.remove (j);
Size-= 1;
}else
{
j + +;
}
}
componentname[] set = new Componentname[size];
ComponentName defaultlauncher=new componentname (Examplepackagename, exampleactivityname);
int defaultmatch=0;
for (int i=0;i<size;i++) {
Final ResolveInfo ResolveInfo = Resolveinfolist.get (i);
LOG.D (TAG, resolveinfo.tostring ());
Set[i] = new ComponentName (resolveinfo.activityinfo.packagename,resolveinfo.activityinfo.name);
if (Defaultlauncher.getclassname (). Equals (ResolveInfo.activityInfo.name)) {
Defaultmatch = Resolveinfo.match;
}
}
SLOG.E (TAG, "defaultmatch=" +integer.tohexstring (Defaultmatch));
Intentfilter filter=new Intentfilter ();
Filter.addaction (Intent.action_main);
Filter.addcategory (Intent.category_home);
Filter.addcategory (Intent.category_default);
AddPreferredActivity2 (filter, Defaultmatch, set, Defaultlauncher);
}
MTK ADD END
}
2. Add the AddPreferredActivity2 function to the Packagemanagerservice.java.
public void AddPreferredActivity2 (intentfilter filter, int match,
Componentname[] Set, componentname activity) {
LOG.D ("Debug_default", "AddPreferredActivity2 is called.");
Writer
Synchronized (mpackages) {
SLOG.I (TAG, "Adding preferred activity" + activity + ":");
Filter.dump (New Logprinter (Log.info, TAG), "");
MSETTINGS.EDITPREFERREDACTIVITIESLPW (0). addfilter (
New Preferredactivity (filter, match, set, activity, true));
Schedulewritesettingslocked ();
}
}
3. Modify the Packagemanagerservice.java function findpreferredactivity
(1) The original removematches to increase the judging conditions, in launcher not remove
if (! ( Intent.getaction ()! = null && intent.getaction (). Equals (intent. Action_main) && intent.getcategories ()!=null && intent.getcategories (). Contains (intent. Category_home)) {//MTK ADD
SLOG.D (TAG, "launcher");
}else{
if (removematches) {
Pir.removefilter (PA);
if (debug_preferred) {
SLOG.V (TAG, "removing match" + pa.mPref.mComponent);
}
(2)
if (Always &&!pa.mpref.sameset (query, priority)) {
SLOG.I (TAG, "Result set changed, dropping preferred activity for"
+ Intent + "type" + Resolvedtype);
if (debug_preferred) {
SLOG.V (TAG, "removing preferred activity since set changed"
+ pa.mPref.mComponent);
}
Pir.removefilter (PA);
Re-add the filter as a "last Chosen" entry (!always)
Preferredactivity Lastchosen = new Preferredactivity (
PA, Pa.mPref.mMatch, NULL, pa.mPref.mComponent, FALSE);
Pir.addfilter (Lastchosen);
MSETTINGS.WRITEPACKAGERESTRICTIONSLPR (USERID);
return null;
}
The above paragraph is modified to read:
if (Always &&!pa.mpref.sameset (query, priority)) {
if (! ( Intent.getaction ()! = null && intent.getaction (). Equals (intent. Action_main) && intent.getcategories ()!=null &&
Intent.getcategories (). Contains (intent. Category_home)) {//MTK ADD
SLOG.I (TAG, "Result set changed, dropping preferred activity for"
+ Intent + "type" + Resolvedtype);
if (debug_preferred) {
SLOG.V (TAG, "removing preferred activity since set changed"
+ pa.mPref.mComponent);
}
Pir.removefilter (PA);
Re-add the filter as a "last Chosen" entry (!always)
Preferredactivity Lastchosen = new Preferredactivity (
PA, Pa.mPref.mMatch, NULL, pa.mPref.mComponent, FALSE);
Pir.addfilter (Lastchosen);
MSETTINGS.WRITEPACKAGERESTRICTIONSLPR (USERID);
return null;
}
}
SLOG.I (TAG, "Result set not change, not drop preferred activity for special intent:" +intent);//MTK ADD
yay! Either the set matched or we ' re looking for the last chosen
Special Note:
JB Series Findpreferredactivity slightly adjusted, see below:
Modify the Findpreferredactivity method of Packagemanagerservice.java (framework/base/services/java/com/android/server/pm/), Compare this method to the following piece of code:
if (!pa.mpref.sameset (query, priority)) {
SLOG.I (TAG, "Result set changed, dropping preferred activity for" + intent + "type" + Resolvedtype);
Pir.removefilter (PA);
return null;
}
Modified to:
if (!pa.mpref.sameset (query, priority)) {
if (! ( Intent.getaction ()! = null && intent.getaction (). Equals (intent. Action_main) && intent.getcategories ()!=null &&
Intent.getcategories (). Contains (intent. Category_home)) {//MTK ADD
SLOG.I (TAG, "Result set changed, dropping preferred activity for" + intent + "type" + Resolvedtype);
Pir.removefilter (PA);
return null;
}//MTK ADD
SLOG.I (TAG, "Result set not change, not drop preferred activity for special intent:" +intent);//MTK ADD
}
Ps:
If the user is in the list of all applications, manage applications, applications, and so on, find the default launcher set earlier and cancel the default values, the system will re-eject the launcher selection box.
Android when there are multiple launcher system, how to set the boot automatically into the default launcher?