WorkingTipsONCellsAndroid10CN

1. cells源码准备

从github克隆代码至本地目录

# mkdir -p ~/Code/show/cells
# cd ~/Code/show/cells
# git clone https://github.com/jianglin-code/cells-android10.git
# cd cells-android10
# ls
cells  frameworks  kernel  README.md  system

2. aosp 10源码准备

对标cells源码中的要求, 克隆特定版本的aosp10源码(10.0.0_r33):

# mkdir -p ~/Code/show/aosp10
# cd ~/Code/show/aosp10
# repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-10.0.0_r33
# repo sync -j8

3. 内核源码准备

因为使用的真机是pixel 3a,内核源码的获取见以下代码:

# mkdir -p ~/Code/show/android-kernel
# cd ~/Code/show/android-kernel
#  repo init --depth 1 -u https://aosp.tuna.tsinghua.edu.cn/kernel/manifest -b android-msm-bonito-4.9-android10
# repo sync -j4
# ls
build  build.config  prebuilts  prebuilts-master  private
# du -hs *
732K	build
0	build.config
189M	prebuilts
5.8G	prebuilts-master
870M	private

4. 二进制驱动准备

从以下网址查找真机对应需要的二进制驱动标号:
https://source.android.com/setup/start/build-numbers#source-code-tags-and-builds:

QQ2A.200305.002	android-10.0.0_r30	Android10	Pixel 2、Pixel 2 XL、Pixel 3、Pixel 3 XL、Pixel 3a、Pixel 3a XL	2020-03-05

根据查找出的代号,从以下网址下载二进制驱动文件:
https://developers.google.cn/android/drivers?hl=zh-cn#sargoqq2a.200405.005:

/images/2022_02_02_22_55_30_880x211.jpg

将下载的二进制驱动文件拷贝到aosp源码树:

# cp extract-google_devices-sargo.sh extract-qcom-sargo.sh /root/Code/show/aosp10

5. 编译内核

使用cells源码中的相应目录替换aosp10内核中对应代码:

# mv private/msm-google private/msm-google.back
# cp -ar  ~/Code/show/cells/cells-android10/kernel/ private/msm-google

使用以下命令编译内核:

# cd private/msm-google
# make mrproper
# cd ../../
# cp -r private/msm-google.back/techpack/ private/msm-google/
# vim build/build.sh
comment the line of soong_zip(line 798)
# build/build.sh

检验内核编译出的二进制文件:

# ls out/android-msm-pixel-4.9/dist/
abi.prop  Image.lz4              kernel-uapi-headers.tar.gz  System.map  wlan.ko
dtbo.img  kernel-headers.tar.gz  sdm670.dtb                  vmlinux

6. aosp源码编译

解压二进制驱动代码:

# ./extract-google_devices-sargo.sh 
# ./extract-qcom-sargo.sh 

替换aosp中内置的内核代码:

# mv device/google/bonito-kernel/Image.lz4 device/google/bonito-kernel/Image.lz4.back
# cp /root/Code/show/android-kernel/out/android-msm-pixel-4.9/dist/Image.lz4 device/google/bonito-kernel/Image.lz4

将cells源码并入到aosp编译树中:

# cp -r /root/Code/show/cells/cells-android10/cells/ vendor/
# vim device/google/bonito/device.mk
Added at the last line:   
$(call inherit-product-if-exists, vendor/cells/cells_build.mk)

开始编译:

# source build/envsetup.sh
# lunch aosp_sargo-userdebug
# vim frameworks/base/data/etc/privapp-permissions-platform.xml
增加: 
    <privapp-permissions package="com.cells.cellswitch.secure">
        <permission name="android.permission.BLUETOOTH_PRIVILEGED"/>
    </privapp-permissions>
# vim vendor/cells/switchsystem/src/com/cells/cellswitch/secure/view/SwitchActivity.java
注释掉: 
//import android.os.CellsManager;
//import android.os.ICellsManager;
# cp -r /root/Code/show/aosp10back/frameworks/multidex/library/
frameworks/multidex
# m -j128

编译到80%左右时将失败,重新计算依赖后编译方可成功:

# development/vndk/tools/header-checker/utils/create_reference_dumps.py  -l libbinder && development/vndk/tools/header-checker/utils/create_reference_dumps.py  -l libhwbinder_noltopgo && development/vndk/tools/header-checker/utils/create_reference_dumps.py  -l libhidlbase && m -j128

检验编译输出文件:

