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

The following examples show how to use android.hardware.usb.UsbDevice#getDeviceName() . 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: 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 2
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 3
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 4
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 5
Source File: BTChipTransportAndroid.java    From green_android with GNU General Public License v3.0 5 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 (ACTION_USB_PERMISSION.equals(action)) {
		boolean permission = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED,
				false);
           Log.d(LOG_TAG, "ACTION_USB_PERMISSION: " + permission + " Device: " + deviceName);

           // sync with connect
           gotRights.add(permission);
	}
}
 
Example 6
Source File: BTChipTransportAndroid.java    From WalletCordova with GNU Lesser General Public License v2.1 5 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 (ACTION_USB_PERMISSION.equals(action)) {
		boolean permission = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED,
				false);
           Log.d(LOG_TAG, "ACTION_USB_PERMISSION: " + permission + " Device: " + deviceName);

           // sync with connect
           gotRights.add(permission);
	}
}
 
Example 7
Source File: USBMonitor.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
		 * this class needs permission to access USB device before constructing
		 * @param monitor
		 * @param device
		 */
		private UsbControlBlock(final USBMonitor monitor, final UsbDevice device) {
			if (DEBUG) Log.i(TAG, "UsbControlBlock:constructor");
			mWeakMonitor = new WeakReference<USBMonitor>(monitor);
			mWeakDevice = new WeakReference<UsbDevice>(device);
			mConnection = monitor.mUsbManager.openDevice(device);
			mInfo = updateDeviceInfo(monitor.mUsbManager, device, null);
			final String name = device.getDeviceName();
			final String[] v = !TextUtils.isEmpty(name) ? name.split("/") : null;
			int busnum = 0;
			int devnum = 0;
			if (v != null) {
				busnum = Integer.parseInt(v[v.length-2]);
				devnum = Integer.parseInt(v[v.length-1]);
			}
			mBusNum = busnum;
			mDevNum = devnum;
//			if (DEBUG) {
				if (mConnection != null) {
					final int desc = mConnection.getFileDescriptor();
					final byte[] rawDesc = mConnection.getRawDescriptors();
					Log.i(TAG, String.format(Locale.US, "name=%s,desc=%d,busnum=%d,devnum=%d,rawDesc=", name, desc, busnum, devnum) + rawDesc);
				} else {
					Log.e(TAG, "could not connect to device " + name);
				}
//			}
		}
 
Example 8
Source File: BTChipTransportAndroid.java    From GreenBits with GNU General Public License v3.0 5 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 (ACTION_USB_PERMISSION.equals(action)) {
		boolean permission = intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED,
				false);
           Log.d(LOG_TAG, "ACTION_USB_PERMISSION: " + permission + " Device: " + deviceName);

           // sync with connect
           gotRights.add(permission);
	}
}
 
Example 9
Source File: USBMonitor.java    From libcommon with Apache License 2.0 5 votes vote down vote up
/**
		 * 指定したUsbDeviceに関係づけたUsbControlBlockインスタンスを生成する
		 * 内部でopenDeviceをするのでパーミションを取得してないとダメ
		 * @param monitor
		 * @param device
		 */
		private UsbControlBlock(final USBMonitor monitor, final UsbDevice device)
			throws IOException {

//			if (DEBUG) Log.v(TAG, "UsbControlBlock:device=" + device);
			mWeakMonitor = new WeakReference<USBMonitor>(monitor);
			mWeakDevice = new WeakReference<UsbDevice>(device);
			// XXX UsbManager#openDeviceはIllegalArgumentExceptionを投げる可能性がある
			try {
				mConnection = monitor.mUsbManager.openDevice(device);
			} catch (final Exception e) {
				throw new IOException(e);
			}
			final String name = device.getDeviceName();
			if (mConnection != null) {
				final int fd = mConnection.getFileDescriptor();
				final byte[] rawDesc = mConnection.getRawDescriptors();
				Log.i(TAG, String.format(Locale.US,
					"name=%s,fd=%d,rawDesc=", name, fd)
						+ BufferHelper.toHexString(rawDesc, 0, 16));
			} else {
				// 多分ここには来ない(openDeviceの時点でIOException)けど年のために
				throw new IOException("could not connect to device " + name);
			}
			mInfo = UsbDeviceInfo.getDeviceInfo(monitor.mUsbManager, device, null);
			monitor.processConnect(device, this);
		}
 
