I have an issue with getting an USBInterface from an USBDevice when the device is plugged in in an USB hub with more than one device.
When I connect the USB device directly via OTG or via a hub which is connected via OTG everything works fine but as soon as I plug in an extra device in the hub I'm not able to open a connection.
I retrieve all usb device drivers and iterate trough them until i find the device i want to communicate with.
The following code Snippet contains my method for retrieving the usb devices:
String manufacturer = "MY_MANUFACTURER" // Dummy text for this snippet
int interfaceCount; // Number of USB interfaces
UsbManager manager = (UsbManager) getSystemService(Context.USB_SERVICE);
List<UsbSerialDriver> drivers UsbSerialProber.getDefaultProber().findAllDriver(manager);
for (UsbSerialDriver serialDriver : drivers) {
// Check for my specific USB device
if (serialDriver.getDevice().getManufacturerName().equals(manufacturer)) {
interfaceCount = driver.getInterfaceCount();
}
}
When my device is the only device in the hub the number of interfaces is 2, but as soon as i add an other device the count is 0 and the system throws an ArrayIndexOutOfBoundException on getInterfaceCount as soon as i try to open a connection.
Additional Info: I use the usb-serial-for-android library as a wrapper for communicating with the device. It's either an arduino (for testing) or an FTDI chip.