GMS之Launcher中去除默认Search或替换为Chrome Search

将Launcher中搜索框去除

将FeatureFlags.java文件中的QSB_ON_FIRST_SCREEN变量修改为false

java 复制代码
\system\vendor\mediatek\proprietary\packages\apps\Launcher3\src\com\android\launcher3\config\FeatureFlags.java

/**
 * Defines a set of flags used to control various launcher behaviors.
 *
 * <p>All the flags should be defined here with appropriate default values.
 */
public final class FeatureFlags {
    /**
     * Enable moving the QSB on the 0th screen of the workspace. This is not a configuration feature
     * and should be modified at a project level.
     */
   public static final boolean QSB_ON_FIRST_SCREEN = BuildConfig.QSB_ON_FIRST_SCREEN;
   

在源码中是通过launcher3中的BuildConfig.java去获取变量(默认true),那么在这里将变量修改为false即可(自行添加系统变量进行灵活控制也行)

java 复制代码
\system\vendor\mediatek\proprietary\packages\apps\Launcher3\src_build_config\com\android\launcher3\BuildConfig.java

public final class BuildConfig {
    public static final String APPLICATION_ID = "com.android.launcher3";
    public static final boolean DEBUG = false;
    /**
     * Flag to state if the QSB is on the first screen and placed on the top,
     * this can be overwritten in other launchers with a different value, if needed.
     */
    public static final boolean QSB_ON_FIRST_SCREEN = false;
}

最近在Android 13平台修改以上代码后,在Launcher中并不生效,后来发现,如果SearchLauncherQuickStep存在会默认使用,那么我们的修改就不会生效,因此在这里也需要把它注释掉

java 复制代码
system\vendor\partner_gms\products\gms.mk

GMS_PRODUCT_PACKAGES += \
    #SearchLauncherQuickStep

String providerPkg 为 Chrome 浏览器应用的包名

String className 为 launcher中Chrome Search组件的名字

Boolean ruSupport 为了判断当前版本是否为RU版本(一般只有RU地区才需要这样替换Search)

在getSearchWidgetProviderInfo方法中进行修改判断

java 复制代码
system\vendor\mediatek\proprietary\packages\apps\Launcher3\src\com\android\launcher3\qsb\QsbContainerView.java

     /**
     * returns it's AppWidgetProviderInfo using package name from getSearchWidgetPackageName
     * @param context
     * @return AppWidgetProviderInfo
     */
    @Nullable
    public static AppWidgetProviderInfo getSearchWidgetProviderInfo(@NonNull Context context) {
        String providerPkg = getSearchWidgetPackageName(context);
        if (providerPkg == null) {
            return null;
        }

        //add ---------------------------------------------------------
        String  providerPkg = "com.android.chrome";
        String className = "org.chromium.chrome.browser.searchwidget.SearchWidgetProvider";
        Boolean ruSupport = SystemProperties.get("ro.product.name");
        //end ---------------------------------------------------------
        

        AppWidgetProviderInfo defaultWidgetForSearchPackage = null;
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        for (AppWidgetProviderInfo info :
                appWidgetManager.getInstalledProvidersForPackage(providerPkg, null)) {
            if (info.provider.getPackageName().equals(providerPkg) && info.configure == null) {
                if ((info.widgetCategory
                        & AppWidgetProviderInfo.WIDGET_CATEGORY_SEARCHBOX) != 0) {
                             //add ---------------------------------------------------------
                            if(ruSupport){
                                if(className.equals(info.provider.getClassName())){
                                    return info;
                                }
                            }else{
                                return info;
                            }
                            //end ---------------------------------------------------------
                } else if (defaultWidgetForSearchPackage == null) {
                    defaultWidgetForSearchPackage = info;
                }
            }
        }
        return defaultWidgetForSearchPackage;
    }

人的精神思想方面的优势越大,给无聊留下的空间就越小。

相关推荐
智慧老师19 分钟前
Spring基础分析13-Spring Security框架
java·后端·spring
lxyzcm21 分钟前
C++23新特性解析:[[assume]]属性
java·c++·spring boot·c++23
V+zmm101341 小时前
基于微信小程序的乡村政务服务系统springboot+论文源码调试讲解
java·微信小程序·小程序·毕业设计·ssm
路人甲ing..1 小时前
jupyter切换内核方法配置问题总结
chrome·python·jupyter
Oneforlove_twoforjob1 小时前
【Java基础面试题025】什么是Java的Integer缓存池?
java·开发语言·缓存
xmh-sxh-13141 小时前
常用的缓存技术都有哪些
java
搬码后生仔2 小时前
asp.net core webapi项目中 在生产环境中 进不去swagger
chrome·后端·asp.net
AiFlutter2 小时前
Flutter-底部分享弹窗(showModalBottomSheet)
java·前端·flutter
J不A秃V头A2 小时前
IntelliJ IDEA中设置激活的profile
java·intellij-idea
事后不诸葛2 小时前
安卓音频之dumpsys audio
framework·安卓·audio