WifiDisplayStatus.java revision e08ae388d63c4db8f9d9a7ecd634f9a51f6e91b9
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 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 26 * currently connected display and all known displays. 27 * <p> 28 * This object is immutable. 29 * </p> 30 * 31 * @hide 32 */ 33public final class WifiDisplayStatus implements Parcelable { 34 private final boolean mEnabled; 35 private final WifiDisplay mConnectedDisplay; 36 private final WifiDisplay[] mKnownDisplays; 37 private final boolean mScanInProgress; 38 private final boolean mConnectionInProgress; 39 40 public static final Creator<WifiDisplayStatus> CREATOR = new Creator<WifiDisplayStatus>() { 41 public WifiDisplayStatus createFromParcel(Parcel in) { 42 boolean enabled = (in.readInt() != 0); 43 44 WifiDisplay connectedDisplay = null; 45 if (in.readInt() != 0) { 46 connectedDisplay = WifiDisplay.CREATOR.createFromParcel(in); 47 } 48 49 WifiDisplay[] knownDisplays = WifiDisplay.CREATOR.newArray(in.readInt()); 50 for (int i = 0; i < knownDisplays.length; i++) { 51 knownDisplays[i] = WifiDisplay.CREATOR.createFromParcel(in); 52 } 53 54 boolean scanInProgress = (in.readInt() != 0); 55 boolean connectionInProgress = (in.readInt() != 0); 56 57 return new WifiDisplayStatus(enabled, connectedDisplay, knownDisplays, 58 scanInProgress, connectionInProgress); 59 } 60 61 public WifiDisplayStatus[] newArray(int size) { 62 return new WifiDisplayStatus[size]; 63 } 64 }; 65 66 public WifiDisplayStatus() { 67 this(false, null, WifiDisplay.EMPTY_ARRAY, false, false); 68 } 69 70 public WifiDisplayStatus(boolean enabled, 71 WifiDisplay connectedDisplay, WifiDisplay[] knownDisplays, 72 boolean scanInProgress, boolean connectionInProgress) { 73 if (knownDisplays == null) { 74 throw new IllegalArgumentException("knownDisplays must not be null"); 75 } 76 77 mEnabled = enabled; 78 mConnectedDisplay = connectedDisplay; 79 mKnownDisplays = knownDisplays; 80 mScanInProgress = scanInProgress; 81 mConnectionInProgress = connectionInProgress; 82 } 83 84 /** 85 * Returns true if the Wifi display feature is enabled and available for use. 86 * <p> 87 * The value of this property reflects whether Wifi and Wifi P2P functions 88 * are enabled. Enablement is not directly controllable by the user at this 89 * time, except indirectly such as by turning off Wifi altogether. 90 * </p> 91 */ 92 public boolean isEnabled() { 93 return mEnabled; 94 } 95 96 /** 97 * Gets the currently connected Wifi display or null if none. 98 */ 99 public WifiDisplay getConnectedDisplay() { 100 return mConnectedDisplay; 101 } 102 103 /** 104 * Gets the list of all known Wifi displays, never null. 105 */ 106 public WifiDisplay[] getKnownDisplays() { 107 return mKnownDisplays; 108 } 109 110 /** 111 * Returns true if there is currently a Wifi display scan in progress. 112 */ 113 public boolean isScanInProgress() { 114 return mScanInProgress; 115 } 116 117 /** 118 * Returns true if there is currently a Wifi display connection in progress. 119 */ 120 public boolean isConnectionInProgress() { 121 return mConnectionInProgress; 122 } 123 124 @Override 125 public void writeToParcel(Parcel dest, int flags) { 126 dest.writeInt(mEnabled ? 1 : 0); 127 128 if (mConnectedDisplay != null) { 129 dest.writeInt(1); 130 mConnectedDisplay.writeToParcel(dest, flags); 131 } else { 132 dest.writeInt(0); 133 } 134 135 dest.writeInt(mKnownDisplays.length); 136 for (WifiDisplay display : mKnownDisplays) { 137 display.writeToParcel(dest, flags); 138 } 139 140 dest.writeInt(mScanInProgress ? 1 : 0); 141 dest.writeInt(mConnectionInProgress ? 1 : 0); 142 } 143 144 @Override 145 public int describeContents() { 146 return 0; 147 } 148 149 // For debugging purposes only. 150 @Override 151 public String toString() { 152 return "WifiDisplayStatus{enabled=" + mEnabled 153 + ", connectedDisplay=" + mConnectedDisplay 154 + ", knownDisplays=" + Arrays.toString(mKnownDisplays) 155 + ", scanInProgress=" + mScanInProgress 156 + ", connectionInProgress=" + mConnectionInProgress 157 + "}"; 158 } 159} 160