@Test public void removeDevice() { assertThat(usbManager.getDeviceList()).isEmpty(); shadowOf(usbManager).addOrUpdateUsbDevice(usbDevice1, false); shadowOf(usbManager).addOrUpdateUsbDevice(usbDevice2, false); assertThat(usbManager.getDeviceList().values()) .containsExactly(usbDevice1, usbDevice2); shadowOf(usbManager).removeUsbDevice(usbDevice1); assertThat(usbManager.getDeviceList().values()).containsExactly(usbDevice2); }
@Test public void getDeviceList() { assertThat(usbManager.getDeviceList()).isEmpty(); shadowOf(usbManager).addOrUpdateUsbDevice(usbDevice1, true); shadowOf(usbManager).addOrUpdateUsbDevice(usbDevice2, true); assertThat(usbManager.getDeviceList().values()) .containsExactly(usbDevice1, usbDevice2); }
public CommunicationHandler(UsbManager usbManager) { this.mUsbManager = usbManager; mUsbDevice = null; for (final UsbDevice device : mUsbManager.getDeviceList().values()) { Log.d(TAG, "VID : " + device.getVendorId() + "PID : " + device.getProductId()); if (device.getVendorId() == PSLAB_VENDOR_ID && device.getProductId() == PSLAB_PRODUCT_ID) { Log.d(TAG, "Found PSLAB Device"); mUsbDevice = device; device_found = true; break; } } mReadBuffer = new byte[DEFAULT_READ_BUFFER_SIZE]; mWriteBuffer = new byte[DEFAULT_WRITE_BUFFER_SIZE]; }
public void scanForDevices(Context context) { UsbManager usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE); if (usbManager != null) { for (UsbDevice usbDevice : usbManager.getDeviceList().values()) { handleUsbDeviceAttached(context, usbDevice); } } }
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle saved) { usbKey = getArguments().getString(EXTRA_DATA, DEFAULT_STRING); device = usbMan.getDeviceList().get(usbKey); final View view; if (usbKey == null || device == null) { view = inflater.inflate(R.layout.fragment_error, container, false); validData = false; } else { view = inflater.inflate(LAYOUT_ID, container, false); validData = true; } return view; }
/** * Finds and builds all possible {@link UsbSerialDriver UsbSerialDrivers} * from the currently-attached {@link UsbDevice} hierarchy. This method does * not require permission from the Android USB system, since it does not * open any of the devices. * * @param usbManager * @return a list, possibly empty, of all compatible drivers */ public List<UsbSerialDriver> findAllDrivers(final UsbManager usbManager) { final List<UsbSerialDriver> result = new ArrayList<UsbSerialDriver>(); for (final UsbDevice usbDevice : usbManager.getDeviceList().values()) { final UsbSerialDriver driver = probeDevice(usbDevice); if (driver != null) { result.add(driver); } } return result; }
/** * Finds and builds all possible {@link UsbSerialDriver UsbSerialDrivers} * from the currently-attached {@link UsbDevice} hierarchy. This method does * not require permission from the Android USB system, since it does not * open any of the devices. * * @param usbManager * @return a list, possibly empty, of all compatible drivers */ public List<UsbSerialDriver> findAllDrivers(final UsbManager usbManager) { final List<UsbSerialDriver> result = new ArrayList<UsbSerialDriver>(); for (final UsbDevice usbDevice : usbManager.getDeviceList().values()) { final UsbSerialDriver driver = probeDevice(usbDevice); if (driver != null) { result.add(driver); } } return result; }
/** * Retrieves a list of all currently connected {@link android.mtp.MtpDevice}. * * @return the list of MtpDevices */ public List<MtpDevice> getDeviceList() { synchronized (mDevices) { // Query the USB manager since devices might have attached // before we added our listener. for (UsbDevice usbDevice : mUsbManager.getDeviceList().values()) { if (mDevices.get(usbDevice.getDeviceName()) == null) { openDeviceLocked(usbDevice); } } return new ArrayList<MtpDevice>(mDevices.values()); } }
private void requestPermission() { Activity activity = ctx.get(); if (activity != null) { PendingIntent mPermissionIntent = PendingIntent.getBroadcast(activity, 0, new Intent(ACTION_USB_PERMISSION), 0); //here do emulation to ask all connected usb device for permission for (final UsbDevice usbDevice : usbManager.getDeviceList().values()) { if (usbManager.hasPermission(usbDevice)) { afterGetUsbPermission(usbDevice); } else { usbManager.requestPermission(usbDevice, mPermissionIntent); } } } }
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; }
public List<UsbDevice> getPossibleSerialPorts(Context context){ usbManager = (UsbManager) context.getSystemService(Context.USB_SERVICE); HashMap<String, UsbDevice> allDevices = usbManager.getDeviceList(); List<UsbDevice> devices = Stream.of(allDevices.values()) .filter(UsbSerialDevice::isSupported) .toList(); return devices; }
private UsbDevice findDevice(UsbManager manager, int vendorId, int productId) throws DataSourceResourceException { Log.d(TAG, "Looking for USB device with vendor ID " + vendorId + " and product ID " + productId); for(UsbDevice candidateDevice : manager.getDeviceList().values()) { if(candidateDevice.getVendorId() == vendorId && candidateDevice.getProductId() == productId) { Log.d(TAG, "Found USB device " + candidateDevice); return candidateDevice; } } throw new DataSourceResourceException("USB device with vendor " + "ID " + vendorId + " and product ID " + productId + " not found"); }
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; }
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; }
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; }
public static boolean QueryAdapter() { HashMap<String, UsbDevice> devices = manager.getDeviceList(); for (Map.Entry<String, UsbDevice> pair : devices.entrySet()) { UsbDevice dev = pair.getValue(); if (dev.getProductId() == NINTENDO_WIIMOTE_PRODUCT_ID && dev.getVendorId() == NINTENDO_VENDOR_ID) { if (manager.hasPermission(dev)) return true; else RequestPermission(); } } return false; }
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; }
public static boolean QueryAdapter() { HashMap<String, UsbDevice> devices = manager.getDeviceList(); for (Map.Entry<String, UsbDevice> pair : devices.entrySet()) { UsbDevice dev = pair.getValue(); if (dev.getProductId() == 0x0337 && dev.getVendorId() == 0x057e) { if (manager.hasPermission(dev)) return true; else RequestPermission(); } } return false; }
public void discoverDevices(){ try{ for (UsbDevice device : usbManager.getDeviceList().values()) { if(hasPermission(device)) { discoverDevice(device); } else { addRoot(device); } } } catch (Exception e){ CrashReportingManager.logException(e); } }
private void refreshUsbDevices() { mAndroidDeviceMap = mUsbManAndroid.getDeviceList(); mLinuxDeviceMap = mUsbManagerLinux.getUsbDevices(); updateList(mTabController.getHolderForTag(TabController.TAB_ANDROID_INFO), mAndroidDeviceMap); updateList(mTabController.getHolderForTag(TabController.TAB_LINUX_INFO), mLinuxDeviceMap); }