Java Code Examples for android.hardware.usb.UsbDevice#getInterfaceCount()
The following examples show how to use
android.hardware.usb.UsbDevice#getInterfaceCount() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: USBMonitor.java From DeviceConnect-Android with MIT License | 6 votes |
/** * get interface * @param interface_id * @param altsetting * @return * @throws IllegalStateException */ public synchronized UsbInterface getInterface(final int interface_id, final int altsetting) throws IllegalStateException { checkConnection(); SparseArray<UsbInterface> intfs = mInterfaces.get(interface_id); if (intfs == null) { intfs = new SparseArray<UsbInterface>(); mInterfaces.put(interface_id, intfs); } UsbInterface intf = intfs.get(altsetting); if (intf == null) { final UsbDevice device = mWeakDevice.get(); final int n = device.getInterfaceCount(); for (int i = 0; i < n; i++) { final UsbInterface temp = device.getInterface(i); if ((temp.getId() == interface_id) && (temp.getAlternateSetting() == altsetting)) { intf = temp; break; } } if (intf != null) { intfs.append(altsetting, intf); } } return intf; }
Example 2
Source File: CdcAcmSerialDriver.java From usb-serial-for-android with GNU Lesser General Public License v2.1 | 6 votes |
public CdcAcmSerialDriver(UsbDevice device) { mDevice = device; mPorts = new ArrayList<>(); int controlInterfaceCount = 0; int dataInterfaceCount = 0; for( int i = 0; i < device.getInterfaceCount(); i++) { if(device.getInterface(i).getInterfaceClass() == UsbConstants.USB_CLASS_COMM) controlInterfaceCount++; if(device.getInterface(i).getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA) dataInterfaceCount++; } for( int port = 0; port < Math.min(controlInterfaceCount, dataInterfaceCount); port++) { mPorts.add(new CdcAcmSerialPort(mDevice, port)); } if(mPorts.size() == 0) { mPorts.add(new CdcAcmSerialPort(mDevice, -1)); } }
Example 3
Source File: UsbHelper.java From sample-usbenum with Apache License 2.0 | 6 votes |
/** * Enumerate the endpoints and interfaces on the connected device. * * @param device Device to query. * @return String description of the device configuration. */ public static String readDevice(UsbDevice device) { StringBuilder sb = new StringBuilder(); sb.append("Device Name: " + device.getDeviceName() + "\n"); sb.append(String.format( "Device Class: %s -> Subclass: 0x%02x -> Protocol: 0x%02x\n", nameForClass(device.getDeviceClass()), device.getDeviceSubclass(), device.getDeviceProtocol())); for (int i = 0; i < device.getInterfaceCount(); i++) { UsbInterface intf = device.getInterface(i); sb.append(String.format(Locale.US, "-- Interface %d Class: %s -> Subclass: 0x%02x -> Protocol: 0x%02x\n", intf.getId(), nameForClass(intf.getInterfaceClass()), intf.getInterfaceSubclass(), intf.getInterfaceProtocol())); sb.append(String.format(Locale.US, " -- Endpoint Count: %d\n", intf.getEndpointCount())); } return sb.toString(); }
Example 4
Source File: DeviceFilter.java From libcommon with Apache License 2.0 | 6 votes |
private boolean interfaceMatches(@NonNull final UsbDevice device) { // if device doesn't match, check the interfaces final int count = device.getInterfaceCount(); for (int i = 0; i < count; i++) { final UsbInterface intf = device.getInterface(i); if (matches( intf.getInterfaceClass(), intf.getInterfaceSubclass(), intf.getInterfaceProtocol())) { return true; } if (interfaceMatches( intf.getInterfaceClass(), intf.getInterfaceSubclass(), intf.getInterfaceProtocol())) { return true; } } return false; }
Example 5
Source File: USBMonitor.java From UVCCameraZxing with Apache License 2.0 | 6 votes |
/** * output device list to LogCat */ public final void dumpDevices() { final HashMap<String, UsbDevice> list = mUsbManager.getDeviceList(); if (list != null) { final Set<String> keys = list.keySet(); if (keys != null && keys.size() > 0) { final StringBuilder sb = new StringBuilder(); for (final String key: keys) { final UsbDevice device = list.get(key); final int num_interface = device != null ? device.getInterfaceCount() : 0; sb.setLength(0); for (int i = 0; i < num_interface; i++) { sb.append(String.format("interface%d:%s", i, device.getInterface(i).toString())); } Log.i(TAG, "key=" + key + ":" + device + ":" + sb.toString()); } } else { Log.i(TAG, "no device"); } } else { Log.i(TAG, "no device"); } }
Example 6
Source File: CarlifeUtil.java From apollo-DuerOS with Apache License 2.0 | 6 votes |
public boolean isUsbStorageDevice(Context context) { UsbManager mUsbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE); if (null == mUsbManager) { LogUtil.e(TAG, "There is no devices"); return false; } else { LogUtil.v(TAG, "Usb Devices: " + String.valueOf(mUsbManager.toString())); } HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); if (STORAGE_INTERFACE_CONUT == device.getInterfaceCount()) { UsbInterface usbInter = device.getInterface(STORAGE_INTERFACE_ID); if ((STORAGE_INTERFACE_CLASS == usbInter.getInterfaceClass()) && (STORAGE_INTERFACE_SUBCLASS == usbInter.getInterfaceSubclass()) && (STORAGE_INTERFACE_PROTOCOL == usbInter.getInterfaceProtocol())) { LogUtil.e(TAG, "This is mass storage 1"); return true; } } } return false; }
Example 7
Source File: CarlifeUtil.java From apollo-DuerOS with Apache License 2.0 | 6 votes |
public boolean isUsbStorageDevice(UsbDevice device) { if( device == null ) { LogUtil.e(TAG, "this device is null"); return false; } if (STORAGE_INTERFACE_CONUT == device.getInterfaceCount()) { UsbInterface usbInter = device.getInterface(STORAGE_INTERFACE_ID); if ((STORAGE_INTERFACE_CLASS == usbInter.getInterfaceClass()) && (STORAGE_INTERFACE_SUBCLASS == usbInter.getInterfaceSubclass()) && (STORAGE_INTERFACE_PROTOCOL == usbInter.getInterfaceProtocol())) { LogUtil.e(TAG, "this device is mass storage 2"); return true; } } return false; }
Example 8
Source File: Usb.java From android-stm32-dfu-programmer with Apache License 2.0 | 5 votes |
public String getDeviceInfo(UsbDevice device) { if (device == null) return "No device found."; StringBuilder sb = new StringBuilder(); sb.append("Model: " + device.getDeviceName() + "\n"); sb.append("ID: " + device.getDeviceId() + " (0x" + Integer.toHexString(device.getDeviceId()) + ")" + "\n"); sb.append("Class: " + device.getDeviceClass() + "\n"); sb.append("Subclass: " + device.getDeviceSubclass() + "\n"); sb.append("Protocol: " + device.getDeviceProtocol() + "\n"); sb.append("Vendor ID " + device.getVendorId() + " (0x" + Integer.toHexString(device.getVendorId()) + ")" + "\n"); sb.append("Product ID: " + device.getProductId() + " (0x" + Integer.toHexString(device.getProductId()) + ")" + "\n"); sb.append("Device Ver: 0x" + Integer.toHexString(mDeviceVersion) + "\n"); sb.append("Interface count: " + device.getInterfaceCount() + "\n"); for (int i = 0; i < device.getInterfaceCount(); i++) { UsbInterface usbInterface = device.getInterface(i); sb.append("Interface: " + usbInterface.toString() + "\n"); sb.append("Endpoint Count: " + usbInterface.getEndpointCount() + "\n"); for (int j = 0; j < usbInterface.getEndpointCount(); j++) { UsbEndpoint ep = usbInterface.getEndpoint(j); sb.append("Endpoint: " + ep.toString() + "\n"); } } return sb.toString(); }
Example 9
Source File: USBMonitor.java From libcommon with Apache License 2.0 | 5 votes |
/** * インターフェースを取得する * @param interface_id * @param altsetting * @return * @throws IllegalStateException */ @SuppressLint("NewApi") public synchronized UsbInterface getInterface(final int interface_id, final int altsetting) throws IllegalStateException { checkConnection(); SparseArray<UsbInterface> intfs = mInterfaces.get(interface_id); if (intfs == null) { intfs = new SparseArray<UsbInterface>(); mInterfaces.put(interface_id, intfs); } UsbInterface intf = intfs.get(altsetting); if (intf == null) { final UsbDevice device = mWeakDevice.get(); final int n = device.getInterfaceCount(); for (int i = 0; i < n; i++) { final UsbInterface temp = device.getInterface(i); if ((temp.getId() == interface_id) && (temp.getAlternateSetting() == altsetting)) { intf = temp; break; } } if (intf != null) { intfs.append(altsetting, intf); } } return intf; }
Example 10
Source File: DeviceFilter.java From UVCCameraZxing with Apache License 2.0 | 5 votes |
public boolean matches(final UsbDevice device) { if (mVendorId != -1 && device.getVendorId() != mVendorId) return false; if (mProductId != -1 && device.getProductId() != mProductId) return false; /* if (mManufacturerName != null && device.getManufacturerName() == null) return false; if (mProductName != null && device.getProductName() == null) return false; if (mSerialNumber != null && device.getSerialNumber() == null) return false; if (mManufacturerName != null && device.getManufacturerName() != null && !mManufacturerName.equals(device.getManufacturerName())) return false; if (mProductName != null && device.getProductName() != null && !mProductName.equals(device.getProductName())) return false; if (mSerialNumber != null && device.getSerialNumber() != null && !mSerialNumber.equals(device.getSerialNumber())) return false; */ // check device class/subclass/protocol if (matches(device.getDeviceClass(), device.getDeviceSubclass(), device.getDeviceProtocol())) return true; // if device doesn't match, check the interfaces final int count = device.getInterfaceCount(); for (int i = 0; i < count; i++) { final UsbInterface intf = device.getInterface(i); if (matches(intf.getInterfaceClass(), intf.getInterfaceSubclass(), intf.getInterfaceProtocol())) return true; } return false; }
Example 11
Source File: UsbSerialDevice.java From UsbSerial with MIT License | 5 votes |
public static boolean isCdcDevice(UsbDevice device) { int iIndex = device.getInterfaceCount(); for(int i=0;i<=iIndex-1;i++) { UsbInterface iface = device.getInterface(i); if(iface.getInterfaceClass() == UsbConstants.USB_CLASS_CDC_DATA) return true; } return false; }
Example 12
Source File: DeviceFilter.java From AndroidUSBCamera with Apache License 2.0 | 5 votes |
/** * 指定したUsbDeviceがこのDeviceFilterにマッチするかどうかを返す * mExcludeフラグは別途#isExcludeか自前でチェックすること * @param device * @return */ public boolean matches(final UsbDevice device) { if (mVendorId != -1 && device.getVendorId() != mVendorId) { return false; } if (mProductId != -1 && device.getProductId() != mProductId) { return false; } /* if (mManufacturerName != null && device.getManufacturerName() == null) return false; if (mProductName != null && device.getProductName() == null) return false; if (mSerialNumber != null && device.getSerialNumber() == null) return false; if (mManufacturerName != null && device.getManufacturerName() != null && !mManufacturerName.equals(device.getManufacturerName())) return false; if (mProductName != null && device.getProductName() != null && !mProductName.equals(device.getProductName())) return false; if (mSerialNumber != null && device.getSerialNumber() != null && !mSerialNumber.equals(device.getSerialNumber())) return false; */ // check device class/subclass/protocol if (matches(device.getDeviceClass(), device.getDeviceSubclass(), device.getDeviceProtocol())) { return true; } // if device doesn't match, check the interfaces final int count = device.getInterfaceCount(); for (int i = 0; i < count; i++) { final UsbInterface intf = device.getInterface(i); if (matches(intf.getInterfaceClass(), intf.getInterfaceSubclass(), intf.getInterfaceProtocol())) { return true; } } return false; }
Example 13
Source File: FTDISioIds.java From UsbSerial with MIT License | 5 votes |
private static boolean isMicrochipFtdi(UsbDevice dev) { if (dev.getVendorId() != 0x04d8 || dev.getProductId() != 0x000a) return false; for (int i = 0; i < dev.getInterfaceCount(); i++) { UsbInterface intf = dev.getInterface(i); if (intf.getInterfaceClass() == 0xff && intf.getInterfaceSubclass() == 0xff && intf.getInterfaceProtocol() == 0x00) return true; } return false; }
Example 14
Source File: Cp21xxSerialDriver.java From usb-serial-for-android with GNU Lesser General Public License v2.1 | 5 votes |
public Cp21xxSerialDriver(UsbDevice device) { mDevice = device; mPorts = new ArrayList<>(); for( int port = 0; port < device.getInterfaceCount(); port++) { mPorts.add(new Cp21xxSerialPort(mDevice, port)); } }
Example 15
Source File: UsbMidiDeviceAndroid.java From 365browser with Apache License 2.0 | 5 votes |
/** * Constructs a UsbMidiDeviceAndroid. * @param manager * @param device The USB device which this object is assocated with. */ UsbMidiDeviceAndroid(UsbManager manager, UsbDevice device) { mConnection = manager.openDevice(device); mEndpointMap = new SparseArray<UsbEndpoint>(); mRequestMap = new HashMap<UsbEndpoint, UsbRequest>(); mHandler = new Handler(); mUsbDevice = device; mIsClosed = false; mHasInputThread = false; mNativePointer = 0; for (int i = 0; i < device.getInterfaceCount(); ++i) { UsbInterface iface = device.getInterface(i); if (iface.getInterfaceClass() != UsbConstants.USB_CLASS_AUDIO || iface.getInterfaceSubclass() != MIDI_SUBCLASS) { continue; } mConnection.claimInterface(iface, true); for (int j = 0; j < iface.getEndpointCount(); ++j) { UsbEndpoint endpoint = iface.getEndpoint(j); if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) { mEndpointMap.put(endpoint.getEndpointNumber(), endpoint); } } } // Start listening for input endpoints. // This function will create and run a thread if there is USB-MIDI endpoints in the // device. Note that because UsbMidiDevice is shared among all tabs and the thread // will be terminated when the device is disconnected, at most one thread can be created // for each connected USB-MIDI device. startListen(device); }
Example 16
Source File: UsbIpService.java From USBIPServerForAndroid with GNU General Public License v3.0 | 4 votes |
private int detectSpeed(UsbDevice dev, UsbDeviceDescriptor devDesc) { int possibleSpeeds = FLAG_POSSIBLE_SPEED_LOW | FLAG_POSSIBLE_SPEED_FULL | FLAG_POSSIBLE_SPEED_HIGH; for (int i = 0; i < dev.getInterfaceCount(); i++) { UsbInterface iface = dev.getInterface(i); for (int j = 0; j < iface.getEndpointCount(); j++) { UsbEndpoint endpoint = iface.getEndpoint(j); if ((endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) || (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_ISOC)) { // Low speed devices can't implement bulk or iso endpoints possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_LOW; } if (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_CONTROL) { if (endpoint.getMaxPacketSize() > 8) { // Low speed devices can't use control transfer sizes larger than 8 bytes possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_LOW; } if (endpoint.getMaxPacketSize() < 64) { // High speed devices can't use control transfer sizes smaller than 64 bytes possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_HIGH; } } else if (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_INT) { if (endpoint.getMaxPacketSize() > 8) { // Low speed devices can't use interrupt transfer sizes larger than 8 bytes possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_LOW; } if (endpoint.getMaxPacketSize() > 64) { // Full speed devices can't use interrupt transfer sizes larger than 64 bytes possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_FULL; } } else if (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) { // A bulk endpoint alone can accurately distiniguish between // full and high speed devices if (endpoint.getMaxPacketSize() == 512) { // High speed devices can only use 512 byte bulk transfers possibleSpeeds = FLAG_POSSIBLE_SPEED_HIGH; } else { // Otherwise it must be full speed possibleSpeeds = FLAG_POSSIBLE_SPEED_FULL; } } else if (endpoint.getType() == UsbConstants.USB_ENDPOINT_XFER_ISOC) { // If the transfer size is 1024, it must be high speed if (endpoint.getMaxPacketSize() == 1024) { possibleSpeeds = FLAG_POSSIBLE_SPEED_HIGH; } } } } if (devDesc != null) { if (devDesc.bcdUSB < 0x200) { // High speed only supported on USB 2.0 or higher possibleSpeeds &= ~FLAG_POSSIBLE_SPEED_HIGH; } } // Return the lowest speed that we're compatible with System.out.printf("Speed heuristics for device %d left us with 0x%x\n", dev.getDeviceId(), possibleSpeeds); if ((possibleSpeeds & FLAG_POSSIBLE_SPEED_LOW) != 0) { return UsbIpDevice.USB_SPEED_LOW; } else if ((possibleSpeeds & FLAG_POSSIBLE_SPEED_FULL) != 0) { return UsbIpDevice.USB_SPEED_FULL; } else if ((possibleSpeeds & FLAG_POSSIBLE_SPEED_HIGH) != 0) { return UsbIpDevice.USB_SPEED_HIGH; } else { // Something went very wrong in speed detection return UsbIpDevice.USB_SPEED_UNKNOWN; } }
Example 17
Source File: UsbIpService.java From USBIPServerForAndroid with GNU General Public License v3.0 | 4 votes |
@Override public boolean attachToDevice(Socket s, String busId) { UsbDevice dev = getDevice(busId); if (dev == null) { return false; } if (connections.get(dev.getDeviceId()) != null) { // Already attached return false; } if (!usbManager.hasPermission(dev)) { // Try to get permission from the user permission.put(dev.getDeviceId(), null); usbManager.requestPermission(dev, usbPermissionIntent); synchronized (dev) { while (permission.get(dev.getDeviceId()) == null) { try { dev.wait(1000); } catch (InterruptedException e) { return false; } } } // User may have rejected this if (!permission.get(dev.getDeviceId())) { return false; } } UsbDeviceConnection devConn = usbManager.openDevice(dev); if (devConn == null) { return false; } // Claim all interfaces since we don't know which one the client wants for (int i = 0; i < dev.getInterfaceCount(); i++) { if (!devConn.claimInterface(dev.getInterface(i), true)) { System.err.println("Unabled to claim interface "+dev.getInterface(i).getId()); } } // Create a context for this attachment AttachedDeviceContext context = new AttachedDeviceContext(); context.devConn = devConn; context.device = dev; // Count all endpoints on all interfaces int endpointCount = 0; for (int i = 0; i < dev.getInterfaceCount(); i++) { endpointCount += dev.getInterface(i).getEndpointCount(); } // Use a thread pool with a thread per endpoint context.requestPool = new ThreadPoolExecutor(endpointCount, endpointCount, Long.MAX_VALUE, TimeUnit.DAYS, new LinkedBlockingQueue<Runnable>(), new ThreadPoolExecutor.DiscardPolicy()); // Create the active message set context.activeMessages = new HashSet<UsbIpSubmitUrb>(); connections.put(dev.getDeviceId(), context); socketMap.put(s, context); updateNotification(); return true; }
Example 18
Source File: MedtronicCnlService.java From 600SeriesAndroidUploader with MIT License | 4 votes |
private void getUsbInfo() { UsbManager mManager = (UsbManager) getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> deviceList = mManager.getDeviceList(); Iterator<UsbDevice> deviceIterator = deviceList.values().iterator(); while (deviceIterator.hasNext()) { UsbDevice device = deviceIterator.next(); Log.i(TAG, "Model: " + device.getDeviceName()); Log.i(TAG, "ID: " + device.getDeviceId()); Log.i(TAG, "Class: " + device.getDeviceClass()); Log.i(TAG, "Protocol: " + device.getDeviceProtocol()); Log.i(TAG, "Vendor ID " + device.getVendorId()); Log.i(TAG, "Product ID: " + device.getProductId()); Log.i(TAG, "Interface count: " + device.getInterfaceCount()); Log.i(TAG, "---------------------------------------"); // Get interface details for (int index = 0; index < device.getInterfaceCount(); index++) { UsbInterface mUsbInterface = device.getInterface(index); Log.i(TAG, " ***** *****"); Log.i(TAG, " Interface index: " + index); Log.i(TAG, " Interface ID: " + mUsbInterface.getId()); Log.i(TAG, " Inteface class: " + mUsbInterface.getInterfaceClass()); Log.i(TAG, " Interface protocol: " + mUsbInterface.getInterfaceProtocol()); Log.i(TAG, " Endpoint count: " + mUsbInterface.getEndpointCount()); // Get endpoint details for (int epi = 0; epi < mUsbInterface.getEndpointCount(); epi++) { UsbEndpoint mEndpoint = mUsbInterface.getEndpoint(epi); Log.i(TAG, " ++++ ++++ ++++"); Log.i(TAG, " Endpoint index: " + epi); Log.i(TAG, " Attributes: " + mEndpoint.getAttributes()); Log.i(TAG, " Direction: " + mEndpoint.getDirection()); Log.i(TAG, " Number: " + mEndpoint.getEndpointNumber()); Log.i(TAG, " Interval: " + mEndpoint.getInterval()); Log.i(TAG, " Packet size: " + mEndpoint.getMaxPacketSize()); Log.i(TAG, " Type: " + mEndpoint.getType()); } } } Log.i(TAG, " No more devices connected."); }
Example 19
Source File: Trezor.java From GreenBits with GNU General Public License v3.0 | 4 votes |
public static Trezor getDevice(final Context context, final TrezorGUICallback guiFn, final Network network) { final UsbManager manager = (UsbManager)context.getSystemService(Context.USB_SERVICE); for (final UsbDevice device: manager.getDeviceList().values()) { // Check if the device is TREZOR (or AvalonWallet or BWALLET) final int vendorId = device.getVendorId(); final int productId = device.getProductId(); if ((vendorId != 0x534c || productId != 0x0001) && (vendorId != 0x1209 || productId != 0x53c0) && (vendorId != 0x1209 || productId != 0x53c1) && (vendorId != 0x10c4 || productId != 0xea80)) { continue; } Log.i(TAG, "Hardware Wallet device found"); if (device.getInterfaceCount() < 1) { Log.e(TAG, "Wrong interface count"); continue; } // Use first interface final UsbInterface iface = device.getInterface(0); // Try to find read/write endpoints UsbEndpoint readEndpoint = null, writeEndpoint = null; for (int i = 0; i < iface.getEndpointCount(); ++i) { final UsbEndpoint ep = iface.getEndpoint(i); if (readEndpoint == null && ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT && ep.getAddress() == 0x81) { // number = 1 ; dir = USB_DIR_IN readEndpoint = ep; continue; } if (writeEndpoint == null && ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT && (ep.getAddress() == 0x01 || ep.getAddress() == 0x02)) { // number = 1 ; dir = USB_DIR_OUT writeEndpoint = ep; continue; } Log.e(TAG, String.format("ep %d", ep.getAddress())); } if (!isEndpointOK(readEndpoint, "read") || !isEndpointOK(writeEndpoint, "write")) continue; // Try to open the device final UsbDeviceConnection conn = manager.openDevice(device); if (conn == null || !conn.claimInterface(iface, true)) { Log.e(TAG, conn == null ? "Could not open connection" : "Could not claim interface"); continue; } // All OK - return the class return new Trezor(guiFn, device, conn, readEndpoint, writeEndpoint, network); } return null; }
Example 20
Source File: Trezor.java From green_android with GNU General Public License v3.0 | 4 votes |
public static Trezor getDevice(final Context context) { final UsbManager manager = (UsbManager)context.getSystemService(Context.USB_SERVICE); for (final UsbDevice device: manager.getDeviceList().values()) { // Check if the device is TREZOR (or AvalonWallet or BWALLET) final int vendorId = device.getVendorId(); final int productId = device.getProductId(); if ((vendorId != 0x534c || productId != 0x0001) && (vendorId != 0x1209 || productId != 0x53c0) && (vendorId != 0x1209 || productId != 0x53c1) && (vendorId != 0x10c4 || productId != 0xea80)) { continue; } Log.d(TAG, "Hardware Wallet device found"); if (device.getInterfaceCount() < 1) { Log.e(TAG, "Wrong interface count"); continue; } // Use first interface final UsbInterface iface = device.getInterface(0); // Try to find read/write endpoints UsbEndpoint readEndpoint = null, writeEndpoint = null; for (int i = 0; i < iface.getEndpointCount(); ++i) { final UsbEndpoint ep = iface.getEndpoint(i); if (readEndpoint == null && ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT && ep.getAddress() == 0x81) { // number = 1 ; dir = USB_DIR_IN readEndpoint = ep; continue; } if (writeEndpoint == null && ep.getType() == UsbConstants.USB_ENDPOINT_XFER_INT && (ep.getAddress() == 0x01 || ep.getAddress() == 0x02)) { // number = 1 ; dir = USB_DIR_OUT writeEndpoint = ep; continue; } Log.d(TAG, String.format("ep %d", ep.getAddress())); } if (isEndpointBad(readEndpoint, "read") || isEndpointBad(writeEndpoint, "write")) continue; // Try to open the device final UsbDeviceConnection conn = manager.openDevice(device); if (conn == null || !conn.claimInterface(iface, true)) { Log.e(TAG, conn == null ? "Could not open connection" : "Could not claim interface"); continue; } // All OK - return the class return new Trezor(device, conn, readEndpoint, writeEndpoint); } return null; }