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.
[x] add USB permissions to Android's Manifest - works but suboptimal, since it requires the user to first plug the printer, then select our app in the popup that shows. The following scenarios still cause the app to crash when a printer is connected:
if the user closes the permission popup;
if the user selects another app (e.g. Star Quick Setup Utility);
or even if that was done previously but not with the "always" option.
[x] ~a couple of forks seem to include updated versions of the SDK~ all of them have the same issue
[x] try to code the permission request into a fork - my colleague got it running at #59
~I was definitely not able to, but got something done at my fork. The app requests to be opened once the printer is plugged, as suggested in this StarPRNT SDK guide (same as 2nd check above), but I couldn't get properpermissionJava code running~
[ ] check if other StarPrinter plugins have correct permissions or if we could use them instead
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)
```
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 errorUser 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!