# ls out/target/product/sargo/*.img
out/target/product/sargo/boot-debug.img     out/target/product/sargo/ramdisk.img
out/target/product/sargo/boot.img           out/target/product/sargo/ramdisk-recovery.img
out/target/product/sargo/dtb.img            out/target/product/sargo/super_empty.img
out/target/product/sargo/dtbo.img           out/target/product/sargo/system.img
out/target/product/sargo/persist.img        out/target/product/sargo/system_other.img
out/target/product/sargo/product.img        out/target/product/sargo/vbmeta.img
out/target/product/sargo/ramdisk-debug.img  out/target/product/sargo/vendor.img

最终编译树尺寸大小:

# du -hs *
15G     android-kernel
177G    aosp10
2.4G    aosp10back
6.0G    cells

7. 烧写镜像

通过USB连接pixel 3a:

$ adb devices
List of devices attached
92UAY04L95	device

$  adb reboot bootloader

通过以下命令烧录镜像:

$ fastboot devices
92UAY04L95	fastboot
$ export ANDROID_PRODUCT_OUT=/root/Code/show/aosp10/out/target/product/sargo
$ fastboot flashall -w
--------------------------------------------
Bootloader Version...: b4s4-0.2-6355063
Baseband Version.....: g670-00042-200421-B-6414611
Serial Number........: 92UAY04L95
--------------------------------------------
Checking 'product'                                 OKAY [  0.058s]
Setting current slot to 'b'                        OKAY [  0.138s]
.....
Erasing 'userdata'                                 OKAY [  0.311s]
Erase successful, but not automatically formatting.
File system type raw not supported.
Erasing 'metadata'                                 OKAY [  0.006s]
Erase successful, but not automatically formatting.
File system type raw not supported.
Rebooting                                          OKAY [  0.001s]
Finished. Total time: 336.662s

将二进制驱动烧录进真机,从而可以使用无线连接:

# 禁用校验机制
adb root
adb disable-verity
adb shell sync
adb reboot

# 上传模块
adb root
adb remount
adb push /media/nfs1/android-kernel/out/android-msm-pixel-4.9/dist/wlan.ko /vendor/lib/modules/

# 重启手机生效
adb reboot

8. 基本使用场景

检验编译串号:
/images/2022_02_03_10_18_02_498x265.jpg

控制中心是用来切换双系统的快捷方式:

/images/2022_02_03_10_26_40_346x397.jpg

点击控制中心后将出现Start按钮:

/images/2022_02_03_10_27_56_236x459.jpg

点击Start按钮后,第二系统将启动:

/images/2022_02_03_10_28_34_234x472.jpg

启动成功:

/images/2022_02_03_10_29_19_233x477.jpg

再次点击Start按钮进入到第二系统:

/images/2022_02_03_10_30_12_230x475.jpg

在第二系统中点击控制中心将提示推出该系统并回到主系统:

/images/2022_02_03_10_31_09_231x479.jpg

退出后将回到第一系统的锁屏界面:

/images/2022_02_03_10_31_44_235x479.jpg

9. 定制化

定制化1: 语言设置/输入法设置

定制化2:为双系统各自安装软件仓库:

$ adb install apks/MobileAssistant_1.apk 
Performing Streamed Install
Success

定制化3:为双系统安装更多的apks:

定制化4: 更改主题等

CellsOnAndroid10IntegrationCN

1. cells源码准备

从github克隆代码至本地目录

# mkdir -p ~/Code/show/cells
# cd ~/Code/show/cells
# git clone https://github.com/jianglin-code/cells-android10.git
# cd cells-android10
# ls
cells  frameworks  kernel  README.md  system

2. aosp 10源码准备

对标cells源码中的要求, 克隆特定版本的aosp10源码(10.0.0_r33):

# mkdir -p ~/Code/show/aosp10
# cd ~/Code/show/aosp10
# repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-10.0.0_r33
# repo sync -j8

3. 内核源码准备

因为使用的真机是pixel 3a,内核源码的获取见以下代码:

# mkdir -p ~/Code/show/android-kernel
# cd ~/Code/show/android-kernel
#  repo init --depth 1 -u https://aosp.tuna.tsinghua.edu.cn/kernel/manifest -b android-msm-bonito-4.9-android10
# repo sync -j4
# ls
build  build.config  prebuilts  prebuilts-master  private
# du -hs *
732K	build
0	build.config
189M	prebuilts
5.8G	prebuilts-master
870M	private

4. 二进制驱动准备

