Java Code Examples for android.hardware.usb.UsbDevice#getProductId()

The following examples show how to use android.hardware.usb.UsbDevice#getProductId() . 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: SyncingService.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
public UsbDevice findDexcom() {
    Log.i("CALIBRATION-CHECK-IN: ", "Searching for dexcom");
    mUsbManager = (UsbManager) getApplicationContext().getSystemService(Context.USB_SERVICE);
    Log.i("USB MANAGER = ", mUsbManager.toString());
    HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
    Log.i("USB DEVICES = ", deviceList.toString());
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    Log.i("USB DEVICES = ", String.valueOf(deviceList.size()));

    while(deviceIterator.hasNext()){
        UsbDevice device = deviceIterator.next();
        if (device.getVendorId() == 8867 && device.getProductId() == 71
                && device.getDeviceClass() == 2 && device.getDeviceSubclass() ==0
                && device.getDeviceProtocol() == 0){
            dexcom = device;
            Log.i("CALIBRATION-CHECK-IN: ", "Dexcom Found!");
            return device;
        } else {
            Log.w("CALIBRATION-CHECK-IN: ", "that was not a dexcom (I dont think)");
        }
    }
    return null;
}
 
Example 2
Source File: UsbSerialDevice.java    From UsbSerial with MIT License 6 votes vote down vote up
public static boolean isSupported(UsbDevice device)
{
    int vid = device.getVendorId();
    int pid = device.getProductId();

    if(FTDISioIds.isDeviceSupported(device))
        return true;
    else if(CP210xIds.isDeviceSupported(vid, pid))
        return true;
    else if(PL2303Ids.isDeviceSupported(vid, pid))
        return true;
    else if(CH34xIds.isDeviceSupported(vid, pid))
        return true;
    else if(isCdcDevice(device))
        return true;
    else
        return false;
}
 
Example 3
Source File: DeviceFilter.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
 * 指定したUsbDeviceがこのDeviceFilterにマッチするかどうかを返す
 * isExcludeフラグは別途#isExcludeか自前でチェックすること
 * @param device
 * @return
 */
public boolean matches(@NonNull final UsbDevice device) {
	if (mVendorId != -1 && device.getVendorId() != mVendorId) {
		return false;
	}
	if (mProductId != -1 && device.getProductId() != mProductId) {
		return false;
	}

	// check device class/subclass/protocol
	if (matches(
		device.getDeviceClass(),
		device.getDeviceSubclass(),
		device.getDeviceProtocol())) {

		return true;
	}

	// check device interface class/interface subclass/interface protocol
	return interfaceMatches(device);
}
 
