搭载基于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

相关文章

nginx启动命令和默认配置文件的使用

《nginx启动命令和默认配置文件的使用》:本文主要介绍nginx启动命令和默认配置文件的使用,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录常见命令nginx.conf配置文件location匹配规则图片服务器总结常见命令# 默认配置文件启动./nginx

PostgreSQL 默认隔离级别的设置

《PostgreSQL默认隔离级别的设置》PostgreSQL的默认事务隔离级别是读已提交,这是其事务处理系统的基础行为模式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价... 目录一 默认隔离级别概述1.1 默认设置1.2 各版本一致性二 读已提交的特性2.1 行为特征2.2

SQL Server修改数据库名及物理数据文件名操作步骤

《SQLServer修改数据库名及物理数据文件名操作步骤》在SQLServer中重命名数据库是一个常见的操作,但需要确保用户具有足够的权限来执行此操作,:本文主要介绍SQLServer修改数据... 目录一、背景介绍二、操作步骤2.1 设置为单用户模式(断开连接)2.2 修改数据库名称2.3 查找逻辑文件名

Oracle修改端口号之后无法启动的解决方案

《Oracle修改端口号之后无法启动的解决方案》Oracle数据库更改端口后出现监听器无法启动的问题确实较为常见,但并非必然发生,这一问题通常源于​​配置错误或环境冲突​​,而非端口修改本身,以下是系... 目录一、问题根源分析​​​二、保姆级解决方案​​​​步骤1:修正监听器配置文件 (listener.

Linux中修改Apache HTTP Server(httpd)默认端口的完整指南

《Linux中修改ApacheHTTPServer(httpd)默认端口的完整指南》ApacheHTTPServer(简称httpd)是Linux系统中最常用的Web服务器之一,本文将详细介绍如何... 目录一、修改 httpd 默认端口的步骤1. 查找 httpd 配置文件路径2. 编辑配置文件3. 保存

Ubuntu设置程序开机自启动的操作步骤

《Ubuntu设置程序开机自启动的操作步骤》在部署程序到边缘端时,我们总希望可以通电即启动我们写好的程序,本篇博客用以记录如何在ubuntu开机执行某条命令或者某个可执行程序,需要的朋友可以参考下... 目录1、概述2、图形界面设置3、设置为Systemd服务1、概述测试环境:Ubuntu22.04 带图

RedisTemplate默认序列化方式显示中文乱码的解决

《RedisTemplate默认序列化方式显示中文乱码的解决》本文主要介绍了SpringDataRedis默认使用JdkSerializationRedisSerializer导致数据乱码,文中通过示... 目录1. 问题原因2. 解决方案3. 配置类示例4. 配置说明5. 使用示例6. 验证存储结果7.

Python使用Tkinter打造一个完整的桌面应用

《Python使用Tkinter打造一个完整的桌面应用》在Python生态中,Tkinter就像一把瑞士军刀,它没有花哨的特效,却能快速搭建出实用的图形界面,作为Python自带的标准库,无需安装即可... 目录一、界面搭建:像搭积木一样组合控件二、菜单系统:给应用装上“控制中枢”三、事件驱动:让界面“活”

C++/类与对象/默认成员函数@构造函数的用法

《C++/类与对象/默认成员函数@构造函数的用法》:本文主要介绍C++/类与对象/默认成员函数@构造函数的用法,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录名词概念默认成员函数构造函数概念函数特征显示构造函数隐式构造函数总结名词概念默认构造函数:不用传参就可以

C++类和对象之默认成员函数的使用解读

《C++类和对象之默认成员函数的使用解读》:本文主要介绍C++类和对象之默认成员函数的使用方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、默认成员函数有哪些二、各默认成员函数详解默认构造函数析构函数拷贝构造函数拷贝赋值运算符三、默认成员函数的注意事项总结一