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

本文最后更新于:2023年11月9日 晚上

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

将Launcher中搜索框去除

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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
\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即可(自行添加系统变量进行灵活控制也行)

1
2
3
4
5
6
7
8
9
10
11
\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存在会默认使用,那么我们的修改就不会生效,因此在这里也需要把它注释掉

1
2
3
4
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方法中进行修改判断

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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;
}
人的精神思想方面的优势越大,给无聊留下的空间就越小。

GMS之Launcher中去除默认Search或替换为Chrome Search
http://example.com/2023/09/25/GMS之Launcher中去除默认Search或替换为Chrome Search/
作者
阿波~
发布于
2023年9月25日
更新于
2023年11月9日
许可协议