private int getInterfaceIdFromDescriptors() {
            ArrayList<byte[]> descriptors = UsbUtils.getDescriptors(mConnection);
            Log.d(TAG, "USB descriptor:");
            for(byte[] descriptor : descriptors)
                Log.d(TAG, HexDump.toHexString(descriptor));

            if (descriptors.size() > 0 &&
                    descriptors.get(0).length == 18 &&
                    descriptors.get(0)[1] == 1 && // bDescriptorType
                    descriptors.get(0)[4] == (byte)(UsbConstants.USB_CLASS_MISC) && //bDeviceClass
                    descriptors.get(0)[5] == 2 && // bDeviceSubClass
                    descriptors.get(0)[6] == 1) { // bDeviceProtocol
                // is IAD device, see https://www.usb.org/sites/default/files/iadclasscode_r10.pdf
                int port = -1;
                for (int d = 1; d < descriptors.size(); d++) {
                    if (descriptors.get(d).length == 8 &&
                            descriptors.get(d)[1] == 0x0b && // bDescriptorType == IAD
                            descriptors.get(d)[4] == UsbConstants.USB_CLASS_COMM && // bFunctionClass == CDC
                            descriptors.get(d)[5] == USB_SUBCLASS_ACM) { // bFunctionSubClass == ACM
                        port++;
                        if (port == mPortNumber &&
                                descriptors.get(d)[3] == 2) { // bInterfaceCount
                            return descriptors.get(d)[2]; // bFirstInterface
                        }
                    }
                }
            }
            return -1;
        }
USB CDC/ACM serial driver implementation.

@author mike wakerly (opensource@hoho.com)
@see <a
     href="http://www.usb.org/developers/devclass_docs/usbcdc11.pdf">Universal
     Serial Bus Class Definitions for Communication Devices, v1.1</a>
usbSerialForAndroid/src/main/java/com/hoho/android/usbserial/driver/CdcAcmSerialDriver.java