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