android.hardware.usb.UsbDevice Java Examples

The following examples show how to use android.hardware.usb.UsbDevice. 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: UsbUtils.java    From libcommon with Apache License 2.0 8 votes vote down vote up
/**
 * 接続されているUSBの機器リストをLogCatに出力
 * @param context
 */
public static void dumpDevices(@NonNull final Context context) {
	final UsbManager usbManager = ContextUtils.requireSystemService(context, UsbManager.class);
	final HashMap<String, UsbDevice> list = usbManager.getDeviceList();
	if ((list != null) && !list.isEmpty()) {
		final Set<String> keys = list.keySet();
		if (keys != null && keys.size() > 0) {
			final StringBuilder sb = new StringBuilder();
			for (final String key: keys) {
				final UsbDevice device = list.get(key);
				final int num_interface = device != null ? device.getInterfaceCount() : 0;
				sb.setLength(0);
				for (int i = 0; i < num_interface; i++) {
					sb.append(String.format(Locale.US, "interface%d:%s",
						i, device.getInterface(i).toString()));
				}
				Log.i(TAG, "key=" + key + ":" + device + ":" + sb.toString());
			}
		} else {
			Log.i(TAG, "no device");
		}
	} else {
		Log.i(TAG, "no device");
	}
}
 
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: SyncingService.java    From xDrip 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: USBMonitor.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
/**
 * open specific USB device
 * @param device
 */
private final void processConnect(final UsbDevice device) {
	if (destroyed) return;

	updatePermission(device, true);
	mAsyncHandler.post(new Runnable() {
		@Override
		public void run() {
			if (DEBUG) Log.v(TAG, "processConnect:device=" + device);
			UsbControlBlock ctrlBlock;
			final boolean createNew;
			ctrlBlock = mCtrlBlocks.get(device);
			if (ctrlBlock == null) {
				ctrlBlock = new UsbControlBlock(USBMonitor.this, device);
				mCtrlBlocks.put(device, ctrlBlock);
				createNew = true;
			} else {
				createNew = false;
			}
			if (mOnDeviceConnectListener != null) {
				mOnDeviceConnectListener.onConnect(device, ctrlBlock, createNew);
			}
		}
	});
}
 
Example #5
Source File: DeviceConnection.java    From monkeyboard-radio-android with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Checks the devices connected to android and finds the radio. It then attempts to get
 * permission to connect to the radio.
 */
private void requestConnection() {
    Log.v(TAG, "Requesting connection to device");
    UsbDevice device = getDevice();
    if (device != null) {
        IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
        filter.addAction(ACTION_USB_PERMISSION);
        filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
        context.registerReceiver(usbBroadcastReceiver, filter);

        if (usbManager.hasPermission(device)) {
            usbDevice = device;
            openConnection();
        } else {
            Log.v(TAG, "Requesting permission for device");
            usbManager.requestPermission(device, usbPermissionIntent);
        }
    } else {
        if (connectionStateListener != null) {
            connectionStateListener.onFail();
        }
        Log.v(TAG, "No device found");
    }
}
 
Example #6
Source File: USBMonitor.java    From UVCCameraZxing with Apache License 2.0 6 votes vote down vote up
/**
 * request permission to access to USB device
 * @param device
 */
public synchronized void requestPermission(final UsbDevice device) {
	if (DEBUG) Log.v(TAG, "requestPermission:device=" + device);
	if (mPermissionIntent != null) {
		if (device != null) {
			if (mUsbManager.hasPermission(device)) {
				processConnect(device);
			} else {
				mUsbManager.requestPermission(device, mPermissionIntent);
			}
		} else {
			processCancel(device);
		}
	} else {
		processCancel(device);
	}
}
 
Example #7
Source File: UsbHidDevice.java    From UsbHid with MIT License 6 votes vote down vote up
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;
        }
    }
}
 
Example #8
Source File: USBMonitor.java    From UVCCameraZxing with Apache License 2.0 6 votes vote down vote up
/**
 * 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());
		}
	}
}
 
Example #9
Source File: SetupWizardUsbDeviceListFragment.java    From talkback with Apache License 2.0 6 votes vote down vote up
@Override
public void onStart() {
  super.onStart();
  HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
  ListView listView = getRootView().findViewById(R.id.connected_usb_devices_list);
  listView.setAdapter(usbArrayAdapter);
  for (UsbDevice device : deviceList.values()) {
    usbArrayAdapter.add(getDisplayableUsbDeviceName(device));
  }
  usbArrayAdapter.notifyDataSetChanged();
  if (usbArrayAdapter.getCount() == 0) {
    updateScreenBasedOnIfUsbDeviceIsConnected(false);
  }

  IntentFilter intent = new IntentFilter(UsbManager.ACTION_USB_DEVICE_ATTACHED);
  intent.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
  getActivity().registerReceiver(broadcastReceiver, intent);
}
 
Example #10
Source File: USBMonitor.java    From DeviceConnect-Android with MIT License 6 votes vote down vote up
/**
 * return device list, return empty list if no device matched
 * @param filters
 * @return
 * @throws IllegalStateException
 */
