summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Chant <achant@google.com>2018-03-02 13:18:18 -0800
committerAndrew Chant <achant@google.com>2018-03-26 20:55:28 +0000
commit0491f5aa0f3cc6b46bdf433bc900433b965943e2 (patch)
tree1b9cfc681da9925fbeb04c83a44d64d522bb1056
parentd52c532df7c7c481bf6e482c37f4e0ee02618fce (diff)
UsbDescriptorParser: always parse in constructor
UsbDescriptorParser::parseDescriptors always returned true. Remove the return value, and remove the one constructor that doesn't parse descriptors so the device is always in a parsed state. Bug: 74119682 Test: Built Change-Id: I2dd8d439405867d78102a9591dd1db36fe3959dc
-rw-r--r--services/usb/java/com/android/server/usb/UsbHostManager.java49
-rw-r--r--services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java18
-rw-r--r--tests/UsbTests/src/com/android/server/usb/UsbDescriptorParserTests.java5
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;
}