6

I trying to use libusb on not rooted Nexus 5 as advised in this approach (by transferring usb file descriptor from java to native side).

My application ask permission via UsbManager.requestPermission and then run native method that call libusb_init to create libusb_context.

But libusb_init returns LIBUSB_ERROR_OTHER code (-99). After digging in the code I see why this happening. libusb reports 'could not find usbfs' because opendir("/dev/bus/usb") returns 0.

Also from adb shell I can't perform ls /dev, strange because I have rights (on Huawei U8950-1 with the same rights I can do this):

drwxr-xr-x root root 2014-09-04 10:26 dev

Looks like approach described below work not for all android devices. Can someone explain why?

Community
  • 1
  • 1
CAMOBAP
  • 5,523
  • 8
  • 58
  • 93

3 Answers3

3

There is already a fix in this libusb fork:

https://github.com/martinmarinov/rtl_tcp_andro-

Now, not only you will need to pass the file descriptor, you will need to pass the device file path as well via UsbDevice.getDeviceName().

androdroid
  • 66
  • 3
  • Thanks for response, but I preferred https://github.com/Gritzman/libusb because Gritzman's solutions has been implemented without modifying `libusb.h` – CAMOBAP Jan 29 '15 at 14:25
  • @CAMOBAP I'm trying to use Gritzman's version of libusb. How do I pass in the file descriptor? How do I get a libusb_device for the libusb_open() first parameter? Thanks. – Antao Almada Mar 15 '16 at 09:04
  • @AntaoAlmada look at https://github.com/Gritzman/libusb/blob/master/jni/usb/os/linux_usbfs.c (comments with Android). There is no need to modify interface and pass file descriptior – CAMOBAP Mar 15 '16 at 09:44
2

Looks like Android L have an additional restriction about accessing to /dev deirectory. I have no more ideas about this

Update

Security Enhancements in Android 5.0

...

Android sandbox reinforced with SELinux. Android now requires SELinux in enforcing mode for all domains. SELinux is a mandatory access control (MAC) system in the Linux kernel used to augment the existing [discretionary access control (DAC) security] model](http://en.wikipedia.org/wiki/Discretionary_access_control). This new layer provides additional protection against potential security vulnerabilities.

...

Workarounds

  1. Install SELinuxModeChanger and change SELinux mode to permissive
  2. https://github.com/Gritzman/libusb
Community
  • 1
  • 1
CAMOBAP
  • 5,523
  • 8
  • 58
  • 93
0

There is a custom libusb 1.0 which is capable of solving this issue by doing LibusbInit by passing the path of the usb device , this can bypass readdir command http://www.libusb.org/ download from the home webpage itself.