Home | History | Annotate | Download | only in descriptors
      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 
     20 /**
     21  * @hide
     22  * An audio class-specific Interface Header.
     23  * see audio10.pdf section 4.3.2
     24  */
     25 public final class Usb10ACHeader extends UsbACHeaderInterface {
     26     private static final String TAG = "Usb10ACHeader";
     27 
     28     private byte mNumInterfaces = 0; // 7:1 The number of AudioStreaming and MIDIStreaming
     29                                      // interfaces in the Audio Interface Collection to which this
     30                                      // AudioControl interface belongs: n
     31     private byte[] mInterfaceNums = null;   // 8:n List of Audio/MIDI streaming interface
     32                                             // numbers associate with this endpoint
     33     private byte mControls;                 // Vers 2.0 thing
     34 
     35     public Usb10ACHeader(int length, byte type, byte subtype, int subclass, int spec) {
     36         super(length, type, subtype, subclass, spec);
     37     }
     38 
     39     public byte getNumInterfaces() {
     40         return mNumInterfaces;
     41     }
     42 
     43     public byte[] getInterfaceNums() {
     44         return mInterfaceNums;
     45     }
     46 
     47     public byte getControls() {
     48         return mControls;
     49     }
     50 
     51     @Override
     52     public int parseRawDescriptors(ByteStream stream) {
     53 
     54         mTotalLength = stream.unpackUsbShort();
     55         if (mADCRelease >= 0x200) {
     56             mControls = stream.getByte();
     57         } else {
     58             mNumInterfaces = stream.getByte();
     59             mInterfaceNums = new byte[mNumInterfaces];
     60             for (int index = 0; index < mNumInterfaces; index++) {
     61                 mInterfaceNums[index] = stream.getByte();
     62             }
     63         }
     64 
     65         return mLength;
     66     }
     67 
     68     @Override
     69     public void report(ReportCanvas canvas) {
     70         super.report(canvas);
     71 
     72         canvas.openList();
     73         int numInterfaces = getNumInterfaces();
     74         StringBuilder sb = new StringBuilder();
     75         sb.append("" + numInterfaces + " Interfaces");
     76         if (numInterfaces > 0) {
     77             sb.append(" [");
     78             byte[] interfaceNums = getInterfaceNums();
     79             if (interfaceNums != null) {
     80                 for (int index = 0; index < numInterfaces; index++) {
     81                     sb.append("" + interfaceNums[index]);
     82                     if (index < numInterfaces - 1) {
     83                         sb.append(" ");
     84                     }
     85                 }
     86             }
     87             sb.append("]");
     88         }
     89         canvas.writeListItem(sb.toString());
     90         canvas.writeListItem("Controls: " + ReportCanvas.getHexString(getControls()));
     91         canvas.closeList();
     92     }
     93 }
     94