linux_usbfs: Disable hotplug events and scanning on Android
authorVianney le Clément de Saint-Marcq <code@quartic.eu>
Tue, 13 Dec 2016 14:04:11 +0000 (15:04 +0100)
committerNathan Hjelm <hjelmn@me.com>
Wed, 9 Jan 2019 01:21:00 +0000 (18:21 -0700)
On Android, the platform API should be used to scan for and open devices
and pass file descriptors to libusb.  Newer devices (Android 5+) even
prohibit listening for hotplug events, resulting in libusb failing to
initialize without this patch.

Note that this patch effectively renders libusb useless on older devices
that do not have USB support in the platform API (anything before
Android 5).

Closes #242

Signed-off-by: Vianney le Clément de Saint-Marcq <code@quartic.eu>
Signed-off-by: Nathan Hjelm <hjelmn@me.com>
libusb/os/linux_usbfs.c
libusb/version_nano.h

index 1689c4e..a6b7963 100644 (file)
@@ -534,8 +534,10 @@ static int linux_start_event_monitor(void)
 {
 #if defined(USE_UDEV)
        return linux_udev_start_event_monitor();
-#else
+#elif !defined(__ANDROID__)
        return linux_netlink_start_event_monitor();
+#else
+       return LIBUSB_SUCCESS;
 #endif
 }
 
@@ -543,20 +545,22 @@ static int linux_stop_event_monitor(void)
 {
 #if defined(USE_UDEV)
        return linux_udev_stop_event_monitor();
-#else
+#elif !defined(__ANDROID__)
        return linux_netlink_stop_event_monitor();
+#else
+       return LIBUSB_SUCCESS;
 #endif
 }
 
 static int linux_scan_devices(struct libusb_context *ctx)
 {
-       int ret;
+       int ret = 0;
 
        usbi_mutex_static_lock(&linux_hotplug_lock);
 
 #if defined(USE_UDEV)
        ret = linux_udev_scan_devices(ctx);
-#else
+#elif !defined(__ANDROID__)
        ret = linux_default_scan_devices(ctx);
 #endif
 
@@ -569,7 +573,7 @@ static void op_hotplug_poll(void)
 {
 #if defined(USE_UDEV)
        linux_udev_hotplug_poll();
-#else
+#elif !defined(__ANDROID__)
        linux_netlink_hotplug_poll();
 #endif
 }
index c765a8d..df073bd 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11338
+#define LIBUSB_NANO 11339