Example 10
Source File: USBMonitor.java    From AndroidUSBCamera with Apache License 2.0 5 votes vote down vote up
/**
		 * this class needs permission to access USB device before constructing
		 * @param monitor
		 * @param device
		 */
		private UsbControlBlock(final USBMonitor monitor, final UsbDevice device) {
			if (DEBUG) Log.i(TAG, "UsbControlBlock:constructor");
			mWeakMonitor = new WeakReference<USBMonitor>(monitor);
			mWeakDevice = new WeakReference<UsbDevice>(device);
			mConnection = monitor.mUsbManager.openDevice(device);
			mInfo = updateDeviceInfo(monitor.mUsbManager, device, null);
			final String name = device.getDeviceName();
			final String[] v = !TextUtils.isEmpty(name) ? name.split("/") : null;
			int busnum = 0;
			int devnum = 0;
			if (v != null) {
				busnum = Integer.parseInt(v[v.length-2]);
				devnum = Integer.parseInt(v[v.length-1]);
			}
			mBusNum = busnum;
			mDevNum = devnum;
//			if (DEBUG) {
				if (mConnection != null) {
					final int desc = mConnection.getFileDescriptor();
					final byte[] rawDesc = mConnection.getRawDescriptors();
					Log.i(TAG, String.format(Locale.US, "name=%s,desc=%d,busnum=%d,devnum=%d,rawDesc=", name, desc, busnum, devnum) + rawDesc);
				} else {
					Log.e(TAG, "could not connect to device " + name);
				}
//			}
		}
 
Example 11
Source File: USBMonitor.java    From AndroidUSBCamera with Apache License 2.0 4 votes vote down vote up
/**
 * get device name
 * @return
 */
public String getDeviceName() {
	final UsbDevice device = mWeakDevice.get();
	return device != null ? device.getDeviceName() : "";
}
 
Example 12
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;
}
 
Example 13
Source File: USBMonitor.java    From UVCCameraZxing with Apache License 2.0 4 votes vote down vote up
public String getDeviceName() {
	final UsbDevice device = mWeakDevice.get();
	return device != null ? device.getDeviceName() : "";
}
 
Example 14
Source File: UsbUtils.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
public static String getPath(UsbDevice device){
    return device.getDeviceName();
}
 
Example 15
Source File: USBHIDService.java    From USBHIDTerminal with Apache License 2.0 4 votes vote down vote up
@Override
public CharSequence onBuildingDevicesList(UsbDevice usbDevice) {
	return "devID:" + usbDevice.getDeviceId() + " VID:" + Integer.toHexString(usbDevice.getVendorId()) + " PID:" + Integer.toHexString(usbDevice.getProductId()) + " " + usbDevice.getDeviceName();
}
 
Example 16
Source File: UsbUtils.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
public static String getPath(UsbDevice device){
    return device.getDeviceName();
}
 
Example 17
Source File: UsbUtils.java    From FireFiles with Apache License 2.0 4 votes vote down vote up
public static String getPath(UsbDevice device){
    return device.getDeviceName();
}
 
Example 18
Source File: USBMonitor.java    From DeviceConnect-Android with MIT License 4 votes vote down vote up
/**
 * get device name
 * @return
 */
public String getDeviceName() {
	final UsbDevice device = mWeakDevice.get();
	return device != null ? device.getDeviceName() : "";
}
 
Example 19
Source File: NoPermissionsException.java    From yubikit-android with Apache License 2.0 4 votes vote down vote up
public NoPermissionsException(UsbDevice usbDevice) {
    // with L+ devices we can get more verbal device name
    super("No permission granted to communicate with device " + (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP ? usbDevice.getProductName() : usbDevice.getDeviceName()));
}
 
Example 20
Source File: SettingsActivity.java    From Easycam with BSD 3-Clause "New" or "Revised" License 2 votes vote down vote up
private ArrayList<DeviceEntry> enumerateUsbDevices() {

			ArrayList<DeviceEntry> validStreamingDeviceList = new ArrayList<>(5);

			synchronized (JsonManager.lock) {

				//Make sure the JsonManger has been initialized
				if (!JsonManager.isInitialized())
					JsonManager.initialize();


				// Enumerate a list of currently connected Usb devices so we can pick out which
				// ones are supported easycap devices
				UsbManager mUsbManager = (UsbManager) getActivity().getSystemService(Context.USB_SERVICE);
				HashMap<String, UsbDevice> usbDeviceList = mUsbManager.getDeviceList();
				Iterator<UsbDevice> deviceIterator = usbDeviceList.values().iterator();

				// Make sure the device list is empty before enumeration
				validStreamingDeviceList.clear();

				while(deviceIterator.hasNext()) {

					UsbDevice uDevice = deviceIterator.next();

					DeviceInfo devInfo = JsonManager.getDevice(uDevice.getVendorId(), uDevice.getProductId(),
							DeviceInfo.DeviceStandard.NTSC);

					// If a supported device is listed in json list, request permission
					// to access it
					if (devInfo != null) {

						Log.i(TAG, "Supported usb device found: " + uDevice.toString());
						Log.i(TAG, "Device ID: " + uDevice.getDeviceId());
						Log.i(TAG, "Device Name: " + uDevice.getDeviceName());
						Log.i(TAG, "Vendor: ID " + uDevice.getVendorId());
						Log.i(TAG, "Product ID: " + uDevice.getProductId());

						DeviceEntry devEntry = new DeviceEntry();

						devEntry.deviceDescription = devInfo.getDescription() + " @ " + uDevice.getDeviceName();
						devEntry.deviceName = uDevice.getDeviceName() + ":" + devInfo.getVendorID()
								+ ":" + devInfo.getProductID();

						validStreamingDeviceList.add(devEntry);

					}
				}

			}

			return validStreamingDeviceList;
		}