public List<UsbDevice> getDeviceList(final List<DeviceFilter> filters) throws IllegalStateException {
	if (destroyed) throw new IllegalStateException("already destroyed");
	final HashMap<String, UsbDevice> deviceList = mUsbManager.getDeviceList();
	final List<UsbDevice> result = new ArrayList<UsbDevice>();
	if (deviceList != null) {
		if ((filters == null) || filters.isEmpty()) {
			result.addAll(deviceList.values());
		} else {
			for (final UsbDevice device: deviceList.values() ) {
				for (final DeviceFilter filter: filters) {
					if ((filter != null) && filter.matches(device)) {
						// when filter matches
						if (!filter.isExclude) {
							result.add(device);
						}
						break;
					}
				}
			}
		}
	}
	return result;
}
 
Example #11
Source File: UVCService.java    From UVCCameraZxing with Apache License 2.0 6 votes vote down vote up
private void removeService(final UsbDevice device) {
	final int key = device.hashCode();
	synchronized (sServiceSync) {
		final CameraServer service = sCameraServers.get(key);
		if (service != null)
			service.release();
		sCameraServers.remove(key);
		sServiceSync.notifyAll();
	}
	if (checkReleaseService()) {
		if (mUSBMonitor != null) {
			mUSBMonitor.unregister();
			mUSBMonitor = null;
		}
	}
}
 
Example #12
Source File: UsbStorageProvider.java    From FireFiles with Apache License 2.0 6 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    UsbDevice usbDevice = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
    String deviceName = usbDevice.getDeviceName();
    if (UsbStorageProvider.ACTION_USB_PERMISSION.equals(action)) {
        boolean permission = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false);
        if (permission) {
            discoverDevice(usbDevice);
            notifyRootsChanged();
            notifyDocumentsChanged(getContext(), getRootId(usbDevice)+ROOT_SEPERATOR);
        } else {
            // so we don't ask for permission again
        }
    } else if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)
            || UsbManager.ACTION_USB_DEVICE_DETACHED.equals(action)) {
        updateRoots();
    }
}
 
Example #13
Source File: USBGpsSettingsFragment.java    From UsbGps4Droid with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets a summary of the current select product and vendor ids
 */
private String getSelectedDeviceSummary() {
    int productId = sharedPreferences.getInt(
            USBGpsProviderService.PREF_GPS_DEVICE_PRODUCT_ID, DEFAULT_GPS_PRODUCT_ID);
    int vendorId = sharedPreferences.getInt(
            USBGpsProviderService.PREF_GPS_DEVICE_VENDOR_ID, DEFAULT_GPS_VENDOR_ID);

    String deviceDisplayedName = "Device not connected - " + vendorId + ": " + productId;

    for (UsbDevice usbDevice: usbManager.getDeviceList().values()) {
        if (usbDevice.getVendorId() == vendorId && usbDevice.getProductId() == productId) {
            deviceDisplayedName =
                    "USB " + usbDevice.getDeviceProtocol() + " " + usbDevice.getDeviceName() +
                            " | " + vendorId + ": " + productId;

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                deviceDisplayedName = usbDevice.getManufacturerName() + usbDevice.getProductName() +
                        " | " + vendorId + ": " + productId;
            }

            break;
        }
    }

    return deviceDisplayedName;
}
 
Example #14
Source File: TinfoilUSB.java    From ns-usbloader-mobile with GNU General Public License v3.0 5 votes vote down vote up
TinfoilUSB(ResultReceiver resultReceiver,
           Context context,
           UsbDevice usbDevice,
           UsbManager usbManager,
           ArrayList<NSPElement> nspElements) throws Exception{
    super(resultReceiver, context, usbDevice, usbManager);
    this.nspElements = nspElements;
}
 
Example #15
Source File: easycam.java    From Easycam with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (ACTION_USB_PERMISSION.equals(action)) {
        synchronized (this) {
            UsbDevice uDevice = (UsbDevice)intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);

            if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false)) {

                if(uDevice != null) {
                    initView();

                    // Right now the activity doesn't have focus, so if we need to manually
                    // set immersive mode.
                    if (immersive) {
                        camView.setSystemUiVisibility(
                                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                                        | View.SYSTEM_UI_FLAG_FULLSCREEN);

                        currentLayout.post(setAspectRatio);
                    }
                }
                else {
                    Log.d(TAG, "USB Device not valid");
                }
            }
            else {
                Log.d(TAG, "permission denied for device " + uDevice);
            }
        }
    }
}
 