从以下网址查找真机对应需要的二进制驱动标号:
https://source.android.com/setup/start/build-numbers#source-code-tags-and-builds:

QQ2A.200305.002	android-10.0.0_r30	Android10	Pixel 2、Pixel 2 XL、Pixel 3、Pixel 3 XL、Pixel 3a、Pixel 3a XL	2020-03-05

根据查找出的代号,从以下网址下载二进制驱动文件:
https://developers.google.cn/android/drivers?hl=zh-cn#sargoqq2a.200405.005:

/images/2022_02_02_22_55_30_880x211.jpg

将下载的二进制驱动文件拷贝到aosp源码树:

# cp extract-google_devices-sargo.sh extract-qcom-sargo.sh /root/Code/show/aosp10

5. 编译内核

使用cells源码中的相应目录替换aosp10内核中对应代码:

# mv private/msm-google private/msm-google.back
# cp -ar  ~/Code/show/cells/cells-android10/kernel/ private/msm-google

使用以下命令编译内核:

# cd private/msm-google
# make mrproper
# cd ../../
# cp -r private/msm-google.back/techpack/ private/msm-google/
# vim build/build.sh
comment the line of soong_zip(line 798)
# build/build.sh

检验内核编译出的二进制文件:

# ls out/android-msm-pixel-4.9/dist/
abi.prop  Image.lz4              kernel-uapi-headers.tar.gz  System.map  wlan.ko
dtbo.img  kernel-headers.tar.gz  sdm670.dtb                  vmlinux

6. aosp源码编译

解压二进制驱动代码:

# ./extract-google_devices-sargo.sh 
# ./extract-qcom-sargo.sh 

替换aosp中内置的内核代码:

# mv device/google/bonito-kernel/Image.lz4 device/google/bonito-kernel/Image.lz4.back
# cp /root/Code/show/android-kernel/out/android-msm-pixel-4.9/dist/Image.lz4 device/google/bonito-kernel/Image.lz4

将cells源码并入到aosp编译树中:

# cp -r /root/Code/show/cells/cells-android10/cells/ vendor/
# vim device/google/bonito/device.mk
Added at the last line:   
$(call inherit-product-if-exists, vendor/cells/cells_build.mk)

开始编译:

# source build/envsetup.sh
# lunch aosp_sargo-userdebug
# vim frameworks/base/data/etc/privapp-permissions-platform.xml
增加: 
    <privapp-permissions package="com.cells.cellswitch.secure">
        <permission name="android.permission.BLUETOOTH_PRIVILEGED"/>
    </privapp-permissions>
# vim vendor/cells/switchsystem/src/com/cells/cellswitch/secure/view/SwitchActivity.java
注释掉: 
//import android.os.CellsManager;
//import android.os.ICellsManager;
# cp -r /root/Code/show/aosp10back/frameworks/multidex/library/
frameworks/multidex
# m -j128

编译到80%左右时将失败,重新计算依赖后编译方可成功:

# development/vndk/tools/header-checker/utils/create_reference_dumps.py  -l libbinder && development/vndk/tools/header-checker/utils/create_reference_dumps.py  -l libhwbinder_noltopgo && development/vndk/tools/header-checker/utils/create_reference_dumps.py  -l libhidlbase && m -j128

检验编译输出文件:

# ls out/target/product/sargo/*.img
out/target/product/sargo/boot-debug.img     out/target/product/sargo/ramdisk.img
out/target/product/sargo/boot.img           out/target/product/sargo/ramdisk-recovery.img
out/target/product/sargo/dtb.img            out/target/product/sargo/super_empty.img
out/target/product/sargo/dtbo.img           out/target/product/sargo/system.img
out/target/product/sargo/persist.img        out/target/product/sargo/system_other.img
out/target/product/sargo/product.img        out/target/product/sargo/vbmeta.img
out/target/product/sargo/ramdisk-debug.img  out/target/product/sargo/vendor.img

最终编译树尺寸大小:

# du -hs *
15G     android-kernel
177G    aosp10
2.4G    aosp10back
6.0G    cells

7. 烧写镜像

通过USB连接pixel 3a:

$ adb devices
List of devices attached
92UAY04L95	device

$  adb reboot bootloader

通过以下命令烧录镜像:

