下面列出了android.hardware.usb.UsbEndpoint#getAddress ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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;
}
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;
}