Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 20568917 authored by Paul McLean's avatar Paul McLean Committed by Eric Laurent
Browse files

More fine-grained exception handling so we can still use non-excepting descriptors.

Bug: 63655391
Test: Manual - connect various devices and verify the connection state is correct.
Change-Id: Iae6143d2e853e916c8588e0c6f771c00714b3a8a
parent b82963f3
Loading
Loading
Loading
Loading
+23 −18
Original line number Diff line number Diff line
@@ -118,8 +118,7 @@ public class UsbDescriptorParser {
    /**
     * @hide
     */
    public boolean parseDescriptors(byte[] descriptors) {
        try {
    public void parseDescriptors(byte[] descriptors) {
        mDescriptors.clear();

        ByteStream stream = new ByteStream(descriptors);
@@ -127,18 +126,20 @@ public class UsbDescriptorParser {
            UsbDescriptor descriptor = allocDescriptor(stream);
            if (descriptor != null) {
                // Parse
                try {
                    descriptor.parseRawDescriptors(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);
            }
        }
            return true;
        } catch (Exception ex) {
            Log.e(TAG, "Exception parsing USB descriptors.", ex);
        }
        return false;
    }

    /**
@@ -146,7 +147,11 @@ public class UsbDescriptorParser {
     */
    public boolean parseDevice(String deviceAddr) {
        byte[] rawDescriptors = getRawDescriptors(deviceAddr);
        return rawDescriptors != null && parseDescriptors(rawDescriptors);
        if (rawDescriptors != null) {
            parseDescriptors(rawDescriptors);
            return true;
        }
        return false;
    }

    private native byte[] getRawDescriptors(String deviceAddr);