UsbAccessory.java revision 638d7cb3ee0bb3596b01dc19eca9456fa72a36e0
1/* 2 * Copyright (C) 2011 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 17package android.hardware.usb; 18 19import android.os.Bundle; 20import android.os.Parcel; 21import android.os.Parcelable; 22import android.util.Log; 23 24/** 25 * A class representing a USB accessory. 26 * @hide 27 */ 28public class UsbAccessory implements Parcelable { 29 30 private static final String TAG = "UsbAccessory"; 31 32 private final String mManufacturer; 33 private final String mModel; 34 private final String mDescription; 35 private final String mVersion; 36 private final String mUri; 37 private final String mSerial; 38 39 /** 40 * UsbAccessory should only be instantiated by UsbService implementation 41 * @hide 42 */ 43 public UsbAccessory(String manufacturer, String model, String description, 44 String version, String uri, String serial) { 45 mManufacturer = manufacturer; 46 mModel = model; 47 mDescription = description; 48 mVersion = version; 49 mUri = uri; 50 mSerial = serial; 51 } 52 53 /** 54 * UsbAccessory should only be instantiated by UsbService implementation 55 * @hide 56 */ 57 public UsbAccessory(String[] strings) { 58 mManufacturer = strings[0]; 59 mModel = strings[1]; 60 mDescription = strings[2]; 61 mVersion = strings[3]; 62 mUri = strings[4]; 63 mSerial = strings[5]; 64 } 65 66 /** 67 * Returns the manufacturer of the accessory. 68 * 69 * @return the accessory manufacturer 70 */ 71 public String getManufacturer() { 72 return mManufacturer; 73 } 74 75 /** 76 * Returns the model name of the accessory. 77 * 78 * @return the accessory model 79 */ 80 public String getModel() { 81 return mModel; 82 } 83 84 /** 85 * Returns a user visible description of the accessory. 86 * 87 * @return the accessory description 88 */ 89 public String getDescription() { 90 return mDescription; 91 } 92 93 /** 94 * Returns the version of the accessory. 95 * 96 * @return the accessory version 97 */ 98 public String getVersion() { 99 return mVersion; 100 } 101 102 /** 103 * Returns the URI for the accessory. 104 * This is an optional URI that might show information about the accessory 105 * or provide the option to download an application for the accessory 106 * 107 * @return the accessory URI 108 */ 109 public String getUri() { 110 return mUri; 111 } 112 113 /** 114 * Returns the unique serial number for the accessory. 115 * This is an optional serial number that can be used to differentiate 116 * between individual accessories of the same model and manufacturer 117 * 118 * @return the unique serial number 119 */ 120 public String getSerial() { 121 return mSerial; 122 } 123 124 private static boolean compare(String s1, String s2) { 125 if (s1 == null) return (s2 == null); 126 return s1.equals(s2); 127 } 128 129 @Override 130 public boolean equals(Object obj) { 131 if (obj instanceof UsbAccessory) { 132 UsbAccessory accessory = (UsbAccessory)obj; 133 return (compare(mManufacturer, accessory.getManufacturer()) && 134 compare(mModel, accessory.getModel()) && 135 compare(mDescription, accessory.getDescription()) && 136 compare(mVersion, accessory.getVersion()) && 137 compare(mUri, accessory.getUri()) && 138 compare(mSerial, accessory.getSerial())); 139 } 140 return false; 141 } 142 143 @Override 144 public int hashCode() { 145 return ((mManufacturer == null ? 0 : mManufacturer.hashCode()) ^ 146 (mModel == null ? 0 : mModel.hashCode()) ^ 147 (mDescription == null ? 0 : mDescription.hashCode()) ^ 148 (mVersion == null ? 0 : mVersion.hashCode()) ^ 149 (mUri == null ? 0 : mUri.hashCode()) ^ 150 (mSerial == null ? 0 : mSerial.hashCode())); 151 } 152 153 @Override 154 public String toString() { 155 return "UsbAccessory[mManufacturer=" + mManufacturer + 156 ", mModel=" + mModel + 157 ", mDescription=" + mDescription + 158 ", mVersion=" + mVersion + 159 ", mUri=" + mUri + 160 ", mSerial=" + mSerial + "]"; 161 } 162 163 public static final Parcelable.Creator<UsbAccessory> CREATOR = 164 new Parcelable.Creator<UsbAccessory>() { 165 public UsbAccessory createFromParcel(Parcel in) { 166 String manufacturer = in.readString(); 167 String model = in.readString(); 168 String description = in.readString(); 169 String version = in.readString(); 170 String uri = in.readString(); 171 String serial = in.readString(); 172 return new UsbAccessory(manufacturer, model, description, version, uri, serial); 173 } 174 175 public UsbAccessory[] newArray(int size) { 176 return new UsbAccessory[size]; 177 } 178 }; 179 180 public int describeContents() { 181 return 0; 182 } 183 184 public void writeToParcel(Parcel parcel, int flags) { 185 parcel.writeString(mManufacturer); 186 parcel.writeString(mModel); 187 parcel.writeString(mDescription); 188 parcel.writeString(mVersion); 189 parcel.writeString(mUri); 190 parcel.writeString(mSerial); 191 } 192} 193