Example #16
Source File: UsbUtils.java    From FireFiles with Apache License 2.0 5 votes vote down vote up
private static String nameForClass(UsbDevice usbDevice) {
    int classType = usbDevice.getDeviceClass();
    switch (classType) {
        case UsbConstants.USB_CLASS_AUDIO:
            return "Audio";
        case UsbConstants.USB_CLASS_CDC_DATA:
            return "CDC Control";
        case UsbConstants.USB_CLASS_COMM:
            return "Communications";
        case UsbConstants.USB_CLASS_CONTENT_SEC:
            return "Content Security";
        case UsbConstants.USB_CLASS_CSCID:
            return "Content Smart Card";
        case UsbConstants.USB_CLASS_HID:
            return "Human Interface Device";
        case UsbConstants.USB_CLASS_HUB:
            return "Hub";
        case UsbConstants.USB_CLASS_MASS_STORAGE:
            return "Mass Storage";
        case UsbConstants.USB_CLASS_MISC:
            return "Wireless Miscellaneous";
        case UsbConstants.USB_CLASS_PHYSICA:
            return "Physical";
        case UsbConstants.USB_CLASS_PRINTER:
            return "Printer";
        case UsbConstants.USB_CLASS_STILL_IMAGE:
            return "Still Image";
        case UsbConstants.USB_CLASS_VENDOR_SPEC:
            return String.format("Vendor Specific 0x%02x", classType);
        case UsbConstants.USB_CLASS_VIDEO:
            return "Video";
        case UsbConstants.USB_CLASS_WIRELESS_CONTROLLER:
            return "Wireless Controller";
        default:
            return "";
    }
}
 
Example #17
Source File: USBMonitor.java    From UVCCameraZxing with Apache License 2.0 5 votes vote down vote up
private final void processCancel(final UsbDevice device) {
	if (DEBUG) Log.v(TAG, "processCancel:");
	if (mOnDeviceConnectListener != null) {
		mHandler.post(new Runnable() {
			@Override
			public void run() {
				mOnDeviceConnectListener.onCancel();
			}
		});
	}
}
 
Example #18
Source File: UsbSerialProber.java    From usb-with-serial-port with Apache License 2.0 5 votes vote down vote up
/**
 * 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
 */
@Keep
public List<UsbSerialDriver> findAllDrivers(final UsbManager usbManager) {
    final List<UsbSerialDriver> result = new ArrayList<UsbSerialDriver>();
    HashMap<String, UsbDevice> deviceList = usbManager.getDeviceList();
    Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
    while (deviceIterator.hasNext()) {
        UsbDevice usbDevice = deviceIterator.next();
        UsbSerialDriver driver = probeDevice(usbDevice);
        if (driver != null) {
            result.add(driver);
        }
    }
    return result;
}
 
Example #19
Source File: Ledger.java    From xmrwallet with Apache License 2.0 5 votes vote down vote up
static public String connect(UsbManager usbManager, UsbDevice usbDevice) throws IOException {
    if (Instance != null) {
        disconnect();
    }
    Instance = new Ledger(usbManager, usbDevice);
    return Name();
}
 
Example #20
Source File: UsbMidiDeviceAndroid.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a UsbMidiDeviceAndroid.
 * @param manager
 * @param device The USB device which this object is assocated with.
 */
UsbMidiDeviceAndroid(UsbManager manager, UsbDevice device) {
    mConnection = manager.openDevice(device);
    mEndpointMap = new SparseArray<UsbEndpoint>();
    mRequestMap = new HashMap<UsbEndpoint, UsbRequest>();
    mHandler = new Handler();
    mUsbDevice = device;
    mIsClosed = false;
    mHasInputThread = false;
    mNativePointer = 0;

    for (int i = 0; i < device.getInterfaceCount(); ++i) {
        UsbInterface iface = device.getInterface(i);
        if (iface.getInterfaceClass() != UsbConstants.USB_CLASS_AUDIO
                || iface.getInterfaceSubclass() != MIDI_SUBCLASS) {
            continue;
        }
        mConnection.claimInterface(iface, true);
        for (int j = 0; j < iface.getEndpointCount(); ++j) {
            UsbEndpoint endpoint = iface.getEndpoint(j);
            if (endpoint.getDirection() == UsbConstants.USB_DIR_OUT) {
                mEndpointMap.put(endpoint.getEndpointNumber(), endpoint);
            }
        }
    }
    // Start listening for input endpoints.
    // This function will create and run a thread if there is USB-MIDI endpoints in the
    // device. Note that because UsbMidiDevice is shared among all tabs and the thread
    // will be terminated when the device is disconnected, at most one thread can be created
    // for each connected USB-MIDI device.
    startListen(device);
}
 
