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

Windows, ADB, and OTG #3050

Open
2 tasks done
namos-23 opened this issue Feb 23, 2022 · 5 comments
Open
2 tasks done

Windows, ADB, and OTG #3050

namos-23 opened this issue Feb 23, 2022 · 5 comments

Comments

@namos-23
Copy link

namos-23 commented Feb 23, 2022

  • I have searched in existing issues.
  • I have read the FAQ.

Environment

  • OS: Windows 10 and 7 (64 bit)
  • scrcpy version: 1.23
  • installation method: Windows
  • device model: multiple
  • Android version: multiple

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
Copy link
Collaborator

rom1v commented Feb 23, 2022

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. 😦 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 #3011 (comment)

I will investigate.

@rom1v
Copy link
Collaborator

rom1v commented Feb 23, 2022

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

@rom1v
Copy link
Collaborator

rom1v commented Feb 23, 2022

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 libusb/libusb#761.

@vsutardja
Copy link

vsutardja commented Feb 23, 2022

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
Copy link
Collaborator

rom1v commented Feb 23, 2022

@vsutardja Thank you very much for your tests and explanations 👍

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants