blob: c2678341128ba9085004f13a56089d7676635298 [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
23import java.util.Arrays;
24
25/**
26 * Describes the current global state of Wifi display connectivity, including the
Jeff Brown89d55462012-09-19 11:33:42 -070027 * currently connected display and all available or remembered displays.
Jeff Browne08ae382012-09-07 20:36:36 -070028 * <p>
29 * This object is immutable.
30 * </p>
31 *
32 * @hide
33 */
34public final class WifiDisplayStatus implements Parcelable {
Jeff Brown89d55462012-09-19 11:33:42 -070035 private final int mFeatureState;
Jeff Brown180bbc72012-09-08 23:15:00 -070036 private final int mScanState;
37 private final int mActiveDisplayState;
Mathew Inwoodbcbe4402018-08-08 15:42:59 +010038 @UnsupportedAppUsage
Jeff Brown180bbc72012-09-08 23:15:00 -070039 private final WifiDisplay mActiveDisplay;
Mathew Inwoodbcbe4402018-08-08 15:42:59 +010040 @UnsupportedAppUsage
Chong Zhangab87a632013-06-11 10:25:49 -070041 private final WifiDisplay[] mDisplays;
Jeff Brown180bbc72012-09-08 23:15:00 -070042
Chong Zhang1f3ecaa2013-05-03 15:55:36 -070043 /** Session info needed for Miracast Certification */
44 private final WifiDisplaySessionInfo mSessionInfo;
45
Jeff Brown89d55462012-09-19 11:33:42 -070046 /** Feature state: Wifi display is not available on this device. */
47 public static final int FEATURE_STATE_UNAVAILABLE = 0;
48 /** Feature state: Wifi display is disabled, probably because Wifi is disabled. */
49 public static final int FEATURE_STATE_DISABLED = 1;
50 /** Feature state: Wifi display is turned off in settings. */
51 public static final int FEATURE_STATE_OFF = 2;
52 /** Feature state: Wifi display is turned on in settings. */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +010053 @UnsupportedAppUsage
Jeff Brown89d55462012-09-19 11:33:42 -070054 public static final int FEATURE_STATE_ON = 3;
55
56 /** Scan state: Not currently scanning. */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +010057 @UnsupportedAppUsage
Jeff Brown180bbc72012-09-08 23:15:00 -070058 public static final int SCAN_STATE_NOT_SCANNING = 0;
Jeff Brown89d55462012-09-19 11:33:42 -070059 /** Scan state: Currently scanning. */
Jeff Brown180bbc72012-09-08 23:15:00 -070060 public static final int SCAN_STATE_SCANNING = 1;
61
Jeff Brown89d55462012-09-19 11:33:42 -070062 /** Display state: Not connected. */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +010063 @UnsupportedAppUsage
Jeff Brown180bbc72012-09-08 23:15:00 -070064 public static final int DISPLAY_STATE_NOT_CONNECTED = 0;
Jeff Brown89d55462012-09-19 11:33:42 -070065 /** Display state: Connecting to active display. */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +010066 @UnsupportedAppUsage
Jeff Brown180bbc72012-09-08 23:15:00 -070067 public static final int DISPLAY_STATE_CONNECTING = 1;
Jeff Brown89d55462012-09-19 11:33:42 -070068 /** Display state: Connected to active display. */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +010069 @UnsupportedAppUsage
Jeff Brown180bbc72012-09-08 23:15:00 -070070 public static final int DISPLAY_STATE_CONNECTED = 2;
Jeff Browne08ae382012-09-07 20:36:36 -070071
72 public static final Creator<WifiDisplayStatus> CREATOR = new Creator<WifiDisplayStatus>() {
73 public WifiDisplayStatus createFromParcel(Parcel in) {
Jeff Brown89d55462012-09-19 11:33:42 -070074 int featureState = in.readInt();
Jeff Brown180bbc72012-09-08 23:15:00 -070075 int scanState = in.readInt();
76 int activeDisplayState= in.readInt();
Jeff Browne08ae382012-09-07 20:36:36 -070077
Jeff Brown180bbc72012-09-08 23:15:00 -070078 WifiDisplay activeDisplay = null;
Jeff Browne08ae382012-09-07 20:36:36 -070079 if (in.readInt() != 0) {
Jeff Brown180bbc72012-09-08 23:15:00 -070080 activeDisplay = WifiDisplay.CREATOR.createFromParcel(in);
Jeff Browne08ae382012-09-07 20:36:36 -070081 }
82
Chong Zhangab87a632013-06-11 10:25:49 -070083 WifiDisplay[] displays = WifiDisplay.CREATOR.newArray(in.readInt());
84 for (int i = 0; i < displays.length; i++) {
85 displays[i] = WifiDisplay.CREATOR.createFromParcel(in);
Jeff Brown89d55462012-09-19 11:33:42 -070086 }
87
Chong Zhang1f3ecaa2013-05-03 15:55:36 -070088 WifiDisplaySessionInfo sessionInfo =
89 WifiDisplaySessionInfo.CREATOR.createFromParcel(in);
90
Jeff Brown89d55462012-09-19 11:33:42 -070091 return new WifiDisplayStatus(featureState, scanState, activeDisplayState,
Chong Zhang1f3ecaa2013-05-03 15:55:36 -070092 activeDisplay, displays, sessionInfo);
Jeff Browne08ae382012-09-07 20:36:36 -070093 }
94
95 public WifiDisplayStatus[] newArray(int size) {
96 return new WifiDisplayStatus[size];
97 }
98 };
99
100 public WifiDisplayStatus() {
Jeff Brown89d55462012-09-19 11:33:42 -0700101 this(FEATURE_STATE_UNAVAILABLE, SCAN_STATE_NOT_SCANNING, DISPLAY_STATE_NOT_CONNECTED,
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700102 null, WifiDisplay.EMPTY_ARRAY, null);
Jeff Browne08ae382012-09-07 20:36:36 -0700103 }
104
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700105 public WifiDisplayStatus(int featureState, int scanState, int activeDisplayState,
106 WifiDisplay activeDisplay, WifiDisplay[] displays, WifiDisplaySessionInfo sessionInfo) {
Chong Zhangab87a632013-06-11 10:25:49 -0700107 if (displays == null) {
108 throw new IllegalArgumentException("displays must not be null");
Jeff Browne08ae382012-09-07 20:36:36 -0700109 }
110
Jeff Brown89d55462012-09-19 11:33:42 -0700111 mFeatureState = featureState;
Jeff Brown180bbc72012-09-08 23:15:00 -0700112 mScanState = scanState;
113 mActiveDisplayState = activeDisplayState;
114 mActiveDisplay = activeDisplay;
Chong Zhangab87a632013-06-11 10:25:49 -0700115 mDisplays = displays;
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700116
117 mSessionInfo = (sessionInfo != null) ? sessionInfo : new WifiDisplaySessionInfo();
Jeff Browne08ae382012-09-07 20:36:36 -0700118 }
119
120 /**
Jeff Brown89d55462012-09-19 11:33:42 -0700121 * Returns the state of the Wifi display feature on this device.
Jeff Browne08ae382012-09-07 20:36:36 -0700122 * <p>
Jeff Brown89d55462012-09-19 11:33:42 -0700123 * The value of this property reflects whether the device supports the Wifi display,
124 * whether it has been enabled by the user and whether the prerequisites for
125 * connecting to displays have been met.
Jeff Browne08ae382012-09-07 20:36:36 -0700126 * </p>
127 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100128 @UnsupportedAppUsage
Jeff Brown89d55462012-09-19 11:33:42 -0700129 public int getFeatureState() {
130 return mFeatureState;
Jeff Browne08ae382012-09-07 20:36:36 -0700131 }
132
133 /**
Jeff Brown180bbc72012-09-08 23:15:00 -0700134 * Returns the current state of the Wifi display scan.
135 *
136 * @return One of: {@link #SCAN_STATE_NOT_SCANNING} or {@link #SCAN_STATE_SCANNING}.
Jeff Browne08ae382012-09-07 20:36:36 -0700137 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100138 @UnsupportedAppUsage
Jeff Brown180bbc72012-09-08 23:15:00 -0700139 public int getScanState() {
140 return mScanState;
141 }
142
143 /**
144 * Get the state of the currently active display.
145 *
146 * @return One of: {@link #DISPLAY_STATE_NOT_CONNECTED}, {@link #DISPLAY_STATE_CONNECTING},
147 * or {@link #DISPLAY_STATE_CONNECTED}.
148 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100149 @UnsupportedAppUsage
Jeff Brown180bbc72012-09-08 23:15:00 -0700150 public int getActiveDisplayState() {
151 return mActiveDisplayState;
152 }
153
154 /**
155 * Gets the Wifi display that is currently active. It may be connecting or
156 * connected.
157 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100158 @UnsupportedAppUsage
Jeff Brown180bbc72012-09-08 23:15:00 -0700159 public WifiDisplay getActiveDisplay() {
160 return mActiveDisplay;
Jeff Browne08ae382012-09-07 20:36:36 -0700161 }
162
163 /**
Chong Zhangab87a632013-06-11 10:25:49 -0700164 * Gets the list of Wifi displays, returns a combined list of all available
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700165 * Wifi displays as reported by the most recent scan, and all remembered
Chong Zhangab87a632013-06-11 10:25:49 -0700166 * Wifi displays (not necessarily available at the time).
Jeff Browne08ae382012-09-07 20:36:36 -0700167 */
Mathew Inwoodbcbe4402018-08-08 15:42:59 +0100168 @UnsupportedAppUsage
Chong Zhangab87a632013-06-11 10:25:49 -0700169 public WifiDisplay[] getDisplays() {
170 return mDisplays;
Jeff Browne08ae382012-09-07 20:36:36 -0700171 }
172
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700173 /**
174 * Gets the Wifi display session info (required for certification only)
175 */
176 public WifiDisplaySessionInfo getSessionInfo() {
177 return mSessionInfo;
178 }
179
Jeff Browne08ae382012-09-07 20:36:36 -0700180 @Override
181 public void writeToParcel(Parcel dest, int flags) {
Jeff Brown89d55462012-09-19 11:33:42 -0700182 dest.writeInt(mFeatureState);
Jeff Brown180bbc72012-09-08 23:15:00 -0700183 dest.writeInt(mScanState);
184 dest.writeInt(mActiveDisplayState);
Jeff Browne08ae382012-09-07 20:36:36 -0700185
Jeff Brown180bbc72012-09-08 23:15:00 -0700186 if (mActiveDisplay != null) {
Jeff Browne08ae382012-09-07 20:36:36 -0700187 dest.writeInt(1);
Jeff Brown180bbc72012-09-08 23:15:00 -0700188 mActiveDisplay.writeToParcel(dest, flags);
Jeff Browne08ae382012-09-07 20:36:36 -0700189 } else {
190 dest.writeInt(0);
191 }
192
Chong Zhangab87a632013-06-11 10:25:49 -0700193 dest.writeInt(mDisplays.length);
194 for (WifiDisplay display : mDisplays) {
Jeff Browne08ae382012-09-07 20:36:36 -0700195 display.writeToParcel(dest, flags);
196 }
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700197
198 mSessionInfo.writeToParcel(dest, flags);
Jeff Browne08ae382012-09-07 20:36:36 -0700199 }
200
201 @Override
202 public int describeContents() {
203 return 0;
204 }
205
206 // For debugging purposes only.
207 @Override
208 public String toString() {
Jeff Brown89d55462012-09-19 11:33:42 -0700209 return "WifiDisplayStatus{featureState=" + mFeatureState
Jeff Brown180bbc72012-09-08 23:15:00 -0700210 + ", scanState=" + mScanState
211 + ", activeDisplayState=" + mActiveDisplayState
212 + ", activeDisplay=" + mActiveDisplay
Chong Zhangab87a632013-06-11 10:25:49 -0700213 + ", displays=" + Arrays.toString(mDisplays)
Chong Zhang1f3ecaa2013-05-03 15:55:36 -0700214 + ", sessionInfo=" + mSessionInfo
Jeff Browne08ae382012-09-07 20:36:36 -0700215 + "}";
216 }
217}