简体   繁体   English

Android L | libusb_init返回LIBUSB_ERROR_OTHER(-99)

[英]Android L | libusb_init returns LIBUSB_ERROR_OTHER (-99)

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). 我尝试在这种方法中建议使用libusb而不是根源Nexus 5(通过将usb文件描述符从java传输到本机端)。

My application ask permission via UsbManager.requestPermission and then run native method that call libusb_init to create libusb_context . 我的应用程序通过UsbManager.requestPermission请求权限,然后运行调用libusb_init本机方法来创建libusb_context

But libusb_init returns LIBUSB_ERROR_OTHER code (-99). 但是libusb_init返回LIBUSB_ERROR_OTHER代码(-99)。 After digging in the code I see why this happening. 在挖掘代码后,我明白为什么会发生这种情况。 libusb reports 'could not find usbfs' because opendir("/dev/bus/usb") returns 0 . libusb报告'could not find usbfs'因为opendir("/dev/bus/usb")返回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): 另外从adb shell我不能执行ls /dev ,奇怪因为我有权利(在华为U8950-1上具有相同权限我可以这样做):

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

Looks like approach described below work not for all android devices. 看起来像下面描述的方法不适用于所有Android设备。 Can someone explain why? 有人可以解释原因吗?

There is already a fix in this libusb fork: 这个libusb fork已经有了一个修复:

https://github.com/martinmarinov/rtl_tcp_andro- 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(). 现在,您不仅需要传递文件描述符,还需要通过UsbDevice.getDeviceName()传递设备文件路径。

Looks like Android L have an additional restriction about accessing to /dev deirectory. 看起来Android L对访问/dev deirectory有额外的限制。 I have no more ideas about this 我对此没有更多的想法

Update 更新

Security Enhancements in Android 5.0 Android 5.0中的安全增强功能

... ...

Android sandbox reinforced with SELinux . 使用SELinux增强Android沙箱。 Android now requires SELinux in enforcing mode for all domains. Android现在要求SELinux在所有域的强制模式下使用。 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 ). SELinux是Linux内核中的强制访问控制(MAC)系统 ,用于增强现有的[自主访问控制(DAC)安全]模型]( 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 安装SELinuxModeChanger并将SELinux模式更改为permissive
  2. https://github.com/Gritzman/libusb https://github.com/Gritzman/libusb

有一个自定义libusb 1.0能够通过传递usb设备的路径来执行LibusbInit来解决这个问题,这可以绕过来自主页网页本身的readdir命令http://www.libusb.org/ download。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM