|
| 1 | +/* |
| 2 | + * Copyright (C) 2012 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 android.hardware.display; |
| 18 | + |
| 19 | +import android.os.Parcel; |
| 20 | +import android.os.Parcelable; |
| 21 | + |
| 22 | +/** |
| 23 | + * Describes the properties of a Wifi display. |
| 24 | + * <p> |
| 25 | + * This object is immutable. |
| 26 | + * </p> |
| 27 | + * |
| 28 | + * @hide |
| 29 | + */ |
| 30 | +public final class WifiDisplay implements Parcelable { |
| 31 | + private final String mDeviceAddress; |
| 32 | + private final String mDeviceName; |
| 33 | + |
| 34 | + public static final WifiDisplay[] EMPTY_ARRAY = new WifiDisplay[0]; |
| 35 | + |
| 36 | + public static final Creator<WifiDisplay> CREATOR = new Creator<WifiDisplay>() { |
| 37 | + public WifiDisplay createFromParcel(Parcel in) { |
| 38 | + String deviceAddress = in.readString(); |
| 39 | + String deviceName = in.readString(); |
| 40 | + return new WifiDisplay(deviceAddress, deviceName); |
| 41 | + } |
| 42 | + |
| 43 | + public WifiDisplay[] newArray(int size) { |
| 44 | + return size == 0 ? EMPTY_ARRAY : new WifiDisplay[size]; |
| 45 | + } |
| 46 | + }; |
| 47 | + |
| 48 | + public WifiDisplay(String deviceAddress, String deviceName) { |
| 49 | + if (deviceAddress == null) { |
| 50 | + throw new IllegalArgumentException("deviceAddress must not be null"); |
| 51 | + } |
| 52 | + if (deviceName == null) { |
| 53 | + throw new IllegalArgumentException("deviceName must not be null"); |
| 54 | + } |
| 55 | + |
| 56 | + mDeviceAddress = deviceAddress; |
| 57 | + mDeviceName = deviceName; |
| 58 | + } |
| 59 | + |
| 60 | + /** |
| 61 | + * Gets the MAC address of the Wifi display device. |
| 62 | + */ |
| 63 | + public String getDeviceAddress() { |
| 64 | + return mDeviceAddress; |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * Gets the name of the Wifi display device. |
| 69 | + */ |
| 70 | + public String getDeviceName() { |
| 71 | + return mDeviceName; |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public boolean equals(Object o) { |
| 76 | + return o instanceof WifiDisplay && equals((WifiDisplay)o); |
| 77 | + } |
| 78 | + |
| 79 | + public boolean equals(WifiDisplay other) { |
| 80 | + return other != null |
| 81 | + && mDeviceAddress.equals(other.mDeviceAddress) |
| 82 | + && mDeviceName.equals(other.mDeviceName); |
| 83 | + } |
| 84 | + |
| 85 | + @Override |
| 86 | + public int hashCode() { |
| 87 | + // The address on its own should be sufficiently unique for hashing purposes. |
| 88 | + return mDeviceAddress.hashCode(); |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public void writeToParcel(Parcel dest, int flags) { |
| 93 | + dest.writeString(mDeviceAddress); |
| 94 | + dest.writeString(mDeviceName); |
| 95 | + } |
| 96 | + |
| 97 | + @Override |
| 98 | + public int describeContents() { |
| 99 | + return 0; |
| 100 | + } |
| 101 | + |
| 102 | + // For debugging purposes only. |
| 103 | + @Override |
| 104 | + public String toString() { |
| 105 | + return mDeviceName + " (" + mDeviceAddress + ")"; |
| 106 | + } |
| 107 | +} |
0 commit comments