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

2023-11-01 07:12

本文主要是介绍搭载基于RK3229的Android5.1修改开机默认桌面Launcher,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1、找到ActivityManagerService.java

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

 boolean startHomeActivityLocked(int userId, String reason) {setDefaultLauncher(userId);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;}Intent intent = getHomeIntent();ActivityInfo aInfo =resolveActivityInfo(intent, STOCK_PM_FLAGS, userId);if (aInfo != null) {intent.setComponent(new ComponentName(aInfo.applicationInfo.packageName, aInfo.name));// Don't do this if the home app is currently being// instrumented.aInfo = new ActivityInfo(aInfo);aInfo.applicationInfo = getAppInfoForUser(aInfo.applicationInfo, userId);ProcessRecord app = getProcessRecordLocked(aInfo.processName,aInfo.applicationInfo.uid, true);if (app == null || app.instrumentationClass == null) {intent.setFlags(intent.getFlags() | Intent.FLAG_ACTIVITY_NEW_TASK);mStackSupervisor.startHomeActivity(intent, aInfo, reason);}}return true;}

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");

    private void setDefaultLauncher(int userId){// get default component//String  packageName = SystemProperties.get("persist.sys.yz.defpackage", "com.zhaisoft.app.hesiling");// String  className = SystemProperties.get("persist.sys.yz.defclass", "com.zhaisoft.app.hesiling.activity.MainActivity");String  packageName = SystemProperties.get("persist.sys.yz.defpackage", "com.zhai.ads");String  className = SystemProperties.get("persist.sys.yz.defclass", "com.zhai.touchhome.Loading");Slog.i(TAG, "default packageName = " + packageName + ", default className = " + className);if(!packageName.equals("no") && !className.equals("no")){boolean firstLaunch = SystemProperties.getBoolean("persist.sys.sw.firstLaunch", true);Slog.d(TAG, "firstLaunch = " + firstLaunch);if(firstLaunch){mFirstLaunch = true;// do this only for the first bootSystemProperties.set("persist.sys.sw.firstLaunch", "false");}Slog.d(TAG, "mFirstLaunch = " + mFirstLaunch);// if(mFirstLaunch){IPackageManager pm = ActivityThread.getPackageManager();//clear the current preferred launcherArrayList<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 activitiesIntent 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 matchIntentFilter 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 launcherComponentName launcher = new ComponentName(packageName, className);try{pm.addPreferredActivity(filter, bestMatch, set, launcher, userId);} catch (RemoteException e) {throw new RuntimeException("Package manager has died", e);}//}}}

3、寻找HomeSettings.java

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

    void makeCurrentHome(HomeAppPreference newHome) {if (mCurrentHome != null) {mCurrentHome.setChecked(false);}newHome.setChecked(true);mCurrentHome = newHome;mPm.replacePreferredActivity(mHomeFilter, IntentFilter.MATCH_CATEGORY_EMPTY,mHomeComponentSet, newHome.activityName);//huangxing add System.out.println("huangxing----activityName== " + newHome.activityName);//ComponentName chatActivity =new ComponentName();String launcherInfo  = newHome.activityName.toString();System.out.println("huangxing----launcherInfo== " + launcherInfo);if(launcherInfo.indexOf("com.android.launcher3") != -1){SystemProperties.set("persist.sys.yz.defpackage", "com.android.launcher3");SystemProperties.set("persist.sys.yz.defclass", "com.android.launcher3.Launcher");System.out.println("huangxing---launcher3-----");}else if(launcherInfo.indexOf("com.zhai.ads") != -1){SystemProperties.set("persist.sys.yz.defpackage", "com.zhai.ads");SystemProperties.set("persist.sys.yz.defclass", "com.zhai.touchhome.Loading");System.out.println("huangxing---com.zhai.ads-----");}else {//wjz addSystem.out.println("huangxing---heshiling launcher-----");SystemProperties.set("persist.sys.yz.defpackage", "com.zhaisoft.app.hesiling");SystemProperties.set("persist.sys.yz.defclass", "com.zhaisoft.app.hesiling.activity.MainActivity");//SystemProperties.set("persist.sys.yz.defpackage", "com.zhai.ads");//SystemProperties.set("persist.sys.yz.defclass", "com.zhai.touchhome.Loading");}getActivity().setResult(Activity.RESULT_OK);}

这篇关于搭载基于RK3229的Android5.1修改开机默认桌面Launcher的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/321357

相关文章

CentOS7更改默认SSH端口与配置指南

《CentOS7更改默认SSH端口与配置指南》SSH是Linux服务器远程管理的核心工具,其默认监听端口为22,由于端口22众所周知,这也使得服务器容易受到自动化扫描和暴力破解攻击,本文将系统性地介绍... 目录引言为什么要更改 SSH 默认端口?步骤详解:如何更改 Centos 7 的 SSH 默认端口1

Python结合PyWebView库打造跨平台桌面应用

《Python结合PyWebView库打造跨平台桌面应用》随着Web技术的发展,将HTML/CSS/JavaScript与Python结合构建桌面应用成为可能,本文将系统讲解如何使用PyWebView... 目录一、技术原理与优势分析1.1 架构原理1.2 核心优势二、开发环境搭建2.1 安装依赖2.2 验

Docker镜像修改hosts及dockerfile修改hosts文件的实现方式

《Docker镜像修改hosts及dockerfile修改hosts文件的实现方式》:本文主要介绍Docker镜像修改hosts及dockerfile修改hosts文件的实现方式,具有很好的参考价... 目录docker镜像修改hosts及dockerfile修改hosts文件准备 dockerfile 文

Python实现无痛修改第三方库源码的方法详解

《Python实现无痛修改第三方库源码的方法详解》很多时候,我们下载的第三方库是不会有需求不满足的情况,但也有极少的情况,第三方库没有兼顾到需求,本文将介绍几个修改源码的操作,大家可以根据需求进行选择... 目录需求不符合模拟示例 1. 修改源文件2. 继承修改3. 猴子补丁4. 追踪局部变量需求不符合很

PyCharm如何设置新建文件默认为LF换行符

《PyCharm如何设置新建文件默认为LF换行符》:本文主要介绍PyCharm如何设置新建文件默认为LF换行符问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录PyCharm设置新建文件默认为LF换行符设置换行符修改换行符总结PyCharm设置新建文件默认为LF

Linux修改pip和conda缓存路径的几种方法

《Linux修改pip和conda缓存路径的几种方法》在Python生态中,pip和conda是两种常见的软件包管理工具,它们在安装、更新和卸载软件包时都会使用缓存来提高效率,适当地修改它们的缓存路径... 目录一、pip 和 conda 的缓存机制1. pip 的缓存机制默认缓存路径2. conda 的缓

Linux修改pip临时目录方法的详解

《Linux修改pip临时目录方法的详解》在Linux系统中,pip在安装Python包时会使用临时目录(TMPDIR),但默认的临时目录可能会受到存储空间不足或权限问题的影响,所以本文将详细介绍如何... 目录引言一、为什么要修改 pip 的临时目录?1. 解决存储空间不足的问题2. 解决权限问题3. 提

Linux文件名修改方法大全

《Linux文件名修改方法大全》在Linux系统中,文件名修改是一个常见且重要的操作,文件名修改可以更好地管理文件和文件夹,使其更具可读性和有序性,本文将介绍三种在Linux系统下常用的文件名修改方法... 目录一、引言二、使用mv命令修改文件名三、使用rename命令修改文件名四、mv命令和rename命

电脑开机提示krpt.dll丢失怎么解决? krpt.dll文件缺失的多种解决办法

《电脑开机提示krpt.dll丢失怎么解决?krpt.dll文件缺失的多种解决办法》krpt.dll是Windows操作系统中的一个动态链接库文件,它对于系统的正常运行起着重要的作用,本文将详细介绍... 在使用 Windows 操作系统的过程中,用户有时会遇到各种错误提示,其中“找不到 krpt.dll”

mybatis-plus 实现查询表名动态修改的示例代码

《mybatis-plus实现查询表名动态修改的示例代码》通过MyBatis-Plus实现表名的动态替换,根据配置或入参选择不同的表,本文主要介绍了mybatis-plus实现查询表名动态修改的示... 目录实现数据库初始化依赖包配置读取类设置 myBATis-plus 插件测试通过 mybatis-plu