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