$ fastboot devices
92UAY04L95	fastboot
$ export ANDROID_PRODUCT_OUT=/root/Code/show/aosp10/out/target/product/sargo
$ fastboot flashall -w
--------------------------------------------
Bootloader Version...: b4s4-0.2-6355063
Baseband Version.....: g670-00042-200421-B-6414611
Serial Number........: 92UAY04L95
--------------------------------------------
Checking 'product'                                 OKAY [  0.058s]
Setting current slot to 'b'                        OKAY [  0.138s]
.....
Erasing 'userdata'                                 OKAY [  0.311s]
Erase successful, but not automatically formatting.
File system type raw not supported.
Erasing 'metadata'                                 OKAY [  0.006s]
Erase successful, but not automatically formatting.
File system type raw not supported.
Rebooting                                          OKAY [  0.001s]
Finished. Total time: 336.662s

将二进制驱动烧录进真机,从而可以使用无线连接:

# 禁用校验机制
adb root
adb disable-verity
adb shell sync
adb reboot

# 上传模块
adb root
adb remount
adb push /media/nfs1/android-kernel/out/android-msm-pixel-4.9/dist/wlan.ko /vendor/lib/modules/

# 重启手机生效
adb reboot

8. 基本使用场景

检验编译串号:
/images/2022_02_03_10_18_02_498x265.jpg

控制中心是用来切换双系统的快捷方式:

/images/2022_02_03_10_26_40_346x397.jpg

点击控制中心后将出现Start按钮:

/images/2022_02_03_10_27_56_236x459.jpg

点击Start按钮后,第二系统将启动:

/images/2022_02_03_10_28_34_234x472.jpg

启动成功:

/images/2022_02_03_10_29_19_233x477.jpg

再次点击Start按钮进入到第二系统:

/images/2022_02_03_10_30_12_230x475.jpg

在第二系统中点击控制中心将提示推出该系统并回到主系统:

/images/2022_02_03_10_31_09_231x479.jpg

退出后将回到第一系统的锁屏界面:

/images/2022_02_03_10_31_44_235x479.jpg

9. 定制化

定制化1: 语言设置/输入法设置

定制化2:为双系统各自安装软件仓库:

$ adb install apks/MobileAssistant_1.apk 
Performing Streamed Install
Success

定制化3:为双系统安装更多的apks:

定制化4: 更改主题等

WorkingTipsOnCellsOnAndroid10

1. cells src preparation

Clone the cells source code via:

# mkdir -p ~/Code/show/cells
# cd ~/Code/show/cells
# git clone https://github.com/jianglin-code/cells-android10.git
# cd cells-android10
# ls
cells  frameworks  kernel  README.md  system

2. aosp 10 src preparation

Clone the specified aosp 10 version(10.0.0_r33):

# mkdir -p ~/Code/show/aosp10
# cd ~/Code/show/aosp10
# repo init -u https://mirrors.tuna.tsinghua.edu.cn/git/AOSP/platform/manifest -b android-10.0.0_r33
# repo sync -j8

3. Kernel src preparation

For pixel 3a, clone the kernel src via:

# mkdir -p ~/Code/show/android-kernel
# cd ~/Code/show/android-kernel
#  repo init --depth 1 -u https://aosp.tuna.tsinghua.edu.cn/kernel/manifest -b android-msm-bonito-4.9-android10
# repo sync -j4
# ls
build  build.config  prebuilts  prebuilts-master  private
# du -hs *
732K	build
0	build.config
189M	prebuilts
5.8G	prebuilts-master
870M	private

4. Driver binary preparation

Find the binary version from https://source.android.com/setup/start/build-numbers#source-code-tags-and-builds:

QQ2A.200305.002	android-10.0.0_r30	Android10	Pixel 2、Pixel 2 XL、Pixel 3、Pixel 3 XL、Pixel 3a、Pixel 3a XL	2020-03-05

Downlod the driver binary from https://developers.google.cn/android/drivers?hl=zh-cn#sargoqq2a.200405.005:

/images/2022_02_02_22_55_30_880x211.jpg

Copy the downloaded files to aosp10 src tree:

# cp extract-google_devices-sargo.sh extract-qcom-sargo.sh /root/Code/show/aosp10

5. Build kernel

Replace the source code via:

# mv private/msm-google private/msm-google.back
# cp -ar  ~/Code/show/cells/cells-android10/kernel/ private/msm-google

Build the kernel via:

# cd private/msm-google
# make mrproper
# cd ../../
# cp -r private/msm-google.back/techpack/ private/msm-google/
# vim build/build.sh
comment the line of soong_zip(line 798)
# build/build.sh

Examine the kernel out files:

