linux_usbfs: Use fallback usbfs path on Android
authorVianney le Clément de Saint-Marcq <code@quartic.eu>
Tue, 15 Mar 2016 14:04:02 +0000 (15:04 +0100)
committerNathan Hjelm <hjelmn@me.com>
Wed, 9 Jan 2019 01:20:34 +0000 (18:20 -0700)
On newer Android devices (5+), SELinux policies block normal processes
from reading /dev.  The consequence is that the usbfs path cannot be
found.  Rather than failing to initialize libusb in such case, fall back
to /dev/bus/usb.  This path will actually not be used, as USB devices
should be opened through the Android API, passing the file descriptor to
libusb_wrap_sys_device.

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 2e7add4..1689c4e 100644 (file)
@@ -341,8 +341,10 @@ static const char *find_usbfs_path(void)
 
 /* On udev based systems without any usb-devices /dev/bus/usb will not
  * exist. So if we've not found anything and we're using udev for hotplug
- * simply assume /dev/bus/usb rather then making libusb_init fail. */
-#if defined(USE_UDEV)
+ * simply assume /dev/bus/usb rather then making libusb_init fail.
+ * Make the same assumption for Android where SELinux policies might block us
+ * from reading /dev on newer devices. */
+#if defined(USE_UDEV) || defined(__ANDROID__)
        if (ret == NULL)
                ret = "/dev/bus/usb";
 #endif
index c87b18f..c765a8d 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11337
+#define LIBUSB_NANO 11338