1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.server.usb.descriptors; 17 18 import com.android.server.usb.descriptors.report.ReportCanvas; 19 import com.android.server.usb.descriptors.report.UsbStrings; 20 21 /** 22 * @hide 23 */ 24 public abstract class UsbACTerminal extends UsbACInterface { 25 private static final String TAG = "UsbACTerminal"; 26 27 // Note that these fields are the same for both the 28 // audio class-specific Output Terminal Interface.(audio10.pdf section 4.3.2.2) 29 // and audio class-specific Input Terminal interface.(audio10.pdf section 4.3.2.1) 30 // so we may as well unify the parsing here. 31 protected byte mTerminalID; // 3:1 ID of this Output Terminal. (0x02) 32 protected int mTerminalType; // 4:2 USB Streaming. (0x0101) 33 protected byte mAssocTerminal; // 6:1 Unused (0x00) 34 UsbACTerminal(int length, byte type, byte subtype, int subclass)35 public UsbACTerminal(int length, byte type, byte subtype, int subclass) { 36 super(length, type, subtype, subclass); 37 } 38 getTerminalID()39 public byte getTerminalID() { 40 return mTerminalID; 41 } 42 getTerminalType()43 public int getTerminalType() { 44 return mTerminalType; 45 } 46 getAssocTerminal()47 public byte getAssocTerminal() { 48 return mAssocTerminal; 49 } 50 isInputTerminal()51 public boolean isInputTerminal() { 52 return mTerminalType == UsbTerminalTypes.TERMINAL_IN_MIC 53 || mTerminalType == UsbTerminalTypes.TERMINAL_BIDIR_HEADSET 54 || mTerminalType == UsbTerminalTypes.TERMINAL_BIDIR_UNDEFINED 55 || mTerminalType == UsbTerminalTypes.TERMINAL_EXTERN_LINE; 56 } 57 58 @Override parseRawDescriptors(ByteStream stream)59 public int parseRawDescriptors(ByteStream stream) { 60 mTerminalID = stream.getByte(); 61 mTerminalType = stream.unpackUsbShort(); 62 mAssocTerminal = stream.getByte(); 63 64 return mLength; 65 } 66 67 @Override report(ReportCanvas canvas)68 public void report(ReportCanvas canvas) { 69 super.report(canvas); 70 71 canvas.openList(); 72 int terminalType = getTerminalType(); 73 canvas.writeListItem("Type: " + ReportCanvas.getHexString(terminalType) + ": " 74 + UsbStrings.getTerminalName(terminalType)); 75 canvas.writeListItem("ID: " + ReportCanvas.getHexString(getTerminalID())); 76 canvas.writeListItem("Associated terminal: " 77 + ReportCanvas.getHexString(getAssocTerminal())); 78 canvas.closeList(); 79 } 80 } 81