diff options
author | Paul McLean <pmclean@google.com> | 2019-08-07 09:13:14 -0600 |
---|---|---|
committer | Paul McLean <pmclean@google.com> | 2019-08-21 14:14:32 -0600 |
commit | a51ae9b5ab550c68d74ed1dc564b89ec1bbfa627 (patch) | |
tree | 06e0c86aa1524d4bebaf724c935a6d36aadf5e33 /services/usb/java | |
parent | 922859af1d5df5e04e0adc87332aa3bbc57e0f14 (diff) |
Fixing UsbDescriptorParser errors associated with video cameras.
Added framework to (eventually) parse video interface descriptors,
but at least not report errors/warnings when encountering them.
Centralizing control of logging towards making it a run-time option.
Bug: 124374863
Test: build, flash, connect USB device, pull and examine log...
run "adb shell dumpsys usb dump-descriptors -dump-list",
examine output, use device with JavaRecorder app.
Change-Id: I5d039b51c321d6ceb33a803f78e71f00908f1d69
Diffstat (limited to 'services/usb/java')
13 files changed, 357 insertions, 78 deletions
diff --git a/services/usb/java/com/android/server/usb/descriptors/ByteStream.java b/services/usb/java/com/android/server/usb/descriptors/ByteStream.java index 1e823b63d5b2..56dc3e05a240 100644 --- a/services/usb/java/com/android/server/usb/descriptors/ByteStream.java +++ b/services/usb/java/com/android/server/usb/descriptors/ByteStream.java @@ -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(); } } @@ -210,6 +212,7 @@ public final class ByteStream { mReadCount -= numBytes; mIndex -= numBytes; } else { + mIndex = 0; throw new IndexOutOfBoundsException(); } } diff --git a/services/usb/java/com/android/server/usb/descriptors/UsbACEndpoint.java b/services/usb/java/com/android/server/usb/descriptors/UsbACEndpoint.java index 7ebccf39868c..0535d717222e 100644 --- a/services/usb/java/com/android/server/usb/descriptors/UsbACEndpoint.java +++ b/services/usb/java/com/android/server/usb/descriptors/UsbACEndpoint.java @@ -45,7 +45,6 @@ abstract class UsbACEndpoint extends UsbDescriptor { @Override public int parseRawDescriptors(ByteStream stream) { mSubtype = stream.getByte(); - return mLength; } @@ -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: diff --git a/services/usb/java/com/android/server/usb/descriptors/UsbACInterface.java b/services/usb/java/com/android/server/usb/descriptors/UsbACInterface.java index 38c12a1f6c16..82fbfb89c498 100644 --- a/services/usb/java/com/android/server/usb/descriptors/UsbACInterface.java +++ b/services/usb/java/com/android/server/usb/descriptors/UsbACInterface.java @@ -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 { @@ -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 { @@ -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 { @@ -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 { @@ -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: diff --git a/services/usb/java/com/android/server/usb/descriptors/UsbConfigDescriptor.java b/services/usb/java/com/android/server/usb/descriptors/UsbConfigDescriptor.java index 639aa4e03849..de2dd101acfd 100644 --- a/services/usb/java/com/android/server/usb/descriptors/UsbConfigDescriptor.java +++ b/services/usb/java/com/android/server/usb/descriptors/UsbConfigDescriptor.java @@ -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 @@ -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++) { diff --git a/services/usb/java/com/android/server/usb/descriptors/UsbDescriptor.java b/services/usb/java/com/android/server/usb/descriptors/UsbDescriptor.java index ff67667e848d..44422a2d4603 100644 --- a/services/usb/java/com/android/server/usb/descriptors/UsbDescriptor.java +++ b/services/usb/java/com/android/server/usb/descriptors/UsbDescriptor.java @@ -43,7 +43,7 @@ public abstract class UsbDescriptor implements Reporting { protected int mHierarchyLevel; protected final int mLength; // 0:1 bLength Number Size of the Descriptor in Bytes (18 bytes) - // we store this as an int because Java bytes are SIGNED. + // we store this as an int because Java bytes are SIGNED. protected final byte mType; // 1:1 bDescriptorType Constant Device Descriptor (0x01) private byte[] mRawData; @@ -52,11 +52,11 @@ public abstract class UsbDescriptor implements Reporting { private static byte[] sStringBuffer = new byte[SIZE_STRINGBUFFER]; // Status - public static final int STATUS_UNPARSED = 0; - public static final int STATUS_PARSED_OK = 1; - public static final int STATUS_PARSED_UNDERRUN = 2; - public static final int STATUS_PARSED_OVERRUN = 3; - public static final int STATUS_PARSE_EXCEPTION = 4; + public static final int STATUS_UNPARSED = 0; + public static final int STATUS_PARSED_OK = 1; + public static final int STATUS_PARSED_UNDERRUN = 2; + public static final int STATUS_PARSED_OVERRUN = 3; + public static final int STATUS_PARSE_EXCEPTION = 4; private int mStatus = STATUS_UNPARSED; @@ -78,53 +78,53 @@ 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 // Class IDs - public static final int CLASSID_DEVICE = 0x00; - public static final int CLASSID_AUDIO = 0x01; - public static final int CLASSID_COM = 0x02; - public static final int CLASSID_HID = 0x03; + public static final int CLASSID_DEVICE = 0x00; + public static final int CLASSID_AUDIO = 0x01; + public static final int CLASSID_COM = 0x02; + public static final int CLASSID_HID = 0x03; // public static final int CLASSID_??? = 0x04; - public static final int CLASSID_PHYSICAL = 0x05; - public static final int CLASSID_IMAGE = 0x06; - public static final int CLASSID_PRINTER = 0x07; - public static final int CLASSID_STORAGE = 0x08; - public static final int CLASSID_HUB = 0x09; - public static final int CLASSID_CDC_CONTROL = 0x0A; - public static final int CLASSID_SMART_CARD = 0x0B; + public static final int CLASSID_PHYSICAL = 0x05; + public static final int CLASSID_IMAGE = 0x06; + public static final int CLASSID_PRINTER = 0x07; + public static final int CLASSID_STORAGE = 0x08; + public static final int CLASSID_HUB = 0x09; + public static final int CLASSID_CDC_CONTROL = 0x0A; + public static final int CLASSID_SMART_CARD = 0x0B; //public static final int CLASSID_??? = 0x0C; - public static final int CLASSID_SECURITY = 0x0D; - public static final int CLASSID_VIDEO = 0x0E; - public static final int CLASSID_HEALTHCARE = 0x0F; - public static final int CLASSID_AUDIOVIDEO = 0x10; - public static final int CLASSID_BILLBOARD = 0x11; - public static final int CLASSID_TYPECBRIDGE = 0x12; - public static final int CLASSID_DIAGNOSTIC = 0xDC; - public static final int CLASSID_WIRELESS = 0xE0; - public static final int CLASSID_MISC = 0xEF; - public static final int CLASSID_APPSPECIFIC = 0xFE; + public static final int CLASSID_SECURITY = 0x0D; + public static final int CLASSID_VIDEO = 0x0E; + public static final int CLASSID_HEALTHCARE = 0x0F; + public static final int CLASSID_AUDIOVIDEO = 0x10; + public static final int CLASSID_BILLBOARD = 0x11; + public static final int CLASSID_TYPECBRIDGE = 0x12; + public static final int CLASSID_DIAGNOSTIC = 0xDC; + public static final int CLASSID_WIRELESS = 0xE0; + public static final int CLASSID_MISC = 0xEF; + public static final int CLASSID_APPSPECIFIC = 0xFE; public static final int CLASSID_VENDSPECIFIC = 0xFF; // Audio Subclass codes - public static final int AUDIO_SUBCLASS_UNDEFINED = 0x00; - public static final int AUDIO_AUDIOCONTROL = 0x01; - public static final int AUDIO_AUDIOSTREAMING = 0x02; - public static final int AUDIO_MIDISTREAMING = 0x03; + public static final int AUDIO_SUBCLASS_UNDEFINED = 0x00; + public static final int AUDIO_AUDIOCONTROL = 0x01; + public static final int AUDIO_AUDIOSTREAMING = 0x02; + public static final int AUDIO_MIDISTREAMING = 0x03; // Request IDs - public static final int REQUEST_GET_STATUS = 0x00; - public static final int REQUEST_CLEAR_FEATURE = 0x01; - public static final int REQUEST_SET_FEATURE = 0x03; - public static final int REQUEST_GET_ADDRESS = 0x05; - public static final int REQUEST_GET_DESCRIPTOR = 0x06; - public static final int REQUEST_SET_DESCRIPTOR = 0x07; - public static final int REQUEST_GET_CONFIGURATION = 0x08; - public static final int REQUEST_SET_CONFIGURATION = 0x09; + public static final int REQUEST_GET_STATUS = 0x00; + public static final int REQUEST_CLEAR_FEATURE = 0x01; + public static final int REQUEST_SET_FEATURE = 0x03; + public static final int REQUEST_GET_ADDRESS = 0x05; + public static final int REQUEST_GET_DESCRIPTOR = 0x06; + public static final int REQUEST_SET_DESCRIPTOR = 0x07; + public static final int REQUEST_GET_CONFIGURATION = 0x08; + public static final int REQUEST_SET_CONFIGURATION = 0x09; // USB control transfer timeout public static final int USB_CONTROL_TRANSFER_TIMEOUT_MS = 200; @@ -163,7 +163,6 @@ public abstract class UsbDescriptor implements Reporting { public int getOverUnderRunCount() { return mOverUnderRunCount; } - public String getStatusString() { return sStatusStrings[mStatus]; } @@ -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)); + } + } } 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 c02110186d8d..4f62d5a5c967 100644 --- a/services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java +++ b/services/usb/java/com/android/server/usb/descriptors/UsbDescriptorParser.java @@ -26,7 +26,7 @@ import java.util.ArrayList; */ public final class UsbDescriptorParser { private static final String TAG = "UsbDescriptorParser"; - private static final boolean DEBUG = false; + public static final boolean DEBUG = false; private final String mDeviceAddr; @@ -115,6 +115,8 @@ public final class UsbDescriptorParser { int length = stream.getUnsignedByte(); byte type = stream.getByte(); + UsbDescriptor.logDescriptorName(type, length); + UsbDescriptor descriptor = null; switch (type) { /* @@ -174,14 +176,56 @@ public final class UsbDescriptorParser { break; /* - * Audio Class Specific + * Various Class Specific */ - case UsbDescriptor.DESCRIPTORTYPE_AUDIO_INTERFACE: - descriptor = UsbACInterface.allocDescriptor(this, stream, length, type); + case UsbDescriptor.DESCRIPTORTYPE_CLASSSPECIFIC_INTERFACE: + if (mCurInterfaceDescriptor != null) { + switch (mCurInterfaceDescriptor.getUsbClass()) { + case UsbDescriptor.CLASSID_AUDIO: + descriptor = UsbACInterface.allocDescriptor(this, stream, length, type); + break; + + case UsbDescriptor.CLASSID_VIDEO: + Log.d(TAG, " UsbDescriptor.CLASSID_VIDEO subType:0x" + + Integer.toHexString(stream.getByte())); + descriptor = UsbVCInterface.allocDescriptor(this, stream, length, type); + break; + + case UsbDescriptor.CLASSID_AUDIOVIDEO: + Log.d(TAG, " UsbDescriptor.CLASSID_AUDIOVIDEO subType:0x" + + Integer.toHexString(stream.getByte())); + break; + + default: + Log.d(TAG, " Unparsed Class-specific Interface:0x" + + Integer.toHexString(mCurInterfaceDescriptor.getUsbClass())); + break; + } + } break; - case UsbDescriptor.DESCRIPTORTYPE_AUDIO_ENDPOINT: - descriptor = UsbACEndpoint.allocDescriptor(this, length, type); + case UsbDescriptor.DESCRIPTORTYPE_CLASSSPECIFIC_ENDPOINT: + if (mCurInterfaceDescriptor != null) { + switch (mCurInterfaceDescriptor.getUsbClass()) { + case UsbDescriptor.CLASSID_AUDIO: + descriptor = UsbACEndpoint.allocDescriptor(this, length, type); + break; + case UsbDescriptor.CLASSID_VIDEO: + Log.d(TAG, "UsbDescriptor.CLASSID_VIDEO subType:0x" + + Integer.toHexString(stream.getByte())); + descriptor = UsbVCEndpoint.allocDescriptor(this, length, type); + break; + + case UsbDescriptor.CLASSID_AUDIOVIDEO: + Log.d(TAG, "UsbDescriptor.CLASSID_AUDIOVIDEO subType:0x" + + Integer.toHexString(stream.getByte())); + break; + default: + Log.d(TAG, " Unparsed Class-specific Endpoint:0x" + + Integer.toHexString(mCurInterfaceDescriptor.getUsbClass())); + break; + } + } break; default: @@ -190,8 +234,6 @@ public final class UsbDescriptorParser { if (descriptor == null) { // Unknown Descriptor - Log.i(TAG, "Unknown Descriptor len: " + length + " type:0x" - + Integer.toHexString(type)); descriptor = new UsbUnknown(length, type); } @@ -210,10 +252,6 @@ public final class UsbDescriptorParser { * @hide */ public void parseDescriptors(byte[] descriptors) { - if (DEBUG) { - Log.d(TAG, "parseDescriptors() - start"); - } - ByteStream stream = new ByteStream(descriptors); while (stream.available() > 0) { UsbDescriptor descriptor = null; @@ -325,8 +363,8 @@ public final class UsbDescriptorParser { public ArrayList<UsbDescriptor> getACInterfaceDescriptors(byte subtype, int subclass) { ArrayList<UsbDescriptor> list = new ArrayList<UsbDescriptor>(); for (UsbDescriptor descriptor : mDescriptors) { - if (descriptor.getType() == UsbDescriptor.DESCRIPTORTYPE_AUDIO_INTERFACE) { - // ensure that this isn't an unrecognized DESCRIPTORTYPE_AUDIO_INTERFACE + if (descriptor.getType() == UsbDescriptor.DESCRIPTORTYPE_CLASSSPECIFIC_INTERFACE) { + // ensure that this isn't an unrecognized DESCRIPTORTYPE_CLASSSPECIFIC_INTERFACE if (descriptor instanceof UsbACInterface) { UsbACInterface acDescriptor = (UsbACInterface) descriptor; if (acDescriptor.getSubtype() == subtype @@ -334,8 +372,8 @@ public final class UsbDescriptorParser { list.add(descriptor); } } else { - Log.w(TAG, "Unrecognized Audio Interface l: " + descriptor.getLength() - + " t:0x" + Integer.toHexString(descriptor.getType())); + Log.w(TAG, "Unrecognized Audio Interface len: " + descriptor.getLength() + + " type:0x" + Integer.toHexString(descriptor.getType())); } } } diff --git a/services/usb/java/com/android/server/usb/descriptors/UsbDeviceDescriptor.java b/services/usb/java/com/android/server/usb/descriptors/UsbDeviceDescriptor.java index f50b9cbc5e3d..e6e10fef9f9a 100644 --- a/services/usb/java/com/android/server/usb/descriptors/UsbDeviceDescriptor.java +++ b/services/usb/java/com/android/server/usb/descriptors/UsbDeviceDescriptor.java @@ -31,7 +31,6 @@ import java.util.ArrayList; */ public final class UsbDeviceDescriptor extends UsbDescriptor { private static final String TAG = "UsbDeviceDescriptor"; - private static final boolean DEBUG = false; public static final int USBSPEC_1_0 = 0x0100; public static final int USBSPEC_1_1 = 0x0110; @@ -136,19 +135,19 @@ public final class UsbDeviceDescriptor extends UsbDescriptor { * @hide */ public UsbDevice.Builder toAndroid(UsbDescriptorParser parser) { - if (DEBUG) { + if (UsbDescriptorParser.DEBUG) { Log.d(TAG, "toAndroid()"); } String mfgName = getMfgString(parser); String prodName = getProductString(parser); - if (DEBUG) { + if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " mfgName:" + mfgName + " prodName:" + prodName); } String versionString = getDeviceReleaseString(); String serialStr = getSerialString(parser); - if (DEBUG) { + if (UsbDescriptorParser.DEBUG) { Log.d(TAG, " versionString:" + versionString + " serialStr:" + serialStr); } diff --git a/services/usb/java/com/android/server/usb/descriptors/UsbEndpointDescriptor.java b/services/usb/java/com/android/server/usb/descriptors/UsbEndpointDescriptor.java index 4da31ea469c3..5eb0a2f75ded 100644 --- a/services/usb/java/com/android/server/usb/descriptors/UsbEndpointDescriptor.java +++ b/services/usb/java/com/android/server/usb/descriptors/UsbEndpointDescriptor.java @@ -27,7 +27,6 @@ import com.android.server.usb.descriptors.report.ReportCanvas; */ public class UsbEndpointDescriptor extends UsbDescriptor { private static final String TAG = "UsbEndpointDescriptor"; - private static final boolean DEBUG = false; public static final int MASK_ENDPOINT_ADDRESS = 0b000000000001111; public static final int MASK_ENDPOINT_DIRECTION = (byte) 0b0000000010000000; @@ -110,7 +109,7 @@ public class UsbEndpointDescriptor extends UsbDescriptor { } /* package */ UsbEndpoint toAndroid(UsbDescriptorParser parser) { - if (DEBUG) { + if (UsbDescriptorParser.DEBUG) { Log.d(TAG, "toAndroid() type:" + Integer.toHexString(mAttributes & MASK_ATTRIBS_TRANSTYPE) + " sync:" + Integer.toHexString(mAttributes & MASK_ATTRIBS_SYNCTYPE) diff --git a/services/usb/java/com/android/server/usb/descriptors/UsbInterfaceDescriptor.java b/services/usb/java/com/android/server/usb/descriptors/UsbInterfaceDescriptor.java index 632e3dc500fa..1dc6069bbb0a 100644 --- a/services/usb/java/com/android/server/usb/descriptors/UsbInterfaceDescriptor.java +++ b/services/usb/java/com/android/server/usb/descriptors/UsbInterfaceDescriptor.java @@ -31,7 +31,6 @@ import java.util.ArrayList; */ public class UsbInterfaceDescriptor extends UsbDescriptor { private static final String TAG = "UsbInterfaceDescriptor"; - private static final boolean DEBUG = false; protected int mInterfaceNumber; // 2:1 Number of Interface protected byte mAlternateSetting; // 3:1 Value used to select alternative setting @@ -95,7 +94,7 @@ public class UsbInterfaceDescriptor extends UsbDescriptor { } UsbInterface toAndroid(UsbDescriptorParser parser) { - if (DEBUG) { + if (UsbDescriptorParser.DEBUG) { Log.d(TAG, "toAndroid() class:" + Integer.toHexString(mUsbClass) + " subclass:" + Integer.toHexString(mUsbSubclass) + " " + mEndpointDescriptors.size() + " endpoints."); diff --git a/services/usb/java/com/android/server/usb/descriptors/UsbVCEndpoint.java b/services/usb/java/com/android/server/usb/descriptors/UsbVCEndpoint.java new file mode 100644 index 000000000000..39fbc0d50b87 --- /dev/null +++ b/services/usb/java/com/android/server/usb/descriptors/UsbVCEndpoint.java @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.server.usb.descriptors; + +import android.util.Log; + +/** + * @hide + * A video class-specific Endpoint + * see + */ +abstract class UsbVCEndpoint extends UsbDescriptor { + private static final String TAG = "UsbVCEndpoint"; + + UsbVCEndpoint(int length, byte type, int subclass) { + super(length, type); + // mSubclass = subclass; + } + + public static UsbDescriptor allocDescriptor(UsbDescriptorParser parser, + int length, byte type) { + UsbInterfaceDescriptor interfaceDesc = parser.getCurInterface(); + int subClass = interfaceDesc.getUsbSubclass(); + switch (subClass) { +// case AUDIO_AUDIOCONTROL: +// if (UsbDescriptorParser.DEBUG) { +// Log.i(TAG, "---> AUDIO_AUDIOCONTROL"); +// } +// return new UsbACAudioControlEndpoint(length, type, subClass); +// +// case AUDIO_AUDIOSTREAMING: +// if (UsbDescriptorParser.DEBUG) { +// Log.i(TAG, "---> AUDIO_AUDIOSTREAMING"); +// } +// return new UsbACAudioStreamEndpoint(length, type, subClass); +// +// case AUDIO_MIDISTREAMING: +// if (UsbDescriptorParser.DEBUG) { +// Log.i(TAG, "---> AUDIO_MIDISTREAMING"); +// } +// return new UsbACMidiEndpoint(length, type, subClass); + + default: + Log.w(TAG, "Unknown Video Class Endpoint id:0x" + Integer.toHexString(subClass)); + return null; + } + } +} diff --git a/services/usb/java/com/android/server/usb/descriptors/UsbVCInterface.java b/services/usb/java/com/android/server/usb/descriptors/UsbVCInterface.java new file mode 100644 index 000000000000..c9eb1ec36eb1 --- /dev/null +++ b/services/usb/java/com/android/server/usb/descriptors/UsbVCInterface.java @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2019 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.android.server.usb.descriptors; + +import android.util.Log; + +/** + * @hide + * A video class-specific Interface. + * see USB_Video_Class_1.1.pdf, section 3.7.2 + */ +public abstract class UsbVCInterface extends UsbDescriptor { + private static final String TAG = "UsbVCInterface"; + + // Class-specific Video Subtypes + public static final byte VCI_UNDEFINED = 0x00; + public static final byte VCI_VEADER = 0x01; + public static final byte VCI_INPUT_TERMINAL = 0x02; + public static final byte VCI_VOUTPUT_TERMINAL = 0x03; + public static final byte VCI_SELECTOR_UNIT = 0x04; + public static final byte VCI_VROCESSING_UNIT = 0x05; + public static final byte VCI_VEXTENSION_UNIT = 0x06; + + // See “Universal Serial Bus Device Class Definition for Video + protected final byte mSubtype; // 2:1 HEADER descriptor subtype + protected final int mSubclass; // from the mSubclass member of the + // "enclosing" Interface Descriptor + + public UsbVCInterface(int length, byte type, byte subtype, int subclass) { + super(length, type); + mSubtype = subtype; + mSubclass = subclass; + } + + /** + * Allocates an audio class interface subtype based on subtype and subclass. + */ + public static UsbDescriptor allocDescriptor(UsbDescriptorParser parser, ByteStream stream, + int length, byte type) { + byte subtype = stream.getByte(); + UsbInterfaceDescriptor interfaceDesc = parser.getCurInterface(); + int subClass = interfaceDesc.getUsbSubclass(); + if (UsbDescriptorParser.DEBUG) { + Log.d(TAG, " Video Class-specific Interface subClass:0x" + + Integer.toHexString(subClass)); + } + switch (subClass) { + // TODO - Create descriptor classes and parse these... + case VCI_UNDEFINED: + if (UsbDescriptorParser.DEBUG) { + Log.d(TAG, " ---> VCI_UNDEFINED"); + } + break; + + case VCI_VEADER: + if (UsbDescriptorParser.DEBUG) { + Log.d(TAG, " ---> VCI_VEADER"); + } + break; + + case VCI_INPUT_TERMINAL: + if (UsbDescriptorParser.DEBUG) { + Log.d(TAG, " ---> VCI_INPUT_TERMINAL"); + } + break; + + case VCI_VOUTPUT_TERMINAL: + if (UsbDescriptorParser.DEBUG) { + Log.d(TAG, " ---> VCI_VOUTPUT_TERMINAL"); + } + break; + + case VCI_SELECTOR_UNIT: + if (UsbDescriptorParser.DEBUG) { + Log.d(TAG, " ---> VCI_SELECTOR_UNIT"); + } + break; + + case VCI_VROCESSING_UNIT: + if (UsbDescriptorParser.DEBUG) { + Log.d(TAG, " ---> VCI_VROCESSING_UNIT"); + } + break; + + case VCI_VEXTENSION_UNIT: + if (UsbDescriptorParser.DEBUG) { + Log.d(TAG, " ---> VCI_VEXTENSION_UNIT"); + } + break; + + default: + Log.w(TAG, "Unknown Video Class Interface Subclass: 0x" + + Integer.toHexString(subClass)); + return null; + } + + return null; + } +} diff --git a/services/usb/java/com/android/server/usb/descriptors/report/UsbStrings.java b/services/usb/java/com/android/server/usb/descriptors/report/UsbStrings.java index fb4576a6ee78..918ba2cc9249 100644 --- a/services/usb/java/com/android/server/usb/descriptors/report/UsbStrings.java +++ b/services/usb/java/com/android/server/usb/descriptors/report/UsbStrings.java @@ -56,9 +56,10 @@ public final class UsbStrings { sDescriptorNames.put(UsbDescriptor.DESCRIPTORTYPE_HID, "HID"); sDescriptorNames.put(UsbDescriptor.DESCRIPTORTYPE_REPORT, "Report"); sDescriptorNames.put(UsbDescriptor.DESCRIPTORTYPE_PHYSICAL, "Physical"); - sDescriptorNames.put(UsbDescriptor.DESCRIPTORTYPE_AUDIO_INTERFACE, - "Audio Class Interface"); - sDescriptorNames.put(UsbDescriptor.DESCRIPTORTYPE_AUDIO_ENDPOINT, "Audio Class Endpoint"); + sDescriptorNames.put(UsbDescriptor.DESCRIPTORTYPE_CLASSSPECIFIC_INTERFACE, + "Class-specific Interface"); + sDescriptorNames.put(UsbDescriptor.DESCRIPTORTYPE_CLASSSPECIFIC_ENDPOINT, + "Class-specific Endpoint"); sDescriptorNames.put(UsbDescriptor.DESCRIPTORTYPE_HUB, "Hub"); sDescriptorNames.put(UsbDescriptor.DESCRIPTORTYPE_SUPERSPEED_HUB, "Superspeed Hub"); sDescriptorNames.put(UsbDescriptor.DESCRIPTORTYPE_ENDPOINT_COMPANION, diff --git a/services/usb/java/com/android/server/usb/descriptors/tree/UsbDescriptorsTree.java b/services/usb/java/com/android/server/usb/descriptors/tree/UsbDescriptorsTree.java index 1aa30fa94f42..72fa8977b675 100644 --- a/services/usb/java/com/android/server/usb/descriptors/tree/UsbDescriptorsTree.java +++ b/services/usb/java/com/android/server/usb/descriptors/tree/UsbDescriptorsTree.java @@ -126,11 +126,13 @@ public final class UsbDescriptorsTree { // // Audio Class Descriptors // - case UsbDescriptor.DESCRIPTORTYPE_AUDIO_INTERFACE: - addACInterface((UsbACInterface) descriptor); + case UsbDescriptor.DESCRIPTORTYPE_CLASSSPECIFIC_INTERFACE: + //TODO: This needs to be parsed out to Audio/Video... + // addACInterface((UsbACInterface) descriptor); break; - case UsbDescriptor.DESCRIPTORTYPE_AUDIO_ENDPOINT: + case UsbDescriptor.DESCRIPTORTYPE_CLASSSPECIFIC_ENDPOINT: + //TODO: This needs to be parsed out to Audio/Video... break; } } |