Example #21
Source File: UsbUtils.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * シリアルナンバーを取得できる機器の場合にはシリアルナンバーを含めたデバイスキーを取得する
 * シリアルナンバーを取得できなければgetDeviceKeyNameと同じ
 * @param context
 * @param device
 * @return
 */
@NonNull
public static String getDeviceKeyNameWithSerial(
	@NonNull final Context context,
	@Nullable final UsbDevice device) {

	final UsbDeviceInfo info = UsbDeviceInfo.getDeviceInfo(context, device);
	return getDeviceKeyName(device, true,
		info.serial, info.manufacturer, info.configCounts, info.version);
}
 
Example #22
Source File: CommonUsbSerialPort.java    From usb-with-serial-port with Apache License 2.0 5 votes vote down vote up
public CommonUsbSerialPort(UsbDevice device, int portNumber) {
    mDevice = device;
    mPortNumber = portNumber;

    mReadBuffer = new byte[DEFAULT_READ_BUFFER_SIZE];
    mWriteBuffer = new byte[DEFAULT_WRITE_BUFFER_SIZE];
}
 
Example #23
Source File: UsbSerialProber.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 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;
}
 
Example #24
Source File: BTChipTransportAndroid.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
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));
       if (device.getProductId() == PID_WINUSB) {
       	return new BTChipTransportAndroidWinUSB(connection, dongleInterface, in, out, TIMEOUT);
       }
       else {
       	return new BTChipTransportAndroidHID(connection, dongleInterface, in, out, TIMEOUT, ledger);
       }
}
 
Example #25
Source File: ReadData.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
public ReadData(UsbSerialDriver device, UsbDeviceConnection connection, UsbDevice usbDevice) {
        mSerialDevice = device;
        mConnection = connection;
        mDevice = usbDevice;
        try {
      mSerialDevice.getPorts().get(0).open(connection);
        } catch(IOException e) {
            Log.d("FAILED WHILE", "trying to open");
        }
//        }
    }
 
Example #26
Source File: USBMonitor.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
 * 指定したUsbDeviceをopenする
 * @param device
 * @return
 * @throws SecurityException パーミッションがなければSecurityExceptionを投げる
 */
public UsbControlBlock openDevice(final UsbDevice device) throws IOException {
	if (DEBUG) Log.v(TAG, "openDevice:device=" + device);
	if (hasPermission(device)) {
		return new UsbControlBlock(USBMonitor.this, device);    // この中でopenDeviceする
	} else {
		throw new IOException("has no permission or invalid UsbDevice(already disconnected?)");
	}
}
 
Example #27
Source File: UVCDeviceManager.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
private UVCDevice getDevice(final UsbDevice usbDevice) {
    synchronized (mAttachedDevices) {
        for (Iterator<UVCDevice> it = mAttachedDevices.iterator(); it.hasNext(); ) {
            UVCDevice device = it.next();
            if (device.isSameDevice(usbDevice)) {
                return device;
            }
        }
    }
    return null;
}
 
Example #28
Source File: UsbMidiDeviceFactoryAndroid.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a UsbMidiDeviceAndroid.
 * @param nativePointer The native pointer to which the created factory is associated.
 */
UsbMidiDeviceFactoryAndroid(long nativePointer) {
    mUsbManager = (UsbManager) ContextUtils.getApplicationContext().getSystemService(
            Context.USB_SERVICE);
    mNativePointer = nativePointer;
    mReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Parcelable extra = intent.getParcelableExtra(UsbManager.EXTRA_DEVICE);
            if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(intent.getAction())) {
                requestDevicePermissionIfNecessary((UsbDevice) extra);
            }
            if (UsbManager.ACTION_USB_DEVICE_DETACHED.equals(intent.getAction())) {
                onUsbDeviceDetached((UsbDevice) extra);
            }
            if (ACTION_USB_PERMISSION.equals(intent.getAction())) {
                onUsbDevicePermissionRequestDone(context, intent);
            }
        }
    };
    IntentFilter filter = new IntentFilter();
    filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    filter.addAction(ACTION_USB_PERMISSION);
    ContextUtils.getApplicationContext().registerReceiver(mReceiver, filter);
    mRequestedDevices = new HashSet<UsbDevice>();
}
 
Example #29
Source File: CommonUsbSerialDriver.java    From MedtronicUploader with GNU General Public License v2.0 5 votes vote down vote up
public CommonUsbSerialDriver(UsbDevice device, UsbDeviceConnection connection) {
    mDevice = device;
    mConnection = connection;

    mReadBuffer = new byte[DEFAULT_READ_BUFFER_SIZE];
    mWriteBuffer = new byte[DEFAULT_WRITE_BUFFER_SIZE];
}
 
Example #30
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;
}