auctifera-josed / starprnt

Cordova plugin for the Star micronics printers
MIT License
40 stars 39 forks source link

Android exception: "User has not given «app» permission to access device «bus»" #58

Open igorsantos07 opened 2 years ago

igorsantos07 commented 2 years ago

We've been using the plugin just fine for around a year, and now all of sudden a specific user reported our app is crashing when portDiscovery() is called with a USB printer connected.

Investigating the Android logs (with wireless adb + «app_root_folder»/platforms/android/cordova/log), I found the following error User has not given «id»/«app.key» permission to access device /dev/bus/usb/001/002 (full log at the end). I see no information on permissions at the plugin README, nor information on how to request these permissions from Cordova. Also found nothing besides Bluetooth permissions in source code...

This was noticed on multiple Android devices, all running Android 11. There were no recent updates in either code or OS, not that we recall. cordova-plugin-starprnt was used at 2.2.0 and 2.1.0, both cause the same error.

That said, it seems to work fine on Android 7, but the device only asks for permission when actually sending a print job. Printer search worked normally, without requesting permissions.

Other things we tried:

Full exception ``` FATAL EXCEPTION: pool-2-thread-1 Process: com.xyz.abc, PID: 25787 java.lang.SecurityException: User has not given 10697/com.xyz.abc permission to access device at android.os.Parcel.createExceptionOrNull(Parcel.java:2373) at android.os.Parcel.createException(Parcel.java:2357) at android.os.Parcel.readException(Parcel.java:2340) at android.os.Parcel.readException(Parcel.java:2282) at android.hardware.usb.IUsbSerialReader$Stub$Proxy.getSerial(IUsbSerialReader.java:123) at android.hardware.usb.UsbDevice.getSerialNumber(UsbDevice.java:157) at com.starmicronics.stario.e.b(Unknown Source:43) at com.starmicronics.stario.e.a(Unknown Source:0) at com.starmicronics.stario.StarIOPort.searchPrinter(Unknown Source:49) at starprnt.cordova.StarPRNT.getPortDiscovery(StarPRNT.java:268) at starprnt.cordova.StarPRNT.access$000(StarPRNT.java:58) at starprnt.cordova.StarPRNT$2.run(StarPRNT.java:223) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) at java.lang.Thread.run(Thread.java:923) Caused by: android.os.RemoteException: Remote stack trace: at com.android.server.usb.UsbUserPermissionManager.checkPermission(UsbUserPermissionManager.java:654) at com.android.server.usb.UsbSerialReader.getSerial(UsbSerialReader.java:98) at android.hardware.usb.IUsbSerialReader$Stub.onTransact(IUsbSerialReader.java:84) at android.os.Binder.execTransactInternal(Binder.java:1165) at android.os.Binder.execTransact(Binder.java:1134) ```

Any help is greatly appreciated!