star-micronics / StarPRNT-SDK-Android-Java

StarPRNT SDK for Android including libraries for supporting application development for Star printers.
https://www.star-m.jp/products/s_print/sdk/starprnt_sdk/manual/android_java/en/index.html
Other
15 stars 4 forks source link

SecurityException when StarIOPort probes internals of a connected USB HUB #13

Closed Nilzor closed 1 week ago

Nilzor commented 1 year ago

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

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.

bandit-ibayashi commented 7 months ago

@Nilzor Sincere apologies for our delay in responding to you. We much appreciate your report. The StarIoPort3.1 lib is provided in this repository and is therefore correct in reporting its location here.

Sorry, but this is the intended design - we do not consider assigning individual permissions to each of these ports when there are multiple ports, for example, in a USB hub.

We have designed our Android with the intention to allow USB connections between Android and our printers by stating the USB Vendor ID and USB Product ID of the product in the device_filter.xml. https://www.star-m.jp/products/s_print/sdk/starprnt_sdk/manual/android_java/en/configure_application.html#device-filter-xmlaccessory-filter-xml

Therefore, we would be very appreciated if you could continue to apply your current workaround.

I have also tested with the USB hub which has an Ethernet port (ELECOM DST-C09WH), but I could not find any difference in terms of authorisation, with or without Ethernet ports. If this perception is incorrect, we would be grateful if you could let us know.