diff options
3 files changed, 22 insertions, 50 deletions
diff --git a/services/usb/java/com/android/server/usb/UsbHostManager.java b/services/usb/java/com/android/server/usb/UsbHostManager.java index 0fcd075e8200..e3e381ec6fe1 100644 --- a/services/usb/java/com/android/server/usb/UsbHostManager.java +++ b/services/usb/java/com/android/server/usb/UsbHostManager.java @@ -329,40 +329,31 @@ public class UsbHostManager { return false; } - UsbDescriptorParser parser = new UsbDescriptorParser(deviceAddress); - if (parser.parseDescriptors(descriptors)) { - - UsbDevice newDevice = parser.toAndroidUsbDevice(); - if (newDevice == null) { - Slog.e(TAG, "Couldn't create UsbDevice object."); - // Tracking - addConnectionRecord(deviceAddress, ConnectionRecord.CONNECT_BADDEVICE, - parser.getRawDescriptors()); + UsbDescriptorParser parser = new UsbDescriptorParser(deviceAddress, descriptors); + UsbDevice newDevice = parser.toAndroidUsbDevice(); + if (newDevice == null) { + Slog.e(TAG, "Couldn't create UsbDevice object."); + // Tracking + addConnectionRecord(deviceAddress, ConnectionRecord.CONNECT_BADDEVICE, + parser.getRawDescriptors()); + } else { + mDevices.put(deviceAddress, newDevice); + + // It is fine to call this only for the current user as all broadcasts are + // sent to all profiles of the user and the dialogs should only show once. + ComponentName usbDeviceConnectionHandler = getUsbDeviceConnectionHandler(); + if (usbDeviceConnectionHandler == null) { + getCurrentUserSettings().deviceAttached(newDevice); } else { - mDevices.put(deviceAddress, newDevice); - - // It is fine to call this only for the current user as all broadcasts are - // sent to all profiles of the user and the dialogs should only show once. - ComponentName usbDeviceConnectionHandler = getUsbDeviceConnectionHandler(); - if (usbDeviceConnectionHandler == null) { - getCurrentUserSettings().deviceAttached(newDevice); - } else { - getCurrentUserSettings().deviceAttachedForFixedHandler(newDevice, - usbDeviceConnectionHandler); - } + getCurrentUserSettings().deviceAttachedForFixedHandler(newDevice, + usbDeviceConnectionHandler); + } - mUsbAlsaManager.usbDeviceAdded(deviceAddress, newDevice, parser); + mUsbAlsaManager.usbDeviceAdded(deviceAddress, newDevice, parser); - // Tracking - addConnectionRecord(deviceAddress, ConnectionRecord.CONNECT, - parser.getRawDescriptors()); - } - } else { - Slog.e(TAG, "Error parsing USB device descriptors for " + deviceAddress); // Tracking - addConnectionRecord(deviceAddress, ConnectionRecord.CONNECT_BADPARSE, + addConnectionRecord(deviceAddress, ConnectionRecord.CONNECT, parser.getRawDescriptors()); - return false; } } diff --git a/services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java b/services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java index 956efc075d0a..c704fe34866f 100644 --- a/services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java +++ b/services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java @@ -43,11 +43,6 @@ public final class UsbDescriptorParser { // Obtained from the first AudioClass Header descriptor. private int mACInterfacesSpec = UsbDeviceDescriptor.USBSPEC_1_0; - public UsbDescriptorParser(String deviceAddr) { - mDeviceAddr = deviceAddr; - mDescriptors = new ArrayList<UsbDescriptor>(DESCRIPTORS_ALLOC_SIZE); - } - /** * Connect this parser to an existing set of already parsed descriptors. * This is useful for reporting. @@ -214,7 +209,7 @@ public final class UsbDescriptorParser { /** * @hide */ - public boolean parseDescriptors(byte[] descriptors) { + public void parseDescriptors(byte[] descriptors) { if (DEBUG) { Log.d(TAG, "parseDescriptors() - start"); } @@ -248,17 +243,6 @@ public final class UsbDescriptorParser { if (DEBUG) { Log.d(TAG, "parseDescriptors() - end " + mDescriptors.size() + " descriptors."); } - return true; - } - - /** - * @hide - */ - public boolean parseDevice() { - byte[] rawDescriptors = getRawDescriptors(); - - return rawDescriptors != null - ? parseDescriptors(rawDescriptors) : false; } public byte[] getRawDescriptors() { diff --git a/tests/UsbTests/src/com/android/server/usb/UsbDescriptorParserTests.java b/tests/UsbTests/src/com/android/server/usb/UsbDescriptorParserTests.java index f32395226f4a..4b64083c2367 100644 --- a/tests/UsbTests/src/com/android/server/usb/UsbDescriptorParserTests.java +++ b/tests/UsbTests/src/com/android/server/usb/UsbDescriptorParserTests.java @@ -61,10 +61,7 @@ public class UsbDescriptorParserTests { } // Testing same codepath as UsbHostManager.java:usbDeviceAdded - UsbDescriptorParser parser = new UsbDescriptorParser("test-usb-addr"); - if (!parser.parseDescriptors(descriptors)) { - fail("failed to parse descriptors."); - } + UsbDescriptorParser parser = new UsbDescriptorParser("test-usb-addr", descriptors); return parser; } |