Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 1 | /* |
| 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 Lockwood | c4308f0 | 2011-03-01 08:04:54 -0800 | [diff] [blame] | 17 | package android.hardware.usb; |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 18 | |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
| 21 | |
| 22 | /** |
Mike Lockwood | 11dd5ae | 2011-04-01 14:00:08 -0400 | [diff] [blame] | 23 | * 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 Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 28 | * |
| 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 Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 34 | */ |
Mike Lockwood | c4308f0 | 2011-03-01 08:04:54 -0800 | [diff] [blame] | 35 | public class UsbInterface implements Parcelable { |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 36 | |
Mike Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 37 | 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 Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 42 | |
| 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 Lockwood | 11dd5ae | 2011-04-01 14:00:08 -0400 | [diff] [blame] | 58 | * This is an integer that uniquely identifies the interface on the device. |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 59 | * |
| 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 Lockwood | 11dd5ae | 2011-04-01 14:00:08 -0400 | [diff] [blame] | 68 | * Some useful constants for USB classes can be found in {@link UsbConstants} |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 69 | * |
| 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 Lockwood | c4308f0 | 2011-03-01 08:04:54 -0800 | [diff] [blame] | 95 | * Returns the number of {@link android.hardware.usb.UsbEndpoint}s this interface contains. |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 96 | * |
| 97 | * @return the number of endpoints |
| 98 | */ |
| 99 | public int getEndpointCount() { |
| 100 | return mEndpoints.length; |
| 101 | } |
| 102 | |
| 103 | /** |
Mike Lockwood | c4308f0 | 2011-03-01 08:04:54 -0800 | [diff] [blame] | 104 | * Returns the {@link android.hardware.usb.UsbEndpoint} at the given index. |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 105 | * |
| 106 | * @return the endpoint |
| 107 | */ |
| 108 | public UsbEndpoint getEndpoint(int index) { |
| 109 | return (UsbEndpoint)mEndpoints[index]; |
| 110 | } |
| 111 | |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 112 | @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 Lockwood | acc29cc | 2011-03-11 08:18:08 -0500 | [diff] [blame] | 127 | return new UsbInterface(id, Class, subClass, protocol, endpoints); |
Mike Lockwood | e7d511e | 2010-12-30 13:39:37 -0500 | [diff] [blame] | 128 | } |
| 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 | } |