Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
7 of 8 tasks
igorsantos07 opened this issue Jun 3, 2022 · 0 comments · May be fixed by #62
Open
7 of 8 tasks

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

igorsantos07 opened this issue Jun 3, 2022 · 0 comments · May be fixed by #62

Comments

@igorsantos07
Copy link

igorsantos07 commented Jun 3, 2022

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:

  • look for the permission code in Java: didn't find anything similar to what's suggested in Android guides
  • 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.
  • a couple of forks seem to include updated versions of the SDK all of them have the same issue
  • try to code the permission request into a fork - my colleague got it running at Android USB permissions #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 proper permission Java 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)

Any help is greatly appreciated!

igorsantos07 added a commit to igorsantos07/cordova-plugin-starprnt that referenced this issue Jun 6, 2022
I was able to include the permission XML that allows any app to "respond" to a just-plugged printer, but......... not more than that.
Any Java code I included (even blatantly broken stuff) never caused an issue during compilation or runtime, not more than the current bug causes. No clue how to actually compile the plugin and get it into the debug app.

This is supposed to be a solution for auctifera-josed#58
igorsantos07 added a commit to igorsantos07/cordova-plugin-starprnt that referenced this issue Jun 6, 2022
I was able to include the permission XML that allows any app to "respond" to a just-plugged printer, but......... not more than that. Some changes on the iOS side was done too, but that was easier since it's simply a no-op (and is untested too).
Any Java code I included (even blatantly broken stuff) never caused an issue during compilation or runtime, not more than the current bug causes. No clue how to actually compile the plugin and get it into the debug app.

This is supposed to be a solution for auctifera-josed#58
@igorsantos07 igorsantos07 linked a pull request Nov 16, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant