Loading services/usb/java/com/android/server/usb/descriptors/ByteStream.java +5 −2 Original line number Diff line number Diff line Loading @@ -185,12 +185,14 @@ public final class ByteStream { // Positive offsets only throw new IllegalArgumentException(); } // do arithmetic and comparison in long to ovoid potention integer overflow // do arithmetic and comparison in long to avoid potential integer overflow long longNewIndex = (long) mIndex + (long) numBytes; if (longNewIndex < (long) mBytes.length) { if (longNewIndex <= (long) mBytes.length) { mReadCount += numBytes; mIndex += numBytes; } else { // Position the stream to the end so available() will return 0 mIndex = mBytes.length; throw new IndexOutOfBoundsException(); } } Loading @@ -210,6 +212,7 @@ public final class ByteStream { mReadCount -= numBytes; mIndex -= numBytes; } else { mIndex = 0; throw new IndexOutOfBoundsException(); } } Loading services/usb/java/com/android/server/usb/descriptors/UsbACEndpoint.java +9 −1 Original line number Diff line number Diff line Loading @@ -45,7 +45,6 @@ abstract class UsbACEndpoint extends UsbDescriptor { @Override public int parseRawDescriptors(ByteStream stream) { mSubtype = stream.getByte(); return mLength; } Loading @@ -55,12 +54,21 @@ abstract class UsbACEndpoint extends UsbDescriptor { int subClass = interfaceDesc.getUsbSubclass(); switch (subClass) { case AUDIO_AUDIOCONTROL: if (UsbDescriptorParser.DEBUG) { Log.d(TAG, "---> AUDIO_AUDIOCONTROL"); } return new UsbACAudioControlEndpoint(length, type, subClass); case AUDIO_AUDIOSTREAMING: if (UsbDescriptorParser.DEBUG) { Log.d(TAG, "---> AUDIO_AUDIOSTREAMING"); } return new UsbACAudioStreamEndpoint(length, type, subClass); case AUDIO_MIDISTREAMING: if (UsbDescriptorParser.DEBUG) { Log.d(TAG, "---> AUDIO_MIDISTREAMING"); } return new UsbACMidiEndpoint(length, type, subClass); default: Loading services/usb/java/com/android/server/usb/descriptors/UsbACInterface.java +39 −0 Original line number Diff line number Diff line Loading @@ -100,8 +100,14 @@ public abstract class UsbACInterface extends UsbDescriptor { switch (subtype) { case ACI_HEADER: { if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " ---> ACI_HEADER"); } int acInterfaceSpec = stream.unpackUsbShort(); parser.setACInterfaceSpec(acInterfaceSpec); if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " acInterfaceSpec:0x" + Integer.toHexString(acInterfaceSpec)); } if (acInterfaceSpec == UsbDeviceDescriptor.USBSPEC_2_0) { return new Usb20ACHeader(length, type, subtype, subClass, acInterfaceSpec); } else { Loading @@ -111,7 +117,13 @@ public abstract class UsbACInterface extends UsbDescriptor { case ACI_INPUT_TERMINAL: { if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " ---> ACI_INPUT_TERMINAL"); } int acInterfaceSpec = parser.getACInterfaceSpec(); if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " acInterfaceSpec:0x" + Integer.toHexString(acInterfaceSpec)); } if (acInterfaceSpec == UsbDeviceDescriptor.USBSPEC_2_0) { return new Usb20ACInputTerminal(length, type, subtype, subClass); } else { Loading @@ -121,7 +133,13 @@ public abstract class UsbACInterface extends UsbDescriptor { case ACI_OUTPUT_TERMINAL: { if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " ---> ACI_OUTPUT_TERMINAL"); } int acInterfaceSpec = parser.getACInterfaceSpec(); if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " acInterfaceSpec:0x" + Integer.toHexString(acInterfaceSpec)); } if (acInterfaceSpec == UsbDeviceDescriptor.USBSPEC_2_0) { return new Usb20ACOutputTerminal(length, type, subtype, subClass); } else { Loading @@ -130,14 +148,26 @@ public abstract class UsbACInterface extends UsbDescriptor { } case ACI_SELECTOR_UNIT: if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " ---> ACI_SELECTOR_UNIT"); } return new UsbACSelectorUnit(length, type, subtype, subClass); case ACI_FEATURE_UNIT: if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " ---> ACI_FEATURE_UNIT"); } return new UsbACFeatureUnit(length, type, subtype, subClass); case ACI_MIXER_UNIT: { if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " ---> ACI_MIXER_UNIT"); } int acInterfaceSpec = parser.getACInterfaceSpec(); if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " acInterfaceSpec:0x" + Integer.toHexString(acInterfaceSpec)); } if (acInterfaceSpec == UsbDeviceDescriptor.USBSPEC_2_0) { return new Usb20ACMixerUnit(length, type, subtype, subClass); } else { Loading Loading @@ -215,14 +245,23 @@ public abstract class UsbACInterface extends UsbDescriptor { int subClass = interfaceDesc.getUsbSubclass(); switch (subClass) { case AUDIO_AUDIOCONTROL: if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " AUDIO_AUDIOCONTROL"); } return allocAudioControlDescriptor( parser, stream, length, type, subtype, subClass); case AUDIO_AUDIOSTREAMING: if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " AUDIO_AUDIOSTREAMING"); } return allocAudioStreamingDescriptor( parser, stream, length, type, subtype, subClass); case AUDIO_MIDISTREAMING: if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " AUDIO_MIDISTREAMING"); } return allocMidiStreamingDescriptor(length, type, subtype, subClass); default: Loading services/usb/java/com/android/server/usb/descriptors/UsbConfigDescriptor.java +2 −3 Original line number Diff line number Diff line Loading @@ -30,7 +30,6 @@ import java.util.ArrayList; */ public final class UsbConfigDescriptor extends UsbDescriptor { private static final String TAG = "UsbConfigDescriptor"; private static final boolean DEBUG = false; private int mTotalLength; // 2:2 Total length in bytes of data returned private byte mNumInterfaces; // 4:1 Number of Interfaces Loading Loading @@ -79,14 +78,14 @@ public final class UsbConfigDescriptor extends UsbDescriptor { } UsbConfiguration toAndroid(UsbDescriptorParser parser) { if (DEBUG) { if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " toAndroid()"); } String name = parser.getDescriptorString(mConfigIndex); UsbConfiguration config = new UsbConfiguration(mConfigValue, name, mAttribs, mMaxPower); UsbInterface[] interfaces = new UsbInterface[mInterfaceDescriptors.size()]; if (DEBUG) { if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " " + mInterfaceDescriptors.size() + " interfaces."); } for (int index = 0; index < mInterfaceDescriptors.size(); index++) { Loading services/usb/java/com/android/server/usb/descriptors/UsbDescriptor.java +61 −42 Original line number Diff line number Diff line Loading @@ -78,8 +78,8 @@ public abstract class UsbDescriptor implements Reporting { public static final byte DESCRIPTORTYPE_HID = 0x21; // 33 public static final byte DESCRIPTORTYPE_REPORT = 0x22; // 34 public static final byte DESCRIPTORTYPE_PHYSICAL = 0x23; // 35 public static final byte DESCRIPTORTYPE_AUDIO_INTERFACE = 0x24; // 36 public static final byte DESCRIPTORTYPE_AUDIO_ENDPOINT = 0x25; // 37 public static final byte DESCRIPTORTYPE_CLASSSPECIFIC_INTERFACE = 0x24; // 36 public static final byte DESCRIPTORTYPE_CLASSSPECIFIC_ENDPOINT = 0x25; // 37 public static final byte DESCRIPTORTYPE_HUB = 0x29; // 41 public static final byte DESCRIPTORTYPE_SUPERSPEED_HUB = 0x2A; // 42 public static final byte DESCRIPTORTYPE_ENDPOINT_COMPANION = 0x30; // 48 Loading Loading @@ -163,7 +163,6 @@ public abstract class UsbDescriptor implements Reporting { public int getOverUnderRunCount() { return mOverUnderRunCount; } public String getStatusString() { return sStatusStrings[mStatus]; } Loading Loading @@ -278,4 +277,24 @@ public abstract class UsbDescriptor implements Reporting { + " Len: " + getLength(); canvas.writeParagraph(text, false); } /* * Logging Helpers */ static String getDescriptorName(byte descriptorType, int descriptorLength) { String name = UsbStrings.getDescriptorName(descriptorType); if (name != null) { return name; } else { return "Unknown Descriptor Type " + descriptorType + " 0x" + Integer.toHexString(descriptorType) + " length:" + descriptorLength; } } static void logDescriptorName(byte descriptorType, int descriptorLength) { if (UsbDescriptorParser.DEBUG) { Log.d(TAG, "----> " + getDescriptorName(descriptorType, descriptorLength)); } } } Loading
services/usb/java/com/android/server/usb/descriptors/ByteStream.java +5 −2 Original line number Diff line number Diff line Loading @@ -185,12 +185,14 @@ public final class ByteStream { // Positive offsets only throw new IllegalArgumentException(); } // do arithmetic and comparison in long to ovoid potention integer overflow // do arithmetic and comparison in long to avoid potential integer overflow long longNewIndex = (long) mIndex + (long) numBytes; if (longNewIndex < (long) mBytes.length) { if (longNewIndex <= (long) mBytes.length) { mReadCount += numBytes; mIndex += numBytes; } else { // Position the stream to the end so available() will return 0 mIndex = mBytes.length; throw new IndexOutOfBoundsException(); } } Loading @@ -210,6 +212,7 @@ public final class ByteStream { mReadCount -= numBytes; mIndex -= numBytes; } else { mIndex = 0; throw new IndexOutOfBoundsException(); } } Loading
services/usb/java/com/android/server/usb/descriptors/UsbACEndpoint.java +9 −1 Original line number Diff line number Diff line Loading @@ -45,7 +45,6 @@ abstract class UsbACEndpoint extends UsbDescriptor { @Override public int parseRawDescriptors(ByteStream stream) { mSubtype = stream.getByte(); return mLength; } Loading @@ -55,12 +54,21 @@ abstract class UsbACEndpoint extends UsbDescriptor { int subClass = interfaceDesc.getUsbSubclass(); switch (subClass) { case AUDIO_AUDIOCONTROL: if (UsbDescriptorParser.DEBUG) { Log.d(TAG, "---> AUDIO_AUDIOCONTROL"); } return new UsbACAudioControlEndpoint(length, type, subClass); case AUDIO_AUDIOSTREAMING: if (UsbDescriptorParser.DEBUG) { Log.d(TAG, "---> AUDIO_AUDIOSTREAMING"); } return new UsbACAudioStreamEndpoint(length, type, subClass); case AUDIO_MIDISTREAMING: if (UsbDescriptorParser.DEBUG) { Log.d(TAG, "---> AUDIO_MIDISTREAMING"); } return new UsbACMidiEndpoint(length, type, subClass); default: Loading
services/usb/java/com/android/server/usb/descriptors/UsbACInterface.java +39 −0 Original line number Diff line number Diff line Loading @@ -100,8 +100,14 @@ public abstract class UsbACInterface extends UsbDescriptor { switch (subtype) { case ACI_HEADER: { if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " ---> ACI_HEADER"); } int acInterfaceSpec = stream.unpackUsbShort(); parser.setACInterfaceSpec(acInterfaceSpec); if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " acInterfaceSpec:0x" + Integer.toHexString(acInterfaceSpec)); } if (acInterfaceSpec == UsbDeviceDescriptor.USBSPEC_2_0) { return new Usb20ACHeader(length, type, subtype, subClass, acInterfaceSpec); } else { Loading @@ -111,7 +117,13 @@ public abstract class UsbACInterface extends UsbDescriptor { case ACI_INPUT_TERMINAL: { if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " ---> ACI_INPUT_TERMINAL"); } int acInterfaceSpec = parser.getACInterfaceSpec(); if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " acInterfaceSpec:0x" + Integer.toHexString(acInterfaceSpec)); } if (acInterfaceSpec == UsbDeviceDescriptor.USBSPEC_2_0) { return new Usb20ACInputTerminal(length, type, subtype, subClass); } else { Loading @@ -121,7 +133,13 @@ public abstract class UsbACInterface extends UsbDescriptor { case ACI_OUTPUT_TERMINAL: { if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " ---> ACI_OUTPUT_TERMINAL"); } int acInterfaceSpec = parser.getACInterfaceSpec(); if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " acInterfaceSpec:0x" + Integer.toHexString(acInterfaceSpec)); } if (acInterfaceSpec == UsbDeviceDescriptor.USBSPEC_2_0) { return new Usb20ACOutputTerminal(length, type, subtype, subClass); } else { Loading @@ -130,14 +148,26 @@ public abstract class UsbACInterface extends UsbDescriptor { } case ACI_SELECTOR_UNIT: if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " ---> ACI_SELECTOR_UNIT"); } return new UsbACSelectorUnit(length, type, subtype, subClass); case ACI_FEATURE_UNIT: if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " ---> ACI_FEATURE_UNIT"); } return new UsbACFeatureUnit(length, type, subtype, subClass); case ACI_MIXER_UNIT: { if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " ---> ACI_MIXER_UNIT"); } int acInterfaceSpec = parser.getACInterfaceSpec(); if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " acInterfaceSpec:0x" + Integer.toHexString(acInterfaceSpec)); } if (acInterfaceSpec == UsbDeviceDescriptor.USBSPEC_2_0) { return new Usb20ACMixerUnit(length, type, subtype, subClass); } else { Loading Loading @@ -215,14 +245,23 @@ public abstract class UsbACInterface extends UsbDescriptor { int subClass = interfaceDesc.getUsbSubclass(); switch (subClass) { case AUDIO_AUDIOCONTROL: if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " AUDIO_AUDIOCONTROL"); } return allocAudioControlDescriptor( parser, stream, length, type, subtype, subClass); case AUDIO_AUDIOSTREAMING: if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " AUDIO_AUDIOSTREAMING"); } return allocAudioStreamingDescriptor( parser, stream, length, type, subtype, subClass); case AUDIO_MIDISTREAMING: if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " AUDIO_MIDISTREAMING"); } return allocMidiStreamingDescriptor(length, type, subtype, subClass); default: Loading
services/usb/java/com/android/server/usb/descriptors/UsbConfigDescriptor.java +2 −3 Original line number Diff line number Diff line Loading @@ -30,7 +30,6 @@ import java.util.ArrayList; */ public final class UsbConfigDescriptor extends UsbDescriptor { private static final String TAG = "UsbConfigDescriptor"; private static final boolean DEBUG = false; private int mTotalLength; // 2:2 Total length in bytes of data returned private byte mNumInterfaces; // 4:1 Number of Interfaces Loading Loading @@ -79,14 +78,14 @@ public final class UsbConfigDescriptor extends UsbDescriptor { } UsbConfiguration toAndroid(UsbDescriptorParser parser) { if (DEBUG) { if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " toAndroid()"); } String name = parser.getDescriptorString(mConfigIndex); UsbConfiguration config = new UsbConfiguration(mConfigValue, name, mAttribs, mMaxPower); UsbInterface[] interfaces = new UsbInterface[mInterfaceDescriptors.size()]; if (DEBUG) { if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " " + mInterfaceDescriptors.size() + " interfaces."); } for (int index = 0; index < mInterfaceDescriptors.size(); index++) { Loading
services/usb/java/com/android/server/usb/descriptors/UsbDescriptor.java +61 −42 Original line number Diff line number Diff line Loading @@ -78,8 +78,8 @@ public abstract class UsbDescriptor implements Reporting { public static final byte DESCRIPTORTYPE_HID = 0x21; // 33 public static final byte DESCRIPTORTYPE_REPORT = 0x22; // 34 public static final byte DESCRIPTORTYPE_PHYSICAL = 0x23; // 35 public static final byte DESCRIPTORTYPE_AUDIO_INTERFACE = 0x24; // 36 public static final byte DESCRIPTORTYPE_AUDIO_ENDPOINT = 0x25; // 37 public static final byte DESCRIPTORTYPE_CLASSSPECIFIC_INTERFACE = 0x24; // 36 public static final byte DESCRIPTORTYPE_CLASSSPECIFIC_ENDPOINT = 0x25; // 37 public static final byte DESCRIPTORTYPE_HUB = 0x29; // 41 public static final byte DESCRIPTORTYPE_SUPERSPEED_HUB = 0x2A; // 42 public static final byte DESCRIPTORTYPE_ENDPOINT_COMPANION = 0x30; // 48 Loading Loading @@ -163,7 +163,6 @@ public abstract class UsbDescriptor implements Reporting { public int getOverUnderRunCount() { return mOverUnderRunCount; } public String getStatusString() { return sStatusStrings[mStatus]; } Loading Loading @@ -278,4 +277,24 @@ public abstract class UsbDescriptor implements Reporting { + " Len: " + getLength(); canvas.writeParagraph(text, false); } /* * Logging Helpers */ static String getDescriptorName(byte descriptorType, int descriptorLength) { String name = UsbStrings.getDescriptorName(descriptorType); if (name != null) { return name; } else { return "Unknown Descriptor Type " + descriptorType + " 0x" + Integer.toHexString(descriptorType) + " length:" + descriptorLength; } } static void logDescriptorName(byte descriptorType, int descriptorLength) { if (UsbDescriptorParser.DEBUG) { Log.d(TAG, "----> " + getDescriptorName(descriptorType, descriptorLength)); } } }