blob: 77acdc04afd2bda4402463e53ed6a9135c04c832 [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;
Chong Zhangab87a632013-06-11 10:25:49 -070023import java.util.ArrayList;
24import java.util.List;
Jeff Browne08ae382012-09-07 20:36:36 -070025
26/**
27 * Describes the current global state of Wifi display connectivity, including the
Jeff Brown89d55462012-09-19 11:33:42 -070028 * currently connected display and all available or remembered displays.
Jeff Browne08ae382012-09-07 20:36:36 -070029 * <p>
30 * This object is immutable.
31 * </p>
32 *
33 * @hide
34 */
35public final class WifiDisplayStatus implements Parcelable {
Jeff Brown89d55462012-09-19 11:33:42 -070036 private final int mFeatureState;
Jeff Brown180bbc72012-09-08 23:15:00 -070037 private final int mScanState;
38 private final int mActiveDisplayState;
39 private final WifiDisplay mActiveDisplay;
Chong Zhangab87a632013-06-11 10:25:49 -070040 private final WifiDisplay[] mDisplays;
Jeff Brown180bbc72012-09-08 23:15:00 -070041
Jeff Brown89d55462012-09-19 11:33:42 -070042 /** Feature state: Wifi display is not available on this device. */
43 public static final int FEATURE_STATE_UNAVAILABLE = 0;
44 /** Feature state: Wifi display is disabled, probably because Wifi is disabled. */
45 public static final int FEATURE_STATE_DISABLED = 1;
46 /** Feature state: Wifi display is turned off in settings. */
47 public static final int FEATURE_STATE_OFF = 2;
48 /** Feature state: Wifi display is turned on in settings. */
49 public static final int FEATURE_STATE_ON = 3;
50
51 /** Scan state: Not currently scanning. */
Jeff Brown180bbc72012-09-08 23:15:00 -070052 public static final int SCAN_STATE_NOT_SCANNING = 0;
Jeff Brown89d55462012-09-19 11:33:42 -070053 /** Scan state: Currently scanning. */
Jeff Brown180bbc72012-09-08 23:15:00 -070054 public static final int SCAN_STATE_SCANNING = 1;
55
Jeff Brown89d55462012-09-19 11:33:42 -070056 /** Display state: Not connected. */
Jeff Brown180bbc72012-09-08 23:15:00 -070057 public static final int DISPLAY_STATE_NOT_CONNECTED = 0;
Jeff Brown89d55462012-09-19 11:33:42 -070058 /** Display state: Connecting to active display. */
Jeff Brown180bbc72012-09-08 23:15:00 -070059 public static final int DISPLAY_STATE_CONNECTING = 1;
Jeff Brown89d55462012-09-19 11:33:42 -070060 /** Display state: Connected to active display. */
Jeff Brown180bbc72012-09-08 23:15:00 -070061 public static final int DISPLAY_STATE_CONNECTED = 2;
Jeff Browne08ae382012-09-07 20:36:36 -070062
63 public static final Creator<WifiDisplayStatus> CREATOR = new Creator<WifiDisplayStatus>() {
64 public WifiDisplayStatus createFromParcel(Parcel in) {
Jeff Brown89d55462012-09-19 11:33:42 -070065 int featureState = in.readInt();
Jeff Brown180bbc72012-09-08 23:15:00 -070066 int scanState = in.readInt();
67 int activeDisplayState= in.readInt();
Jeff Browne08ae382012-09-07 20:36:36 -070068
Jeff Brown180bbc72012-09-08 23:15:00 -070069 WifiDisplay activeDisplay = null;
Jeff Browne08ae382012-09-07 20:36:36 -070070 if (in.readInt() != 0) {
Jeff Brown180bbc72012-09-08 23:15:00 -070071 activeDisplay = WifiDisplay.CREATOR.createFromParcel(in);
Jeff Browne08ae382012-09-07 20:36:36 -070072 }
73
Chong Zhangab87a632013-06-11 10:25:49 -070074 WifiDisplay[] displays = WifiDisplay.CREATOR.newArray(in.readInt());
75 for (int i = 0; i < displays.length; i++) {
76 displays[i] = WifiDisplay.CREATOR.createFromParcel(in);
Jeff Brown89d55462012-09-19 11:33:42 -070077 }
78
79 return new WifiDisplayStatus(featureState, scanState, activeDisplayState,
Chong Zhangab87a632013-06-11 10:25:49 -070080 activeDisplay, displays);
Jeff Browne08ae382012-09-07 20:36:36 -070081 }
82
83 public WifiDisplayStatus[] newArray(int size) {
84 return new WifiDisplayStatus[size];
85 }
86 };
87
88 public WifiDisplayStatus() {
Jeff Brown89d55462012-09-19 11:33:42 -070089 this(FEATURE_STATE_UNAVAILABLE, SCAN_STATE_NOT_SCANNING, DISPLAY_STATE_NOT_CONNECTED,
Chong Zhangab87a632013-06-11 10:25:49 -070090 null, WifiDisplay.EMPTY_ARRAY);
Jeff Browne08ae382012-09-07 20:36:36 -070091 }
92
Jeff Brown89d55462012-09-19 11:33:42 -070093 public WifiDisplayStatus(int featureState, int scanState,
Chong Zhangab87a632013-06-11 10:25:49 -070094 int activeDisplayState, WifiDisplay activeDisplay, WifiDisplay[] displays) {
95 if (displays == null) {
96 throw new IllegalArgumentException("displays must not be null");
Jeff Browne08ae382012-09-07 20:36:36 -070097 }
98
Jeff Brown89d55462012-09-19 11:33:42 -070099 mFeatureState = featureState;
Jeff Brown180bbc72012-09-08 23:15:00 -0700100 mScanState = scanState;
101 mActiveDisplayState = activeDisplayState;
102 mActiveDisplay = activeDisplay;
Chong Zhangab87a632013-06-11 10:25:49 -0700103 mDisplays = displays;
Jeff Browne08ae382012-09-07 20:36:36 -0700104 }
105
106 /**
Jeff Brown89d55462012-09-19 11:33:42 -0700107 * Returns the state of the Wifi display feature on this device.
Jeff Browne08ae382012-09-07 20:36:36 -0700108 * <p>
Jeff Brown89d55462012-09-19 11:33:42 -0700109 * The value of this property reflects whether the device supports the Wifi display,
110 * whether it has been enabled by the user and whether the prerequisites for
111 * connecting to displays have been met.
Jeff Browne08ae382012-09-07 20:36:36 -0700112 * </p>
113 */
Jeff Brown89d55462012-09-19 11:33:42 -0700114 public int getFeatureState() {
115 return mFeatureState;
Jeff Browne08ae382012-09-07 20:36:36 -0700116 }
117
118 /**
Jeff Brown180bbc72012-09-08 23:15:00 -0700119 * Returns the current state of the Wifi display scan.
120 *
121 * @return One of: {@link #SCAN_STATE_NOT_SCANNING} or {@link #SCAN_STATE_SCANNING}.
Jeff Browne08ae382012-09-07 20:36:36 -0700122 */
Jeff Brown180bbc72012-09-08 23:15:00 -0700123 public int getScanState() {
124 return mScanState;
125 }
126
127 /**
128 * Get the state of the currently active display.
129 *
130 * @return One of: {@link #DISPLAY_STATE_NOT_CONNECTED}, {@link #DISPLAY_STATE_CONNECTING},
131 * or {@link #DISPLAY_STATE_CONNECTED}.
132 */
133 public int getActiveDisplayState() {
134 return mActiveDisplayState;
135 }
136
137 /**
138 * Gets the Wifi display that is currently active. It may be connecting or
139 * connected.
140 */
141 public WifiDisplay getActiveDisplay() {
142 return mActiveDisplay;
Jeff Browne08ae382012-09-07 20:36:36 -0700143 }
144
145 /**
Chong Zhangab87a632013-06-11 10:25:49 -0700146 * Gets the list of Wifi displays, returns a combined list of all available
147 * Wifi displays as reported by the most recent scan, and all remembered
148 * Wifi displays (not necessarily available at the time).
Jeff Browne08ae382012-09-07 20:36:36 -0700149 */
Chong Zhangab87a632013-06-11 10:25:49 -0700150 public WifiDisplay[] getDisplays() {
151 return mDisplays;
Jeff Browne08ae382012-09-07 20:36:36 -0700152 }
153
Jeff Browne08ae382012-09-07 20:36:36 -0700154 @Override
155 public void writeToParcel(Parcel dest, int flags) {
Jeff Brown89d55462012-09-19 11:33:42 -0700156 dest.writeInt(mFeatureState);
Jeff Brown180bbc72012-09-08 23:15:00 -0700157 dest.writeInt(mScanState);
158 dest.writeInt(mActiveDisplayState);
Jeff Browne08ae382012-09-07 20:36:36 -0700159
Jeff Brown180bbc72012-09-08 23:15:00 -0700160 if (mActiveDisplay != null) {
Jeff Browne08ae382012-09-07 20:36:36 -0700161 dest.writeInt(1);
Jeff Brown180bbc72012-09-08 23:15:00 -0700162 mActiveDisplay.writeToParcel(dest, flags);
Jeff Browne08ae382012-09-07 20:36:36 -0700163 } else {
164 dest.writeInt(0);
165 }
166
Chong Zhangab87a632013-06-11 10:25:49 -0700167 dest.writeInt(mDisplays.length);
168 for (WifiDisplay display : mDisplays) {
Jeff Browne08ae382012-09-07 20:36:36 -0700169 display.writeToParcel(dest, flags);
170 }
Jeff Browne08ae382012-09-07 20:36:36 -0700171 }
172
173 @Override
174 public int describeContents() {
175 return 0;
176 }
177
178 // For debugging purposes only.
179 @Override
180 public String toString() {
Jeff Brown89d55462012-09-19 11:33:42 -0700181 return "WifiDisplayStatus{featureState=" + mFeatureState
Jeff Brown180bbc72012-09-08 23:15:00 -0700182 + ", scanState=" + mScanState
183 + ", activeDisplayState=" + mActiveDisplayState
184 + ", activeDisplay=" + mActiveDisplay
Chong Zhangab87a632013-06-11 10:25:49 -0700185 + ", displays=" + Arrays.toString(mDisplays)
Jeff Browne08ae382012-09-07 20:36:36 -0700186 + "}";
187 }
188}