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