# ls out/android-msm-pixel-4.9/dist/
abi.prop  Image.lz4              kernel-uapi-headers.tar.gz  System.map  wlan.ko
dtbo.img  kernel-headers.tar.gz  sdm670.dtb                  vmlinux

6. Build the aosp

Extract the binary files:

# ./extract-google_devices-sargo.sh 
# ./extract-qcom-sargo.sh 

Replace the kernel:

# mv device/google/bonito-kernel/Image.lz4 device/google/bonito-kernel/Image.lz4.back
# cp /root/Code/show/android-kernel/out/android-msm-pixel-4.9/dist/Image.lz4 device/google/bonito-kernel/Image.lz4

Including the cells into building:

# cp -r /root/Code/show/cells/cells-android10/cells/ vendor/
# vim device/google/bonito/device.mk
Added at the last line:   
$(call inherit-product-if-exists, vendor/cells/cells_build.mk)

Building via:

# source build/envsetup.sh
# lunch aosp_sargo-userdebug
# vim frameworks/base/data/etc/privapp-permissions-platform.xml
Added: 
    <privapp-permissions package="com.cells.cellswitch.secure">
        <permission name="android.permission.BLUETOOTH_PRIVILEGED"/>
    </privapp-permissions>
# vim vendor/cells/switchsystem/src/com/cells/cellswitch/secure/view/SwitchActivity.java
Commentd: 
//import android.os.CellsManager;
//import android.os.ICellsManager;
# cp -r /root/Code/show/aosp10back/frameworks/multidex/library/
frameworks/multidex
# m -j128

The building will failed, solved via:

# development/vndk/tools/header-checker/utils/create_reference_dumps.py  -l libbinder && development/vndk/tools/header-checker/utils/create_reference_dumps.py  -l libhwbinder_noltopgo && development/vndk/tools/header-checker/utils/create_reference_dumps.py  -l libhidlbase && m -j128

Output:

# ls out/target/product/sargo/*.img
out/target/product/sargo/boot-debug.img     out/target/product/sargo/ramdisk.img
out/target/product/sargo/boot.img           out/target/product/sargo/ramdisk-recovery.img
out/target/product/sargo/dtb.img            out/target/product/sargo/super_empty.img
out/target/product/sargo/dtbo.img           out/target/product/sargo/system.img
out/target/product/sargo/persist.img        out/target/product/sargo/system_other.img
out/target/product/sargo/product.img        out/target/product/sargo/vbmeta.img
out/target/product/sargo/ramdisk-debug.img  out/target/product/sargo/vendor.img

Final size for building:

# du -hs *
15G     android-kernel
177G    aosp10
2.4G    aosp10back
6.0G    cells

7. Flashing

With pixel 3a connected with usb:

$ adb devices
List of devices attached
92UAY04L95	device

$  adb reboot bootloader

Flash with following command:

$ fastboot devices
92UAY04L95	fastboot
$ export ANDROID_PRODUCT_OUT=/root/Code/show/aosp10/out/target/product/sargo
$ fastboot flashall -w
--------------------------------------------
Bootloader Version...: b4s4-0.2-6355063
Baseband Version.....: g670-00042-200421-B-6414611
Serial Number........: 92UAY04L95
--------------------------------------------
Checking 'product'                                 OKAY [  0.058s]
Setting current slot to 'b'                        OKAY [  0.138s]
.....
Erasing 'userdata'                                 OKAY [  0.311s]
Erase successful, but not automatically formatting.
File system type raw not supported.
Erasing 'metadata'                                 OKAY [  0.006s]
Erase successful, but not automatically formatting.
File system type raw not supported.
Rebooting                                          OKAY [  0.001s]
Finished. Total time: 336.662s

Flashing with wlan.ko, so that we could get wireless connection:

# disable-verity on the phone
adb root
adb disable-verity
adb shell sync
adb reboot

# push module
adb root
adb remount
adb push /media/nfs1/android-kernel/out/android-msm-pixel-4.9/dist/wlan.ko /vendor/lib/modules/

# reboot phone
adb reboot

8. Basic Usage

View the build number:
/images/2022_02_03_10_18_02_498x265.jpg

Control is the switch for dual-system:

/images/2022_02_03_10_26_40_346x397.jpg

Press Control shows the Start button:

/images/2022_02_03_10_27_56_236x459.jpg

The second system is starting:

/images/2022_02_03_10_28_34_234x472.jpg

After started:

/images/2022_02_03_10_29_19_233x477.jpg

