UsbAccessory.java revision b547fc297f24ce2d74fc86ef2a79a4424b6b4c59
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 mType;
27    private final String mVersion;
28
29    /* package */ UsbAccessory(android.hardware.usb.UsbAccessory accessory) {
30        mManufacturer = accessory.getManufacturer();
31        mModel = accessory.getModel();
32        mType = accessory.getType();
33        mVersion = accessory.getVersion();
34    }
35
36    /**
37     * Returns the manufacturer of the accessory.
38     *
39     * @return the accessory manufacturer
40     */
41    public String getManufacturer() {
42        return mManufacturer;
43    }
44
45    /**
46     * Returns the model name of the accessory.
47     *
48     * @return the accessory model
49     */
50    public String getModel() {
51        return mModel;
52    }
53
54    /**
55     * Returns the type of the accessory.
56     *
57     * @return the accessory type
58     */
59    public String getType() {
60        return mType;
61    }
62
63    /**
64     * Returns the version of the accessory.
65     *
66     * @return the accessory version
67     */
68    public String getVersion() {
69        return mVersion;
70    }
71
72    private static boolean compare(String s1, String s2) {
73        if (s1 == null) return (s2 == null);
74        return s1.equals(s2);
75    }
76
77    @Override
78    public boolean equals(Object obj) {
79        if (obj instanceof UsbAccessory) {
80            UsbAccessory accessory = (UsbAccessory)obj;
81            return (compare(mManufacturer, accessory.getManufacturer()) &&
82                    compare(mModel, accessory.getModel()) &&
83                    compare(mType, accessory.getType()) &&
84                    compare(mVersion, accessory.getVersion()));
85        }
86        return false;
87    }
88
89    @Override
90    public String toString() {
91        return "UsbAccessory[mManufacturer=" + mManufacturer +
92                            ", mModel=" + mModel +
93                            ", mType=" + mType +
94                            ", mVersion=" + mVersion + "]";
95    }
96}
97