GMS之Launcher中去除默认Search或替换为Chrome Search
将Launcher中搜索框去除
将FeatureFlags.java文件中的QSB_ON_FIRST_SCREEN变量修改为false
\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即可(自行添加系统变量进行灵活控制也行)
\system\vendor\mediatek\proprietary\packages\apps\Launcher3\src_build_config\com\android\launcher3\BuildConfig.javapublic 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存在会默认使用,那么我们的修改就不会生效,因此在这里也需要把它注释掉
system\vendor\partner_gms\products\gms.mkGMS_PRODUCT_PACKAGES += \#SearchLauncherQuickStep
如何将默认的Search替换为其他的? 比如项目是出货RU(俄罗斯)的,根据要求需要将Launcher中的默认Google Search 要更换为 Chrome Search
String providerPkg 为 Chrome 浏览器应用的包名
String className 为 launcher中Chrome Search组件的名字
Boolean ruSupport 为了判断当前版本是否为RU版本(一般只有RU地区才需要这样替换Search)
在getSearchWidgetProviderInfo方法中进行修改判断
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*/@Nullablepublic 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;}