From 7d545bef6077d55dcbc3533e416698bf62085d41 Mon Sep 17 00:00:00 2001 From: Paul McLean Date: Fri, 28 Jul 2017 17:36:15 -0700 Subject: Fix exceptions causing HTC dongle (and JBL headset) to fail connection logic. Bug: 64108509 Test: Manual Change-Id: I9574f34cea4ff9ef3e18553a138f1a8b95b1b108 --- .../usb/descriptors/UsbDescriptorParser.java | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'services/usb/java') 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 303a577767ad..d4a0ac4a0da3 100644 --- a/services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java +++ b/services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java @@ -123,21 +123,27 @@ public class UsbDescriptorParser { ByteStream stream = new ByteStream(descriptors); while (stream.available() > 0) { - UsbDescriptor descriptor = allocDescriptor(stream); + UsbDescriptor descriptor = null; + try { + descriptor = allocDescriptor(stream); + } catch (Exception ex) { + Log.e(TAG, "Exception allocating USB descriptor.", ex); + } + if (descriptor != null) { // Parse try { descriptor.parseRawDescriptors(stream); + + // Its OK to add the invalid descriptor as the postParse() + // routine will mark it as invalid. + mDescriptors.add(descriptor); + + // Clean up + descriptor.postParse(stream); } catch (Exception ex) { Log.e(TAG, "Exception parsing USB descriptors.", ex); } - - // Its OK to add the invalid descriptor as the postParse() - // routine will mark it as invalid. - mDescriptors.add(descriptor); - - // Clean up - descriptor.postParse(stream); } } } -- cgit v1.2.3-59-g8ed1b