下面列出了怎么用android.hardware.usb.UsbInterface的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public @NonNull
Iso7816Connection openIso7816Connection() throws IOException {
UsbInterface ccidInterface = getInterface(UsbConstants.USB_CLASS_CSCID);
if (ccidInterface == null) {
throw new IOException("No CCID interface found!");
}
Pair<UsbEndpoint, UsbEndpoint> endpointPair = findEndpoints(ccidInterface, UsbConstants.USB_ENDPOINT_XFER_BULK);
if (endpointPair.first == null || endpointPair.second == null) {
throw new IOException("Unable to find endpoints!");
}
UsbDeviceConnection connection = openConnection();
if (connection == null) {
throw new IOException("exception in UsbManager.openDevice");
}
if (!connection.claimInterface(ccidInterface, true)) {
connection.close();
throw new IOException("Interface couldn't be claimed");
}
return new UsbIso7816Connection(connection, ccidInterface, endpointPair.first, endpointPair.second);
}
/**
* Creates and starts session for communication with yubikey using HID interface
* @return session for communication with yubikey (supported over USB only)
* @throws IOException if Keyboard HID interface or endpoints are not found
*/
public @NonNull
UsbHidConnection openHidKeyboardConnection() throws IOException {
UsbInterface hidInterface = getInterface(UsbConstants.USB_CLASS_HID);
if (hidInterface == null) {
throw new IOException("No HID interface found");
}
if (hidInterface.getInterfaceSubclass() != UsbConstants.USB_INTERFACE_SUBCLASS_BOOT) {
throw new IOException("No expected HID interface");
}
UsbDeviceConnection connection = openConnection();
if (connection == null) {
throw new IOException("exception in UsbManager.openDevice");
}
if (!connection.claimInterface(hidInterface, true)) {
connection.close();
throw new IOException("Interface couldn't be claimed");
}
return new UsbHidConnection(connection, hidInterface);
}
/**
* Gets bulkin and bulkout endpoints of specified interface
* @param usbInterface interface of usb device
* @return the pair of endpoints: in and out
*/
private Pair<UsbEndpoint, UsbEndpoint> findEndpoints(UsbInterface usbInterface, int type) {
UsbEndpoint endpointIn = null;
UsbEndpoint endpointOut = null;
for (int i = 0; i < usbInterface.getEndpointCount(); i++) {
UsbEndpoint endpoint = usbInterface.getEndpoint(i);
if (endpoint.getType() == type) {
if (endpoint.getDirection() == UsbConstants.USB_DIR_IN) {
endpointIn = endpoint;
} else {
endpointOut = endpoint;
}
}
}
return new Pair<>(endpointIn, endpointOut);
}
public static UsbHidDevice[] enumerate(Context context, int vid, int pid) throws Exception {
UsbManager usbManager = (UsbManager) context.getApplicationContext().getSystemService(Context.USB_SERVICE);
if (usbManager == null) {
throw new Exception("no usb service");
}
Map<String, UsbDevice> devices = usbManager.getDeviceList();
List<UsbHidDevice> usbHidDevices = new ArrayList<>();
for (UsbDevice device : devices.values()) {
if ((vid == 0 || device.getVendorId() == vid) && (pid == 0 || device.getProductId() == pid)) {
for (int i = 0; i < device.getInterfaceCount(); i++) {
UsbInterface usbInterface = device.getInterface(i);
if (usbInterface.getInterfaceClass() == INTERFACE_CLASS_HID) {
UsbHidDevice hidDevice = new UsbHidDevice(device, usbInterface, usbManager);
usbHidDevices.add(hidDevice);
}
}
}
}
return usbHidDevices.toArray(new UsbHidDevice[usbHidDevices.size()]);
}
private UsbHidDevice(UsbDevice usbDevice, UsbInterface usbInterface, UsbManager usbManager) {
mUsbDevice = usbDevice;
mUsbInterface = usbInterface;
mUsbManager= usbManager;
for (int i = 0; i < mUsbInterface.getEndpointCount(); i++) {
UsbEndpoint endpoint = mUsbInterface.getEndpoint(i);
int dir = endpoint.getDirection();
int type = endpoint.getType();
if (mInUsbEndpoint == null && dir == UsbConstants.USB_DIR_IN && type == UsbConstants.USB_ENDPOINT_XFER_INT) {
mInUsbEndpoint = endpoint;
}
if (mOutUsbEndpoint == null && dir == UsbConstants.USB_DIR_OUT && type == UsbConstants.USB_ENDPOINT_XFER_INT) {
mOutUsbEndpoint = endpoint;
}
}
}
@Override
protected void openInt(UsbDeviceConnection connection) throws IOException {
for (int i = 0; i < mDevice.getInterfaceCount(); i++) {
UsbInterface usbIface = mDevice.getInterface(i);
if (!mConnection.claimInterface(usbIface, true)) {
throw new IOException("Could not claim data interface");
}
}
UsbInterface dataIface = mDevice.getInterface(mDevice.getInterfaceCount() - 1);
for (int i = 0; i < dataIface.getEndpointCount(); i++) {
UsbEndpoint ep = dataIface.getEndpoint(i);
if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
if (ep.getDirection() == UsbConstants.USB_DIR_IN) {
mReadEndpoint = ep;
} else {
mWriteEndpoint = ep;
}
}
}
initialize();
setBaudRate(DEFAULT_BAUD_RATE);
}
public static BTChipTransport open(UsbManager manager, UsbDevice device) throws IOException {
UsbDeviceConnection connection = manager.openDevice(device);
if (connection == null) throw new IOException("Device not connected");
// Must only be called once permission is granted (see http://developer.android.com/reference/android/hardware/usb/UsbManager.html)
// Important if enumerating, rather than being awaken by the intent notification
UsbInterface dongleInterface = device.getInterface(0);
UsbEndpoint in = null;
UsbEndpoint out = null;
for (int i = 0; i < dongleInterface.getEndpointCount(); i++) {
UsbEndpoint tmpEndpoint = dongleInterface.getEndpoint(i);
if (tmpEndpoint.getDirection() == UsbConstants.USB_DIR_IN) {
in = tmpEndpoint;
} else {
out = tmpEndpoint;
}
}
connection.claimInterface(dongleInterface, true);
return new BTChipTransportAndroidHID(connection, dongleInterface, in, out);
}
/**
* 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();
}
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;
}
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;
}
/**
* 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;
}
protected void setupUsb(UsbDevice device) {
UsbInterface inf = device.getInterface(0);
UsbDeviceConnection conn = mUsbManager.openDevice(device);
if (conn == null) {
Log.wtf("MainActivity", "unable to open device?");
return;
}
if (!conn.claimInterface(inf, true)) {
conn.close();
Log.wtf("MainActivity", "unable to claim interface!");
return;
}
mBlinkDevice = device;
mBlinkConn = conn;
}
protected void setupUsb(UsbDevice device) {
UsbInterface inf = device.getInterface(0);
UsbDeviceConnection conn = mUsbManager.openDevice(device);
if (conn == null) {
Log.wtf("MainActivity", "unable to open device?");
return;
}
if (!conn.claimInterface(inf, true)) {
conn.close();
Log.wtf("MainActivity", "unable to claim interface!");
return;
}
mBlinkDevice = device;
mBlinkConn = conn;
}
@Override
protected void openInt(UsbDeviceConnection connection) throws IOException {
mIsRestrictedPort = mDevice.getInterfaceCount() == 2 && mPortNumber == 1;
if(mPortNumber >= mDevice.getInterfaceCount()) {
throw new IOException("Unknown port number");
}
UsbInterface dataIface = mDevice.getInterface(mPortNumber);
if (!mConnection.claimInterface(dataIface, true)) {
throw new IOException("Could not claim interface " + mPortNumber);
}
for (int i = 0; i < dataIface.getEndpointCount(); i++) {
UsbEndpoint ep = dataIface.getEndpoint(i);
if (ep.getType() == UsbConstants.USB_ENDPOINT_XFER_BULK) {
if (ep.getDirection() == UsbConstants.USB_DIR_IN) {
mReadEndpoint = ep;
} else {
mWriteEndpoint = ep;
}
}
}
setConfigSingle(SILABSER_IFC_ENABLE_REQUEST_CODE, UART_ENABLE);
setConfigSingle(SILABSER_SET_MHS_REQUEST_CODE, MCR_ALL | CONTROL_WRITE_DTR | CONTROL_WRITE_RTS);
// setConfigSingle(SILABSER_SET_BAUDDIV_REQUEST_CODE, BAUD_RATE_GEN_FREQ / DEFAULT_BAUD_RATE);
// setParameters(DEFAULT_BAUD_RATE, DEFAULT_DATA_BITS, DEFAULT_STOP_BITS, DEFAULT_PARITY);
}
/**
* open specific interface
* @param interfaceIndex
* @return
*/
public synchronized UsbInterface open(final int interfaceIndex) {
if (DEBUG) Log.i(TAG, "UsbControlBlock#open:" + interfaceIndex);
final UsbDevice device = mWeakDevice.get();
UsbInterface intf = null;
intf = mInterfaces.get(interfaceIndex);
if (intf == null) {
intf = device.getInterface(interfaceIndex);
if (intf != null) {
synchronized (mInterfaces) {
mInterfaces.append(interfaceIndex, intf);
}
}
}
return intf;
}
/**
* close specified interface. USB device itself still keep open.
*/
public synchronized void close() {
if (DEBUG) Log.i(TAG, "UsbControlBlock#close:");
if (mConnection != null) {
final int n = mInterfaces.size();
int key;
UsbInterface intf;
for (int i = 0; i < n; i++) {
key = mInterfaces.keyAt(i);
intf = mInterfaces.get(key);
mConnection.releaseInterface(intf);
}
mConnection.close();
mConnection = null;
final USBMonitor monitor = mWeakMonitor.get();
if (monitor != null) {
if (monitor.mOnDeviceConnectListener != null) {
final UsbDevice device = mWeakDevice.get();
monitor.mOnDeviceConnectListener.onDisconnect(device, this);
}
monitor.mCtrlBlocks.remove(getDevice());
}
}
}
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;
}
@Override
public void onConnect() {
// Serial mode only
// TODO: find the interface and endpoint indexes no matter what mode it is
int ifIdx = 1;
int epInIdx = 1;
int epOutIdx = 0;
UsbInterface iface = usbDevice.getInterface(ifIdx);
if (usbConnection.claimInterface(iface, true)) {
logger.log("Interface claimed successfully\n");
} else {
logger.log("ERROR - can't claim interface\n");
return;
}
endpointIn = iface.getEndpoint(epInIdx);
endpointOut = iface.getEndpoint(epOutIdx);
super.onConnect();
}
/**
* 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;
}
/**
* Request a device access permission if there is a MIDI interface in the device.
*
* @param device a USB device
*/
private void requestDevicePermissionIfNecessary(UsbDevice device) {
for (UsbDevice d : mRequestedDevices) {
if (d.getDeviceId() == device.getDeviceId()) {
// It is already requested.
return;
}
}
for (int i = 0; i < device.getInterfaceCount(); ++i) {
UsbInterface iface = device.getInterface(i);
if (iface.getInterfaceClass() == UsbConstants.USB_CLASS_AUDIO
&& iface.getInterfaceSubclass() == UsbMidiDeviceAndroid.MIDI_SUBCLASS) {
// There is at least one interface supporting MIDI.
mUsbManager.requestPermission(device,
PendingIntent.getBroadcast(ContextUtils.getApplicationContext(), 0,
new Intent(ACTION_USB_PERMISSION), 0));
mRequestedDevices.add(device);
break;
}
}
}
public static void dumpInterfaces(UsbDevice dev) {
for (int i = 0; i < dev.getInterfaceCount(); i++) {
System.out.printf("%d - Iface %d (%02x/%02x/%02x)\n",
i, dev.getInterface(i).getId(),
dev.getInterface(i).getInterfaceClass(),
dev.getInterface(i).getInterfaceSubclass(),
dev.getInterface(i).getInterfaceProtocol());
UsbInterface iface = dev.getInterface(i);
for (int j = 0; j < iface.getEndpointCount(); j++) {
System.out.printf("\t%d - Endpoint %d (%x/%x)\n",
j, iface.getEndpoint(j).getEndpointNumber(),
iface.getEndpoint(j).getAddress(),
iface.getEndpoint(j).getAttributes());
}
}
}
/**
* Gets interface of a specified class
* @param usbClass UsbConstants that identifies interface class (e.g. UsbConstants.USB_CLASS_CSCID or UsbConstants.USB_CLASS_HID)
* @return interface of device
*/
private UsbInterface getInterface(int usbClass) {
UsbInterface selectedInterface = null;
for (int i = 0; i < usbDevice.getInterfaceCount(); i++) {
UsbInterface usbInterface = usbDevice.getInterface(i);
if (usbInterface.getInterfaceClass() == usbClass) {
selectedInterface = usbInterface;
break;
}
}
return selectedInterface;
}
public BTChipTransportAndroidHID(UsbDeviceConnection connection, UsbInterface dongleInterface, UsbEndpoint in, UsbEndpoint out, int timeout, boolean ledger) {
this.connection = connection;
this.dongleInterface = dongleInterface;
this.in = in;
this.out = out;
this.ledger = ledger;
// Compatibility with old prototypes, to be removed
if (!this.ledger) {
this.ledger = (in.getEndpointNumber() != out.getEndpointNumber());
}
this.timeout = timeout;
transferBuffer = new byte[HID_BUFFER_SIZE];
}
public BTChipTransportAndroidWinUSB(UsbDeviceConnection connection, UsbInterface dongleInterface, UsbEndpoint in, UsbEndpoint out, int timeout) {
this.connection = connection;
this.dongleInterface = dongleInterface;
this.in = in;
this.out = out;
this.timeout = timeout;
transferBuffer = new byte[260];
}
public static BTChipTransport open(UsbManager manager, UsbDevice device) {
// Must only be called once permission is granted (see http://developer.android.com/reference/android/hardware/usb/UsbManager.html)
// Important if enumerating, rather than being awaken by the intent notification
UsbInterface dongleInterface = device.getInterface(0);
UsbEndpoint in = null;
UsbEndpoint out = null;
boolean ledger;
for (int i=0; i<dongleInterface.getEndpointCount(); i++) {
UsbEndpoint tmpEndpoint = dongleInterface.getEndpoint(i);
if (tmpEndpoint.getDirection() == UsbConstants.USB_DIR_IN) {
in = tmpEndpoint;
}
else {
out = tmpEndpoint;
}
}
UsbDeviceConnection connection = manager.openDevice(device);
if (connection == null) {
return null;
}
connection.claimInterface(dongleInterface, true);
ledger = ((device.getProductId() == PID_HID_LEDGER) || (device.getProductId() == PID_HID_LEDGER_PROTON)
|| (device.getProductId() == PID_NANOS) || (device.getProductId() == PID_BLUE) || (device.getProductId() == PID_NANOX));
if (device.getProductId() == PID_WINUSB) {
return new BTChipTransportAndroidWinUSB(connection, dongleInterface, in, out, TIMEOUT);
}
else {
return new BTChipTransportAndroidHID(connection, dongleInterface, in, out, TIMEOUT, ledger);
}
}
public BTChipTransportAndroidHID(UsbDeviceConnection connection, UsbInterface dongleInterface, UsbEndpoint in, UsbEndpoint out) {
this.connection = connection;
this.dongleInterface = dongleInterface;
this.in = in;
this.out = out;
transferBuffer = new byte[HID_BUFFER_SIZE];
}
public boolean isADBDeviceIn() {
final int usbClassAdb = 255;
final int usbSubClassAdb = 66;
final int usbProtocolAdb = 1;
UsbManager mUsbManager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE);
if (null == mUsbManager) {
return false;
}
HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
Log.d( TAG, "device count=" + deviceList.size() );
int nInedex = 0;
boolean bGetADBDevice = false;
while (deviceIterator.hasNext()) {
UsbDevice device = deviceIterator.next();
int interfaceCount = device.getInterfaceCount();
Log.d( TAG, "Device Info index ::" + nInedex + "Interface Count ::" + interfaceCount );
for (int interfaceIndex = 0; interfaceIndex < interfaceCount; interfaceIndex++) {
UsbInterface usbInterface = device.getInterface(interfaceIndex);
Log.d( TAG, "Interface ::[Class=" + usbInterface.getInterfaceClass() + "][Sub Class="
+ usbInterface.getInterfaceSubclass()
+ "][Protocol=" + usbInterface.getInterfaceProtocol() + "]");
if ((usbClassAdb == usbInterface.getInterfaceClass())
&& (usbSubClassAdb == usbInterface.getInterfaceSubclass())
&& (usbProtocolAdb == usbInterface.getInterfaceProtocol())) {
Log.d( TAG, "GetADB Initeface !!!!!!" );
bGetADBDevice = true;
break;
}
}
++nInedex;
}
return bGetADBDevice;
}
/**
* 指定した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;
}
/**
* close interface
* @param intf
* @throws IllegalStateException
*/
public synchronized void releaseInterface(final UsbInterface intf) throws IllegalStateException {
checkConnection();
final SparseArray<UsbInterface> intfs = mInterfaces.get(intf.getId());
if (intfs != null) {
final int index = intfs.indexOfValue(intf);
intfs.removeAt(index);
if (intfs.size() == 0) {
mInterfaces.remove(intf.getId());
}
}
mConnection.releaseInterface(intf);
}
/**
* Close device
* This also close interfaces if they are opened in Java side
*/
public synchronized void close() {
if (DEBUG) Log.i(TAG, "UsbControlBlock#close:");
if (mConnection != null) {
final int n = mInterfaces.size();
for (int i = 0; i < n; i++) {
final SparseArray<UsbInterface> intfs = mInterfaces.valueAt(i);
if (intfs != null) {
final int m = intfs.size();
for (int j = 0; j < m; j++) {
final UsbInterface intf = intfs.valueAt(j);
mConnection.releaseInterface(intf);
}
intfs.clear();
}
}
mInterfaces.clear();
mConnection.close();
mConnection = null;
final USBMonitor monitor = mWeakMonitor.get();
if (monitor != null) {
if (monitor.mOnDeviceConnectListener != null) {
monitor.mOnDeviceConnectListener.onDisconnect(mWeakDevice.get(), UsbControlBlock.this);
}
monitor.mCtrlBlocks.remove(getDevice());
}
}
}