| /* |
| * Copyright (C) 2011 The Android Open Source Project |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| |
| package android.hardware.usb; |
| |
| import android.os.Bundle; |
| import android.os.Parcel; |
| import android.os.Parcelable; |
| import android.util.Log; |
| |
| /** |
| * A class representing a USB accessory. |
| */ |
| public class UsbAccessory implements Parcelable { |
| |
| private static final String TAG = "UsbAccessory"; |
| |
| private final String mManufacturer; |
| private final String mModel; |
| private final String mDescription; |
| private final String mVersion; |
| private final String mUri; |
| |
| /** |
| * UsbAccessory should only be instantiated by UsbService implementation |
| * @hide |
| */ |
| public UsbAccessory(String manufacturer, String model, String description, |
| String version, String uri) { |
| mManufacturer = manufacturer; |
| mModel = model; |
| mDescription = description; |
| mVersion = version; |
| mUri = uri; |
| } |
| |
| /** |
| * UsbAccessory should only be instantiated by UsbService implementation |
| * @hide |
| */ |
| public UsbAccessory(String[] strings) { |
| mManufacturer = strings[0]; |
| mModel = strings[1]; |
| mDescription = strings[2]; |
| mVersion = strings[3]; |
| mUri = strings[4]; |
| } |
| |
| /** |
| * Returns the manufacturer of the accessory. |
| * |
| * @return the accessory manufacturer |
| */ |
| public String getManufacturer() { |
| return mManufacturer; |
| } |
| |
| /** |
| * Returns the model name of the accessory. |
| * |
| * @return the accessory model |
| */ |
| public String getModel() { |
| return mModel; |
| } |
| |
| /** |
| * Returns a user visible description of the accessory. |
| * |
| * @return the accessory description |
| */ |
| public String getDescription() { |
| return mDescription; |
| } |
| |
| /** |
| * Returns the version of the accessory. |
| * |
| * @return the accessory version |
| */ |
| public String getVersion() { |
| return mVersion; |
| } |
| |
| /** |
| * Returns the URI for the accessory. |
| * This is an optional URI that might show information about the accessory |
| * or provide the option to download an application for the accessory |
| * |
| * @return the accessory URI |
| */ |
| public String getUri() { |
| return mUri; |
| } |
| |
| private static boolean compare(String s1, String s2) { |
| if (s1 == null) return (s2 == null); |
| return s1.equals(s2); |
| } |
| |
| @Override |
| public boolean equals(Object obj) { |
| if (obj instanceof UsbAccessory) { |
| UsbAccessory accessory = (UsbAccessory)obj; |
| return (compare(mManufacturer, accessory.getManufacturer()) && |
| compare(mModel, accessory.getModel()) && |
| compare(mDescription, accessory.getDescription()) && |
| compare(mVersion, accessory.getVersion()) && |
| compare(mUri, accessory.getUri())); |
| } |
| return false; |
| } |
| |
| @Override |
| public int hashCode() { |
| return ((mManufacturer == null ? 0 : mManufacturer.hashCode()) ^ |
| (mModel == null ? 0 : mModel.hashCode()) ^ |
| (mDescription == null ? 0 : mDescription.hashCode()) ^ |
| (mVersion == null ? 0 : mVersion.hashCode()) ^ |
| (mUri == null ? 0 : mUri.hashCode())); |
| } |
| |
| @Override |
| public String toString() { |
| return "UsbAccessory[mManufacturer=" + mManufacturer + |
| ", mModel=" + mModel + |
| ", mDescription=" + mDescription + |
| ", mVersion=" + mVersion + |
| ", mUri=" + mUri + "]"; |
| } |
| |
| public static final Parcelable.Creator<UsbAccessory> CREATOR = |
| new Parcelable.Creator<UsbAccessory>() { |
| public UsbAccessory createFromParcel(Parcel in) { |
| String manufacturer = in.readString(); |
| String model = in.readString(); |
| String description = in.readString(); |
| String version = in.readString(); |
| String uri = in.readString(); |
| return new UsbAccessory(manufacturer, model, description, version, uri); |
| } |
| |
| public UsbAccessory[] newArray(int size) { |
| return new UsbAccessory[size]; |
| } |
| }; |
| |
| public int describeContents() { |
| return 0; |
| } |
| |
| public void writeToParcel(Parcel parcel, int flags) { |
| parcel.writeString(mManufacturer); |
| parcel.writeString(mModel); |
| parcel.writeString(mDescription); |
| parcel.writeString(mVersion); |
| parcel.writeString(mUri); |
| } |
| } |