| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.hardware.usb; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.os.Parcel; |
| 22 |
import android.os.Parcelable; |
| 23 |
|
| 24 |
import com.android.internal.util.Preconditions; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
public class UsbConfiguration implements Parcelable { |
| 40 |
|
| 41 |
private final int mId; |
| 42 |
private final @Nullable String mName; |
| 43 |
private final int mAttributes; |
| 44 |
private final int mMaxPower; |
| 45 |
|
| 46 |
|
| 47 |
private @Nullable Parcelable[] mInterfaces; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
private static final int ATTR_SELF_POWERED = 1 << 6; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
private static final int ATTR_REMOTE_WAKEUP = 1 << 5; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
public UsbConfiguration(int id, @Nullable String name, int attributes, int maxPower) { |
| 64 |
mId = id; |
| 65 |
mName = name; |
| 66 |
mAttributes = attributes; |
| 67 |
mMaxPower = maxPower; |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public int getId() { |
| 77 |
return mId; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
public @Nullable String getName() { |
| 86 |
return mName; |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
public boolean isSelfPowered() { |
| 96 |
return (mAttributes & ATTR_SELF_POWERED) != 0; |
| 97 |
} |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
public boolean isRemoteWakeup() { |
| 106 |
return (mAttributes & ATTR_REMOTE_WAKEUP) != 0; |
| 107 |
} |
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public int getAttributes() { |
| 117 |
return mAttributes; |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
public int getMaxPower() { |
| 126 |
return mMaxPower * 2; |
| 127 |
} |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
public int getInterfaceCount() { |
| 135 |
return mInterfaces.length; |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
public @NonNull UsbInterface getInterface(int index) { |
| 144 |
return (UsbInterface)mInterfaces[index]; |
| 145 |
} |
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
public void setInterfaces(@NonNull Parcelable[] interfaces) { |
| 152 |
mInterfaces = Preconditions.checkArrayElementsNotNull(interfaces, "interfaces"); |
| 153 |
} |
| 154 |
|
| 155 |
@Override |
| 156 |
public String toString() { |
| 157 |
StringBuilder builder = new StringBuilder("UsbConfiguration[mId=" + mId + |
| 158 |
",mName=" + mName + ",mAttributes=" + mAttributes + |
| 159 |
",mMaxPower=" + mMaxPower + ",mInterfaces=["); |
| 160 |
for (int i = 0; i < mInterfaces.length; i++) { |
| 161 |
builder.append("\n"); |
| 162 |
builder.append(mInterfaces[i].toString()); |
| 163 |
} |
| 164 |
builder.append("]"); |
| 165 |
return builder.toString(); |
| 166 |
} |
| 167 |
|
| 168 |
public static final @android.annotation.NonNull Parcelable.Creator<UsbConfiguration> CREATOR = |
| 169 |
new Parcelable.Creator<UsbConfiguration>() { |
| 170 |
public UsbConfiguration createFromParcel(Parcel in) { |
| 171 |
int id = in.readInt(); |
| 172 |
String name = in.readString(); |
| 173 |
int attributes = in.readInt(); |
| 174 |
int maxPower = in.readInt(); |
| 175 |
Parcelable[] interfaces = in.readParcelableArray(UsbInterface.class.getClassLoader()); |
| 176 |
UsbConfiguration configuration = new UsbConfiguration(id, name, attributes, maxPower); |
| 177 |
configuration.setInterfaces(interfaces); |
| 178 |
return configuration; |
| 179 |
} |
| 180 |
|
| 181 |
public UsbConfiguration[] newArray(int size) { |
| 182 |
return new UsbConfiguration[size]; |
| 183 |
} |
| 184 |
}; |
| 185 |
|
| 186 |
public int describeContents() { |
| 187 |
return 0; |
| 188 |
} |
| 189 |
|
| 190 |
public void writeToParcel(Parcel parcel, int flags) { |
| 191 |
parcel.writeInt(mId); |
| 192 |
parcel.writeString(mName); |
| 193 |
parcel.writeInt(mAttributes); |
| 194 |
parcel.writeInt(mMaxPower); |
| 195 |
parcel.writeParcelableArray(mInterfaces, 0); |
| 196 |
} |
| 197 |
} |