Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly handle USB attach of Android device in USB debugging mode #5717

Open
BLuFeNiX opened this issue Mar 9, 2020 · 13 comments
Open

Correctly handle USB attach of Android device in USB debugging mode #5717

BLuFeNiX opened this issue Mar 9, 2020 · 13 comments
Labels
C: other hardware support P: default Priority: default. Default priority for new issues, to be replaced given sufficient information. T: enhancement Type: enhancement. A new feature that does not yet exist or improvement of existing functionality.

Comments

@BLuFeNiX
Copy link

BLuFeNiX commented Mar 9, 2020

The problem you're addressing (if any)
As discussed in the closed issue ticket here: #2202
Android devices in debugging mode (ie: for Android app development) cannot be attached to a VM.

Describe the solution you'd like
Provide a way to connect the Android device while in USB debugging mode. Even a special-case script or some kind of config option would be better than nothing.

Where is the value to a user, and who might that user be?
Android developers can use Qubes for work.

Describe alternatives you've considered
There is an ADB over TCP workaround, but this is not ideal, and also requires that the user be connected to a network.

EDIT: This workaround isn't even feasible on most Android devices, as the ADB over network setting is not exposed via any UI, and must be activated by a shell command via ADB. So, you still need a working USB ADB connection in order to hand over to WiFi ADB. Additionally, this setting reverts when the phone is rebooted, making it impossible to "set and forget."

Related, non-duplicate issues
#2202

@BLuFeNiX BLuFeNiX added P: default Priority: default. Default priority for new issues, to be replaced given sufficient information. T: enhancement Type: enhancement. A new feature that does not yet exist or improvement of existing functionality. labels Mar 9, 2020
@strugee
Copy link
Contributor

strugee commented Mar 9, 2020

This appears to be a recentish regression. This definitely worked at some point. A few months ago I think? (I can also reproduce this issue; I ran into #5701 while diagnosing the problem reported here, but I never followed up.)

@BLuFeNiX
Copy link
Author

@strugee Well that's good news, since I thought my enhancement request might be turned down given that #2202 seems to have been closed as "Won't Fix."

I will wait for someone to ask me for logs, since I am unsure of what will be useful.

@ejose19
Copy link

ejose19 commented Mar 11, 2020

This indeed worked with Android 9, but with Android 10 it's gone again.

@andrewdavidwong andrewdavidwong added this to the Far in the future milestone Mar 12, 2020
@n0madK
Copy link

n0madK commented Mar 15, 2020

A workaround is to run adb in sys-usb and use it over rpc. Obviously not ideal, but until there's a better solution:

In dom0 /etc/qubes-rpc/policy/qubes.ConnectTCP
android @default allow,target=sys-usb

In sys-usb, install adb or copy it from your Android Studio install (works best if this is the same version that Android Studio is expecting). Then make sure sys-usb can see your device
adb devices

In "android" vm, increase xen_gntalloc limit to prevent ioctl errors (put this in your /rw/config/rc.local for your convenience):
echo 4096 > /sys/module/xen_gntalloc/parameters/limit

make sure Android Studio is closed, and no adb server is running, then run
qvm-connect-tcp ::5037

Now you should be able to use adb like normal. Whenever you close Android Studio or issue a adb kill-server from android vm, you'll have to re-start it in sys-usb.

@ejose19
Copy link

ejose19 commented Mar 15, 2020

The other workaround would be passing a different usb controller to the adb qube, to not run anything in sys-usb and avoid any risk (even if small). If there's a single one in the system maybe a usb PCI card will do the job.

@BLuFeNiX
Copy link
Author

BLuFeNiX commented Mar 17, 2020

@n0madK Neat, I might try that out. My workaround for the time being has been:

  1. copy adb binary to sys-usb
  2. run adb tcpip 5555 from sys-usb
  3. run adb connect <android_device_IP> from the desired domain

However, the latency and bandwidth is not great, so your solution sounds better for a long-term fix.

@ejose19 Also interesting, but I'm on a laptop, so no PCI slots.

@manishjhawar
Copy link

In dom0 /etc/qubes-rpc/qubes.ConnectTCP
android @default allow,target=sys-usb

the path for above should be /etc/qubes-rpc/policy/qubes.ConnectTCP

HTH

@marmarek
Copy link
Member

marmarek commented Apr 7, 2020

Yes, of course.

@n0madK
Copy link

n0madK commented Apr 7, 2020

Apologies, corrected the typo

@ky-ex
Copy link

ky-ex commented May 19, 2021

I have trouble to use the workaround.
Latest QubesOS release.
sys-usb based on Fedora 30.
adb devices inside sys-usb works fine.
Added "android-access-vm @default allow,target=sys-usb" to file /etc/qubes-rpc/policy/qubes.ConnectTCP in dom0.
In android-access-vm I ran "echo 4096 > /sys/module/xen_gntalloc/parameters/limit" and "qvm-connect-tcp ::5037" (which reports: Binding TCP '@default:5037' to 'localhost:5037' )

Now, if I execute "adb devices" inside android-access-vm, it reports
"adb server version (40) doesn't match this client (39); killing..."
(which causes the adb instance inside sys-usb to exit)
and starts a new instance (inside android-access-vm).

However, that new adb instance doesn't work. Running adb devices inside android-access-vm again gives me "socat ... connection refused", child exited, error protocol fault.

What is my mistake?

@ehanoc
Copy link

ehanoc commented Apr 17, 2023

Any update on this? This makes Android development and debugging quite hard if possible at all. Thet network workarounds haven't worked for me

@andrewdavidwong andrewdavidwong removed this from the Release TBD milestone Aug 13, 2023
@alexandre-khoury
Copy link

Any update?

@ViliusSutkus89
Copy link

ViliusSutkus89 commented Oct 6, 2023

usbip redirects whole USB port, not just the currently attached device. I've found this to work just fine in this particular use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: other hardware support P: default Priority: default. Default priority for new issues, to be replaced given sufficient information. T: enhancement Type: enhancement. A new feature that does not yet exist or improvement of existing functionality.
Projects
None yet
Development

No branches or pull requests