Press Start for entering the 2nd system:

/images/2022_02_03_10_30_12_230x475.jpg

Press Control will show hints for Exit this system:

/images/2022_02_03_10_31_09_231x479.jpg

After exit, the system will show on the screen lock:

/images/2022_02_03_10_31_44_235x479.jpg

9. Customization

Language setting.

Install software shop in both system.:

$ adb install apks/MobileAssistant_1.apk 
Performing Streamed Install
Success

Install more apks in both systems.

Changing the theme.

BuildAOSP10Kernel

为模拟器emulator编译aosp10的内核.

内核源码获取

需要获取模拟器自身的内核代码,方法是通过adb shell进入到shell下运行uname -a

尽量找和默认内核差不多的版本的内核进行编译,否则有可能编译出的内核无法启动系统。这里选择的是4.14.112+.

$ git clone https://android.googlesource.com/kernel/goldfish.git
$ git checkout -b android-goldfish-4.14-gchips remotes/origin/android-goldfish-4.14-gchips
$ git branch 
* android-goldfish-4.14-gchips
  master

获取的内核源码架构如下:

# ls
arch                          build-kernel.sh  CREDITS        firmware  ipc      lib          modules.builtin  README    sound       verity_dev_keys.x509
block                         built-in.o       crypto         fs        Kbuild   MAINTAINERS  modules.order    samples   System.map  virt
build.config.goldfish.arm64   certs            Documentation  include   Kconfig  Makefile     Module.symvers   scripts   tools       vmlinux
build.config.goldfish.x86_64  COPYING          drivers        init      kernel   mm           net              security  usr         vmlinux.o

内核编译链获取

内核编译链在编译好的aosp10源码下,编译方法不再详细讲解。

# ls prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/
bin  COPYING  COPYING3  COPYING3.LIB  COPYING.LIB  COPYING.RUNTIME  lib  libexec  MODULE_LICENSE_GPL  NOTICE  OWNERS  repo.prop  x86_64-linux-android
# ls prebuilts/qemu-kernel/build-kernel.sh
prebuilts/qemu-kernel/build-kernel.sh

编译

android-goldfish-4.14-gchips内核中需要做以下修改以通过编译:

# vim /security/selinux/include/classmap.h
添加:
    #include <linux/socket.h>
# vim scripts/selinux/mdp/mdp.c 
# scripts/selinux/genheaders/genheaders.c
去掉头文件包含的 #include <sys/socket.h>

编译配置:

export PATH=$PATH:/home/xxxxx/Code/aosp10/prebuilts/gcc/linux-x86/x86/x86_64-linux-android-4.9/bin
export ARCH=x86_64
export CROSS_COMPILE=x86_64-linux-android-
export REAL_CROSS_COMPILE=x86_64-linux-android-

创建内核定义文件:

# cp arch/x86/configs/x86_64_ranchu_defconfig  arch/x86/configs/x86_64_emu_defconfig

编译:

# /home/xxxx/Code/aosp10/prebuilts/qemu-kernel/build-kernel.sh --arch=x86_64

最终编译成品:

# cp /tmp/kernel-qemu/x86_64-4.14.112/kernel-qemu  ~/

测试内核

emulator启动的时候显式指定所需的内核:

# emulator -show-kernel -kernel ~/kernel-qemu

检测内核的方式同样是通过adb shell进入到命令行界面下查看内核。

RunWaydroidUbportsOnPixel3a

最近会研究一些安卓虚拟化的知识,这里记录下来在Pixel 3a上刷Ubports后,在Ubports中启用waydroid的过程。

1. 准备工作/相关概念

Pixel 3a一支,淘宝很容易买到,注意要买可解锁BootLoader的,价格大概是四五百块,取决于成色。

选择Pixel 3a是因为它是Ubports官方支持中比较完善的几个之一,官方的设备支持列表如下:
https://devices.ubuntu-touch.io/?pk_vid=5294f9f7280f826e164306913156a7ee

当然如果手头有别的可以刷的手机也可以尝试下, Pixel 3a的刷机体验是比较好的。

Ubports: Ubuntu touch.
Waydroid: 以前称为Anbox-Halium,是Anbox 的重建版本,旨在使用比Anbox 更新更流畅的安卓算力体验。

2. 操作指南

2.1 刷入安卓9

参考https://devices.ubuntu-touch.io/device/sargo/

全翻墙的情况下,访问:

