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 | |
| 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
| 21 | |
| 22 | import java.util.Arrays; |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 23 | import java.util.ArrayList; |
| 24 | import java.util.List; |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Describes the current global state of Wifi display connectivity, including the |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 28 | * currently connected display and all available or remembered displays. |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 29 | * <p> |
| 30 | * This object is immutable. |
| 31 | * </p> |
| 32 | * |
| 33 | * @hide |
| 34 | */ |
| 35 | public final class WifiDisplayStatus implements Parcelable { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 36 | private final int mFeatureState; |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 37 | private final int mScanState; |
| 38 | private final int mActiveDisplayState; |
| 39 | private final WifiDisplay mActiveDisplay; |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 40 | private final WifiDisplay[] mDisplays; |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 41 | |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 42 | /** 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 Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 52 | public static final int SCAN_STATE_NOT_SCANNING = 0; |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 53 | /** Scan state: Currently scanning. */ |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 54 | public static final int SCAN_STATE_SCANNING = 1; |
| 55 | |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 56 | /** Display state: Not connected. */ |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 57 | public static final int DISPLAY_STATE_NOT_CONNECTED = 0; |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 58 | /** Display state: Connecting to active display. */ |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 59 | public static final int DISPLAY_STATE_CONNECTING = 1; |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 60 | /** Display state: Connected to active display. */ |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 61 | public static final int DISPLAY_STATE_CONNECTED = 2; |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 62 | |
| 63 | public static final Creator<WifiDisplayStatus> CREATOR = new Creator<WifiDisplayStatus>() { |
| 64 | public WifiDisplayStatus createFromParcel(Parcel in) { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 65 | int featureState = in.readInt(); |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 66 | int scanState = in.readInt(); |
| 67 | int activeDisplayState= in.readInt(); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 68 | |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 69 | WifiDisplay activeDisplay = null; |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 70 | if (in.readInt() != 0) { |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 71 | activeDisplay = WifiDisplay.CREATOR.createFromParcel(in); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 74 | WifiDisplay[] displays = WifiDisplay.CREATOR.newArray(in.readInt()); |
| 75 | for (int i = 0; i < displays.length; i++) { |
| 76 | displays[i] = WifiDisplay.CREATOR.createFromParcel(in); |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | return new WifiDisplayStatus(featureState, scanState, activeDisplayState, |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 80 | activeDisplay, displays); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | public WifiDisplayStatus[] newArray(int size) { |
| 84 | return new WifiDisplayStatus[size]; |
| 85 | } |
| 86 | }; |
| 87 | |
| 88 | public WifiDisplayStatus() { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 89 | this(FEATURE_STATE_UNAVAILABLE, SCAN_STATE_NOT_SCANNING, DISPLAY_STATE_NOT_CONNECTED, |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 90 | null, WifiDisplay.EMPTY_ARRAY); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 93 | public WifiDisplayStatus(int featureState, int scanState, |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 94 | int activeDisplayState, WifiDisplay activeDisplay, WifiDisplay[] displays) { |
| 95 | if (displays == null) { |
| 96 | throw new IllegalArgumentException("displays must not be null"); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 97 | } |
| 98 | |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 99 | mFeatureState = featureState; |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 100 | mScanState = scanState; |
| 101 | mActiveDisplayState = activeDisplayState; |
| 102 | mActiveDisplay = activeDisplay; |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 103 | mDisplays = displays; |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | /** |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 107 | * Returns the state of the Wifi display feature on this device. |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 108 | * <p> |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 109 | * 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 Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 112 | * </p> |
| 113 | */ |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 114 | public int getFeatureState() { |
| 115 | return mFeatureState; |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /** |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 119 | * 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 Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 122 | */ |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 123 | 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 Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /** |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 146 | * 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 Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 149 | */ |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 150 | public WifiDisplay[] getDisplays() { |
| 151 | return mDisplays; |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 152 | } |
| 153 | |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 154 | @Override |
| 155 | public void writeToParcel(Parcel dest, int flags) { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 156 | dest.writeInt(mFeatureState); |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 157 | dest.writeInt(mScanState); |
| 158 | dest.writeInt(mActiveDisplayState); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 159 | |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 160 | if (mActiveDisplay != null) { |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 161 | dest.writeInt(1); |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 162 | mActiveDisplay.writeToParcel(dest, flags); |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 163 | } else { |
| 164 | dest.writeInt(0); |
| 165 | } |
| 166 | |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 167 | dest.writeInt(mDisplays.length); |
| 168 | for (WifiDisplay display : mDisplays) { |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 169 | display.writeToParcel(dest, flags); |
| 170 | } |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
| 173 | @Override |
| 174 | public int describeContents() { |
| 175 | return 0; |
| 176 | } |
| 177 | |
| 178 | // For debugging purposes only. |
| 179 | @Override |
| 180 | public String toString() { |
Jeff Brown | 89d5546 | 2012-09-19 11:33:42 -0700 | [diff] [blame] | 181 | return "WifiDisplayStatus{featureState=" + mFeatureState |
Jeff Brown | 180bbc7 | 2012-09-08 23:15:00 -0700 | [diff] [blame] | 182 | + ", scanState=" + mScanState |
| 183 | + ", activeDisplayState=" + mActiveDisplayState |
| 184 | + ", activeDisplay=" + mActiveDisplay |
Chong Zhang | ab87a63 | 2013-06-11 10:25:49 -0700 | [diff] [blame] | 185 | + ", displays=" + Arrays.toString(mDisplays) |
Jeff Brown | e08ae38 | 2012-09-07 20:36:36 -0700 | [diff] [blame] | 186 | + "}"; |
| 187 | } |
| 188 | } |