USB passthrough to connect a RealSense camera in Android Emulator - android

I want to connect an Intel Realsense camera (D455) to my android virtual device, running on the android emulator, so I can debug my android APP using the Realsense camera.
On this page, it seems that the latest android studio emulator supports USB passthrough, so I tried the following command:
./emulator -avd Nexus_6P_API_29 -qemu -usb -device usb-host,vendorid=0x8086,productid=0x0b5c
where -avd Nexus_6P_API_29 specifies the name of the android virtual device, and vendorid and productid are obtained by lsusb.
The emulator gives the following error message (showing it 3 times):
qemu-system-x86_64: Warning: speed mismatch trying to attach usb device "Intel(R) RealSense(TM) Depth Ca" ( speed) to bus "usb-bus.0", port "1" (full speed)
It seems the emulator does find the device, but there's a "speed mismatching" problem. I found a good explanation of the problem on this page, saying usb-bus corresponds to USB 1.0. As the Realsense camera supports usb-3.2, I think I should use usb-3.0, so I tried the following:
./emulator -avd Nexus_6P_API_29 -qemu -usb -device nec-usb-xhci,id=xhci -device usb-host,vendorid=0x8086,productid=0x0b5c
specifying nec-usb-xhci for usb-3.0.
However I'm getting the error message as:
qemu-system-x86_64: Warning: speed mismatch trying to attach usb device "Intel(R) RealSense(TM) Depth Ca" ( speed) to bus "xhci.0", port "1" (full+high+super speed)
I noted that, the speed of the camera is displayed as ( speed). (I.e. the actual speed, while normally should be one of (full speed)/(high speed)/(super speed), is blank.)
I guess the speed mismatch problem has something to do with this blank speed. Has anyone had similar experiences ? Thanks in advance !

Only EHCI is already built in the kernel on AVDs.
I've wrote on XDA a little guide with some deeper informations about it.
You can read more there.
If your device can handle EHCI, you could try it with:
-qemu -usb -device usb-ehci,id=ehci -device usb-host,bus=ehci.0,vendorid=0x8086,productid=0x0b5c
Otherwise, recompile your kernel with XHCI enabled.
Perhaps some other steps are necessary as well. Like adding permissions to android.hardware.usb.host
Update: 22.03.2021
I figured it is (was) a speed reporting issue from emulator qemu. Now with the Emulator Version 30.5.3 this issue is fixed and it works with all my UVC Standard cameras, on EHCI und XHCI. Also the built in Face Time Camera works as USB attached Device. But, only two Apps from the PlayStore were able to show me the footage. USB Camera - Connect EasyCap or USB WebCam very smooth and nice footage. UVC Camera / Usb Camera with driver from userspace with hugh jitter.

Related

Cannot connect Android emulator to a virtual serial port

I have a virtual serial port installed on my Windows 10 system, which sets up a bridge between virtual ports named COM2 and COM3. I wrote a test application for desktop to see whether the bridge works and there was no problem. The data sent from COM2 was correctly received in COM3. So the ports seem to be fine.
Now I want to run the android emulator connected to one of these virtual ports. The command I wrote is this:
emulator.exe -avd android6 -partition-size 512 -qemu -serial COM2
First, the configuration panel for the serial port appeared:
but after confirming the port config, the following error message appears and the emulator never starts:
HAX is working and emulator runs in fast virt mode.
c:\Program Files (x86)\Android\android-sdk\tools\..\emulator\qemu\windows-x86_64\qemu-system-i386.exe: -serial COM2: Failed SetCommState
c:\Program Files (x86)\Android\android-sdk\tools\..\emulator\qemu\windows-x86_64\qemu-system-i386.exe: -serial COM2: could not connect serial device to character backend 'COM2'
Now the irony is, if I change COM2 to COM1 which is an actual serial port, the emulator starts without any problems and connects to that port after showing the port-configuration window. So I think the issue here has something to do with COM2 being virtual.
I tried everything I could and searched fruitlessly for hours to figure out what's wrong, which led to nothing useful (including this totally irrelevant question)
Upon further investigation, I found out that some virtual port software just don't support connecting to the emulator. After that I installed the Virtual Serial Port Driver by Eltima and it just works fine.
DISCLAIMER: This is not a promotion and I don't have any kind of affiliation with Eltima. I added the answer only because it might save some others from a lot of trouble and headache. The only valid conclusion from this answer is Eltima's software works with emulator, while others seemingly don't function properly.

Android: fastboot does not find virtual device / emulator

I want to flash a special disk image onto an Android Emulator (Google Pixel 2) using adb and fastboot. The virtual device can only be detected by adb but not by fastboot. I already tried (cmd as an administrator):
C:\windows\system32>adb devices
List of devices attached
emulator-5554 device
C:\windows\system32>adb reboot bootloader
C:\windows\system32>fastboot devices
C:\windows\system32>
I am using Android Studio (Android SDK and Google USB drivers are installed properly, i also enabled USB debugging in the emulator) on Windows 10. Is it possible (in principle) to use fastboot together with an emulator? If yes, do you have an idea why it does not work here?
No, you can't use fastboot with Android Studio emulator. AVD does not have a bootloader, it just boots the system and ramdisk images.
If you want to use fastboot, you'll need a real device that supports it (mostly everyone but Samsung's).
You may find more information in this post: how to reboot the emulator into recovery mode

Authorization problem for Android emulator on macOS Mojave?

