当前位置:   article > 正文

搭载基于RK3229的Android5.1修改开机默认桌面Launcher_rk3229替换桌面

rk3229替换桌面

1、找到ActivityManagerService.java

在..\rk3229_5.1_box\frameworks\base\services\core\java\com\android\server\am目录找到ActivityManagerService.java文件。在文件里找到startHomeActivityLocked函数里的setDefaultLauncher。

  1. boolean startHomeActivityLocked(int userId, String reason) {
  2. setDefaultLauncher(userId);
  3. if (mFactoryTest == FactoryTest.FACTORY_TEST_LOW_LEVEL
  4. && mTopAction == null) {
  5. // We are running in factory test mode, but unable to find
  6. // the factory test app, so just sit around displaying the
  7. // error message and don't try to start anything.
  8. return false;
  9. }
  10. Intent intent = getHomeIntent();
  11. ActivityInfo aInfo =
  12. resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);
  13. if (aInfo != null) {
  14. intent.setComponent(new ComponentName(
  15. aInfo.applicationInfo.packageName, aInfo.name));
  16. // Don't do this if the home app is currently being
  17. // instrumented.
  18. aInfo = new ActivityInfo(aInfo);
  19. aInfo.applicationInfo = getAppInfoForUser(aInfo.applicationInfo, userId);
  20. ProcessRecord app = getProcessRecordLocked(aInfo.processName,
  21. aInfo.applicationInfo.uid, true);
  22. if (app == null || app.instrumentationClass == null) {
  23. intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);
  24. mStackSupervisor.startHomeActivity(intent, aInfo, reason);
  25. }
  26. }
  27. return true;
  28. }

2、设置开机默认桌面包名

在setDefaultLauncher设置开机默认桌面launch的包名。我开发的固件,所要启动的包名如下:

         String  packageName = SystemProperties.get("persist.sys.yz.defpackage", "com.zhai.ads");
         String  className = SystemProperties.get("persist.sys.yz.defclass", "com.zhai.touchhome.Loading");

  1. private void setDefaultLauncher(int userId)
  2. {
  3. // get default component
  4. //String packageName = SystemProperties.get("persist.sys.yz.defpackage", "com.zhaisoft.app.hesiling");
  5. // String className = SystemProperties.get("persist.sys.yz.defclass", "com.zhaisoft.app.hesiling.activity.MainActivity");
  6. String packageName = SystemProperties.get("persist.sys.yz.defpackage", "com.zhai.ads");
  7. String className = SystemProperties.get("persist.sys.yz.defclass", "com.zhai.touchhome.Loading");
  8. Slog.i(TAG, "default packageName = " + packageName + ", default className = " + className);
  9. if(!packageName.equals("no") && !className.equals("no")){
  10. boolean firstLaunch = SystemProperties.getBoolean("persist.sys.sw.firstLaunch", true);
  11. Slog.d(TAG, "firstLaunch = " + firstLaunch);
  12. if(firstLaunch){
  13. mFirstLaunch = true;
  14. // do this only for the first boot
  15. SystemProperties.set("persist.sys.sw.firstLaunch", "false");
  16. }
  17. Slog.d(TAG, "mFirstLaunch = " + mFirstLaunch);
  18. // if(mFirstLaunch){
  19. IPackageManager pm = ActivityThread.getPackageManager();
  20. //clear the current preferred launcher
  21. ArrayList<IntentFilter> intentList = new ArrayList<IntentFilter>();
  22. ArrayList<ComponentName> cnList = new ArrayList<ComponentName>();
  23. mContext.getPackageManager().getPreferredActivities(intentList, cnList, null);
  24. IntentFilter dhIF;
  25. for(int i = 0; i < cnList.size(); i++)
  26. {
  27. dhIF = intentList.get(i);
  28. if(dhIF.hasAction(Intent.ACTION_MAIN) &&
  29. dhIF.hasCategory(Intent.CATEGORY_HOME))
  30. {
  31. mContext.getPackageManager().clearPackagePreferredActivities(cnList.get(i).getPackageName());
  32. }
  33. }
  34. // get all Launcher activities
  35. Intent intent = new Intent(Intent.ACTION_MAIN);
  36. intent.addCategory(Intent.CATEGORY_HOME);
  37. List<ResolveInfo> list = new ArrayList<ResolveInfo>();
  38. try
  39. {
  40. list = pm.queryIntentActivities(intent,
  41. intent.resolveTypeIfNeeded(mContext.getContentResolver()),
  42. PackageManager.MATCH_DEFAULT_ONLY, userId);
  43. }catch (RemoteException e) {
  44. throw new RuntimeException("Package manager has died", e);
  45. }
  46. // get all components and the best match
  47. IntentFilter filter = new IntentFilter();
  48. filter.addAction(Intent.ACTION_MAIN);
  49. filter.addCategory(Intent.CATEGORY_HOME);
  50. filter.addCategory(Intent.CATEGORY_DEFAULT);
  51. final int N = list.size();
  52. ComponentName[] set = new ComponentName[N];
  53. int bestMatch = 0;
  54. for (int i = 0; i < N; i++)
  55. {
  56. ResolveInfo r = list.get(i);
  57. set[i] = new ComponentName(r.activityInfo.packageName,
  58. r.activityInfo.name);
  59. if (r.match > bestMatch) bestMatch = r.match;
  60. }
  61. // add the default launcher as the preferred launcher
  62. ComponentName launcher = new ComponentName(packageName, className);
  63. try
  64. {
  65. pm.addPreferredActivity(filter, bestMatch, set, launcher, userId);
  66. } catch (RemoteException e) {
  67. throw new RuntimeException("Package manager has died", e);
  68. }
  69. //}
  70. }
  71. }

