blob: 12486e871c33acc0fd8c402d1a5d01e368a679c0 [file] [log] [blame]
Jeff Browne08ae382012-09-07 20:36:36 -07001/*
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
17package android.hardware.display;
18
Mathew Inwoodbcbe4402018-08-08 15:42:59 +010019import android.annotation.UnsupportedAppUsage;
Jeff Browne08ae382012-09-07 20:36:36 -070020import android.os.Parcel;
21import android.os.Parcelable;
22
Narayan Kamath607223f2018-02-19 14:09:02 +000023import java.util.Objects;
Jeff Brown89d55462012-09-19 11:33:42 -070024
Jeff Browne08ae382012-09-07 20:36:36 -070025/**
26 * Describes the properties of a Wifi display.
27 * <p>
28 * This object is immutable.
29 * </p>
30 *
31 * @hide
32 */
33public final class WifiDisplay implements Parcelable {
34 private final String mDeviceAddress;
35 private final String mDeviceName;
Jeff Brown89d55462012-09-19 11:33:42 -070036 private final String mDeviceAlias;
Chong Zhangab87a632013-06-11 10:25:49 -070037 private final boolean mIsAvailable;
Chong Zhang21f60392013-06-04 18:01:46 -070038 private final boolean mCanConnect;
Chong Zhangab87a632013-06-11 10:25:49 -070039 private final boolean mIsRemembered;
Jeff Browne08ae382012-09-07 20:36:36 -070040
41 public static final WifiDisplay[] EMPTY_ARRAY = new WifiDisplay[0];
42
43 public static final Creator<WifiDisplay> CREATOR = new Creator<WifiDisplay>() {
44 public WifiDisplay createFromParcel(Parcel in) {
45 String deviceAddress = in.readString();
46 String deviceName = in.readString();
Jeff Brown89d55462012-09-19 11:33:42 -070047 String deviceAlias = in.readString();
Chong Zhangab87a632013-06-11 10:25:49 -070048 boolean isAvailable = (in.readInt() != 0);
Chong Zhang21f60392013-06-04 18:01:46 -070049 boolean canConnect = (in.readInt() != 0);
Chong Zhangab87a632013-06-11 10:25:49 -070050 boolean isRemembered = (in.readInt() != 0);
51 return new WifiDisplay(deviceAddress, deviceName, deviceAlias,
52 isAvailable, canConnect, isRemembered);
Jeff Browne08ae382012-09-07 20:36:36 -070053 }
54
55 public WifiDisplay[] newArray(int size) {
56 return size == 0 ? EMPTY_ARRAY : new WifiDisplay[size];
57 }
58 };
59
Chong Zhangab87a632013-06-11 10:25:49 -070060 public WifiDisplay(String deviceAddress, String deviceName, String deviceAlias,
61 boolean available, boolean canConnect, boolean remembered) {
Jeff Browne08ae382012-09-07 20:36:36 -070062 if (deviceAddress == null) {
63 throw new IllegalArgumentException("deviceAddress must not be null");
64 }
65 if (deviceName == null) {
66 throw new IllegalArgumentException("deviceName must not be null");
67 }
68
69 mDeviceAddress = deviceAddress;
70 mDeviceName = deviceName;
Jeff Brown89d55462012-09-19 11:33:42 -070071 mDeviceAlias = deviceAlias;
Chong Zhangab87a632013-06-11 10:25:49 -070072 mIsAvailable = available;
Chong Zhang21f60392013-06-04 18:01:46 -070073 mCanConnect = canConnect;
Chong Zhangab87a632013-06-11 10:25:49 -070074 mIsRemembered = remembered;
Jeff Browne08ae382012-09-07 20:36:36 -070075 }
76
77 /**
78 * Gets the MAC address of the Wifi display device.
79 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +010080 @UnsupportedAppUsage
Jeff Browne08ae382012-09-07 20:36:36 -070081 public String getDeviceAddress() {
82 return mDeviceAddress;
83 }
84
85 /**
86 * Gets the name of the Wifi display device.
87 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +010088 @UnsupportedAppUsage
Jeff Browne08ae382012-09-07 20:36:36 -070089 public String getDeviceName() {
90 return mDeviceName;
91 }
92
Jeff Brown89d55462012-09-19 11:33:42 -070093 /**
94 * Gets the user-specified alias of the Wifi display device, or null if none.
95 * <p>
96 * The alias should be used in the UI whenever available. It is the value
97 * provided by the user when renaming the device.
98 * </p>
99 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100100 @UnsupportedAppUsage
Jeff Brown89d55462012-09-19 11:33:42 -0700101 public String getDeviceAlias() {
102 return mDeviceAlias;
103 }
104
105 /**
Chong Zhangab87a632013-06-11 10:25:49 -0700106 * Returns true if device is available, false otherwise.
107 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100108 @UnsupportedAppUsage
Chong Zhangab87a632013-06-11 10:25:49 -0700109 public boolean isAvailable() {
110 return mIsAvailable;
111 }
112
113 /**
114 * Returns true if device can be connected to (not in use), false otherwise.
Chong Zhang21f60392013-06-04 18:01:46 -0700115 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100116 @UnsupportedAppUsage
Chong Zhang21f60392013-06-04 18:01:46 -0700117 public boolean canConnect() {
118 return mCanConnect;
119 }
120
121 /**
Chong Zhangab87a632013-06-11 10:25:49 -0700122 * Returns true if device has been remembered, false otherwise.
123 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100124 @UnsupportedAppUsage
Chong Zhangab87a632013-06-11 10:25:49 -0700125 public boolean isRemembered() {
126 return mIsRemembered;
127 }
128
129 /**
Jeff Brown89d55462012-09-19 11:33:42 -0700130 * Gets the name to show in the UI.
131 * Uses the device alias if available, otherwise uses the device name.
132 */
133 public String getFriendlyDisplayName() {
134 return mDeviceAlias != null ? mDeviceAlias : mDeviceName;
135 }
136
Jeff Browne08ae382012-09-07 20:36:36 -0700137 @Override
138 public boolean equals(Object o) {
139 return o instanceof WifiDisplay && equals((WifiDisplay)o);
140 }
141
Chong Zhangab87a632013-06-11 10:25:49 -0700142 /**
143 * Returns true if the two displays have the same identity (address, name and alias).
144 * This method does not compare the current status of the displays.
145 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100146 @UnsupportedAppUsage
Jeff Browne08ae382012-09-07 20:36:36 -0700147 public boolean equals(WifiDisplay other) {
148 return other != null
149 && mDeviceAddress.equals(other.mDeviceAddress)
Jeff Brown89d55462012-09-19 11:33:42 -0700150 && mDeviceName.equals(other.mDeviceName)
Narayan Kamath607223f2018-02-19 14:09:02 +0000151 && Objects.equals(mDeviceAlias, other.mDeviceAlias);
Jeff Browne08ae382012-09-07 20:36:36 -0700152 }
153
Jeff Brown74da1092012-11-07 16:02:13 -0800154 /**
155 * Returns true if the other display is not null and has the same address as this one.
156 * Can be used to perform identity comparisons on displays ignoring properties
157 * that might change during a connection such as the name or alias.
158 */
159 public boolean hasSameAddress(WifiDisplay other) {
160 return other != null && mDeviceAddress.equals(other.mDeviceAddress);
161 }
162
Jeff Browne08ae382012-09-07 20:36:36 -0700163 @Override
164 public int hashCode() {
165 // The address on its own should be sufficiently unique for hashing purposes.
166 return mDeviceAddress.hashCode();
167 }
168
169 @Override
170 public void writeToParcel(Parcel dest, int flags) {
171 dest.writeString(mDeviceAddress);
172 dest.writeString(mDeviceName);
Jeff Brown89d55462012-09-19 11:33:42 -0700173 dest.writeString(mDeviceAlias);
Chong Zhangab87a632013-06-11 10:25:49 -0700174 dest.writeInt(mIsAvailable ? 1 : 0);
Chong Zhang21f60392013-06-04 18:01:46 -0700175 dest.writeInt(mCanConnect ? 1 : 0);
Chong Zhangab87a632013-06-11 10:25:49 -0700176 dest.writeInt(mIsRemembered ? 1 : 0);
Jeff Browne08ae382012-09-07 20:36:36 -0700177 }
178
179 @Override
180 public int describeContents() {
181 return 0;
182 }
183
184 // For debugging purposes only.
185 @Override
186 public String toString() {
Jeff Brown89d55462012-09-19 11:33:42 -0700187 String result = mDeviceName + " (" + mDeviceAddress + ")";
188 if (mDeviceAlias != null) {
189 result += ", alias " + mDeviceAlias;
190 }
Chong Zhangab87a632013-06-11 10:25:49 -0700191 result += ", isAvailable " + mIsAvailable + ", canConnect " + mCanConnect
192 + ", isRemembered " + mIsRemembered;
Jeff Brown89d55462012-09-19 11:33:42 -0700193 return result;
Jeff Browne08ae382012-09-07 20:36:36 -0700194 }
195}