J 창고

[Android] Emulator 환경에서 USB Host 기능 사용하기 본문

컴퓨터/Linux

[Android] Emulator 환경에서 USB Host 기능 사용하기

JSFamily 2021. 6. 25. 18:30

 

1. 개요

Android Device에 USB-Serial 을 통해 Device를 연동해야 하는데 이때 Android Emulator 환경에서 테스트 할 수 있는 방법이 있어 공유해 본다.

Android Emulator를 동작시키는 QEMU의 USB passthrough 기능을 통하여 VID:PID USB Device를 Android USB-Host와 연동할 수 있다.

Android 10 기준으로 작성하였으며 USB passthrough 기능은 Linux Host에서만 지원한다.
(최근 Release 된 ChangeNote에 Windows 도 지원 된다고 명시되어 있으나 문제가 있는지 Revert 되었다)

 

2. 설정

2.1 Android Studio 설치

https://developer.android.com/studio#downloads

 

Download Android Studio and SDK tools  |  Android 스튜디오

developer.android.com

 

2.2 Setup SDK and make Android AVDs device1) Initial setup

1) Initial setup

2) Run AVD Manager

3) Create AVD Device

3-1) Select AVD Device “Pixel 3a”

3-2) Select Android Q(x86_64 / Android 10.0 (Google APIs) ) 
do not select “Android 10.0 (Google Play)

3-3) Download Android Q(X86_64) images

 

2.3 Run Android Emulator via command line

1) Go to Android Emuator Root

cd /PATH/TO/ANDROID/SDK/ROOT/Android/Sdk/emulator

2) Excute Command

./emulator @Pixel_3a_API_29 -writable-system -show-kernel -verbose -qemu -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=${USBVID},productid=${USBPID} 

 

2.4 Make permissions to connect usb device as host

1) disable verification

adb root
adb shell avbctl disable-verification
adb disable-verity
adb reboot

2) remount

adb root
adb remount
adb shell

3) write permission (in android)

echo '<permissions><feature name="android.hardware.usb.host"/></permissions>' > /system/etc/permissions/android.hardware.usb.host.xml
echo '<permissions> <feature name="android.hardware.usb.accessory" /> <library name="com.android.future.usb.accessory" file="/system/framework/com.android.future.usb.accessory.jar" /> </permissions>' > /system/etc/permissions/android.hardware.usb.accessory.xml
exit

4) reboot 

adb reboot

 

2.5 Check usb connection is working

아래와 같이 VID/PID를 명시한 Device가 인식된 것을 확인할 수 있다.

Kernel에서 확인되는 Device Log

 

ADB Logcat에서 확인되는 UsbHostManager Log

 

3. Reference

https://source.android.com/devices/automotive/start/passthrough

 

에뮬레이터 USB 패스 스루 통합 가이드  |  Android 오픈소스 프로젝트

이 문서에서는 두 개의 주변 장치 (Bluetooth 및 Wi-Fi)를 AAOS 에뮬레이터에 연결하는 방법을 설명합니다. 이 과정에서 운전자 지원과 관련된 세 가지 영역이 핵심입니다. 게스트 커널 게스트 안드로

source.android.com

https://gist.github.com/Alabate/200f021e644baed84993dd6109811ba2

 

Use custom USB device with Android emulator by using custom built kernel on Ubuntu 18.04

Use custom USB device with Android emulator by using custom built kernel on Ubuntu 18.04 - usb-android-emulator-ubuntu.md

gist.github.com

 

Comments