summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author jiabin <jiabin@google.com> 2024-02-21 20:29:47 +0000
committer Jiabin Huang <jiabin@google.com> 2024-02-27 22:54:41 +0000
commit66d7513001c4fd16eaead0f3a0322928c1d711ce (patch)
tree03a9d4bbd4b37951144138a359f55315ddece055
parent84820f19174e948627f179b75508f4cd2ab54c29 (diff)
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
-rw-r--r--services/usb/java/com/android/server/usb/UsbHostManager.java8
1 files changed, 6 insertions, 2 deletions
diff --git a/services/usb/java/com/android/server/usb/UsbHostManager.java b/services/usb/java/com/android/server/usb/UsbHostManager.java
index 8b44579eda33..36adeec74e36 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 @@ public class UsbHostManager {
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 @@ public class UsbHostManager {
}
// Tracking
- addConnectionRecord(deviceAddress, ConnectionRecord.CONNECT,
- parser.getRawDescriptors());
+ addConnectionRecord(deviceAddress, ConnectionRecord.CONNECT, descriptors);
// Stats collection
FrameworkStatsLog.write(FrameworkStatsLog.USB_DEVICE_ATTACHED,