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.tree; 17 18 import com.android.server.usb.descriptors.UsbInterfaceDescriptor; 19 import com.android.server.usb.descriptors.report.ReportCanvas; 20 21 import java.util.ArrayList; 22 23 /** 24 * @hide 25 * Represents an interface in the descriptors tree. 26 */ 27 public final class UsbDescriptorsInterfaceNode extends UsbDescriptorsTreeNode { 28 private static final String TAG = "UsbDescriptorsInterfaceNode"; 29 30 private final UsbInterfaceDescriptor mInterfaceDescriptor; 31 32 private final ArrayList<UsbDescriptorsEndpointNode> mEndpointNodes = new ArrayList<>(); 33 private final ArrayList<UsbDescriptorsACInterfaceNode> mACInterfaceNodes = new ArrayList<>(); 34 35 /** 36 * Constructor. 37 * @param interfaceDescriptor The Interface Descriptor object wrapped by this tree node. 38 */ UsbDescriptorsInterfaceNode(UsbInterfaceDescriptor interfaceDescriptor)39 public UsbDescriptorsInterfaceNode(UsbInterfaceDescriptor interfaceDescriptor) { 40 mInterfaceDescriptor = interfaceDescriptor; 41 } 42 43 /** 44 * Adds an endpoint descriptor as a child of this interface node. 45 * @param endpointNode The endpoint descriptor node to add to this interface node. 46 */ addEndpointNode(UsbDescriptorsEndpointNode endpointNode)47 public void addEndpointNode(UsbDescriptorsEndpointNode endpointNode) { 48 mEndpointNodes.add(endpointNode); 49 } 50 51 /** 52 * Adds an Audio-class interface descriptor as a child of this interface node. 53 * @param acInterfaceNode The audio-class descriptor node to add to this interface node. 54 */ addACInterfaceNode(UsbDescriptorsACInterfaceNode acInterfaceNode)55 public void addACInterfaceNode(UsbDescriptorsACInterfaceNode acInterfaceNode) { 56 mACInterfaceNodes.add(acInterfaceNode); 57 } 58 59 @Override report(ReportCanvas canvas)60 public void report(ReportCanvas canvas) { 61 mInterfaceDescriptor.report(canvas); 62 63 // Audio Class Interfaces 64 if (mACInterfaceNodes.size() > 0) { 65 canvas.writeParagraph("Audio Class Interfaces", false); 66 canvas.openList(); 67 for (UsbDescriptorsACInterfaceNode node : mACInterfaceNodes) { 68 node.report(canvas); 69 } 70 canvas.closeList(); 71 } 72 73 // Endpoints 74 if (mEndpointNodes.size() > 0) { 75 canvas.writeParagraph("Endpoints", false); 76 canvas.openList(); 77 for (UsbDescriptorsEndpointNode node : mEndpointNodes) { 78 node.report(canvas); 79 } 80 canvas.closeList(); 81 } 82 } 83 } 84