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.UsbConfigDescriptor; 19 import com.android.server.usb.descriptors.report.ReportCanvas; 20 21 import java.util.ArrayList; 22 23 /** 24 * @hide 25 * Represents a configuration in the descriptors tree. 26 */ 27 public final class UsbDescriptorsConfigNode extends UsbDescriptorsTreeNode { 28 private static final String TAG = "UsbDescriptorsConfigNode"; 29 30 private final UsbConfigDescriptor mConfigDescriptor; 31 32 private final ArrayList<UsbDescriptorsInterfaceNode> mInterfaceNodes = new ArrayList<>(); 33 34 /** 35 * Constructor. 36 * @param configDescriptor The Config Descriptor object wrapped by this tree node. 37 */ UsbDescriptorsConfigNode(UsbConfigDescriptor configDescriptor)38 public UsbDescriptorsConfigNode(UsbConfigDescriptor configDescriptor) { 39 mConfigDescriptor = configDescriptor; 40 } 41 42 /** 43 * Adds the inteface node logical contained in this configuration. 44 * @param interfaceNode The inteface treenode to assocate with this configuration. 45 */ addInterfaceNode(UsbDescriptorsInterfaceNode interfaceNode)46 public void addInterfaceNode(UsbDescriptorsInterfaceNode interfaceNode) { 47 mInterfaceNodes.add(interfaceNode); 48 } 49 50 @Override report(ReportCanvas canvas)51 public void report(ReportCanvas canvas) { 52 mConfigDescriptor.report(canvas); 53 54 canvas.openList(); 55 56 // Interfaces 57 for (UsbDescriptorsInterfaceNode node : mInterfaceNodes) { 58 node.report(canvas); 59 } 60 61 canvas.closeList(); 62 } 63 } 64