本文介紹如何將兩個外圍設備(藍牙和 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