I am unable to run my Android application on the emulator from Android Studio on macOS Mojave. But I have no problem running the same application using the physical device connected to the USB port. I think the problem might be that the emulator is not authorized to access the webcam of my Macbook Pro. On the terminal:
$ emulator -webcam-list
List of web cameras connected to the computer:
Camera 'webcam0' is connected to device 'CC24342DY7CF6VVDK' on channel 0 using pixel format 'YUYV'
But when I start the emulator on the CLI, I have this message:
$ emulator -avd Pixel_2_API_29
emulator: WARNING: Camera name 'webcam0' is not found in the list of connected cameras.
Use '-webcam-list' emulator option to obtain the list of connected camera names.
There is an issue here about this problem: https://youtrack.jetbrains.com/issue/IDEA-219288
But my terminal is authorized to access the webcam. I can run other applications accessing the camera from the CLI without a problem.
So I think this is something wrong. Any suggestion?
Note: Currently, MediaRecorder does not work on the emulator.
This has nothing to do with macOS security.
https://developer.android.com/reference/android/media/MediaRecorder

Running Android 5.0.1 x86 virtual device with host GPU disabled

I am working on automating screenshots capture for one of my apps.
Since I want to capture screenshots of some activities and widgets that differ according to the system locale, I start for each desired language a new Android virtual device (emulator) with the correct properties for setting the system locale. Then, specific user interactions are simulated with uiautomator.
My workflow is working as expected but I have an issue with screenshots capture. Indeed, using UiDevice.takeScreenshot(File storePath) or screencap on the emulator always creates an empty file.
It seems to be a known issue with AVD running with Host GPU enabled (which is my case). The proposed workaround is to start the emulator with Host GPU disabled. Unfortunately, when I start the virtual device with Host GPU disabled, the emulated screen remains black.
I have taken a look at the output of the emulator with the -verbose option and abd -e logcat command (emulator output, logcat output). In logcat ouput I have identified the following error but I cannot figure out the cause of it:
E/SurfaceFlinger( 929): hwcomposer module not found
E/SurfaceFlinger( 929): ERROR: failed to open framebuffer (No such file or directory), aborting
Below is the command I use to start the emulator:
LD_LIBRARY_PATH=$ANDROID_HOME/tools/lib:$LD_LIBRARY_PATH emulator -avd screenshots -skin nexus_6 \
-skindir $ANDROID_STUDIO_HOME/plugins/android/lib/device-art-resources -no-audio \
-prop persist.sys.language=en -prop persist.sys.country=en -verbose -qemu -m 512 -enable-kvm &
I am running Fedora 21 with an Nvidia GPU.
Does someone has succeeded to start an Android virtual device with a recent system image with Host GPU disabled? Any help or suggestion is welcomed.
Holy cow! The problem I am facing is a known issue. Workaround is to use a skin with lower screen resolution (e.g. nexus_4).

Connect USB device to Android Emulator?

We've been looking into Android 3.1+ and its ability to read/write to USB devices connected to the OTG/Host port.
I've found some code examples that allow me to detect and read/write to a USB HID device, but at the moment, I simply don't have a physical 3.1+ compatible device to deploy and remotely debug on.
Does anyone know how I can attach my HID device to the emulator, via the PC/Eclipse so the app can detect and read/write to/from the device?
I've tried listing the currently connected USB Devices but it shows none, as you'd no doubt guess.
Any ideas?
Cheers
The Android emulator is based on QEMU. Even if the emulator version is so ancient, there appears to be support for passing USB devices from the host. It does not seem to be available for ARM devices though, the emulated ARM machine does not have a USB controller. (I have already tried enabling all USB host controllers for the goldfish_armv7 kernel based on Linux 3.4, without luck. The default emulator goldfish_armv7 kernel does not even have Host USB enabled.)
If you are not limited to ARM and can use x86, then I suggest to check out http://www.android-x86.org/, its images can be used with a standard QEMU i386 (or x86_64) machine. This also yields better performance by using the KVM extension on Linux.
To passthrough a USB device with of vendor ID 1234 and device ID abcd, you can run the emulator command:
emulator -avd x86-machine -qemu -usb -usbdevice host:1234:abcd
Or, when using QEMU:
qemu-system-i386 -m 1G -cdrom android-x86.iso -usb -usbdevice host:1234:abcd
You will need read/write permissions for /dev/bus/usb/XXX/YYY, for that you can create a udev rule such as:
SUBSYSTEM!="usb", GOTO="end_skip_usb"
ATTRS{idVendor}=="1234", ATTRS{idProduct}=="abcd", TAG+="uaccess"
LABEL="end_skip_usb"
Now, upon insertion of the USB device, your emulator should recognize a USB device. This is tested for a Linux installation with a Android x86 4.3 image.
AFAIK this isn't possible. Android emulators do not emulate many things that exist in real devices... but this reminds me of an attempt to run ADB over Bluetooth.
This isn't a direct positive answer to your question but perhaps it can help you find a workaround the way I did: Install an "emulator" on a physical x86 netbook (dual-boot) and use the links referred to in my posts to accomplish what you are trying to do via WiFi or Bluetooth.
Hope this helps.
Create android Virtual Machine on virtualBox or vm player with this image.
Connect USB and connect with Eclipse using ADB connect (your device IP).
Installed android guest in virtualbox with Windows 7 host using image android-x86-4.0-r1-eeepc.iso from here (because my company's computer locked bios and I couldn't enable the vt-x emulation I had to install a version prior to 4.4). Then pluged in a usb drive, opened VM - Settings - USB in Virtualbox Manager, clicked the second icon on the right with a plus sign on it, chose the usb drive. Virtualbox then installed driver for the USB drive. After it finished, booted the android VM. Started OpenManager, went to mnt/USB, and files of the usb drive were there!

Categories

Resources