欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

全志 增加启动默launcher函数 Patch

发布时间:2024/10/14 编程问答 55 豆豆
生活随笔 收集整理的这篇文章主要介绍了 全志 增加启动默launcher函数 Patch 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
add 添加启动默launcher函数diff --git a/android/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java b/android/fr index 446b0e4..9b7e2ba 100755 --- a/android/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java +++ b/android/frameworks/base/services/core/java/com/android/server/am/ActivityManagerService.java @@ -3692,7 +3692,81 @@ public final class ActivityManagerService extends ActivityManagerNative}return intent;} - + + /* launch the defualt launcher when the system boots for the first time */ + private boolean mFirstLaunch = false; + private void setDefaultLauncher(int userId) + { + // get default component + String packageName = SystemProperties.get("ro.sw.defaultlauncherpackage", "no"); + String className = SystemProperties.get("ro.sw.defaultlauncherclass", "no"); + Slog.i(TAG, "default packageName = " + packageName + ", default className = " + className); + if(!packageName.equals("no") && !className.equals("no")){ + boolean firstLaunch = true;//SystemProperties.getBoolean("persist.sys.sw.firstLaunch", true); + Slog.d(TAG, "firstLaunch = " + firstLaunch); + if(firstLaunch){ + mFirstLaunch = true; + // do this only for the first boot + SystemProperties.set("persist.sys.sw.firstLaunch", "false"); + } + Slog.d(TAG, "mFirstLaunch = " + mFirstLaunch); + if(mFirstLaunch){ + IPackageManager pm = ActivityThread.getPackageManager(); + + //clear the current preferred launcher + 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()); + } + } + + // get all Launcher activities + 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, userId); + }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(); + 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); + if (r.match > bestMatch) bestMatch = r.match; + } + // add the default launcher as the preferred launcher + ComponentName launcher = new ComponentName(packageName, className); + try + { + pm.addPreferredActivity(filter, bestMatch, set, launcher, userId); + } catch (RemoteException e) { + throw new RuntimeException("Package manager has died", e); + } + } + } + } + boolean startHomeActivityLocked(int userId, String reason) {if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL&& mTopAction == null) { @@ -3701,6 +3775,10 @@ public final class ActivityManagerService extends ActivityManagerNative// error message and don't try to start anything.return false;} + /* launch the defualt launcher when the system boots for the first time */ + setDefaultLauncher(userId); + +

总结

以上是生活随笔为你收集整理的全志 增加启动默launcher函数 Patch的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。