@TargetApi(HONEYCOMB_MR2) public UsbDeviceConnectionAssert hasRawDescriptors(byte[] descriptors) { isNotNull(); byte[] actualDescriptors = actual.getRawDescriptors(); assertThat(actualDescriptors) // .overridingErrorMessage("Expected raw descriptors <%s> but was <%s>.", descriptors, actualDescriptors) // .isEqualTo(descriptors); return this; }
public float getFirmwareVersion() { if (mConnection == null) { return 0.0f; } byte[] rawDescs = mConnection.getRawDescriptors(); return Float.parseFloat(Integer.toHexString(rawDescs[13] & 0x0ff) + "." + Integer.toHexString(rawDescs[12] & 0x0ff)); }
/** * Get UsbDevice's manufacturer name * * @param usbDevice the UsbDevice * @param usbDeviceConnection the UsbDeviceConnection * @return the manufacturer name */ @SuppressLint("NewApi") @Nullable public static String getManufacturerName(@NonNull UsbDevice usbDevice, @NonNull UsbDeviceConnection usbDeviceConnection) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return usbDevice.getManufacturerName(); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { byte[] rawDescriptors = usbDeviceConnection.getRawDescriptors(); try { byte[] buffer = new byte[255]; int indexOfManufacturerName = rawDescriptors[14] & 0xff; int manufacturerNameLength = usbDeviceConnection.controlTransfer(UsbConstants.USB_DIR_IN, USB_REQUEST_GET_DESCRIPTOR, (USB_DATA_TYPE_STRING << 8) | indexOfManufacturerName, 0, buffer, 255, 0); return new String(buffer, 2, manufacturerNameLength - 2, "UTF-16LE"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return null; } }
/** * Get UsbDevice's product name * * @param usbDevice the UsbDevice * @param usbDeviceConnection the UsbDeviceConnection * @return the product name */ @SuppressLint("NewApi") @Nullable public static String getProductName(@NonNull UsbDevice usbDevice, @NonNull UsbDeviceConnection usbDeviceConnection) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { return usbDevice.getProductName(); } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) { byte[] rawDescriptors = usbDeviceConnection.getRawDescriptors(); try { byte[] buffer = new byte[255]; int indexOfProductName = rawDescriptors[15] & 0xff; int productNameLength = usbDeviceConnection.controlTransfer(UsbConstants.USB_DIR_IN, USB_REQUEST_GET_DESCRIPTOR, (USB_DATA_TYPE_STRING << 8) | indexOfProductName, 0, buffer, 255, 0); return new String(buffer, 2, productNameLength - 2, "UTF-16LE"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } return null; }
@TargetApi(HONEYCOMB_MR2) public UsbDeviceConnectionAssert hasRawDescriptors(byte[] descriptors) { isNotNull(); byte[] actualDescriptors = actual.getRawDescriptors(); assertThat(actualDescriptors) // .overridingErrorMessage("Expected raw descriptors <%s> but was <%s>.", descriptors, actualDescriptors) // .isEqualTo(descriptors); return this; }