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 
51     @Override
parseRawDescriptors(ByteStream stream)52     public int parseRawDescriptors(ByteStream stream) {
53         mTerminalID = stream.getByte();
54         mTerminalType = stream.unpackUsbShort();
55         mAssocTerminal = stream.getByte();
56 
57         return mLength;
58     }
59 
60     @Override
report(ReportCanvas canvas)61     public void report(ReportCanvas canvas) {
62         super.report(canvas);
63 
64         canvas.openList();
65         int terminalType = getTerminalType();
66         canvas.writeListItem("Type: " + ReportCanvas.getHexString(terminalType) + ": "
67                 + UsbStrings.getTerminalName(terminalType));
68         canvas.writeListItem("ID: " + ReportCanvas.getHexString(getTerminalID()));
69         canvas.closeList();
70     }
71 }
72