Skip to content

Commit c7a2339

Browse files
committed
libusb: add support for potential Android JNI backend
1 parent b72a367 commit c7a2339

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

libusb/hid.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,17 @@ struct hid_device_info HID_API_EXPORT *hid_enumerate(unsigned short vendor_id,
595595
res = libusb_open(dev, &handle);
596596

597597
if (res >= 0) {
598+
#ifdef __ANDROID__
599+
/* There is (a potential) libusb Android backend, in which
600+
device descriptor is not accurate up until the device is opened.
601+
https://github.com/libusb/libusb/pull/874#discussion_r632801373
602+
A workaround is to re-read the descriptor again.
603+
Even if it is not going to be accepted into libusb master,
604+
having it here won't do any harm, since reading the device descriptor
605+
is as cheap as copy 18 bytes of data. */
606+
libusb_get_device_descriptor(dev, &desc);
607+
#endif
608+
598609
/* Serial Number */
599610
if (desc.iSerialNumber > 0)
600611
cur_dev->serial_number =
@@ -927,6 +938,12 @@ hid_device * HID_API_EXPORT hid_open_path(const char *path)
927938
break;
928939
}
929940
good_open = 1;
941+
942+
#ifdef __ANDROID__
943+
/* See remark in hid_enumerate */
944+
libusb_get_device_descriptor(usb_dev, &desc);
945+
#endif
946+
930947
#ifdef DETACH_KERNEL_DRIVER
931948
/* Detach the kernel driver, but only if the
932949
device is managed by the kernel */

0 commit comments

Comments
 (0)