1
0
mirror of https://github.com/mik3y/usb-serial-for-android synced 2025-06-14 11:26:26 +00:00

persist USB permission

kai-morich 2021-09-13 22:08:43 +02:00
parent 5f363f1595
commit 0fb25c3037

@ -38,6 +38,36 @@ Most Arduinos with CDC driver use the DTR line to determine serial channel readi
You don't. <code>/dev/tty*</code> is the Linux kernel's driver interface to various serial devices. Certain devices and custom ROMs ''may'' expose serial devices this way, but this library does not use this interface.
== How to persist USB permission? ==
After adding <code>vendor-id</code> and <code>device-id</code> to [https://github.com/mik3y/usb-serial-for-android/blob/master/usbSerialExamples/src/main/res/xml/device_filter.xml device_filter.xml]
the USB device connection dialog has a ''"Always open {app} when {device} is attached"'' checkbox and the permission dialog has a ''"Use by default for this USB device"'' checkbox.
When the checkbox is selected, the permission is retained over USB device re-attach, also after Android reboot.
'''If the device remains attached during Android reboot, the permission is only retained in some cases:'''
The issue is identified in [https://issuetracker.google.com/issues/77658221 Bug 77658221], but set to ''Won't Fix'' by Google.
The persisted permission file is only loaded when attaching an USB device, so starting the App after reboot without re-attaching any device, the App again asks for permission.
The bug recommends to add <code>android:directBootAware="true"</code> to your activity in <code>AndroidManifest.xml</code>, which improves the situation for some Android devices, e.g.:
{|
! USB device attached after boot !! colspan="2"|USB device attached during reboot !! !!
|-
! Permission retained on App start !! Permission retained<br>on App start !! App autostart !! [https://developer.android.com/guide/topics/manifest/activity-element#directBootAware directBootAware] !! Device
|-
| 🟢 || 🟢 || 🟢 || - || Android 11 / Samsung
|-
| 🟢 || 🟢 || 🟢 || true || Android 8 / Samsung
|-
| 🟢 || 🟢 || 🔴 || true || Android 11 / Lineage OS
|-
| 🟢 || 🔴 || 🔴 || false || Android 11 / Lineage OS <br> Android 8 / Samsung <br> ...
|-
|}
== Can I open multiple connections in one application? ==
You can connect to multiple devices and to multiple ports of a multi-port device in one App.