use of android.hardware.usb.UsbDevice in project android_frameworks_base by crdroidandroid.
the class UsbAlsaManager method dump.
//
// Logging
//
public void dump(IndentingPrintWriter pw) {
pw.println("USB Audio Devices:");
for (UsbDevice device : mAudioDevices.keySet()) {
pw.println(" " + device.getDeviceName() + ": " + mAudioDevices.get(device));
}
pw.println("USB MIDI Devices:");
for (UsbDevice device : mMidiDevices.keySet()) {
pw.println(" " + device.getDeviceName() + ": " + mMidiDevices.get(device));
}
}
use of android.hardware.usb.UsbDevice in project android_frameworks_base by crdroidandroid.
the class UsbHostManager method usbDeviceRemoved.
/* Called from JNI in monitorUsbHostBus to report USB device removal */
private void usbDeviceRemoved(String deviceName) {
synchronized (mLock) {
UsbDevice device = mDevices.remove(deviceName);
if (device != null) {
mUsbAlsaManager.usbDeviceRemoved(device);
getCurrentSettings().deviceDetached(device);
}
}
}
use of android.hardware.usb.UsbDevice in project android_frameworks_base by AOSPA.
the class MtpManager method openDevice.
synchronized MtpDeviceRecord openDevice(int deviceId) throws IOException {
UsbDevice rawDevice = null;
for (final UsbDevice candidate : mManager.getDeviceList().values()) {
if (candidate.getDeviceId() == deviceId) {
rawDevice = candidate;
break;
}
}
ensureNotNull(rawDevice, "Not found USB device: " + deviceId);
if (!mManager.hasPermission(rawDevice)) {
mManager.grantPermission(rawDevice);
if (!mManager.hasPermission(rawDevice)) {
throw new IOException("Failed to grant a device permission.");
}
}
final MtpDevice device = new MtpDevice(rawDevice);
final UsbDeviceConnection connection = ensureNotNull(mManager.openDevice(rawDevice), "Failed to open a USB connection.");
if (!device.open(connection)) {
// We cannot open connection when another application use the device.
throw new BusyDeviceException();
}
// Handle devices that fail to obtain storages just after opening a MTP session.
final int[] storageIds = ensureNotNull(device.getStorageIds(), "Not found MTP storages in the device.");
mDevices.put(deviceId, device);
return createDeviceRecord(rawDevice);
}
use of android.hardware.usb.UsbDevice in project android_frameworks_base by AOSPA.
the class ReceiverActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(getIntent().getAction())) {
final UsbDevice device = getIntent().getParcelableExtra(UsbManager.EXTRA_DEVICE);
try {
final MtpDocumentsProvider provider = MtpDocumentsProvider.getInstance();
provider.openDevice(device.getDeviceId());
final String deviceRootId = provider.getDeviceDocumentId(device.getDeviceId());
final Uri uri = DocumentsContract.buildRootUri(MtpDocumentsProvider.AUTHORITY, deviceRootId);
final Intent intent = new Intent(DocumentsContract.ACTION_BROWSE);
intent.setData(uri);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.putExtra(DocumentsContract.EXTRA_FANCY_FEATURES, true);
this.startActivity(intent);
} catch (IOException exception) {
Log.e(MtpDocumentsProvider.TAG, "Failed to open device", exception);
}
}
finish();
}
use of android.hardware.usb.UsbDevice in project android-uploader by nightscout.
the class SyncingService method isG4Connected.
public static boolean isG4Connected(Context c) {
// Iterate through devices and see if the dexcom is connected
// Allowing us to start to start syncing if the G4 is already connected
// vendor-id="8867" product-id="71" class="2" subclass="0" protocol="0"
UsbManager manager = (UsbManager) c.getSystemService(Context.USB_SERVICE);
if (manager == null)
return false;
HashMap<String, UsbDevice> deviceList = manager.getDeviceList();
Iterator<UsbDevice> deviceIterator = deviceList.values().iterator();
boolean g4Connected = false;
while (deviceIterator.hasNext()) {
UsbDevice device = deviceIterator.next();
if (device.getVendorId() == 8867 && device.getProductId() == 71 && device.getDeviceClass() == 2 && device.getDeviceSubclass() == 0 && device.getDeviceProtocol() == 0) {
g4Connected = true;
}
}
return g4Connected;
}
Aggregations