StarPRNT-SDK-Android-Java icon indicating copy to clipboard operation
StarPRNT-SDK-Android-Java copied to clipboard

SecurityException when StarIOPort probes internals of a connected USB HUB

Open Nilzor opened this issue 1 year ago • 1 comments

Scope

This is probably a shortcoming in the StarIoPort3.1 lib that causes an error when used on Android devices. I couldn't find any place to report bugs for StarIOPort so I chose to do it here. Please forward if this is the wrong channel.

Description

I have a setup where a Samsung S21 phone is connected to a smart USB HUB which have multiple USB ports and an Ethernet port. A Star S230i is connected to one of the USB ports. StarIOPort probes for serial number of all USB devices when calling getPort(), even if I have specified which port is the Star Printer. This causes a security exception if the user has not granted permission for all USB peripherals, including the Realtek Etherenet chip in the HUB (even if no ethernet cable is connected). I think it should not be necessary to ask the user for permission to access an Ethernet port when using the Star printer.

Stacktrace

This is the stacktrace I get by calling

StarIOPort.getPort("USB:1-4", portSettings, 10000, context)

Note that the port name "USB:1-4" does not match with the port actually requested serial number from (002/003 which would be "USB:2-3" I suppose)

java.lang.SecurityException: User has not given 10408/com.my.app permission to access device /dev/bus/usb/002/003
at android.os.Parcel.createExceptionOrNull(Parcel.java:3023)
at android.os.Parcel.createException(Parcel.java:3007)
at android.os.Parcel.readException(Parcel.java:2990)
at android.os.Parcel.readException(Parcel.java:2932)
at android.hardware.usb.IUsbSerialReader$Stub$Proxy.getSerial(IUsbSerialReader.java:126)
at android.hardware.usb.UsbDevice.getSerialNumber(UsbDevice.java:157)
at com.starmicronics.stario.e.b(Unknown Source:43)
at com.starmicronics.stario.e.d(Unknown Source:60)
at com.starmicronics.stario.e.<init>(Unknown Source:36)
at com.starmicronics.stario.StarIOPort.getPort(Unknown Source:216)
at (internals of com.my.app)

Workaround

I ask the user for permission to access the Ethernet chip on port 002/003 prior to calling getPort.

Device, printer and hub

The error was reproduces with both the two mentioned USB hubs, and I assume any hub that contains an Ethernet chip/connector.

Your development environment

Windows 10

To Reproduce

  • Perform a clean install of an app interfacing against Star SM-S230i over USB, while the printer is connected via a HUB with an Ethernet port
  • Do not ask for or grant permission to access the Ethernet chip via USB
  • Ask for and grant permission to the Star SM-S230i printer

Expected behavior

That we'd be able to get a normal result from getPort and continue to access and use the printer through the SDK.

Nilzor avatar Aug 02 '23 08:08 Nilzor