https://flash.android.com/release, 按提示操作, 记得选择图示为PQ3B.190801.002的安卓9版本。

/images/2022_01_25_09_06_50_621x486.jpg

看到此提示则代表刷入已经成功:

/images/2022_01_25_07_58_49_612x183.jpg 刷入成功后会提示需要lock bootloader, 按照提示先将bootloader锁定后,进入到安卓9中执行初始化操作. 接着进入到解锁bootloader以便刷Ubports.

2.2 解锁bootloader:

首先要做的是开启Usb调试 关于手机->版本号上狂点,直至打开开发者模式, 而后系统->开发者选项->调试->USB调试.

# adb devices
List of devices attached
xxxxxx5	device

# adb reboot bootloader

此时手机会停在fastboot阶段,在终端中继续敲入

# fastboot flashing unlock
OKAY [  0.338s]
Finished. Total time: 0.338s

此时在手机上按音量-键选择到unlock bootloader的选项后,继续按电源键确定。bootloader解锁成功后需重新启动并重新设置手机。此时需要重新开启usb调试等。

2.3 刷入ubports

再次强调: ubports刷入的先决条件是pixel 3a上运行的安卓版本为PQ3B.190801.002

ArchLinux上通过snap安装ubports刷机软件, 参考网址如下:

https://snapcraft.io/install/ubports-installer/arch

开启刷机软件开始刷ubports:

sudo ubports-installer

/images/2022_01_25_08_25_47_803x441.jpg

确认手机型号:

/images/2022_01_25_08_26_04_657x371.jpg

选择devel版(如果不是为了体验waydroid也可以选择为stable版), 一定要选择wipe userdata,否则刷机将一直卡顿不会成功:

/images/2022_01_25_08_26_38_621x462.jpg

这里提示在fastboot菜单中需要选择为Recovery Mode才可以继续安装,在手机上按音量-键结合电源键选择,进入到恢复模式后点下一步:

/images/2022_01_25_08_27_53_716x365.jpg

现在ubports-installer将自动下载镜像并进行刷机,刷机速度取决于下载速度, 推荐在空闲时段操作,在早上7、8点时大概几分钟时间刷好:

/images/2022_01_25_08_29_20_554x581.jpg

刷机软件提示出以下界面的时候,手机将重启,这时需要耐心等待手机上的刷机进程完成写入操作,刷机过程中会有个黄色的小标志在不停转动, 而后将重启:

/images/2022_01_25_08_31_21_651x492.jpg

经过一系列设置之后,Ubports将启动成功并进入到系统中。

2.4 安装waydroid

确认自己安装的是开发者版本,如果是stable的话,在关于->检查更新下的配置按钮中,切换成开发者版本就可以了:

/images/2022_01_25_08_47_25_478x309.jpg

waydroid中也是可以使用adb命令的,使用adb命令连接到手机上后,运行waydroid的安装操作, adb命令的一个参考如下(以下参考演示了如何连接到手机、如何从手机取回截屏):

$ adb devices
List of devices attached
92UAY04L95	device

$ adb shell
phablet@ubuntu-phablet:~$ ls
Desktop  Documents  Downloads  Music  Pictures  Public  Templates  Videos
phablet@ubuntu-phablet:~$ cd Pictures/
phablet@ubuntu-phablet:~/Pictures$ ls
Screenshots
phablet@ubuntu-phablet:~/Pictures$ cd Screenshots/
phablet@ubuntu-phablet:~/Pictures/Screenshots$ ls
screenshot20220125_084411555.png
phablet@ubuntu-phablet:~/Pictures/Screenshots$ exit

$ adb pull /home/phablet/Pictures/Screenshots/screenshot20220125_084411555.png
/home/phablet/Pictures/Screenshots/screenshot20220125_084411555.png: 1 file pulled, 0 skipped. 2.7 MB/s (76661 bytes in 0.027s)

可以检查一下磁盘占用情况, 确保安装waydroid具备足够的磁盘空间:

