Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 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 | |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 19 | import android.annotation.UnsupportedAppUsage; |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
| 23 | import java.util.Arrays; |
| 24 | |
| 25 | /** |
| 26 | * Describes the current global state of Wifi display connectivity, including the |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 27 | * currently connected display and all available or remembered displays. |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 28 | * <p> |
| 29 | * This object is immutable. |
| 30 | * </p> |
| 31 | * |
| 32 | * @hide |
| 33 | */ |
| 34 | public final class WifiDisplayStatus implements Parcelable { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 35 | private final int mFeatureState; |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 36 | private final int mScanState; |
| 37 | private final int mActiveDisplayState; |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 38 | @UnsupportedAppUsage |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 39 | private final WifiDisplay mActiveDisplay; |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 40 | @UnsupportedAppUsage |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 41 | private final WifiDisplay[] mDisplays; |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 42 | |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 43 | /** Session info needed for Miracast Certification */ |
| 44 | private final WifiDisplaySessionInfo mSessionInfo; |
| 45 | |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 46 | /** 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 Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 53 | @UnsupportedAppUsage |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 54 | public static final int FEATURE_STATE_ON = 3; |
| 55 | |
| 56 | /** Scan state: Not currently scanning. */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 57 | @UnsupportedAppUsage |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 58 | public static final int SCAN_STATE_NOT_SCANNING = 0; |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 59 | /** Scan state: Currently scanning. */ |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 60 | public static final int SCAN_STATE_SCANNING = 1; |
| 61 | |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 62 | /** Display state: Not connected. */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 63 | @UnsupportedAppUsage |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 64 | public static final int DISPLAY_STATE_NOT_CONNECTED = 0; |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 65 | /** Display state: Connecting to active display. */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 66 | @UnsupportedAppUsage |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 67 | public static final int DISPLAY_STATE_CONNECTING = 1; |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 68 | /** Display state: Connected to active display. */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 69 | @UnsupportedAppUsage |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 70 | public static final int DISPLAY_STATE_CONNECTED = 2; |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 71 | |
Jeff Sharkey | 9e8f83d | 2019-02-28 12:06:45 -0700 | [diff] [blame] | 72 | public static final @android.annotation.NonNull Creator<WifiDisplayStatus> CREATOR = new Creator<WifiDisplayStatus>() { |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 73 | public WifiDisplayStatus createFromParcel(Parcel in) { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 74 | int featureState = in.readInt(); |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 75 | int scanState = in.readInt(); |
| 76 | int activeDisplayState= in.readInt(); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 77 | |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 78 | WifiDisplay activeDisplay = null; |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 79 | if (in.readInt() != 0) { |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 80 | activeDisplay = WifiDisplay.CREATOR.createFromParcel(in); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 81 | } |
| 82 | |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 83 | WifiDisplay[] displays = WifiDisplay.CREATOR.newArray(in.readInt()); |
| 84 | for (int i = 0; i < displays.length; i++) { |
| 85 | displays[i] = WifiDisplay.CREATOR.createFromParcel(in); |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 88 | WifiDisplaySessionInfo sessionInfo = |
| 89 | WifiDisplaySessionInfo.CREATOR.createFromParcel(in); |
| 90 | |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 91 | return new WifiDisplayStatus(featureState, scanState, activeDisplayState, |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 92 | activeDisplay, displays, sessionInfo); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | public WifiDisplayStatus[] newArray(int size) { |
| 96 | return new WifiDisplayStatus[size]; |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | public WifiDisplayStatus() { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 101 | this(FEATURE_STATE_UNAVAILABLE, SCAN_STATE_NOT_SCANNING, DISPLAY_STATE_NOT_CONNECTED, |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 102 | null, WifiDisplay.EMPTY_ARRAY, null); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 105 | public WifiDisplayStatus(int featureState, int scanState, int activeDisplayState, |
| 106 | WifiDisplay activeDisplay, WifiDisplay[] displays, WifiDisplaySessionInfo sessionInfo) { |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 107 | if (displays == null) { |
| 108 | throw new IllegalArgumentException("displays must not be null"); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 111 | mFeatureState = featureState; |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 112 | mScanState = scanState; |
| 113 | mActiveDisplayState = activeDisplayState; |
| 114 | mActiveDisplay = activeDisplay; |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 115 | mDisplays = displays; |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 116 | |
| 117 | mSessionInfo = (sessionInfo != null) ? sessionInfo : new WifiDisplaySessionInfo(); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | /** |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 121 | * Returns the state of the Wifi display feature on this device. |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 122 | * <p> |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 123 | * 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 Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 126 | * </p> |
| 127 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 128 | @UnsupportedAppUsage |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 129 | public int getFeatureState() { |
| 130 | return mFeatureState; |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /** |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 134 | * 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 Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 137 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 138 | @UnsupportedAppUsage |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 139 | 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 Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 149 | @UnsupportedAppUsage |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 150 | 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 Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 158 | @UnsupportedAppUsage |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 159 | public WifiDisplay getActiveDisplay() { |
| 160 | return mActiveDisplay; |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | /** |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 164 | * Gets the list of Wifi displays, returns a combined list of all available |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 165 | * Wifi displays as reported by the most recent scan, and all remembered |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 166 | * Wifi displays (not necessarily available at the time). |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 167 | */ |
Mathew Inwood | bcbe440 | 2018-08-08 15:42:59 +0100 | [diff] [blame] | 168 | @UnsupportedAppUsage |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 169 | public WifiDisplay[] getDisplays() { |
| 170 | return mDisplays; |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 173 | /** |
| 174 | * Gets the Wifi display session info (required for certification only) |
| 175 | */ |
| 176 | public WifiDisplaySessionInfo getSessionInfo() { |
| 177 | return mSessionInfo; |
| 178 | } |
| 179 | |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 180 | @Override |
| 181 | public void writeToParcel(Parcel dest, int flags) { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 182 | dest.writeInt(mFeatureState); |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 183 | dest.writeInt(mScanState); |
| 184 | dest.writeInt(mActiveDisplayState); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 185 | |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 186 | if (mActiveDisplay != null) { |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 187 | dest.writeInt(1); |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 188 | mActiveDisplay.writeToParcel(dest, flags); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 189 | } else { |
| 190 | dest.writeInt(0); |
| 191 | } |
| 192 | |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 193 | dest.writeInt(mDisplays.length); |
| 194 | for (WifiDisplay display : mDisplays) { |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 195 | display.writeToParcel(dest, flags); |
| 196 | } |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 197 | |
| 198 | mSessionInfo.writeToParcel(dest, flags); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | @Override |
| 202 | public int describeContents() { |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | // For debugging purposes only. |
| 207 | @Override |
| 208 | public String toString() { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 209 | return "WifiDisplayStatus{featureState=" + mFeatureState |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 210 | + ", scanState=" + mScanState |
| 211 | + ", activeDisplayState=" + mActiveDisplayState |
| 212 | + ", activeDisplay=" + mActiveDisplay |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 213 | + ", displays=" + Arrays.toString(mDisplays) |
Chong Zhang | 1f3ecaa | 2013-05-03 15:55:36 -0700 | [diff] [blame] | 214 | + ", sessionInfo=" + mSessionInfo |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 215 | + "}"; |
| 216 | } |
| 217 | } |