UsbAccessory.java revision 2cc0377200b94b2f68f34e34554f2aa39e09cbce
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 com.android.future.usb;
18
19/**
20 * A class representing a USB accessory.
21 */
22public final 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
30    /* package */ UsbAccessory(android.hardware.usb.UsbAccessory accessory) {
31        mManufacturer = accessory.getManufacturer();
32        mModel = accessory.getModel();
33        mDescription = accessory.getDescription();
34        mVersion = accessory.getVersion();
35        mUri = accessory.getUri();
36    }
37
38    /**
39     * Returns the manufacturer of the accessory.
40     *
41     * @return the accessory manufacturer
42     */
43    public String getManufacturer() {
44        return mManufacturer;
45    }
46
47    /**
48     * Returns the model name of the accessory.
49     *
50     * @return the accessory model
51     */
52    public String getModel() {
53        return mModel;
54    }
55
56    /**
57     * Returns a user visible description of the accessory.
58     *
59     * @return the accessory description
60     */
61    public String getDescription() {
62        return mDescription;
63    }
64
65    /**
66     * Returns the version of the accessory.
67     *
68     * @return the accessory version
69     */
70    public String getVersion() {
71        return mVersion;
72    }
73
74    /**
75     * Returns the URI for the accessory.
76     * This is an optional URI that might show information about the accessory
77     * or provide the option to download an application for the accessory
78     *
79     * @return the accessory URI
80     */
81    public String getUri() {
82        return mUri;
83    }
84
85    private static boolean compare(String s1, String s2) {
86        if (s1 == null) return (s2 == null);
87        return s1.equals(s2);
88    }
89
90    @Override
91    public boolean equals(Object obj) {
92        if (obj instanceof UsbAccessory) {
93            UsbAccessory accessory = (UsbAccessory)obj;
94            return (compare(mManufacturer, accessory.getManufacturer()) &&
95                    compare(mModel, accessory.getModel()) &&
96                    compare(mDescription, accessory.getDescription()) &&
97                    compare(mVersion, accessory.getVersion()) &&
98                    compare(mUri, accessory.getUri()));
99        }
100        return false;
101    }
102
103    @Override
104    public int hashCode() {
105        return ((mManufacturer == null ? 0 : mManufacturer.hashCode()) ^
106                (mModel == null ? 0 : mModel.hashCode()) ^
107                (mDescription == null ? 0 : mDescription.hashCode()) ^
108                (mVersion == null ? 0 : mVersion.hashCode()) ^
109                (mUri == null ? 0 : mUri.hashCode()));
110    }
111
112    @Override
113    public String toString() {
114        return "UsbAccessory[mManufacturer=" + mManufacturer +
115                            ", mModel=" + mModel +
116                            ", mDescription=" + mDescription +
117                            ", mVersion=" + mVersion +
118                            ", mUri=" + mUri + "]";
119    }
120}
121