Use the descriptor passed in when adding USB device instead of querying again.
When USB device is added, the raw descriptor has already been reported.
It is important to check if that raw descriptor is null or not to avoid
crash when creating a parser. What is more, given the descriptor has
been known when added the device, UsbHostManager can just cache that
descriptor instead of querying the raw descriptor again.
Bug: 326268581
Test: repo steps in bug
Change-Id: Iecefbd2eccbd981e77c4afe9cf8b00d830de27d3
diff --git a/services/usb/java/com/android/server/usb/UsbHostManager.java b/services/usb/java/com/android/server/usb/UsbHostManager.java
index 8b44579..36adeec 100644
--- a/services/usb/java/com/android/server/usb/UsbHostManager.java
+++ b/services/usb/java/com/android/server/usb/UsbHostManager.java
@@ -380,6 +380,11 @@
return false;
}
+ if (descriptors == null) {
+ Slog.e(TAG, "Failed to add device as the descriptor is null");
+ return false;
+ }
+
UsbDescriptorParser parser = new UsbDescriptorParser(deviceAddress, descriptors);
if (deviceClass == UsbConstants.USB_CLASS_PER_INTERFACE
&& !checkUsbInterfacesDenyListed(parser)) {
@@ -462,8 +467,7 @@
}
// Tracking
- addConnectionRecord(deviceAddress, ConnectionRecord.CONNECT,
- parser.getRawDescriptors());
+ addConnectionRecord(deviceAddress, ConnectionRecord.CONNECT, descriptors);
// Stats collection
FrameworkStatsLog.write(FrameworkStatsLog.USB_DEVICE_ATTACHED,