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

The following examples show how to use android.hardware.usb.UsbDevice#getVendorId() . 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: UsbDeviceManager.java    From yubikit-android with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    UsbDevice device = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
    if (device == null || device.getVendorId() != YUBICO_VENDOR_ID) {
        // we are not interested in devices other than yubikeys
        return;
    }

    if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) {
        checkPermissions(device, isPermissionRequired);
    } else if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
        // notify user that his current session is not valid anymore
        listener.onSessionRemoved(new UsbSession(usbManager, device));
    }
}
 
Example 2
Source File: UsbSerialProber.java    From usb-serial-for-android with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Probes a single device for a compatible driver.
 * 
 * @param usbDevice the usb device to probe
 * @return a new {@link UsbSerialDriver} compatible with this device, or
 *         {@code null} if none available.
 */
public UsbSerialDriver probeDevice(final UsbDevice usbDevice) {
    final int vendorId = usbDevice.getVendorId();
    final int productId = usbDevice.getProductId();

    final Class<? extends UsbSerialDriver> driverClass =
            mProbeTable.findDriver(vendorId, productId);
    if (driverClass != null) {
        final UsbSerialDriver driver;
        try {
            final Constructor<? extends UsbSerialDriver> ctor =
                    driverClass.getConstructor(UsbDevice.class);
            driver = ctor.newInstance(usbDevice);
        } catch (NoSuchMethodException | IllegalArgumentException | InstantiationException |
                 IllegalAccessException | InvocationTargetException e) {
            throw new RuntimeException(e);
        }
        return driver;
    }
    return null;
}
 
Example 3
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 4
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 5
Source File: RequestLoginActivity.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
protected void onUsbAttach(final UsbDevice usb) {
    Log.d(TAG, "onUsbAttach");
    mUsb = usb;
    if (usb == null)
        return;

    mVendorId = usb.getVendorId();
    Log.d(TAG, "Vendor: " + mVendorId + " Product: " + usb.getProductId());

    if (mVendorId == VENDOR_TREZOR || mVendorId == VENDOR_TREZOR_V2) {
        onTrezor();
    } else if (mVendorId == VENDOR_BTCHIP || mVendorId == VENDOR_LEDGER) {
        if (BTChipTransportAndroid.isLedgerWithScreen(usb)) {
            // User entered PIN on-device
            setupLedgerConnection();
        } else {
            // Prompt for PIN to unlock device before setting it up
            runOnUiThread(new Runnable() { public void run() { showPinDialog(); }});
        }
    }
}
 
Example 6
Source File: UsbMuxdConnect.java    From apollo-DuerOS with Apache License 2.0 5 votes vote down vote up
public boolean scanIphoneDevices() {
    if (mContext == null || mUsbManager == null) {
        LogUtil.e(TAG, "scanUsbDevices fail");
        return false;
    }

    HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
    LogUtil.d(TAG, "device count = " + deviceList.size());
    if (deviceList.size() == 0) {
        return false;
    }
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    while (deviceIterator.hasNext()) {
        UsbDevice device = deviceIterator.next();
        if (device == null) {
            continue;
        }

        int vid = device.getVendorId();
        int pid = device.getProductId();
        LogUtil.d(TAG, "vid = 0x" + DigitalTrans.algorismToHEXString(vid, 4));
        LogUtil.d(TAG, "pid = 0x" + DigitalTrans.algorismToHEXString(pid, 4));

        if (device.getVendorId() == VID_IPHONE) {
            LogUtil.d(TAG, "the device is iPhone");
            return true;
        }
        LogUtil.d(TAG, device.toString());
    }
    return false;
}
 
Example 7
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 8
Source File: BTChipTransportAndroidHID.java    From xmrwallet with Apache License 2.0 5 votes vote down vote up
public static UsbDevice getDevice(UsbManager manager) {
    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
    for (UsbDevice device : deviceList.values()) {
        Timber.d("%04X:%04X %s, %s", device.getVendorId(), device.getProductId(), device.getManufacturerName(), device.getProductName());
        if (device.getVendorId() == VID) {
            final int deviceProductId = device.getProductId();
            for (int pid : PID_HIDS) {
                if (deviceProductId == pid)
                    return device;
            }
        }
    }
    return null;
}
 
Example 9
Source File: MainActivity.java    From astrobee_android with Apache License 2.0 5 votes vote down vote up
protected void enumerateDevices() {
    HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
    for (UsbDevice device : deviceList.values()) {
        if (device.getVendorId() == BLINK_VENDOR_ID && device.getProductId() == BLINK_PRODUCT_ID) {
            if(!mUsbManager.hasPermission(device)) {
                mUsbManager.requestPermission(device, mPermIntent);
            } else {
                setupUsb(device);
            }
        }
    }
}
 