Example 4
Source File: SyncingService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
static public boolean isG4Connected(Context c){
    UsbManager manager = (UsbManager) c.getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
    Log.i("USB DEVICES = ", deviceList.toString());
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    Log.i("USB DEVICES = ", String.valueOf(deviceList.size()));

    while(deviceIterator.hasNext()){
        UsbDevice device = deviceIterator.next();
        if (device.getVendorId() == 8867 && device.getProductId() == 71
                && device.getDeviceClass() == 2 && device.getDeviceSubclass() ==0
                && device.getDeviceProtocol() == 0){
            Log.i("CALIBRATION-CHECK-IN: ", "Dexcom Found!");
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: SyncingService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
static public boolean isG4Connected(Context c){
    UsbManager manager = (UsbManager) c.getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
    Log.w("USB DEVICES = ", deviceList.toString());
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    Log.w("USB DEVICES = ", String.valueOf(deviceList.size()));

    while(deviceIterator.hasNext()){
        UsbDevice device = deviceIterator.next();
        if (device.getVendorId() == 8867 && device.getProductId() == 71
                && device.getDeviceClass() == 2 && device.getDeviceSubclass() ==0
                && device.getDeviceProtocol() == 0){
            Log.w("CALIBRATION-CHECK-IN: ", "Dexcom Found!");
            return true;
        }
    }
    return false;
}
 
Example 6
Source File: BTChipTransportAndroid.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
public static UsbDevice getDevice(UsbManager manager) {
	HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
	for (UsbDevice device : deviceList.values()) {
		if ((device.getVendorId() == VID || device.getVendorId() == VID2) &&
		   ((device.getProductId() == PID_WINUSB) || (device.getProductId() == PID_HID) ||
		    (device.getProductId() == PID_NANOS) || (device.getProductId() == PID_BLUE) ||
		    (device.getProductId() == PID_HID_LEDGER) || (device.getProductId() == PID_HID_LEDGER_PROTON))) {
			return device;
		}
	}
	return null;		
}
 
Example 7
Source File: UsbLinkAndroid.java    From crazyflie-android-client with GNU General Public License v2.0 5 votes vote down vote up
public static List<UsbDevice> findUsbDevices(UsbManager usbManager, int vendorId, int productId) {
    List<UsbDevice> usbDeviceList = new ArrayList<UsbDevice>();
    if (usbManager != null) {
        HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
        // Iterate over USB devices
        for (Entry<String, UsbDevice> e : deviceList.entrySet()) {
            Log.i(LOG_TAG, "String: " + e.getKey() + " " + e.getValue().getVendorId() + " " + e.getValue().getProductId());
            UsbDevice device = e.getValue();
            if (device.getVendorId() == vendorId && device.getProductId() == productId) {
                usbDeviceList.add(device);
            }
        }
    }
    return usbDeviceList;
}
 
Example 8
Source File: USBGpsManager.java    From UsbGps4Droid with GNU General Public License v3.0 5 votes vote down vote up
private UsbDevice getDeviceFromAttached() {
    debugLog("Checking all connected devices");
    for (UsbDevice connectedDevice : usbManager.getDeviceList().values()) {

        debugLog("Checking device: " + connectedDevice.getProductId() + " " + connectedDevice.getVendorId());

        if (connectedDevice.getVendorId() == gpsVendorId & connectedDevice.getProductId() == gpsProductId) {
            debugLog("Found correct device");

            return connectedDevice;
        }
    }

    return null;
}
 
Example 9
Source File: BTChipTransportAndroid.java    From WalletCordova with GNU Lesser General Public License v2.1 5 votes vote down vote up
public static UsbDevice getDevice(UsbManager manager) {
	HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
	for (UsbDevice device : deviceList.values()) {
		if ((device.getVendorId() == VID || device.getVendorId() == VID2) &&
		   ((device.getProductId() == PID_WINUSB) || (device.getProductId() == PID_HID) ||
		    (device.getProductId() == PID_NANOS) || (device.getProductId() == PID_BLUE) ||
		    (device.getProductId() == PID_HID_LEDGER) || (device.getProductId() == PID_HID_LEDGER_PROTON))) {
			return device;
		}
	}
	return null;		
}
 
Example 10
Source File: DeviceFilter.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
	 * 指定した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 11
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 12
Source File: DeviceFilter.java    From UVCCameraZxing with Apache License 2.0 5 votes vote down vote up
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: UsbHidDriver.java    From 600SeriesAndroidUploader with MIT License 5 votes vote down vote up
public static UsbDevice getUsbDevice(UsbManager usbManager, int vendorId, int productId) {
    // Iterate all the available devices and find ours.
    for (UsbDevice device : usbManager.getDeviceList().values()) {
        if (device.getProductId() == productId && device.getVendorId() == vendorId) {
            return device;
        }
    }

    return null;
}
 
Example 14
Source File: UsbTools.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public static UsbDevice getUsbDevice(final int vendorId, final int productId, final String search) {

        final UsbManager manager = (UsbManager) xdrip.getAppContext().getSystemService(Context.USB_SERVICE);
        if (manager == null) return null;
        final HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
        for (Map.Entry<String, UsbDevice> entry : deviceList.entrySet()) {
            final UsbDevice device = entry.getValue();
            if (device.getVendorId() == vendorId && device.getProductId() == productId
                    && device.toString().contains(search)) {
                Log.d(TAG, "Found device: " + entry.getKey() + " " + device.toString());
                return device;
            }
        }
        return null;
    }
 
Example 15
Source File: DeviceConnection.java    From monkeyboard-radio-android with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @return the radio device
 */
private UsbDevice getDevice() {
    for (UsbDevice device : usbManager.getDeviceList().values()) {
        if (device.getProductId() == RadioDevice.PRODUCT_ID &&
                device.getVendorId() == RadioDevice.VENDOR_ID) {
            return device;
        }
    }
    return null;
}
 
Example 16
Source File: USBGpsSettingsFragment.java    From UsbGps4Droid with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Updates the list of available devices in the list preference
 */
private void updateDevicesList() {
    HashMap<String, UsbDevice> connectedUsbDevices = usbManager.getDeviceList();
    String[] entryValues = new String[connectedUsbDevices.size()];
    String[] entries = new String[connectedUsbDevices.size()];

    int i = 0;
    // Loop through usb devices
    for (UsbDevice device : connectedUsbDevices.values()) {
        // Add the name and address to the ListPreference entities and entyValues

        String entryValue = device.getDeviceName() +
                " - " + device.getVendorId() + " : " + device.getProductId();

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            entryValue = device.getManufacturerName() + " " + device.getProductName() +
                    " - " + device.getVendorId() + " : " + device.getProductId();
        }

        entryValues[i] = device.getDeviceName();
        entries[i] = entryValue;
        i++;
    }

    devicePreference.setEntryValues(entryValues);
    devicePreference.setEntries(entries);
}
 
Example 17
Source File: BTChipTransportAndroid.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
public static UsbDevice getDevice(UsbManager manager) {
	HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
	for (UsbDevice device : deviceList.values()) {
		if ((device.getVendorId() == VID || device.getVendorId() == VID2) &&
		   ((device.getProductId() == PID_WINUSB) || (device.getProductId() == PID_HID) ||
		    (device.getProductId() == PID_NANOS) || (device.getProductId() == PID_BLUE) ||
			(device.getProductId() == PID_NANOX) || (device.getProductId() == PID_HID_LEDGER) ||
			(device.getProductId() == PID_HID_LEDGER_PROTON))) {
			return device;
		}
	}
	return null;		
}
 
Example 18
Source File: MainActivity.java    From astrobee_android with Apache License 2.0 5 votes vote down vote up
private static boolean isRoyaleDevice(final UsbDevice device) {
    final int vid = device.getVendorId();
    final int pid = device.getProductId();

    if (vid != ROYALE_VENDOR_ID) {
        return false;
    }

    for (int id : ROYALE_PRODUCT_IDS) {
        if (id == pid)
            return true;
    }
    return false;
}
 
Example 19
Source File: USBMonitor.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
/**
 * get product id
 * @return
 */
public int getProductId() {
	final UsbDevice device = mWeakDevice.get();
	return device != null ? device.getProductId() : 0;
}
 
Example 20
Source File: DeviceFilter.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
@Override
	public boolean equals(final Object obj) {
		// can't compare if we have wildcard strings
		if (mVendorId == -1 || mProductId == -1 || mClass == -1
				|| mSubclass == -1 || mProtocol == -1) {
			return false;
		}
		if (obj instanceof DeviceFilter) {
			final DeviceFilter filter = (DeviceFilter) obj;

			if (filter.mVendorId != mVendorId
					|| filter.mProductId != mProductId
					|| filter.mClass != mClass || filter.mSubclass != mSubclass
					|| filter.mProtocol != mProtocol) {
				return false;
			}
			if ((filter.mManufacturerName != null && mManufacturerName == null)
					|| (filter.mManufacturerName == null && mManufacturerName != null)
					|| (filter.mProductName != null && mProductName == null)
					|| (filter.mProductName == null && mProductName != null)
					|| (filter.mSerialNumber != null && mSerialNumber == null)
					|| (filter.mSerialNumber == null && mSerialNumber != null)) {
				return false;
			}
			if ((filter.mManufacturerName != null && mManufacturerName != null && !mManufacturerName
					.equals(filter.mManufacturerName))
					|| (filter.mProductName != null && mProductName != null && !mProductName
							.equals(filter.mProductName))
					|| (filter.mSerialNumber != null && mSerialNumber != null && !mSerialNumber
							.equals(filter.mSerialNumber))) {
				return false;
			}
			return (filter.isExclude != isExclude);
		}
		if (obj instanceof UsbDevice) {
			final UsbDevice device = (UsbDevice) obj;
			if (isExclude
					|| (device.getVendorId() != mVendorId)
					|| (device.getProductId() != mProductId)
					|| (device.getDeviceClass() != mClass)
					|| (device.getDeviceSubclass() != mSubclass)
					|| (device.getDeviceProtocol() != mProtocol) ) {
				return false;
			}
/*			if ((mManufacturerName != null && device.getManufacturerName() == null)
					|| (mManufacturerName == null && device
							.getManufacturerName() != null)
					|| (mProductName != null && device.getProductName() == null)
					|| (mProductName == null && device.getProductName() != null)
					|| (mSerialNumber != null && device.getSerialNumber() == null)
					|| (mSerialNumber == null && device.getSerialNumber() != null)) {
				return (false);
			} */
/*			if ((device.getManufacturerName() != null && !mManufacturerName
					.equals(device.getManufacturerName()))
					|| (device.getProductName() != null && !mProductName
							.equals(device.getProductName()))
					|| (device.getSerialNumber() != null && !mSerialNumber
							.equals(device.getSerialNumber()))) {
				return (false);
			} */
			return true;
		}
		return false;
	}