blob: 3b510639a6718422a836824457034d5e42b9205a [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.
Mike Lockwoode7d511e2010-12-30 13:39:37 -050029 */
Mike Lockwoodc4308f02011-03-01 08:04:54 -080030public class UsbInterface implements Parcelable {
Mike Lockwoode7d511e2010-12-30 13:39:37 -050031
Mike Lockwoodacc29cc2011-03-11 08:18:08 -050032 private final int mId;
33 private final int mClass;
34 private final int mSubclass;
35 private final int mProtocol;
36 private final Parcelable[] mEndpoints;
Mike Lockwoode7d511e2010-12-30 13:39:37 -050037
38 /**
39 * UsbInterface should only be instantiated by UsbService implementation
40 * @hide
41 */
42 public UsbInterface(int id, int Class, int subClass, int protocol,
43 Parcelable[] endpoints) {
44 mId = id;
45 mClass = Class;
46 mSubclass = subClass;
47 mProtocol = protocol;
48 mEndpoints = endpoints;
49 }
50
51 /**
52 * Returns the interface's ID field.
Mike Lockwood11dd5ae2011-04-01 14:00:08 -040053 * This is an integer that uniquely identifies the interface on the device.
Mike Lockwoode7d511e2010-12-30 13:39:37 -050054 *
55 * @return the interface's ID
56 */
57 public int getId() {
58 return mId;
59 }
60
61 /**
62 * Returns the interface's class field.
Mike Lockwood11dd5ae2011-04-01 14:00:08 -040063 * Some useful constants for USB classes can be found in {@link UsbConstants}
Mike Lockwoode7d511e2010-12-30 13:39:37 -050064 *
65 * @return the interface's class
66 */
67 public int getInterfaceClass() {
68 return mClass;
69 }
70
71 /**
72 * Returns the interface's subclass field.
73 *
74 * @return the interface's subclass
75 */
76 public int getInterfaceSubclass() {
77 return mSubclass;
78 }
79
80 /**
81 * Returns the interface's protocol field.
82 *
83 * @return the interface's protocol
84 */
85 public int getInterfaceProtocol() {
86 return mProtocol;
87 }
88
89 /**
Mike Lockwoodc4308f02011-03-01 08:04:54 -080090 * Returns the number of {@link android.hardware.usb.UsbEndpoint}s this interface contains.
Mike Lockwoode7d511e2010-12-30 13:39:37 -050091 *
92 * @return the number of endpoints
93 */
94 public int getEndpointCount() {
95 return mEndpoints.length;
96 }
97
98 /**
Mike Lockwoodc4308f02011-03-01 08:04:54 -080099 * Returns the {@link android.hardware.usb.UsbEndpoint} at the given index.
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500100 *
101 * @return the endpoint
102 */
103 public UsbEndpoint getEndpoint(int index) {
104 return (UsbEndpoint)mEndpoints[index];
105 }
106
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500107 @Override
108 public String toString() {
109 return "UsbInterface[mId=" + mId + ",mClass=" + mClass +
110 ",mSubclass=" + mSubclass + ",mProtocol=" + mProtocol +
111 ",mEndpoints=" + mEndpoints + "]";
112 }
113
114 public static final Parcelable.Creator<UsbInterface> CREATOR =
115 new Parcelable.Creator<UsbInterface>() {
116 public UsbInterface createFromParcel(Parcel in) {
117 int id = in.readInt();
118 int Class = in.readInt();
119 int subClass = in.readInt();
120 int protocol = in.readInt();
121 Parcelable[] endpoints = in.readParcelableArray(UsbEndpoint.class.getClassLoader());
Mike Lockwoodacc29cc2011-03-11 08:18:08 -0500122 return new UsbInterface(id, Class, subClass, protocol, endpoints);
Mike Lockwoode7d511e2010-12-30 13:39:37 -0500123 }
124
125 public UsbInterface[] newArray(int size) {
126 return new UsbInterface[size];
127 }
128 };
129
130 public int describeContents() {
131 return 0;
132 }
133
134 public void writeToParcel(Parcel parcel, int flags) {
135 parcel.writeInt(mId);
136 parcel.writeInt(mClass);
137 parcel.writeInt(mSubclass);
138 parcel.writeInt(mProtocol);
139 parcel.writeParcelableArray(mEndpoints, 0);
140 }
141}