• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 package com.android.future.usb;
18 
19 /**
20  * A class representing a USB accessory.
21  */
22 public class UsbAccessory {
23 
24     private final String mManufacturer;
25     private final String mModel;
26     private final String mDescription;
27     private final String mVersion;
28     private final String mUri;
29     private final String mSerial;
30 
UsbAccessory(android.hardware.usb.UsbAccessory accessory)31     /* package */ UsbAccessory(android.hardware.usb.UsbAccessory accessory) {
32         mManufacturer = accessory.getManufacturer();
33         mModel = accessory.getModel();
34         mDescription = accessory.getDescription();
35         mVersion = accessory.getVersion();
36         mUri = accessory.getUri();
37         mSerial = accessory.getSerial();
38     }
39 
40     /**
41      * Returns the manufacturer of the accessory.
42      *
43      * @return the accessory manufacturer
44      */
getManufacturer()45     public String getManufacturer() {
46         return mManufacturer;
47     }
48 
49     /**
50      * Returns the model name of the accessory.
51      *
52      * @return the accessory model
53      */
getModel()54     public String getModel() {
55         return mModel;
56     }
57 
58     /**
59      * Returns a user visible description of the accessory.
60      *
61      * @return the accessory description
62      */
getDescription()63     public String getDescription() {
64         return mDescription;
65     }
66 
67     /**
68      * Returns the version of the accessory.
69      *
70      * @return the accessory version
71      */
getVersion()72     public String getVersion() {
73         return mVersion;
74     }
75 
76     /**
77      * Returns the URI for the accessory.
78      * This is an optional URI that might show information about the accessory
79      * or provide the option to download an application for the accessory
80      *
81      * @return the accessory URI
82      */
getUri()83     public String getUri() {
84         return mUri;
85     }
86 
87     /**
88      * Returns the unique serial number for the accessory.
89      * This is an optional serial number that can be used to differentiate
90      * between individual accessories of the same model and manufacturer
91      *
92      * @return the unique serial number
93      */
getSerial()94     public String getSerial() {
95         return mSerial;
96     }
97 
compare(String s1, String s2)98     private static boolean compare(String s1, String s2) {
99         if (s1 == null) return (s2 == null);
100         return s1.equals(s2);
101     }
102 
103     @Override
equals(Object obj)104     public boolean equals(Object obj) {
105         if (obj instanceof UsbAccessory) {
106             UsbAccessory accessory = (UsbAccessory)obj;
107             return (compare(mManufacturer, accessory.getManufacturer()) &&
108                     compare(mModel, accessory.getModel()) &&
109                     compare(mDescription, accessory.getDescription()) &&
110                     compare(mVersion, accessory.getVersion()) &&
111                     compare(mUri, accessory.getUri()) &&
112                     compare(mSerial, accessory.getSerial()));
113         }
114         return false;
115     }
116 
117     @Override
hashCode()118     public int hashCode() {
119         return ((mManufacturer == null ? 0 : mManufacturer.hashCode()) ^
120                 (mModel == null ? 0 : mModel.hashCode()) ^
121                 (mDescription == null ? 0 : mDescription.hashCode()) ^
122                 (mVersion == null ? 0 : mVersion.hashCode()) ^
123                 (mUri == null ? 0 : mUri.hashCode()) ^
124                 (mSerial == null ? 0 : mSerial.hashCode()));
125     }
126 
127     @Override
toString()128     public String toString() {
129         return "UsbAccessory[mManufacturer=" + mManufacturer +
130                             ", mModel=" + mModel +
131                             ", mDescription=" + mDescription +
132                             ", mVersion=" + mVersion +
133                             ", mUri=" + mUri +
134                             ", mSerial=" + mSerial + "]";
135     }
136 }
137