blob: d6c54a8e324bb760ec7c3f9d76927df7d2bc09c4 [file] [log] [blame]
Mike Lockwoode7d511e2010-12-30 13:39:37 -05001/*
2 * Copyright (C) 2010 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
Mike Lockwoodc4308f02011-03-01 08:04:54 -080017package android.hardware.usb;
Mike Lockwoode7d511e2010-12-30 13:39:37 -050018
19import android.os.Bundle;
20import android.os.Parcel;
21import android.os.Parcelable;
22
23/**
Mike Lockwood11dd5ae2011-04-01 14:00:08 -040024 * A class representing an interface on a {@link UsbDevice}.
25 * USB devices can have one or more interfaces, each one providing a different
26 * piece of functionality, separate from the other interfaces.
27 * An interface will have one or more {@link UsbEndpoint}s, which are the
28 * channels by which the host transfers data with the device.
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080029 *
30 * <div class="special reference">
31 * <h3>Developer Guides</h3>
32 * <p>For more information about communicating with USB hardware, read the
33 * <a href="{@docRoot}guide/topics/usb/index.html">USB</a> developer guide.</p>
34 * </div>
Mike Lockwoode7d511e2010-12-30 13:39:37 -050035 */
Mike Lockwoodc4308f02011-03-01 08:04:54 -080036public class UsbInterface implements Parcelable {
Mike Lockwoode7d511e2010-12-30 13:39:37 -050037
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050038 private final int mId;
39 private final int mClass;
40 private final int mSubclass;
41 private final int mProtocol;
42 private final Parcelable[] mEndpoints;
Mike Lockwoode7d511e2010-12-30 13:39:37 -050043
44 /**
45 * UsbInterface should only be instantiated by UsbService implementation
46 * @hide
47 */
48 public UsbInterface(int id, int Class, int subClass, int protocol,
49 Parcelable[] endpoints) {
50 mId = id;
51 mClass = Class;
52 mSubclass = subClass;
53 mProtocol = protocol;
54 mEndpoints = endpoints;
55 }
56
57 /**
58 * Returns the interface's ID field.
Mike Lockwood11dd5ae2011-04-01 14:00:08 -040059 * This is an integer that uniquely identifies the interface on the device.
Mike Lockwoode7d511e2010-12-30 13:39:37 -050060 *
61 * @return the interface's ID
62 */
63 public int getId() {
64 return mId;
65 }
66
67 /**
68 * Returns the interface's class field.
Mike Lockwood11dd5ae2011-04-01 14:00:08 -040069 * Some useful constants for USB classes can be found in {@link UsbConstants}
Mike Lockwoode7d511e2010-12-30 13:39:37 -050070 *
71 * @return the interface's class
72 */
73 public int getInterfaceClass() {
74 return mClass;
75 }
76
77 /**
78 * Returns the interface's subclass field.
79 *
80 * @return the interface's subclass
81 */
82 public int getInterfaceSubclass() {
83 return mSubclass;
84 }
85
86 /**
87 * Returns the interface's protocol field.
88 *
89 * @return the interface's protocol
90 */
91 public int getInterfaceProtocol() {
92 return mProtocol;
93 }
94
95 /**
Mike Lockwoodc4308f02011-03-01 08:04:54 -080096 * Returns the number of {@link android.hardware.usb.UsbEndpoint}s this interface contains.
Mike Lockwoode7d511e2010-12-30 13:39:37 -050097 *
98 * @return the number of endpoints
99 */
100 public int getEndpointCount() {
101 return mEndpoints.length;
102 }
103
104 /**
Mike Lockwoodc4308f02011-03-01 08:04:54 -0800105 * Returns the {@link android.hardware.usb.UsbEndpoint} at the given index.
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500106 *
107 * @return the endpoint
108 */
109 public UsbEndpoint getEndpoint(int index) {
110 return (UsbEndpoint)mEndpoints[index];
111 }
112
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500113 @Override
114 public String toString() {
115 return "UsbInterface[mId=" + mId + ",mClass=" + mClass +
116 ",mSubclass=" + mSubclass + ",mProtocol=" + mProtocol +
117 ",mEndpoints=" + mEndpoints + "]";
118 }
119
120 public static final Parcelable.Creator<UsbInterface> CREATOR =
121 new Parcelable.Creator<UsbInterface>() {
122 public UsbInterface createFromParcel(Parcel in) {
123 int id = in.readInt();
124 int Class = in.readInt();
125 int subClass = in.readInt();
126 int protocol = in.readInt();
127 Parcelable[] endpoints = in.readParcelableArray(UsbEndpoint.class.getClassLoader());
Mike Lockwoodacc29cc2011-03-11 08:18:08 -0500128 return new UsbInterface(id, Class, subClass, protocol, endpoints);
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500129 }
130
131 public UsbInterface[] newArray(int size) {
132 return new UsbInterface[size];
133 }
134 };
135
136 public int describeContents() {
137 return 0;
138 }
139
140 public void writeToParcel(Parcel parcel, int flags) {
141 parcel.writeInt(mId);
142 parcel.writeInt(mClass);
143 parcel.writeInt(mSubclass);
144 parcel.writeInt(mProtocol);
145 parcel.writeParcelableArray(mEndpoints, 0);
146 }
147}