dfphablet@ubuntu-phablet:~$ df -h
Filesystem       Size  Used Avail Use% Mounted on
/dev/root        3.0G  2.2G  804M  73% /
devtmpfs         1.7G  604K  1.7G   1% /dev
tmpfs            1.8G  1.3M  1.8G   1% /run
/dev/loop0       268M  267M     0 100% /android
/dev/mmcblk0p72   49G   27M   47G   1% /userdata
none             4.0K     0  4.0K   0% /sys/fs/cgroup
cgmfs            100K     0  100K   0% /run/cgmanager/fs
tmpfs            1.8G   32K  1.8G   1% /tmp
none             5.0M     0  5.0M   0% /run/lock
none             1.8G  172K  1.8G   1% /run/shm
none             100M     0  100M   0% /run/user
tmpfs            1.8G     0  1.8G   0% /media
tmpfs            1.8G     0  1.8G   0% /var/lib/openvpn/chroot/tmp
tmpfs            1.8G     0  1.8G   0% /var/lib/sudo
/dev/mmcblk0p71  755M  512M  228M  70% /android/vendor
tmpfs            1.8G     0  1.8G   0% /mnt/vendor
/dev/mmcblk0p48   35M  3.8M   30M  12% /mnt/vendor/persist
/dev/mmcblk0p66   12M   80K   11M   1% /android/metadata
/dev/mmcblk0p22   80M   72M  8.8M  90% /android/vendor/firmware_mnt
tmpfs            356M   40K  356M   1% /run/user/32011
tmpfs            356M     0  356M   0% /run/user/0

adb shell下输入如下命令安装waydroid:

sudo -s
sudo mount -o remount,rw /
apt update
apt install waydroid -y
waydroid init

值得注意的是,waydroid init需要从sourceforge拉取700MB左右的镜像,由于众所周知的原因,国内网络一直不是很好,这一步可能会耗费很长的时间。个人建议是在网络空闲时段(例如起个大早来跑)运行该操作。当然具备动手能力的可以用全翻墙网路来跑,速度会快很多。

waydroid命令实际上是一个python脚本,理论上是可以改一下调整它的镜像初始化机制以使用本地包用于离线安装的, 有兴趣的可以更改源码。

root@ubuntu-phablet:~# which waydroid
/usr/bin/waydroid
root@ubuntu-phablet:~# cd /usr/lib/waydroid/
root@ubuntu-phablet:~# grep -i "http" ./ -r | grep channel
./tools/config/__init__.py:    "system_channel": "http://ota.waydro.id/system",
./tools/config/__init__.py:    "vendor_channel": "http://ota.waydro.id/vendor",

waydroid初始化过程:

root@ubuntu-phablet:~# waydroid init
[08:55:02] Download https://sourceforge.net/projects/waydroid/files/images/system/lineage/waydroid_arm64/lineage-17.1-20211021-VANILLA-waydroid_arm64-system.zip/download
[09:04:37] Validating system image
[09:04:38] Extracting to /var/lib/waydroid/images
[09:05:22] Download https://sourceforge.net/projects/waydroid/files/images/vendor/waydroid_arm64/lineage-16.0-20211020-HALIUM_9-waydroid_arm64-vendor.zip/download
[09:05:42] Validating vendor image
[09:05:42] Extracting to /var/lib/waydroid/images

此时需要重启手机以继续安装。

2.5 启动waydroid

启动完毕后,首先启动waydroid容器:

$ adb shell
phablet@ubuntu-phablet:~$ sudo waydroid container start
[sudo] password for phablet: 

然后在另一个adb shell中启动waydroid session, 此时第一个shell里的命令会退出,接着就可以点开waydroid了:

$ waydroid session start
[09:15:30] XDG Session is not "wayland"
[09:15:32] Failed to start Clipboard manager service, check logs
[09:15:51] Android with user 0 is ready

接着在手机里点开wayroid则可以开启waydroid界面.

启动这一步一直没太搞明白应该怎样才是正确的操作。但经历以上操作后,再次关机重启后,waydroid都可以直接在ubports下直接点开

如果遇到初始化问题不成功需要重新开始的话,可以使用以下命令清零waydroid安装:

apt remove waydroid
apt purge waydroid
sudo rm -rf /var/lib/waydroid /home/.waydroid ~/waydroid ~/.share/waydroid ~/.local/share/applications/*aydroid* ~/.local/share/waydroid

2.6 体验waydroid

安装应用宝:

$ adb push MobileAssistant_1.apk /home/phablet/
MobileAssistant_1.apk: 1 file pushed, 0 skipped. 6.1 MB/s (10925622 bytes in 1.720s)
$ apks adb shell
phablet@ubuntu-phablet:~$ sudo waydroid app install ~/MobileAssistant_1.apk
[sudo] password for phablet: 

/images/2022_01_25_09_25_18_406x838.jpg 接下来的操作就是常规的安装apk, 使用apk。

鲁大师跑快40万分:

/images/2022_01_25_09_49_20_405x834.jpg