blob: f7e72c417f77bc85f10d37f5974729d06a6bb0a2 [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
19import android.os.Parcel;
20import android.os.Parcelable;
21
22import java.util.Arrays;
23
24/**
25 * Describes the current global state of Wifi display connectivity, including the
Jeff Brown89d55462012-09-19 11:33:42 -070026 * currently connected display and all available or remembered displays.
Jeff Browne08ae382012-09-07 20:36:36 -070027 * <p>
28 * This object is immutable.
29 * </p>
30 *
31 * @hide
32 */
33public final class WifiDisplayStatus implements Parcelable {
Jeff Brown89d55462012-09-19 11:33:42 -070034 private final int mFeatureState;
Jeff Brown180bbc72012-09-08 23:15:00 -070035 private final int mScanState;
36 private final int mActiveDisplayState;
37 private final WifiDisplay mActiveDisplay;
Jeff Brown89d55462012-09-19 11:33:42 -070038 private final WifiDisplay[] mAvailableDisplays;
39 private final WifiDisplay[] mRememberedDisplays;
Jeff Brown180bbc72012-09-08 23:15:00 -070040
Jeff Brown89d55462012-09-19 11:33:42 -070041 /** Feature state: Wifi display is not available on this device. */
42 public static final int FEATURE_STATE_UNAVAILABLE = 0;
43 /** Feature state: Wifi display is disabled, probably because Wifi is disabled. */
44 public static final int FEATURE_STATE_DISABLED = 1;
45 /** Feature state: Wifi display is turned off in settings. */
46 public static final int FEATURE_STATE_OFF = 2;
47 /** Feature state: Wifi display is turned on in settings. */
48 public static final int FEATURE_STATE_ON = 3;
49
50 /** Scan state: Not currently scanning. */
Jeff Brown180bbc72012-09-08 23:15:00 -070051 public static final int SCAN_STATE_NOT_SCANNING = 0;
Jeff Brown89d55462012-09-19 11:33:42 -070052 /** Scan state: Currently scanning. */
Jeff Brown180bbc72012-09-08 23:15:00 -070053 public static final int SCAN_STATE_SCANNING = 1;
54
Jeff Brown89d55462012-09-19 11:33:42 -070055 /** Display state: Not connected. */
Jeff Brown180bbc72012-09-08 23:15:00 -070056 public static final int DISPLAY_STATE_NOT_CONNECTED = 0;
Jeff Brown89d55462012-09-19 11:33:42 -070057 /** Display state: Connecting to active display. */
Jeff Brown180bbc72012-09-08 23:15:00 -070058 public static final int DISPLAY_STATE_CONNECTING = 1;
Jeff Brown89d55462012-09-19 11:33:42 -070059 /** Display state: Connected to active display. */
Jeff Brown180bbc72012-09-08 23:15:00 -070060 public static final int DISPLAY_STATE_CONNECTED = 2;
Jeff Browne08ae382012-09-07 20:36:36 -070061
62 public static final Creator<WifiDisplayStatus> CREATOR = new Creator<WifiDisplayStatus>() {
63 public WifiDisplayStatus createFromParcel(Parcel in) {
Jeff Brown89d55462012-09-19 11:33:42 -070064 int featureState = in.readInt();
Jeff Brown180bbc72012-09-08 23:15:00 -070065 int scanState = in.readInt();
66 int activeDisplayState= in.readInt();
Jeff Browne08ae382012-09-07 20:36:36 -070067
Jeff Brown180bbc72012-09-08 23:15:00 -070068 WifiDisplay activeDisplay = null;
Jeff Browne08ae382012-09-07 20:36:36 -070069 if (in.readInt() != 0) {
Jeff Brown180bbc72012-09-08 23:15:00 -070070 activeDisplay = WifiDisplay.CREATOR.createFromParcel(in);
Jeff Browne08ae382012-09-07 20:36:36 -070071 }
72
Jeff Brown89d55462012-09-19 11:33:42 -070073 WifiDisplay[] availableDisplays = WifiDisplay.CREATOR.newArray(in.readInt());
74 for (int i = 0; i < availableDisplays.length; i++) {
75 availableDisplays[i] = WifiDisplay.CREATOR.createFromParcel(in);
Jeff Browne08ae382012-09-07 20:36:36 -070076 }
77
Jeff Brown89d55462012-09-19 11:33:42 -070078 WifiDisplay[] rememberedDisplays = WifiDisplay.CREATOR.newArray(in.readInt());
79 for (int i = 0; i < rememberedDisplays.length; i++) {
80 rememberedDisplays[i] = WifiDisplay.CREATOR.createFromParcel(in);
81 }
82
83 return new WifiDisplayStatus(featureState, scanState, activeDisplayState,
84 activeDisplay, availableDisplays, rememberedDisplays);
Jeff Browne08ae382012-09-07 20:36:36 -070085 }
86
87 public WifiDisplayStatus[] newArray(int size) {
88 return new WifiDisplayStatus[size];
89 }
90 };
91
92 public WifiDisplayStatus() {
Jeff Brown89d55462012-09-19 11:33:42 -070093 this(FEATURE_STATE_UNAVAILABLE, SCAN_STATE_NOT_SCANNING, DISPLAY_STATE_NOT_CONNECTED,
94 null, WifiDisplay.EMPTY_ARRAY, WifiDisplay.EMPTY_ARRAY);
Jeff Browne08ae382012-09-07 20:36:36 -070095 }
96
Jeff Brown89d55462012-09-19 11:33:42 -070097 public WifiDisplayStatus(int featureState, int scanState,
98 int activeDisplayState, WifiDisplay activeDisplay,
99 WifiDisplay[] availableDisplays, WifiDisplay[] rememberedDisplays) {
100 if (availableDisplays == null) {
101 throw new IllegalArgumentException("availableDisplays must not be null");
102 }
103 if (rememberedDisplays == null) {
104 throw new IllegalArgumentException("rememberedDisplays must not be null");
Jeff Browne08ae382012-09-07 20:36:36 -0700105 }
106
Jeff Brown89d55462012-09-19 11:33:42 -0700107 mFeatureState = featureState;
Jeff Brown180bbc72012-09-08 23:15:00 -0700108 mScanState = scanState;
109 mActiveDisplayState = activeDisplayState;
110 mActiveDisplay = activeDisplay;
Jeff Brown89d55462012-09-19 11:33:42 -0700111 mAvailableDisplays = availableDisplays;
112 mRememberedDisplays = rememberedDisplays;
Jeff Browne08ae382012-09-07 20:36:36 -0700113 }
114
115 /**
Jeff Brown89d55462012-09-19 11:33:42 -0700116 * Returns the state of the Wifi display feature on this device.
Jeff Browne08ae382012-09-07 20:36:36 -0700117 * <p>
Jeff Brown89d55462012-09-19 11:33:42 -0700118 * The value of this property reflects whether the device supports the Wifi display,
119 * whether it has been enabled by the user and whether the prerequisites for
120 * connecting to displays have been met.
Jeff Browne08ae382012-09-07 20:36:36 -0700121 * </p>
122 */
Jeff Brown89d55462012-09-19 11:33:42 -0700123 public int getFeatureState() {
124 return mFeatureState;
Jeff Browne08ae382012-09-07 20:36:36 -0700125 }
126
127 /**
Jeff Brown180bbc72012-09-08 23:15:00 -0700128 * Returns the current state of the Wifi display scan.
129 *
130 * @return One of: {@link #SCAN_STATE_NOT_SCANNING} or {@link #SCAN_STATE_SCANNING}.
Jeff Browne08ae382012-09-07 20:36:36 -0700131 */
Jeff Brown180bbc72012-09-08 23:15:00 -0700132 public int getScanState() {
133 return mScanState;
134 }
135
136 /**
137 * Get the state of the currently active display.
138 *
139 * @return One of: {@link #DISPLAY_STATE_NOT_CONNECTED}, {@link #DISPLAY_STATE_CONNECTING},
140 * or {@link #DISPLAY_STATE_CONNECTED}.
141 */
142 public int getActiveDisplayState() {
143 return mActiveDisplayState;
144 }
145
146 /**
147 * Gets the Wifi display that is currently active. It may be connecting or
148 * connected.
149 */
150 public WifiDisplay getActiveDisplay() {
151 return mActiveDisplay;
Jeff Browne08ae382012-09-07 20:36:36 -0700152 }
153
154 /**
Jeff Brown89d55462012-09-19 11:33:42 -0700155 * Gets the list of all available Wifi displays as reported by the most recent
156 * scan, never null.
157 * <p>
158 * Some of these displays may already be remembered, others may be unknown.
159 * </p>
Jeff Browne08ae382012-09-07 20:36:36 -0700160 */
Jeff Brown89d55462012-09-19 11:33:42 -0700161 public WifiDisplay[] getAvailableDisplays() {
162 return mAvailableDisplays;
163 }
164
165 /**
166 * Gets the list of all remembered Wifi displays, never null.
167 * <p>
168 * Not all remembered displays will necessarily be available.
169 * </p>
170 */
171 public WifiDisplay[] getRememberedDisplays() {
172 return mRememberedDisplays;
Jeff Browne08ae382012-09-07 20:36:36 -0700173 }
174
Jeff Browne08ae382012-09-07 20:36:36 -0700175 @Override
176 public void writeToParcel(Parcel dest, int flags) {
Jeff Brown89d55462012-09-19 11:33:42 -0700177 dest.writeInt(mFeatureState);
Jeff Brown180bbc72012-09-08 23:15:00 -0700178 dest.writeInt(mScanState);
179 dest.writeInt(mActiveDisplayState);
Jeff Browne08ae382012-09-07 20:36:36 -0700180
Jeff Brown180bbc72012-09-08 23:15:00 -0700181 if (mActiveDisplay != null) {
Jeff Browne08ae382012-09-07 20:36:36 -0700182 dest.writeInt(1);
Jeff Brown180bbc72012-09-08 23:15:00 -0700183 mActiveDisplay.writeToParcel(dest, flags);
Jeff Browne08ae382012-09-07 20:36:36 -0700184 } else {
185 dest.writeInt(0);
186 }
187
Jeff Brown89d55462012-09-19 11:33:42 -0700188 dest.writeInt(mAvailableDisplays.length);
189 for (WifiDisplay display : mAvailableDisplays) {
190 display.writeToParcel(dest, flags);
191 }
192
193 dest.writeInt(mRememberedDisplays.length);
194 for (WifiDisplay display : mRememberedDisplays) {
Jeff Browne08ae382012-09-07 20:36:36 -0700195 display.writeToParcel(dest, flags);
196 }
Jeff Browne08ae382012-09-07 20:36:36 -0700197 }
198
199 @Override
200 public int describeContents() {
201 return 0;
202 }
203
204 // For debugging purposes only.
205 @Override
206 public String toString() {
Jeff Brown89d55462012-09-19 11:33:42 -0700207 return "WifiDisplayStatus{featureState=" + mFeatureState
Jeff Brown180bbc72012-09-08 23:15:00 -0700208 + ", scanState=" + mScanState
209 + ", activeDisplayState=" + mActiveDisplayState
210 + ", activeDisplay=" + mActiveDisplay
Jeff Brown89d55462012-09-19 11:33:42 -0700211 + ", availableDisplays=" + Arrays.toString(mAvailableDisplays)
212 + ", rememberedDisplays=" + Arrays.toString(mRememberedDisplays)
Jeff Browne08ae382012-09-07 20:36:36 -0700213 + "}";
214 }
215}