Example 10
Source File: UsbSerialDevice.java    From UsbSerial with MIT License 5 votes vote down vote up
public static UsbSerialDevice createUsbSerialDevice(UsbDevice device, UsbDeviceConnection connection, int iface)
  {
/*
 * It checks given vid and pid and will return a custom driver or a CDC serial driver.
 * When CDC is returned open() method is even more important, its response will inform about if it can be really
 * opened as a serial device with a generic CDC serial driver
 */
      int vid = device.getVendorId();
      int pid = device.getProductId();

      if(FTDISioIds.isDeviceSupported(device))
          return new FTDISerialDevice(device, connection, iface);
      else if(CP210xIds.isDeviceSupported(vid, pid))
          return new CP2102SerialDevice(device, connection, iface);
      else if(PL2303Ids.isDeviceSupported(vid, pid))
          return new PL2303SerialDevice(device, connection, iface);
      else if(CH34xIds.isDeviceSupported(vid, pid))
          return new CH34xSerialDevice(device, connection, iface);
      else if(isCdcDevice(device))
          return new CDCSerialDevice(device, connection, iface);
      else
          return null;
  }
 
Example 11
Source File: MainActivity.java    From astrobee_android with Apache License 2.0 5 votes vote down vote up
protected void enumerateDevices() {
    HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
    for (UsbDevice device : deviceList.values()) {
        if (device.getVendorId() == BLINK_VENDOR_ID && device.getProductId() == BLINK_PRODUCT_ID) {
            if(!mUsbManager.hasPermission(device)) {
                mUsbManager.requestPermission(device, mPermIntent);
            } else {
                setupUsb(device);
            }
        }
    }
}
 
Example 12
Source File: FaBoFirmwareFragment.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
@Override
public void onResume() {
    super.onResume();

    // SerialPortの生成
    //mStkWriter = new StkWriter(getActivity().getBaseContext());
    //mStkWriter.setListener(this);

    // USBデバイスのチェック.
    UsbManager manager = (UsbManager) mContext.getSystemService(Context.USB_SERVICE);
    HashMap<String, UsbDevice> deviceList = manager.getDeviceList();

    for (UsbDevice device : deviceList.values()) {
        if (device.getVendorId() == FaBoUsbConst.ARDUINO_UNO_VID) {
            mActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mTextViewComment.setText(R.string.arduinoorg_find);
                    mButtonConnect.setEnabled(false);
                    mButtonSend.setVisibility(Button.INVISIBLE);
                    mButtonBack.setVisibility(Button.INVISIBLE);
                }
            });
        } else if (device.getVendorId() == FaBoUsbConst.ARDUINO_CC_UNO_VID) {
            mActivity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    mTextViewComment.setText(R.string.arduinocc_find);
                    mButtonConnect.setEnabled(true);
                    mButtonSend.setVisibility(Button.INVISIBLE);
                    mButtonBack.setVisibility(Button.INVISIBLE);
                }
            });
            break;
        }
    }
}
 
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: UsbDeviceManager.java    From yubikit-android with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if there are yubico device connected to device list
 * @return the object that contains property of device connected over USB
 */
private List<UsbDevice> findDevices() {
    List<UsbDevice> yubikeys = new ArrayList<>();
    for (UsbDevice device : usbManager.getDeviceList().values()) {
        if (!configuration.isFilterYubicoDevices() || device.getVendorId() == YUBICO_VENDOR_ID) {
            yubikeys.add(device);
        }
    }
    return yubikeys;
}
 
Example 15
Source File: BTChipTransportAndroid.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
public static boolean isLedgerWithScreen(final UsbDevice d) {
	final int pId = d.getProductId();
	final boolean screenDevice = pId == PID_NANOS || pId == PID_BLUE;
	return screenDevice && d.getVendorId() == VID2;
}
 
Example 16
Source File: DeviceFilter.java    From AndroidUSBCamera with Apache License 2.0 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;
	}
 
Example 17
Source File: DeviceFilter.java    From UVCCameraZxing with Apache License 2.0 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 (true);
		}
		if (obj instanceof UsbDevice) {
			final UsbDevice device = (UsbDevice) obj;
			if (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;
	}
 
Example 18
Source File: Trezor.java    From GreenBits with GNU General Public License v3.0 4 votes vote down vote up
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 19
Source File: USBMonitor.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
/**
 * get vendor id
 * @return
 */
public int getVenderId() {
	final UsbDevice device = mWeakDevice.get();
	return device != null ? device.getVendorId() : 0;
}
 
Example 20
Source File: BTChipTransportAndroid.java    From WalletCordova with GNU Lesser General Public License v2.1 4 votes vote down vote up
public static boolean isLedgerWithScreen(final UsbDevice d) {
	final int pId = d.getProductId();
	final boolean screenDevice = pId == PID_NANOS || pId == PID_BLUE;
	return screenDevice && d.getVendorId() == VID2;
}