Java Code Examples for android.hardware.usb.UsbInterface#getInterfaceProtocol()

The following examples show how to use android.hardware.usb.UsbInterface#getInterfaceProtocol() . 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: CarlifeUtil.java    From apollo-DuerOS with Apache License 2.0 6 votes vote down vote up
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 2
Source File: CarlifeUtil.java    From apollo-DuerOS with Apache License 2.0 6 votes vote down vote up
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 3
Source File: ConnectManager.java    From apollo-DuerOS with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 4
Source File: DeviceFilter.java    From libcommon with Apache License 2.0 5 votes vote down vote up
@SuppressLint("NewApi")
public DeviceFilter(@NonNull final UsbDevice device, final boolean isExclude) {
	mVendorId = device.getVendorId();
	mProductId = device.getProductId();
	mClass = device.getDeviceClass();
	mSubclass = device.getDeviceSubclass();
	mProtocol = device.getDeviceProtocol();
	// getInterfaceCountは内部配列のlengthを返すので負にはならないはずだけど年のために下限を0にする
	final int count = Math.max(device.getInterfaceCount(), 0);
	mIntfClass = new int[count];
	mIntfSubClass = new int[count];
	mIntfProtocol = new int[count];
	for (int i = 0; i < count; i++) {
		final UsbInterface intf = device.getInterface(i);
		mIntfClass[i] = intf.getInterfaceClass();
		mIntfSubClass[i] = intf.getInterfaceSubclass();
		mIntfProtocol[i] = intf.getInterfaceProtocol();
	}
	if (BuildCheck.isLollipop()) {
		mManufacturerName = device.getManufacturerName();
		mProductName = device.getProductName();
		mSerialNumber = device.getSerialNumber();
	} else {
		mManufacturerName = null;
		mProductName = null;
		mSerialNumber = null;
	}
	this.isExclude = isExclude;
}
 
Example 5
Source File: FTDISioIds.java    From UsbSerial with MIT License 5 votes vote down vote up
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 6
Source File: ConnectManager.java    From apollo-DuerOS with Apache License 2.0 4 votes vote down vote up
public boolean isMobileDeviceIn() {
    final int storageInterfaceConut = 1;
    final int storageInterfaceId = 0;
    final int storageInterfaceClass = 8;
    int storageInterfaceSubclass = 6;
    int storageInterfaceProtocol = 80;

    UsbManager mUsbManager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE);
    if (null == mUsbManager) {
        Log.d( TAG, "############## UsbManager Error!");
        return  false;
    }

    HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    Log.d( TAG, "############################");
    Log.d( TAG, "device count=" + deviceList.size() );

    int nInedex = 0;
    boolean bGetDevice = false;
    while (deviceIterator.hasNext()) {
        UsbDevice device = deviceIterator.next();
        if (storageInterfaceConut == device.getInterfaceCount()) {
            UsbInterface usbInter = device.getInterface(storageInterfaceId);
            if ((storageInterfaceClass == usbInter.getInterfaceClass())
                    && (storageInterfaceSubclass == usbInter.getInterfaceSubclass())
                    && (storageInterfaceProtocol == usbInter.getInterfaceProtocol())) {
                LogUtil.e(TAG, "This is mass storage 1");
                break;
            }
        }

        int interfaceCount = device.getInterfaceCount();
        Log.d( TAG, "Device Info [PID:" + device.getProductId() + "][VID:"
                + device.getDeviceId()
                + "] Interface Count ::" + interfaceCount );
        if ( interfaceCount > 0 ) {
            bGetDevice = true;
        }
        ++nInedex;
    }
    return  bGetDevice;
}
 
Example 7
Source File: UsbIpService.java    From USBIPServerForAndroid with GNU General Public License v3.0 4 votes vote down vote up
private UsbDeviceInfo getInfoForDevice(UsbDevice dev, UsbDeviceConnection devConn) {
	UsbDeviceInfo info = new UsbDeviceInfo();
	UsbIpDevice ipDev = new UsbIpDevice();
	
	ipDev.path = dev.getDeviceName();
	ipDev.busnum = deviceIdToBusNum(dev.getDeviceId());
	ipDev.devnum =  deviceIdToDevNum(dev.getDeviceId());
	ipDev.busid = String.format("%d-%d", ipDev.busnum, ipDev.devnum);
	
	ipDev.idVendor = (short) dev.getVendorId();
	ipDev.idProduct = (short) dev.getProductId();
	ipDev.bcdDevice = -1;
	
	ipDev.bDeviceClass = (byte) dev.getDeviceClass();
	ipDev.bDeviceSubClass = (byte) dev.getDeviceSubclass();
	ipDev.bDeviceProtocol = (byte) dev.getDeviceProtocol();
	
	ipDev.bConfigurationValue = 0;
	ipDev.bNumConfigurations = 1;
	
	ipDev.bNumInterfaces = (byte) dev.getInterfaceCount();
	
	info.dev = ipDev;
	info.interfaces = new UsbIpInterface[ipDev.bNumInterfaces];
	
	for (int i = 0; i < ipDev.bNumInterfaces; i++) {
		info.interfaces[i] = new UsbIpInterface();
		UsbInterface iface = dev.getInterface(i);
		
		info.interfaces[i].bInterfaceClass = (byte) iface.getInterfaceClass();
		info.interfaces[i].bInterfaceSubClass = (byte) iface.getInterfaceSubclass();
		info.interfaces[i].bInterfaceProtocol = (byte) iface.getInterfaceProtocol();
	}
	
	AttachedDeviceContext context = connections.get(dev.getDeviceId());
	UsbDeviceDescriptor devDesc = null;
	if (context != null) {
		// Since we're attached already, we can directly query the USB descriptors
		// to fill some information that Android's USB API doesn't expose
		devDesc = UsbControlHelper.readDeviceDescriptor(context.devConn);
		
		ipDev.bcdDevice = devDesc.bcdDevice;
		ipDev.bNumConfigurations = devDesc.bNumConfigurations;
	}
	
	ipDev.speed = detectSpeed(dev, devDesc);
	
	return info;
}