Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
108.55k stars 10.45k forks source link

`scrcpy --otg` not working (on Linux) #4440

Open ObsydianBlackKnight opened 9 months ago

ObsydianBlackKnight commented 9 months ago

Environment

Issue

scrcpy works:

$ scrcpy
scrcpy v2.2 <https://github.com/Genymobile/scrcpy>
INFO: ADB device found:
INFO:     -->   (usb)  XXX                  device  Pixel_6_Pro
/usr/share/scrcpy/scrcpy-server: 1 file pushed, 0 skipped. 54.9 MB/s (64363 bytes in 0.001s)
[server] INFO: Device: [Google] google Pixel 6 Pro (Android 14)
INFO: Renderer: opengl
INFO: OpenGL version: 4.6 (Compatibility Profile) Mesa 23.2.1-arch1.2
INFO: Trilinear filtering enabled
INFO: Texture: 1440x3120

However scrcpy --otg does not:

$ scrcpy --otg
scrcpy v2.2 <https://github.com/Genymobile/scrcpy>
ERROR: Could not find any USB device
rom1v commented 9 months ago

lsusb?

ObsydianBlackKnight commented 9 months ago

The relevant line is:

Bus 001 Device 081: ID 18d1:4ee7 Google Inc. Nexus/Pixel Device (charging + debug)

adb and scrcpy (without --otg) work via USB, so I'm tempted to assume everything is fine on the USB level.

rom1v commented 9 months ago
scrcpy -Vdebug --otg
lsusb -vd 18d1:4ee7
ObsydianBlackKnight commented 9 months ago
$ scrcpy -Vdebug --otg
scrcpy v2.2 <https://github.com/Genymobile/scrcpy>
[...]
DEBUG: Open USB device 18d1:4ee7: libusb error: Access denied (insufficient permissions)
[...]
ERROR: Could not find any USB device
$ lsusb -vd 18d1:4ee7

Bus 001 Device 081: ID 18d1:4ee7 Google Inc. Nexus/Pixel Device (charging + debug)
Couldn't open device, some information will be missing
Device Descriptor:
  bLength                18
  bDescriptorType         1
  bcdUSB               2.10
  bDeviceClass            0 [unknown]
  bDeviceSubClass         0 [unknown]
  bDeviceProtocol         0 
  bMaxPacketSize0        64
  idVendor           0x18d1 Google Inc.
  idProduct          0x4ee7 Nexus/Pixel Device (charging + debug)
  bcdDevice            5.10
  iManufacturer           1 Google
  iProduct                2 Pixel 6 Pro
  iSerial                 3 XXX
  bNumConfigurations      1
  Configuration Descriptor:
    bLength                 9
    bDescriptorType         2
    wTotalLength       0x0020
    bNumInterfaces          1
    bConfigurationValue     1
    iConfiguration          0 
    bmAttributes         0x80
      (Bus Powered)
    MaxPower              500mA
    Interface Descriptor:
      bLength                 9
      bDescriptorType         4
      bInterfaceNumber        0
      bAlternateSetting       0
      bNumEndpoints           2
      bInterfaceClass       255 Vendor Specific Class
      bInterfaceSubClass     66 [unknown]
      bInterfaceProtocol      1 
      iInterface              4 
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x01  EP 1 OUT
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
      Endpoint Descriptor:
        bLength                 7
        bDescriptorType         5
        bEndpointAddress     0x81  EP 1 IN
        bmAttributes            2
          Transfer Type            Bulk
          Synch Type               None
          Usage Type               Data
        wMaxPacketSize     0x0200  1x 512 bytes
        bInterval               0
ObsydianBlackKnight commented 9 months ago

...I just realized that it does work if I use sudo scrcpy --otg -s ....

Is scrcpy meant to be use by root, in OTG mode?

rom1v commented 9 months ago

Your device could not be opened due to permissions issues:

DEBUG: Open USB device 18d1:4ee7: libusb error: Access denied (insufficient permissions)
$ lsusb -vd 18d1:4ee7

Bus 001 Device 081: ID 18d1:4ee7 Google Inc. Nexus/Pixel Device (charging + debug)
Couldn't open device, some information will be missing

Probably an issue with your udev rules.

Is scrcpy meant to be use by root, in OTG mode?

No. It should never be run as root.

ObsydianBlackKnight commented 9 months ago

OK. Thanks.

I'm using the udev rules set up in /usr/lib/udev/rules.d/51-android.rules by the package extra/android-udev.

I'm surprised that it works with adb and scrcpy, but not with scrcpy --otg. I'll try to learn how udev works to find the problem, then report it upstream.

rom1v commented 9 months ago

I'm surprised that it works with adb and scrcpy,

The adb daemon runs in another process, which probably has the correct permissions. scrcpy calls adb which communicates with the daemon. But in --otg mode, scrcpy accesses the device directly over USB.

ObsydianBlackKnight commented 9 months ago

OK, I understand. Thanks.

I think this issue can be closed then.

rp1231 commented 9 months ago

The otg mode does not work for me as well... I get this message:

ERROR: Multiple (2) USB devices:
ERROR:     -->       303NTQD4G740 (043e:9a39)  LG Electronics Inc. LG Monitor Controls
ERROR:     -->       SN0000000001 (1ea7:0907)  SEMITEK USB-HID Gaming Keyboard
ERROR: Select a device via -s (--serial)

But if I select the semitek usb-hid gaming keyboard it gives me this error:

INFO: FLAC audio: audio buffer increased to 120 ms (use --audio-buffer to set a custom value)
INFO: Killing adb server (if any)...
INFO: USB device found:
INFO:               303NTQD4G740 (043e:9a39)  LG Electronics Inc. LG Monitor Controls
INFO:     -->       SN0000000001 (1ea7:0907)  SEMITEK USB-HID Gaming Keyboard
WARN: On this platform, libusb does not have hotplug capability; device disconnection will not be detected properly
ERROR: REGISTER_HID: libusb error: Entity not found
WARN: Register HID keyboard failed

I am using a logitech mechanical mini keyboard over bluetooth/bolt receiver on a samsung galaxy a34. I don't know why it shows semitek usb hid gaming keyboard ...... I don't have such a keyboard....

rp1231 commented 9 months ago

Does the otg mode not work over bluetooth devices?

rom1v commented 9 months ago

@rp1231 In your case, it is on Windows.

Your android device is just not detected at all (but other devices are detected by libusb). See https://github.com/Genymobile/scrcpy/blob/master/FAQ.md#hidotg-issues-on-windows

RealityMoez commented 9 months ago

Just wanted to share an easy solution I've found.

If you have installed scrcpy from Ubuntu store (snap) - regardless of the outdated 1.25 version. Go to its page in store, and Click Permissions, then Turn ON Access USB hardware directly.

image

image

Ubuntu 20.04.6 LTS