/** * 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; }
/** * USBをOpenする. */ private synchronized void openUsb(final UsbDevice usbDevice) { if (DEBUG) { Log.i(TAG, "----------------------------------------"); Log.i(TAG, "Open USB."); Log.i(TAG, "DeviceName: " + usbDevice.getDeviceName()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Log.i(TAG, "DeviceProductName: " + usbDevice.getProductName()); } Log.i(TAG, "----------------------------------------"); } mParsingSysex = false; if (mFaBoUsbManager != null) { mFaBoUsbManager.closeConnection(); mFaBoUsbManager.checkDevice(usbDevice); mFaBoUsbManager.connection(usbDevice); } else { mFaBoUsbManager = new FaBoUsbManager(mContext); mFaBoUsbManager.setParameter(FaBoUsbConst.BAUNDRATE_57600, FaBoUsbConst.PARITY_NONE, FaBoUsbConst.STOP_1, FaBoUsbConst.FLOW_CONTROL_OFF, FaBoUsbConst.BITRATE_8); mFaBoUsbManager.setListener(mInterface); mFaBoUsbManager.checkDevice(usbDevice); mFaBoUsbManager.connection(usbDevice); } }
for (Map.Entry<String, UsbDevice> entry : usbDevices.entrySet()) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { if (entry.getValue().getProductName().contains("USB Audio")) { log(" USB Headset detected inside UsbManager, continue test"); usb_available = true;
viewHolder.getReportedProduct().setText(device.getProductName()); } else { viewHolder.getReportedVendor().setText(R.string.not_provided);