frameworks\base\services\core\java\com\android\server\am\ActivityManagerService.java
boolean startHomeActivityLocked(int userId, String reason) {
+ setDefaultLauncher();
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;
}
private void setDefaultLauncher() {
boolean mFirstLaunch = true;
String packageName = "默认launcher包名";
String className = "默认launcher入口";
if ((packageName != null && packageName.trim().length() > 1) && (className != null && className.trim().length() > 0)) {
if(mFirstLaunch){
IPackageManager pm = ActivityThread.getPackageManager();
ArrayList<IntentFilter> intentList = new ArrayList<IntentFilter>();
ArrayList<ComponentName> cnList = new ArrayList<ComponentName>();
mContext.getPackageManager().getPreferredActivities(intentList, cnList, null);
IntentFilter dhIF;
for(int i = 0; i < cnList.size(); i++)
{
dhIF = intentList.get(i);
if(dhIF.hasAction(Intent.ACTION_MAIN) &&
dhIF.hasCategory(Intent.CATEGORY_HOME))
{
mContext.getPackageManager().clearPackagePreferredActivities(cnList.get(i).getPackageName());
}
}
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
List<ResolveInfo> list = new ArrayList<ResolveInfo>();
try {
list = pm.queryIntentActivities(intent,
intent.resolveTypeIfNeeded(mContext.getContentResolver()),
PackageManager.MATCH_DEFAULT_ONLY,UserHandle.getCallingUserId()).getList(); //add .getList()
}catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
// get all components and the best match
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_MAIN);
filter.addCategory(Intent.CATEGORY_HOME);
filter.addCategory(Intent.CATEGORY_DEFAULT);
final int N = list.size();
Slog.d(TAG, "N:::::hyhyhyhy:::: = " + N);
ComponentName[] set = new ComponentName[N];
int bestMatch = 0;
for (int i = 0; i < N; i++)
{
ResolveInfo r = list.get(i);
set[i] = new ComponentName(r.activityInfo.packageName,
r.activityInfo.name);
Slog.d(TAG, "r.activityInfo.packageName:::::hyhyhyhy:::: = " + r.activityInfo.packageName);
Slog.d(TAG, "r.activityInfo.name:::::hyhyhyhy:::: = " + r.activityInfo.name);
if (r.match > bestMatch) bestMatch = r.match;
}
//<C9><E8><D6><C3>?<C8><CF>launcher
ComponentName launcher = new ComponentName(packageName, className);
try
{
Log.d("zy","pm.addPreferredActivity");
pm.addPreferredActivity(filter, bestMatch, set, launcher,UserHandle.getCallingUserId());
} catch (RemoteException e) {
throw new RuntimeException("Package manager has died", e);
}
}
}
}
Rk3399-Android-9.0 设置默认Launcher
最新推荐文章于 2024-05-27 14:30:49 发布