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  * A USB HID (Human Interface Descriptor).
     23  * see HID1_11.pdf - 6.2.1
     24  */
     25 public final class UsbHIDDescriptor extends UsbDescriptor {
     26     private static final String TAG = "UsbHIDDescriptor";
     27 
     28     private int mRelease;           // 2:2 the HID Class Specification release.
     29     private byte mCountryCode;      // 4:1 country code of the localized hardware.
     30     private byte mNumDescriptors;   // number of descriptors (always at least one
     31                                     // i.e. Report descriptor.)
     32     private byte mDescriptorType;   // 6:1 type of class descriptor.
     33                                     // See Section 7.1.2: Set_Descriptor
     34                                     // Request for a table of class descriptor constants.
     35     private int mDescriptorLen;     // 7:2 Numeric expression that is the total size of
     36                                     // the Report descriptor.
     37 
     38     public UsbHIDDescriptor(int length, byte type) {
     39         super(length, type);
     40         mHierarchyLevel = 3;
     41     }
     42 
     43     public int getRelease() {
     44         return mRelease;
     45     }
     46 
     47     public byte getCountryCode() {
     48         return mCountryCode;
     49     }
     50 
     51     public byte getNumDescriptors() {
     52         return mNumDescriptors;
     53     }
     54 
     55     public byte getDescriptorType() {
     56         return mDescriptorType;
     57     }
     58 
     59     public int getDescriptorLen() {
     60         return mDescriptorLen;
     61     }
     62 
     63     @Override
     64     public int parseRawDescriptors(ByteStream stream) {
     65         mRelease = stream.unpackUsbShort();
     66         mCountryCode = stream.getByte();
     67         mNumDescriptors = stream.getByte();
     68         mDescriptorType = stream.getByte();
     69         mDescriptorLen = stream.unpackUsbShort();
     70 
     71         return mLength;
     72     }
     73 
     74     @Override
     75     public void report(ReportCanvas canvas) {
     76         super.report(canvas);
     77 
     78         canvas.openList();
     79         canvas.writeListItem("Spec: " + ReportCanvas.getBCDString(getRelease()));
     80         canvas.writeListItem("Type: " + ReportCanvas.getBCDString(getDescriptorType()));
     81         canvas.writeListItem("" + getNumDescriptors() + " Descriptors Len: "
     82                 + getDescriptorLen());
     83         canvas.closeList();
     84     }
     85 }
     86