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