[prev in list] [next in list] [prev in thread] [next in thread] 

List:       libusb-devel
Subject:    Re: [libusb] libusb permission issue on Android
From:       Mike Hansen <ambirdev () gmail ! com>
Date:       2020-07-09 16:18:47
Message-ID: CAELahYs5gVao=XC4GmZfNvN-zyFUA7_oab1d4Ev0RyUPoDtbHg () mail ! gmail ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


Thank you to Peter and Antonio for their responses.   Since this is our own
Android hardware and not an off the shelf device we have the ability to
root the device.   After rooting the device libusb was successful in
allowing our connection to the scanner.

This isn't the ideal solution but it's workable given our constraints.
I'll keep the two possible solutions in our back pocket in case future
HW/OS changes cause us problems even if the device is rooted.

On Tue, Jul 7, 2020 at 4:57 PM Mike Hansen <ambirdev@gmail.com> wrote:

> FYI, we are working with Android 7.1 on our device.
>
> On Tue, Jul 7, 2020 at 4:55 PM Mike Hansen <ambirdev@gmail.com> wrote:
>
>> We have built a USB driver for a scanner using libusb.  Driver works fine
>> on Linux and is partially functional on Android.  The problem on the
>> Android side is that the OS is explicitly blocking access to our device
>> when we query the buses and drill down looking for the scanner.  We have
>> built an app in Android Studio that calls into the native code(our
>> driver/libusb) and that all works well except for the permission issue for
>> libusb.   Note that the Java/Android USBManager in our app CAN enumerate
>> the USB buses and see the scanner attached to the USB port.   We have used
>> the USBManager to explicitly give our app permission to access the USB
>> ports.  Further, we added the permissions in the manifest file to allow
>> access to the USB port.  Yet when we run our app we see in error in logcat
>> like this:
>>
>> 2020-07-07 12:36:49.545 22097-22097/com.ambir.androidas I/com.androidas:
>> type=1400 audit(0.0:1371): avc: denied { open } for path="/dev/bus/usb"
>> dev="tmpfs" ino=1372 scontext=u:r:untrusted_app:s0:c512,c768
>> tcontext=u:object_r:usb_device:s0 tclass=dir permissive=1
>>
>> And the OS logs explicitly state it is libusb that is being blocked.
>>
>> On Linux we just add a udev rule and off we go.  On Android, udev doesn't
>> exist.
>>
>> We don't have root access to our Android hardware as of now(we may be
>> able to do that in the future).
>>
>> In our searches, we have found a couple of instances where someone built
>> a fork of libusb to overcome this issue.  Here are a couple of examples:
>> https://github.com/Gritzman/libusb
>> https://github.com/kuldeepdhaka/libusb/tree/android-open2
>> With an explanatioin why here:
>> https://www.gitmemory.com/issue/gphoto/libgphoto2/335/510499464
>>
>> A couple of questions here:
>> 1)  The work in these forks of libusb, did that ever get into the master
>> branch and now is in the latest code in GIT?
>> 2)  If not for 1), has anyone encountered this issue and found a good way
>> around it?
>>
>

[Attachment #5 (text/html)]

<div dir="ltr">Thank you to Peter and Antonio for their responses.     Since this is \
our own Android hardware and not an off the shelf device we have the ability to root \
the device.     After rooting the device libusb was successful in allowing our \
connection to the scanner.     <div><br></div><div>This isn&#39;t the ideal solution \
but it&#39;s workable given our constraints.   I&#39;ll keep the two possible \
solutions in our back pocket in case future HW/OS changes cause us problems even if \
the device is rooted.</div></div><br><div class="gmail_quote"><div dir="ltr" \
class="gmail_attr">On Tue, Jul 7, 2020 at 4:57 PM Mike Hansen &lt;<a \
href="mailto:ambirdev@gmail.com">ambirdev@gmail.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">FYI, we \
are working with Android 7.1 on our device.</div><br><div class="gmail_quote"><div \
dir="ltr" class="gmail_attr">On Tue, Jul 7, 2020 at 4:55 PM Mike Hansen &lt;<a \
href="mailto:ambirdev@gmail.com" target="_blank">ambirdev@gmail.com</a>&gt; \
wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">We have \
built a USB driver for a scanner using libusb.   Driver works fine on Linux and is \
partially functional on Android.   The problem on the Android side is that the OS is \
explicitly blocking access to our device when we query the buses and drill down \
looking for the scanner.   We have built an app in Android Studio that calls into the \
native code(our driver/libusb) and that all works well except for the permission \
issue for libusb.     Note that the Java/Android USBManager in our app CAN enumerate \
the USB buses and see the scanner attached to the USB port.     We have used the \
USBManager to explicitly give our app permission to access the USB ports.   Further, \
we added the permissions in the manifest file to allow access to the USB port.   Yet \
when we run our app we see in error in logcat like this:<div><br></div><div><span \
style="color:rgb(0,0,0);font-family:&quot;Segoe \
UI&quot;,helvetica,arial,sans-serif;font-size:16px">2020-07-07 12:36:49.545 \
22097-22097/com.ambir.androidas I/com.androidas: type=1400 audit(0.0:1371): avc: \
denied { open } for path=&quot;/dev/bus/usb&quot; dev=&quot;tmpfs&quot; ino=1372 \
scontext=u:r:untrusted_app:s0:c512,c768 tcontext=u:object_r:usb_device:s0 tclass=dir \
permissive=1</span>    <br></div><div><br></div><div>And the OS logs explicitly state \
it is libusb that is being blocked.</div><div><br></div><div>On Linux we just add a \
udev rule and off we go.   On Android, udev doesn&#39;t \
exist.</div><div><br></div><div>We don&#39;t have root access to our Android hardware \
as of now(we may be able to do that in the future).<br></div><div><br></div><div>In \
our searches, we have found a couple of instances where someone built a fork of \
libusb to overcome this issue.   Here are a couple of examples:</div><div><a \
href="https://github.com/Gritzman/libusb" \
target="_blank">https://github.com/Gritzman/libusb</a>  </div><div><a \
href="https://github.com/kuldeepdhaka/libusb/tree/android-open2" \
target="_blank">https://github.com/kuldeepdhaka/libusb/tree/android-open2</a></div><div>With \
an explanatioin why here:</div><div><a \
href="https://www.gitmemory.com/issue/gphoto/libgphoto2/335/510499464" \
target="_blank">https://www.gitmemory.com/issue/gphoto/libgphoto2/335/510499464</a></div><div><br></div><div>A \
couple of questions here:</div><div>1)   The work in these forks of libusb, did that \
ever get into the master branch and now is in the latest code in GIT?</div><div>2)   \
If not for 1), has anyone encountered this issue and found a good way around it?  \
<br></div></div> </blockquote></div>
</blockquote></div>





_______________________________________________
libusb-devel mailing list
libusb-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusb-devel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic