Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
110.25k stars 10.57k forks source link

Windows, ADB, and OTG #3050

Open namos-23 opened 2 years ago

namos-23 commented 2 years ago

Environment

Describe the bug

Apologies if I'm misunderstanding but the existing notes for the OTG function states that ADB is not necessary, but that doesn't actually seem to be the case. Without ADB enabled, "scrcpy --otg" always results in:

"ERROR: Could not find any USB device"

When ADB is enabled, then it works fine - but the interesting thing is that it works even if RSA permission is not granted. Plus, when initializing OTG, scrcpy kills the adb daemon anyways. So maybe there's a flag that's causing it to refuse to start OTG if it doesn't see an ADB device, even though ADB itself isn't needed/used?

Behavior tested and verified to be identical on:

Pixel 5 w/ Android 11 S21 Ultra w/ Android 12 LG G4 w/ Android 6 Moto X4 with Android 9

rom1v commented 2 years ago

Thank you for your report.

Indeed, I can reproduce, but I don't understand why it worked when I implemented it (I am pretty sure that this was one of the first things I tested).

I even retested with the initial binaries posted on #3011, it does not work anymore. :frowning: I had a forced Windows update since then, but it would be surprising that this could cause this issue…

The problem is that it ignores the device because it could not read the device serial:

diff --git a/app/src/usb/usb.c b/app/src/usb/usb.c
index 32a66f98..97aa9a33 100644
--- a/app/src/usb/usb.c
+++ b/app/src/usb/usb.c
@@ -15,6 +15,7 @@ read_string(libusb_device_handle *handle, uint8_t desc_index) {
                                            (unsigned char *) buffer,
                                            sizeof(buffer));
     if (result < 0) {
+        LOGD("Read string: libusb error: %s", libusb_strerror(result));
         return NULL;
     }
DEBUG: Read string: libusb error: Entity not found

Refs https://github.com/Genymobile/scrcpy/pull/3011#issuecomment-1048428631

I will investigate.

rom1v commented 2 years ago

@vsutardja (refs #2773) Could you reproduce the issue?

rom1v commented 2 years ago

I enabled libusb logs at warning level:

diff --git a/app/src/usb/usb.c b/app/src/usb/usb.c
index 32a66f98..bcec9b60 100644
--- a/app/src/usb/usb.c
+++ b/app/src/usb/usb.c
@@ -219,7 +222,11 @@ sc_usb_select_device(struct sc_usb *usb, const char *serial,
 bool
 sc_usb_init(struct sc_usb *usb) {
     usb->handle = NULL;
-    return libusb_init(&usb->context) == LIBUSB_SUCCESS;
+    bool ok = libusb_init(&usb->context) == LIBUSB_SUCCESS;
+    if (ok) {
+        libusb_set_option(usb->context, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_WARNING);
+    }
+    return ok;
 }

 void

Here is the result if USB debugging is disabled:

INFO: Killing adb daemon (if any)...
libusb: error [winusbx_claim_interface] could not access interface 0: [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 1 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 2 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 3 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 4 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 5 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 6 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 7 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 8 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 9 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 10 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 11 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 12 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 13 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 14 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 15 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 16 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 17 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 18 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 19 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 20 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 21 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 22 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 23 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 24 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 25 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 26 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 27 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 28 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 29 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 30 with WinUSB): [1] Fonction incorrecte.
libusb: warning [winusbx_claim_interface] failed to auto-claim interface 0 (required to claim 31 with WinUSB): [1] Fonction incorrecte.
libusb: error [auto_claim] could not auto-claim any interface
DEBUG: Read string: libusb error: Entity not found
ERROR: Could not find any USB device

Calling libusb_claim_interface(handle, 0); does not help either.

Looks like https://github.com/libusb/libusb/issues/761.

vsutardja commented 2 years ago

If enabling/disabling ADB means toggling the USB Debugging setting in the phone's Developer Options, then I can reproduce this issue as well. With it disabled, my Pixel 6 actually appears under Device Manager as a different device (Portable Device instead of Android Device) with a different PID (4EE1 instead of 4EE7) using a different driver (WUDFWpdMtp instead of WinUSB).

What might be happening is that the driver used when USB Debugging is disabled is automatically picked up by a Windows system component which then claims the device, much like how a running adb server automatically claims a USB Debugging-enabled device. After plugging in my USB Debugging-disabled phone, Resource Monitor shows that the handle is already associated with the WUDFHost.exe process:

image

I think a distinction should be made between adb (on the host PC) and USB Debugging (on the target device), where the former is not required but the latter is.

rom1v commented 2 years ago

@vsutardja Thank you very much for your tests and explanations :+1:

So it seems it's not a good news for OTG without USB debugging on Windows :(