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 19 import android.compat.annotation.UnsupportedAppUsage; 20 import android.os.Build; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 import java.util.Arrays; 25 26 /** 27 * Describes the current global state of Wifi display connectivity, including the 28 * currently connected display and all available or remembered displays. 29 * <p> 30 * This object is immutable. 31 * </p> 32 * 33 * @hide 34 */ 35 public final class WifiDisplayStatus implements Parcelable { 36 private final int mFeatureState; 37 private final int mScanState; 38 private final int mActiveDisplayState; 39 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 40 private final WifiDisplay mActiveDisplay; 41 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 42 private final WifiDisplay[] mDisplays; 43 44 /** Session info needed for Miracast Certification */ 45 private final WifiDisplaySessionInfo mSessionInfo; 46 47 /** Feature state: Wifi display is not available on this device. */ 48 public static final int FEATURE_STATE_UNAVAILABLE = 0; 49 /** Feature state: Wifi display is disabled, probably because Wifi is disabled. */ 50 public static final int FEATURE_STATE_DISABLED = 1; 51 /** Feature state: Wifi display is turned off in settings. */ 52 public static final int FEATURE_STATE_OFF = 2; 53 /** Feature state: Wifi display is turned on in settings. */ 54 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 55 public static final int FEATURE_STATE_ON = 3; 56 57 /** Scan state: Not currently scanning. */ 58 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 59 public static final int SCAN_STATE_NOT_SCANNING = 0; 60 /** Scan state: Currently scanning. */ 61 public static final int SCAN_STATE_SCANNING = 1; 62 63 /** Display state: Not connected. */ 64 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 65 public static final int DISPLAY_STATE_NOT_CONNECTED = 0; 66 /** Display state: Connecting to active display. */ 67 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 68 public static final int DISPLAY_STATE_CONNECTING = 1; 69 /** Display state: Connected to active display. */ 70 @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) 71 public static final int DISPLAY_STATE_CONNECTED = 2; 72 73 public static final @android.annotation.NonNull Creator<WifiDisplayStatus> CREATOR = new Creator<WifiDisplayStatus>() { 74 public WifiDisplayStatus createFromParcel(Parcel in) { 75 int featureState = in.readInt(); 76 int scanState = in.readInt(); 77 int activeDisplayState= in.readInt(); 78 79 WifiDisplay activeDisplay = null; 80 if (in.readInt() != 0) { 81 activeDisplay = WifiDisplay.CREATOR.createFromParcel(in); 82 } 83 84 WifiDisplay[] displays = WifiDisplay.CREATOR.newArray(in.readInt()); 85 for (int i = 0; i < displays.length; i++) { 86 displays[i] = WifiDisplay.CREATOR.createFromParcel(in); 87 } 88 89 WifiDisplaySessionInfo sessionInfo = 90 WifiDisplaySessionInfo.CREATOR.createFromParcel(in); 91 92 return new WifiDisplayStatus(featureState, scanState, activeDisplayState, 93 activeDisplay, displays, sessionInfo); 94 } 95 96 public WifiDisplayStatus[] newArray(int size) { 97 return new WifiDisplayStatus[size]; 98 } 99 }; 100 WifiDisplayStatus()101 public WifiDisplayStatus() { 102 this(FEATURE_STATE_UNAVAILABLE, SCAN_STATE_NOT_SCANNING, DISPLAY_STATE_NOT_CONNECTED, 103 null, WifiDisplay.EMPTY_ARRAY, null); 104 } 105 WifiDisplayStatus(int featureState, int scanState, int activeDisplayState, WifiDisplay activeDisplay, WifiDisplay[] displays, WifiDisplaySessionInfo sessionInfo)106 public WifiDisplayStatus(int featureState, int scanState, int activeDisplayState, 107 WifiDisplay activeDisplay, WifiDisplay[] displays, WifiDisplaySessionInfo sessionInfo) { 108 if (displays == null) { 109 throw new IllegalArgumentException("displays must not be null"); 110 } 111 112 mFeatureState = featureState; 113 mScanState = scanState; 114 mActiveDisplayState = activeDisplayState; 115 mActiveDisplay = activeDisplay; 116 mDisplays = displays; 117 118 mSessionInfo = (sessionInfo != null) ? sessionInfo : new WifiDisplaySessionInfo(); 119 } 120 121 /** 122 * Returns the state of the Wifi display feature on this device. 123 * <p> 124 * The value of this property reflects whether the device supports the Wifi display, 125 * whether it has been enabled by the user and whether the prerequisites for 126 * connecting to displays have been met. 127 * </p> 128 */ 129 @UnsupportedAppUsage getFeatureState()130 public int getFeatureState() { 131 return mFeatureState; 132 } 133 134 /** 135 * Returns the current state of the Wifi display scan. 136 * 137 * @return One of: {@link #SCAN_STATE_NOT_SCANNING} or {@link #SCAN_STATE_SCANNING}. 138 */ 139 @UnsupportedAppUsage getScanState()140 public int getScanState() { 141 return mScanState; 142 } 143 144 /** 145 * Get the state of the currently active display. 146 * 147 * @return One of: {@link #DISPLAY_STATE_NOT_CONNECTED}, {@link #DISPLAY_STATE_CONNECTING}, 148 * or {@link #DISPLAY_STATE_CONNECTED}. 149 */ 150 @UnsupportedAppUsage getActiveDisplayState()151 public int getActiveDisplayState() { 152 return mActiveDisplayState; 153 } 154 155 /** 156 * Gets the Wifi display that is currently active. It may be connecting or 157 * connected. 158 */ 159 @UnsupportedAppUsage getActiveDisplay()160 public WifiDisplay getActiveDisplay() { 161 return mActiveDisplay; 162 } 163 164 /** 165 * Gets the list of Wifi displays, returns a combined list of all available 166 * Wifi displays as reported by the most recent scan, and all remembered 167 * Wifi displays (not necessarily available at the time). 168 */ 169 @UnsupportedAppUsage getDisplays()170 public WifiDisplay[] getDisplays() { 171 return mDisplays; 172 } 173 174 /** 175 * Gets the Wifi display session info (required for certification only) 176 */ getSessionInfo()177 public WifiDisplaySessionInfo getSessionInfo() { 178 return mSessionInfo; 179 } 180 181 @Override writeToParcel(Parcel dest, int flags)182 public void writeToParcel(Parcel dest, int flags) { 183 dest.writeInt(mFeatureState); 184 dest.writeInt(mScanState); 185 dest.writeInt(mActiveDisplayState); 186 187 if (mActiveDisplay != null) { 188 dest.writeInt(1); 189 mActiveDisplay.writeToParcel(dest, flags); 190 } else { 191 dest.writeInt(0); 192 } 193 194 dest.writeInt(mDisplays.length); 195 for (WifiDisplay display : mDisplays) { 196 display.writeToParcel(dest, flags); 197 } 198 199 mSessionInfo.writeToParcel(dest, flags); 200 } 201 202 @Override describeContents()203 public int describeContents() { 204 return 0; 205 } 206 207 // For debugging purposes only. 208 @Override toString()209 public String toString() { 210 return "WifiDisplayStatus{featureState=" + mFeatureState 211 + ", scanState=" + mScanState 212 + ", activeDisplayState=" + mActiveDisplayState 213 + ", activeDisplay=" + mActiveDisplay 214 + ", displays=" + Arrays.toString(mDisplays) 215 + ", sessionInfo=" + mSessionInfo 216 + "}"; 217 } 218 } 219