Android AOSP定制去掉Google搜索栏
1.前言:
最近接触了Android系统定制的需求,感觉非常有意思,之前做过Launcher和串口,也自己安装过虚拟机,不过几年没用Linux系统了有点不习惯,Linux命令也不熟悉,刚开始连安装打开AndroidStudio都不会,这里如果不熟悉的小伙伴可以参考以下博客,毕竟Android源码编译都是在Linux环境下进行的,所以熟悉Linux命令还是非常有必要的,此篇作为AOSP定制开发的开篇遇到了很多问题,这里记录一下,废话不多说,直接上代码.
2.简介:
AOSP 概览
Android 是适用于各种不同规格设备的操作系统。任何人都可以通过 Android 开源项目 (AOSP) 查看 Android 的文档和源代码。您可以使用 AOSP 为自己的设备创建自定义 Android OS 变体。
AOSP 的设计可确保不存在一个集中瓶颈,即没有任何行业参与者可一手限制或控制其他参与者的创新。因此,AOSP 是一款功能完善且达到生产质量的开发者产品,其源代码可以开放自定义和移植。
AOSP(Android Open Source Project)是Android的开放源代码项目,为开发者提供了详细的源代码和工具,使得我们能够深入了解Android系统的运作原理。阅读AOSP源码并熟悉其目录结构是了解Android系统内部实现和架构的关键。
3.文章参考:
这里推荐豪哥的FrameWork教程,非常详细和实用,最开始也是跟着豪哥的博客学习了不少知识.
https://juejin.cn/post/7207374216127103033
https://juejin.cn/post/7125309442341961765
https://babyyn.github.io/Sources/AOSP/build.html
4.隐藏Google搜索栏
修改变量配置 QSB_ON_FIRST_SCREEN = false
-
源码路径:packages\apps\Launcher3\src\com\android\launcher3\config\BaseFlags.java
-
源码
abstract class BaseFlags { BaseFlags() {} public static final boolean IS_DOGFOOD_BUILD = false; public static final String AUTHORITY = "com.android.launcher3.settings".intern(); // When enabled allows to use any point on the fast scrollbar to start dragging. public static final boolean LAUNCHER3_DIRECT_SCROLL = true; // When enabled the promise icon is visible in all apps while installation an app. public static final boolean LAUNCHER3_PROMISE_APPS_IN_ALL_APPS = false; // When enabled allows use of spring motions on the icons. public static final boolean LAUNCHER3_SPRING_ICONS = true; // Feature flag to enable moving the QSB on the 0th screen of the workspace. public static final boolean QSB_ON_FIRST_SCREEN = true; // When enabled the all-apps icon is not added to the hotseat. public static final boolean NO_ALL_APPS_ICON = true; // When true, custom widgets are loaded using CustomWidgetParser. public static final boolean ENABLE_CUSTOM_WIDGETS = false; // Features to control Launcher3Go behavior public static final boolean GO_DISABLE_WIDGETS = false; // When enabled shows a work profile tab in all apps public static final boolean ALL_APPS_TABS_ENABLED = true; // When true, overview shows screenshots in the orientation they were taken rather than // trying to make them fit the orientation the device is in. public static final boolean OVERVIEW_USE_SCREENSHOT_ORIENTATION = true; }
-
源码修改
/* * Copyright (C) 2017 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.launcher3.config; /** * Defines a set of flags used to control various launcher behaviors. * * All the flags should be defined here with appropriate default values. To override a value, * redefine it in {@link FeatureFlags}. * * This class is kept package-private to prevent direct access. */ abstract class BaseFlags { BaseFlags() {} public static final boolean IS_DOGFOOD_BUILD = false; public static final String AUTHORITY = "com.android.launcher3.settings".intern(); // When enabled allows to use any point on the fast scrollbar to start dragging. public static final boolean LAUNCHER3_DIRECT_SCROLL = true; // When enabled the promise icon is visible in all apps while installation an app. public static final boolean LAUNCHER3_PROMISE_APPS_IN_ALL_APPS = false; // When enabled allows use of spring motions on the icons. public static final boolean LAUNCHER3_SPRING_ICONS = true; // Feature flag to enable moving the QSB on the 0th screen of the workspace. public static final boolean QSB_ON_FIRST_SCREEN = false; // When enabled the all-apps icon is not added to the hotseat. public static final boolean NO_ALL_APPS_ICON = true; // When true, custom widgets are loaded using CustomWidgetParser. public static final boolean ENABLE_CUSTOM_WIDGETS = false; // Features to control Launcher3Go behavior public static final boolean GO_DISABLE_WIDGETS = false; // When enabled shows a work profile tab in all apps public static final boolean ALL_APPS_TABS_ENABLED = true; // When true, overview shows screenshots in the orientation they were taken rather than // trying to make them fit the orientation the device is in. public static final boolean OVERVIEW_USE_SCREENSHOT_ORIENTATION = true; }
5.注释xml代码
-
源码路径:/packages/apps/Launcher3/res/layout/search_container_workspace.xml
-
源码
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<com.android.launcher3.qsb.QsbContainerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@id/search_container_workspace"
android:padding="0dp" >
<fragment
android:name="com.android.launcher3.qsb.QsbContainerView$QsbFragment"
android:layout_width="match_parent"
android:tag="qsb_view"
android:layout_height="match_parent"/>
</com.android.launcher3.qsb.QsbContainerView>
- 源码修改
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<com.android.launcher3.qsb.QsbContainerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@id/search_container_workspace"
android:padding="0dp" >
<!--<fragment
android:name="com.android.launcher3.qsb.QsbContainerView$QsbFragment"
android:layout_width="match_parent"
android:tag="qsb_view"
android:layout_height="match_parent"/>-->
</com.android.launcher3.qsb.QsbContainerView>
6.注释资源加载代码:
-
源码位置: /packages/apps/Launcher3/src/com/android/launcher3/Workspace.java
-
源码
/** * Initializes and binds the first page * @param qsb an existing qsb to recycle or null. */ public void bindAndInitFirstWorkspaceScreen(View qsb) { if (!FeatureFlags.QSB_ON_FIRST_SCREEN) { return; } // Add the first page CellLayout firstPage = insertNewWorkspaceScreen(Workspace.FIRST_SCREEN_ID, 0); // Always add a QSB on the first screen. if (qsb == null) { // In transposed layout, we add the QSB in the Grid. As workspace does not touch the // edges, we do not need a full width QSB. qsb = LayoutInflater.from(getContext()) .inflate(R.layout.search_container_workspace,firstPage, false); } CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, firstPage.getCountX(), 1); lp.canReorder = false; if (!firstPage.addViewToCellLayout(qsb, 0, R.id.search_container_workspace, lp, true)) { Log.e(TAG, "Failed to add to item at (0, 0) to CellLayout"); } }
源码修改:
public void bindAndInitFirstWorkspaceScreen(View qsb) {
if (!FeatureFlags.QSB_ON_FIRST_SCREEN) {
return;
}
// Add the first page
CellLayout firstPage = insertNewWorkspaceScreen(Workspace.FIRST_SCREEN_ID, 0);
// Always add a QSB on the first screen.
if (qsb == null) {
// In transposed layout, we add the QSB in the Grid. As workspace does not touch the
// edges, we do not need a full width QSB.
qsb = LayoutInflater.from(getContext())
.inflate(R.layout.search_container_workspace,firstPage, false);
}
/* CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, firstPage.getCountX(), 1);
lp.canReorder = false;
if (!firstPage.addViewToCellLayout(qsb, 0, R.id.search_container_workspace, lp, true)) {
Log.e(TAG, "Failed to add to item at (0, 0) to CellLayout");
}*/
}
7.实现的效果如下:
从下图可以看出我们需要的效果已经实现,已经满足我们的需求.
8.文章总结:
以上就是今天的内容,AndroidAOSP开发去掉Google搜索栏,如果熟悉AOSP源码的同学肯定会认为很简单,但是我是最近才刚接触的,过程中遇到了很多,比如Linux环境搭建,Linux命令的使用,AOSP源码的编译和下载,AOSP定制和App开发的有很大区别,必须去看源码,要不然你不知道从哪里下手,看了源码之后,熟悉了流程在去开发得心应手,后面会一步步讲解系统保活、系统深度定制、系统签名
等等。阅读源码是一个很好的习惯,分析源码更是一个好习惯,我们不仅要学会怎么使用,更要学会如何更好地阅读和分析源码,今天的代码先到这里,下一篇我们讲解AOSP如何定制gms。