3、寻找HomeSettings.java

在..\rk3229_5.1_box\packages\apps\Settings\src\com\android\settings里寻找HomeSettings.java文件。在makeCurrentHome里第二次设置自己需要的桌面。主要是客户有两个桌面,需要频繁切换。

  1. void makeCurrentHome(HomeAppPreference newHome) {
  2. if (mCurrentHome != null) {
  3. mCurrentHome.setChecked(false);
  4. }
  5. newHome.setChecked(true);
  6. mCurrentHome = newHome;
  7. mPm.replacePreferredActivity(mHomeFilter, IntentFilter.MATCH_CATEGORY_EMPTY,
  8. mHomeComponentSet, newHome.activityName);
  9. //huangxing add
  10. System.out.println("huangxing----activityName== " + newHome.activityName);
  11. //ComponentName chatActivity =new ComponentName();
  12. String launcherInfo = newHome.activityName.toString();
  13. System.out.println("huangxing----launcherInfo== " + launcherInfo);
  14. if(launcherInfo.indexOf("com.android.launcher3") != -1){
  15. SystemProperties.set("persist.sys.yz.defpackage", "com.android.launcher3");
  16. SystemProperties.set("persist.sys.yz.defclass", "com.android.launcher3.Launcher");
  17. System.out.println("huangxing---launcher3-----");
  18. }else if(launcherInfo.indexOf("com.zhai.ads") != -1){
  19. SystemProperties.set("persist.sys.yz.defpackage", "com.zhai.ads");
  20. SystemProperties.set("persist.sys.yz.defclass", "com.zhai.touchhome.Loading");
  21. System.out.println("huangxing---com.zhai.ads-----");
  22. }else {
  23. //wjz add
  24. System.out.println("huangxing---heshiling launcher-----");
  25. SystemProperties.set("persist.sys.yz.defpackage", "com.zhaisoft.app.hesiling");
  26. SystemProperties.set("persist.sys.yz.defclass", "com.zhaisoft.app.hesiling.activity.MainActivity");
  27. //SystemProperties.set("persist.sys.yz.defpackage", "com.zhai.ads");
  28. //SystemProperties.set("persist.sys.yz.defclass", "com.zhai.touchhome.Loading");
  29. }
  30. getActivity().setResult(Activity.RESULT_OK);
  31. }

4、在System.prop的文件里,设置默认launcher

为了客户定制更加灵活,后来在System.prop里设置了默认launcher的参数。通过脚本配置,进行一站式编译。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小惠珠哦/article/detail/769895
推荐阅读
相关标签
  

闽ICP备14008679号