use of android.hardware.usb.UsbDevice in project android_frameworks_base by DirtyUnicorns.
the class UsbHostManager method beginUsbDeviceAdded.
/* Called from JNI in monitorUsbHostBus() to report new USB devices
Returns true if successful, in which case the JNI code will continue adding configurations,
interfaces and endpoints, and finally call endUsbDeviceAdded after all descriptors
have been processed
*/
private boolean beginUsbDeviceAdded(String deviceName, int vendorID, int productID, int deviceClass, int deviceSubclass, int deviceProtocol, String manufacturerName, String productName, int version, String serialNumber) {
if (DEBUG) {
Slog.d(TAG, "usb:UsbHostManager.beginUsbDeviceAdded(" + deviceName + ")");
// Audio Class Codes:
// Audio: 0x01
// Audio Subclass Codes:
// undefined: 0x00
// audio control: 0x01
// audio streaming: 0x02
// midi streaming: 0x03
// some useful debugging info
Slog.d(TAG, "usb: nm:" + deviceName + " vnd:" + vendorID + " prd:" + productID + " cls:" + deviceClass + " sub:" + deviceSubclass + " proto:" + deviceProtocol);
}
if (isBlackListed(deviceName) || isBlackListed(deviceClass, deviceSubclass, deviceProtocol)) {
return false;
}
synchronized (mLock) {
if (mDevices.get(deviceName) != null) {
Slog.w(TAG, "device already on mDevices list: " + deviceName);
return false;
}
if (mNewDevice != null) {
Slog.e(TAG, "mNewDevice is not null in endUsbDeviceAdded");
return false;
}
// Create version string in "%.%" format
String versionString = Integer.toString(version >> 8) + "." + (version & 0xFF);
mNewDevice = new UsbDevice(deviceName, vendorID, productID, deviceClass, deviceSubclass, deviceProtocol, manufacturerName, productName, versionString, serialNumber);
mNewConfigurations = new ArrayList<UsbConfiguration>();
mNewInterfaces = new ArrayList<UsbInterface>();
mNewEndpoints = new ArrayList<UsbEndpoint>();
}
return true;
}
use of android.hardware.usb.UsbDevice in project android_frameworks_base by DirtyUnicorns.
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 DirtyUnicorns.
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 DirtyUnicorns.
the class TestUtil method findMtpDevice.
private static UsbDevice findMtpDevice(UsbManager usbManager, MtpManager manager) throws IOException {
final HashMap<String, UsbDevice> devices = usbManager.getDeviceList();
if (devices.size() == 0) {
throw new IOException("Device not found.");
}
final UsbDevice device = devices.values().iterator().next();
// Tries to get ownership of the device in case that another application use it.
if (usbManager.hasPermission(device)) {
final UsbDeviceConnection connection = usbManager.openDevice(device);
for (int i = 0; i < device.getInterfaceCount(); i++) {
// Since the test runs real environment, we need to call claim interface with
// force = true to rob interfaces from other applications.
connection.claimInterface(device.getInterface(i), true);
connection.releaseInterface(device.getInterface(i));
}
connection.close();
}
manager.openDevice(device.getDeviceId());
return device;
}
use of android.hardware.usb.UsbDevice in project android_frameworks_base by DirtyUnicorns.
the class TestUtil method setupMtpDevice.
/**
* Requests permission for a MTP device and returns the first MTP device that has at least one
* storage.
*/
static UsbDevice setupMtpDevice(TestResultInstrumentation instrumentation, UsbManager usbManager, MtpManager manager) {
while (true) {
try {
final UsbDevice device = findMtpDevice(usbManager, manager);
waitForStorages(instrumentation, manager, device.getDeviceId());
return device;
} catch (IOException exp) {
instrumentation.show(Objects.toString(exp.getMessage()));
SystemClock.sleep(1000);
// again.
continue;
}
}
}
Aggregations