本文介绍如何将两个外围设备(蓝牙和 Wi-Fi)连接到 AAOS 仿真器。在此过程中,特定于驱动程序支持的三个领域是关键:
- 来宾内核
- 来宾安卓
- Linux主机
首先,您在 Guest 内核中编译并启用相关的 USB 驱动程序。接下来,Guest Android 必须选择正确的 HAL 和服务来启动驱动程序。最后,Linux 主机必须访问 USB 驱动程序,然后将其传输到QEMU 。
加密狗测试
测试了以下加密狗:
- 华硕 USB-BT400 USB 适配器 USBBT400
- Auscomer 的 USB Wi-Fi 蓝牙适配器
其他加密狗可能会工作,但是,没有其他加密狗经过测试。
原生 USB 支持
QEMU 带有将 USB 传递给仿真器的选项。 AAOS 系统映像已处理连接的电话。有关详细信息,请参阅Android 开放式附件 (AOA) 。
因为手机在建立 AOA 连接时会更改vendorID
和productID
的值,所以当手机处于 AOA 模式时,新的 USB 接口(以及原来的 USB 接口)会看到设备。
要确定 AOA 模式前后vendorID
和productID
的值,请使用lsusb
:
# Note Vendor ID and Product ID of your phone
$ lsusb
Bus 001 Device 079: ID 18d1:4ee1 Google Inc. Nexus/Pixel Device (MTP)
# Start up an emulator!
$ ./emulator @AVD_NAME -no-snapshot -qemu -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=0x18d1,productid=0x4ee1 -device usb-host,bus=ehci.0,vendorid=0x18d1,productid=0x2d00
或者,将物理端口传递给 QEMU:
# First plug something into the interested USB port and note the Bus and Device number.
$ lsusb
Bus 001 Device 012: ID 0bda:c820 Realtek Semiconductor Corp. 802.11ac NIC
# Now figure out where the Port number is.
$ lsusb -t
/: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=xhci_hcd/12p, 480M
|__ Port 4: Dev 12, If 1, Class=Wireless, Driver=btusb, 480M
|__ Port 4: Dev 12, If 2, Class=Vendor Specific Class, Driver=, 480M
|__ Port 4: Dev 12, If 0, Class=Wireless, Driver=btusb, 480M
# Launch the emulator
./emulator @AVD_NAME -no-snapshot -qemu -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,hostbus=1,hostport=4
# Now, whatever you plug into the emulator, USB passthrough will happen on the fly.
AAOS 系统映像识别手机,将其置于 AOA 模式,并在 AOA 模式运行时再次识别。
要支持 USB 直通,请确认您使用的是 Emulator 30.5.0 :
# Check for the emulator version
$ emulator --version
Emulator 30.5.0包含libusb
升级和临时解决方法,以解决 ASUS 加密狗支持的速度兼容性问题:
- https://android-review.googlesource.com/c/platform/external/qemu/+/1573247
- https://android-review.googlesource.com/c/platform/external/qemu/+/1580924
- https://android-review.googlesource.com/c/platform/external/libusb/+/1580923
蓝牙支持
为了支持蓝牙直通,Google 测试了 ASUS USB-BT400 USB Adapter USBBT400和 Auscomer 的 USB Wi-Fi Bluetooth Adapter。
首先,您需要为加密狗添加内核支持。要了解 Android 蓝牙堆栈,请参阅蓝牙。对于 HIDL,模拟器使用模拟实现。因此,请使用本机 Linux 实现进行切换。
来宾内核
要支持 USB 蓝牙加密狗:
将缺少的
btusb.ko
添加到您的内核中:--- a/goldfish_defconfig.fragment +++ b/goldfish_defconfig.fragment @@ -1,6 +1,7 @@ # CONFIG_CRYPTO_DEV_VIRTIO is not set CONFIG_BLK_DEV_MD=m +CONFIG_BT_HCIBTUSB=m CONFIG_CPUFREQ_DUMMY=m
来宾安卓
在
vendor.mk
文件中,包括 Linux 本机 HIDL 和几个权限:PRODUCT_PACKAGES += \ android.hardware.bluetooth@1.1-service.btlinux PRODUCT_COPY_FILES += \ frameworks/native/data/etc/android.hardware.usb.host.xml:$(TARGET_COPY_OUT_VENDOR)/etc/permissions/android.hardware.usb.host.xml
创建单向路径属性以切换出 HIDL,使其使用 Linux 本机 HIDL 实现:
selinux/common/domain.te get_prop(domain, qemu_prop) +get_prop(domain, vendor_build_prop)
selinux/common/property_contexts qemu.cmdline u:object_r:qemu_cmdline:s0 +qemu.preferred.bt.service u:object_r:qemu_prop:s0
每当属性
qemu.preferred.bt.service
设置为passthrough
时,您将关闭 HIDL 实现:service btlinux-1.1 /vendor/bin/hw/android.hardware.bluetooth@1.1-service.btlinux class hal user bluetooth group bluetooth net_admin net_bt_admin capabilities NET_ADMIN NET_RAW SYS_NICE disabled on property:qemu.preferred.bt.service=passthrough stop vendor.bluetooth-1-1 start btlinux-1.1
添加蓝牙配置文件以获得完整功能,例如在真实 USB 设备上:
hal/bluetooth/bdroid_buildcfg.h #ifndef _BDROID_BUILDCFG_H #define _BDROID_BUILDCFG_H #define BTM_DEF_LOCAL_NAME "gCar Emulator" #define BTA_AV_SINK_INCLUDED TRUE /* Handsfree device */ #define BTA_DM_COD {0x26, 0x04, 0x08} #endif
修改
BoardConfig.mk
文件以确定配置文件的保存位置:BoardConfig.mk # Bluetooth BOARD_HAVE_BLUETOOTH := true BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR := vendor/auto/embedded/hal/bluetooth
Linux主机
在 Linux 主机上:
更新
udev
设置以允许用户进程(例如 QEMU)拥有读/写权限:$ echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="0b05", ATTRS{idProduct}=="17cb", MODE="0666", GROUP="plugdev"' | sudo tee /etc/udev/rules.d/99-mynew.rules >/dev/null $ sudo udevadm control --reload $ sudo udevadm trigger
要运行模拟器,请设置以下命令行参数:
# Start up an emulator! $ ./emulator @AVD_NAME -no-snapshot -prop qemu.preferred.bt.service=passthrough -qemu -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=0x0b05,productid=0x17cb # Start Bluetooth Passthrough
无线网络支持
为了验证双蓝牙和 Wi-Fi,Google 使用 USB Wi-Fi 蓝牙适配器进行了测试。
来宾内核
这个特殊的 USB 加密狗使用 RTL8821CU 芯片,上游的主线内核还不支持。您可以在8821cu找到新开发的内核模块。
然后,在changelist 1575108中,将外部内核模块集成到金鱼内核源代码中以对其进行编译。
最后,内核模块编译,但有一些 CFI 崩溃。您需要手动修补代码以解决此问题。有关详细信息,请参阅Android 内核中的控制流完整性。
启用CONFIG_CFI_PERMISSIVE
并首先调试堆栈的其余部分可能会有所帮助:
--- a/goldfish_defconfig.fragment
+++ b/goldfish_defconfig.fragment
@@ -1,6 +1,7 @@
CONFIG_CFI_CLANG=m
+CONFIG_CFI_PERMISSIVE=m
在任何情况下,请转到更改列表 1575109以查看 CFI 崩溃的正确修复。
来宾安卓
要了解有关 Wi-Fi 堆栈的更多信息,请参阅Wi-Fi 概述。模拟器带有使 Wi-Fi 工作的设置。
Linux主机
在 Linux 主机上,您必须更新udev
设置以使用户进程(例如 QEMU)具有读/写权限。
# /lib/udev/rules.d/40-usb_modeswitch.rules
$ ATTR{idVendor}=="0bda", ATTR{idProduct}=="1a2b", RUN+="usb_modeswitch '/%k'"
$ echo 'SUBSYSTEM=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="c820", MODE="0666", GROUP="plugdev"' | sudo tee /etc/udev/rules.d/99-mynew2.rules >/dev/null
$ sudo udevadm control --reload
$ sudo udevadm trigger
要将加密狗传递给 QEMU:
# Start up an emulator!
$ ./emulator @AVD_NAME -no-snapshot -qemu -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=0x0bda,productid=0xc820
端口更改列表
移植以下更改列表:
- https://android-review.googlesource.com/c/kernel/common-modules/virtual-device/+/1575107
- https://android-review.googlesource.com/c/kernel/common-modules/virtual-device/+/1575108
- https://android-review.googlesource.com/c/kernel/common-modules/virtual-device/+/1575109