blob: fb2bdd455c6248c5bc74085cc652a02b80b3e0e9 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
2 * Copyright (C) 2008 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.net.wifi;
18
Chelsea Derrickadae06b2014-07-16 12:53:40 -070019import android.annotation.SystemApi;
Sky Faber3e3857c2014-09-22 13:54:18 -070020import android.content.pm.PackageManager;
Jaewan Kim63461552014-03-10 17:10:51 +090021import android.net.IpConfiguration;
22import android.net.IpConfiguration.ProxySettings;
Jaewan Kim63461552014-03-10 17:10:51 +090023import android.net.ProxyInfo;
Lorenzo Colitti0a82e802014-07-31 00:48:01 +090024import android.net.StaticIpConfiguration;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.os.Parcel;
Jaewan Kim63461552014-03-10 17:10:51 +090026import android.os.Parcelable;
Bartosz Fabianowski6fb07562016-01-12 15:43:19 +010027import android.os.UserHandle;
Irfan Sheriff26d00762013-02-05 09:44:12 -080028import android.text.TextUtils;
Ritesh Reddyaeb4c062016-01-26 19:40:48 +000029import android.util.BackupUtils;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080030
Ritesh Reddyaeb4c062016-01-26 19:40:48 +000031import java.io.ByteArrayOutputStream;
32import java.io.DataInputStream;
33import java.io.DataOutputStream;
34import java.io.IOException;
xinhe8d106782015-12-01 14:44:37 -080035import java.util.Arrays;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080036import java.util.BitSet;
xinhe8d106782015-12-01 14:44:37 -080037import java.util.HashMap;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038
39/**
40 * A class representing a configured Wi-Fi network, including the
Irfan Sheriff9b813192013-01-11 14:03:55 -080041 * security configuration.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042 */
Jaewan Kim67897972014-04-07 09:01:24 +000043public class WifiConfiguration implements Parcelable {
Irfan Sheriff9b813192013-01-11 14:03:55 -080044 private static final String TAG = "WifiConfiguration";
Ritesh Reddyaeb4c062016-01-26 19:40:48 +000045 /**
46 * Current Version of the Backup Serializer.
47 */
48 private static final int BACKUP_VERSION = 2;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080049 /** {@hide} */
50 public static final String ssidVarName = "ssid";
51 /** {@hide} */
52 public static final String bssidVarName = "bssid";
53 /** {@hide} */
54 public static final String pskVarName = "psk";
55 /** {@hide} */
56 public static final String[] wepKeyVarNames = { "wep_key0", "wep_key1", "wep_key2", "wep_key3" };
57 /** {@hide} */
58 public static final String wepTxKeyIdxVarName = "wep_tx_keyidx";
59 /** {@hide} */
60 public static final String priorityVarName = "priority";
61 /** {@hide} */
62 public static final String hiddenSSIDVarName = "scan_ssid";
Irfan Sheriff5ee89802010-09-16 17:53:34 -070063 /** {@hide} */
Yuhao Zheng5f9385f2014-06-30 15:32:08 -070064 public static final String pmfVarName = "ieee80211w";
65 /** {@hide} */
66 public static final String updateIdentiferVarName = "update_identifier";
67 /** {@hide} */
Irfan Sheriff5ee89802010-09-16 17:53:34 -070068 public static final int INVALID_NETWORK_ID = -1;
xinhea0be0fb2015-01-07 17:57:38 -080069
Vinit Deshpandea772f0c2016-01-27 19:05:24 -080070 /** {@hide} */
71 private String mPasspointManagementObjectTree;
72
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080073 /**
74 * Recognized key management schemes.
75 */
76 public static class KeyMgmt {
77 private KeyMgmt() { }
Chung-yih Wang5069cc72009-06-03 17:33:47 +080078
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080079 /** WPA is not used; plaintext or static WEP could be used. */
80 public static final int NONE = 0;
81 /** WPA pre-shared key (requires {@code preSharedKey} to be specified). */
82 public static final int WPA_PSK = 1;
83 /** WPA using EAP authentication. Generally used with an external authentication server. */
84 public static final int WPA_EAP = 2;
85 /** IEEE 802.1X using EAP authentication and (optionally) dynamically
86 * generated WEP keys. */
87 public static final int IEEE8021X = 3;
88
Irfan Sheriffec8d23a2011-02-16 17:00:33 -080089 /** WPA2 pre-shared key for use with soft access point
90 * (requires {@code preSharedKey} to be specified).
91 * @hide
92 */
Jeremy Kleinb6253772016-01-06 11:47:03 -080093 @SystemApi
Irfan Sheriffec8d23a2011-02-16 17:00:33 -080094 public static final int WPA2_PSK = 4;
Vinit Deshpandea772f0c2016-01-27 19:05:24 -080095 /**
96 * Hotspot 2.0 r2 OSEN:
97 * @hide
98 */
99 public static final int OSEN = 5;
Irfan Sheriffec8d23a2011-02-16 17:00:33 -0800100
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 public static final String varName = "key_mgmt";
102
Irfan Sheriffec8d23a2011-02-16 17:00:33 -0800103 public static final String[] strings = { "NONE", "WPA_PSK", "WPA_EAP", "IEEE8021X",
Vinit Deshpandea772f0c2016-01-27 19:05:24 -0800104 "WPA2_PSK", "OSEN" };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800105 }
Chung-yih Wang5069cc72009-06-03 17:33:47 +0800106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 /**
108 * Recognized security protocols.
109 */
110 public static class Protocol {
111 private Protocol() { }
112
113 /** WPA/IEEE 802.11i/D3.0 */
114 public static final int WPA = 0;
115 /** WPA2/IEEE 802.11i */
116 public static final int RSN = 1;
Vinit Deshpandea772f0c2016-01-27 19:05:24 -0800117 /** HS2.0 r2 OSEN
118 * @hide
119 */
120 public static final int OSEN = 2;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121
122 public static final String varName = "proto";
123
Vinit Deshpandea772f0c2016-01-27 19:05:24 -0800124 public static final String[] strings = { "WPA", "RSN", "OSEN" };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800125 }
126
127 /**
128 * Recognized IEEE 802.11 authentication algorithms.
129 */
130 public static class AuthAlgorithm {
131 private AuthAlgorithm() { }
132
133 /** Open System authentication (required for WPA/WPA2) */
134 public static final int OPEN = 0;
135 /** Shared Key authentication (requires static WEP keys) */
136 public static final int SHARED = 1;
137 /** LEAP/Network EAP (only used with LEAP) */
138 public static final int LEAP = 2;
139
140 public static final String varName = "auth_alg";
141
142 public static final String[] strings = { "OPEN", "SHARED", "LEAP" };
143 }
144
145 /**
146 * Recognized pairwise ciphers for WPA.
147 */
148 public static class PairwiseCipher {
149 private PairwiseCipher() { }
150
151 /** Use only Group keys (deprecated) */
152 public static final int NONE = 0;
153 /** Temporal Key Integrity Protocol [IEEE 802.11i/D7.0] */
154 public static final int TKIP = 1;
155 /** AES in Counter mode with CBC-MAC [RFC 3610, IEEE 802.11i/D7.0] */
156 public static final int CCMP = 2;
157
158 public static final String varName = "pairwise";
Chung-yih Wang5069cc72009-06-03 17:33:47 +0800159
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800160 public static final String[] strings = { "NONE", "TKIP", "CCMP" };
161 }
162
163 /**
164 * Recognized group ciphers.
165 * <pre>
166 * CCMP = AES in Counter mode with CBC-MAC [RFC 3610, IEEE 802.11i/D7.0]
167 * TKIP = Temporal Key Integrity Protocol [IEEE 802.11i/D7.0]
168 * WEP104 = WEP (Wired Equivalent Privacy) with 104-bit key
169 * WEP40 = WEP (Wired Equivalent Privacy) with 40-bit key (original 802.11)
170 * </pre>
171 */
172 public static class GroupCipher {
173 private GroupCipher() { }
174
175 /** WEP40 = WEP (Wired Equivalent Privacy) with 40-bit key (original 802.11) */
176 public static final int WEP40 = 0;
177 /** WEP104 = WEP (Wired Equivalent Privacy) with 104-bit key */
178 public static final int WEP104 = 1;
179 /** Temporal Key Integrity Protocol [IEEE 802.11i/D7.0] */
180 public static final int TKIP = 2;
181 /** AES in Counter mode with CBC-MAC [RFC 3610, IEEE 802.11i/D7.0] */
182 public static final int CCMP = 3;
Vinit Deshpandea772f0c2016-01-27 19:05:24 -0800183 /** Hotspot 2.0 r2 OSEN
184 * @hide
185 */
186 public static final int GTK_NOT_USED = 4;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800187
188 public static final String varName = "group";
189
Vinit Deshpandea772f0c2016-01-27 19:05:24 -0800190 public static final String[] strings =
191 { "WEP40", "WEP104", "TKIP", "CCMP", "GTK_NOT_USED" };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800192 }
193
194 /** Possible status of a network configuration. */
195 public static class Status {
196 private Status() { }
197
198 /** this is the network we are currently connected to */
199 public static final int CURRENT = 0;
200 /** supplicant will not attempt to use this network */
201 public static final int DISABLED = 1;
202 /** supplicant will consider this network available for association */
203 public static final int ENABLED = 2;
204
205 public static final String[] strings = { "current", "disabled", "enabled" };
206 }
207
Isaac Levy8dc6a1b2011-07-27 08:00:03 -0700208 /** @hide */
Lorenzo Colitti1ac50cb2015-04-06 17:19:19 +0900209 public static final int UNKNOWN_UID = -1;
210
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800211 /**
212 * The ID number that the supplicant uses to identify this
213 * network configuration entry. This must be passed as an argument
214 * to most calls into the supplicant.
215 */
216 public int networkId;
217
218 /**
219 * The current status of this network configuration entry.
xinhe8d106782015-12-01 14:44:37 -0800220 * Fixme We need remove this field to use only Quality network selection status only
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800221 * @see Status
222 */
223 public int status;
Isaac Levy8dc6a1b2011-07-27 08:00:03 -0700224
225 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800226 * The network's SSID. Can either be an ASCII string,
227 * which must be enclosed in double quotation marks
Ben Dodson4e8620f2010-08-25 10:55:47 -0700228 * (e.g., {@code "MyNetwork"}, or a string of
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800229 * hex digits,which are not enclosed in quotes
230 * (e.g., {@code 01a243f405}).
231 */
232 public String SSID;
233 /**
234 * When set, this network configuration entry should only be used when
235 * associating with the AP having the specified BSSID. The value is
236 * a string in the format of an Ethernet MAC address, e.g.,
237 * <code>XX:XX:XX:XX:XX:XX</code> where each <code>X</code> is a hex digit.
238 */
239 public String BSSID;
xinhea0be0fb2015-01-07 17:57:38 -0800240
241 /**
Peter Qiud6676162016-02-11 16:45:44 -0800242 * 2GHz band.
243 * @hide
244 */
245 public static final int AP_BAND_2GHZ = 0;
246
247 /**
248 * 5GHz band.
249 * @hide
250 */
251 public static final int AP_BAND_5GHZ = 1;
252
253 /**
xinhea0be0fb2015-01-07 17:57:38 -0800254 * The band which AP resides on
255 * 0-2G 1-5G
256 * By default, 2G is chosen
xinhe7e5e7912015-04-21 15:42:03 -0700257 * @hide
xinhea0be0fb2015-01-07 17:57:38 -0800258 */
Peter Qiud6676162016-02-11 16:45:44 -0800259 public int apBand = AP_BAND_2GHZ;
xinhea0be0fb2015-01-07 17:57:38 -0800260
261 /**
262 * The channel which AP resides on,currently, US only
263 * 2G 1-11
264 * 5G 36,40,44,48,149,153,157,161,165
265 * 0 - find a random available channel according to the apBand
xinhe7e5e7912015-04-21 15:42:03 -0700266 * @hide
xinhea0be0fb2015-01-07 17:57:38 -0800267 */
268 public int apChannel = 0;
269
Yuhao Zheng8a9eb812014-05-27 10:35:02 -0700270 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800271 * Pre-shared key for use with WPA-PSK.
272 * <p/>
273 * When the value of this key is read, the actual key is
274 * not returned, just a "*" if the key has a value, or the null
275 * string otherwise.
276 */
277 public String preSharedKey;
278 /**
279 * Up to four WEP keys. Either an ASCII string enclosed in double
Ben Dodson4e8620f2010-08-25 10:55:47 -0700280 * quotation marks (e.g., {@code "abcdef"} or a string
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800281 * of hex digits (e.g., {@code 0102030405}).
282 * <p/>
283 * When the value of one of these keys is read, the actual key is
284 * not returned, just a "*" if the key has a value, or the null
285 * string otherwise.
286 */
287 public String[] wepKeys;
Chung-yih Wang5069cc72009-06-03 17:33:47 +0800288
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800289 /** Default WEP key index, ranging from 0 to 3. */
290 public int wepTxKeyIndex;
291
292 /**
293 * Priority determines the preference given to a network by {@code wpa_supplicant}
294 * when choosing an access point with which to associate.
295 */
296 public int priority;
297
298 /**
299 * This is a network that does not broadcast its SSID, so an
300 * SSID-specific probe request must be used for scans.
301 */
302 public boolean hiddenSSID;
303
304 /**
Yuhao Zheng5f9385f2014-06-30 15:32:08 -0700305 * This is a network that requries Protected Management Frames (PMF).
306 * @hide
307 */
308 public boolean requirePMF;
309
310 /**
311 * Update identifier, for Passpoint network.
312 * @hide
313 */
314 public String updateIdentifier;
315
316 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800317 * The set of key management protocols supported by this configuration.
318 * See {@link KeyMgmt} for descriptions of the values.
319 * Defaults to WPA-PSK WPA-EAP.
320 */
321 public BitSet allowedKeyManagement;
322 /**
323 * The set of security protocols supported by this configuration.
324 * See {@link Protocol} for descriptions of the values.
325 * Defaults to WPA RSN.
326 */
327 public BitSet allowedProtocols;
328 /**
329 * The set of authentication protocols supported by this configuration.
330 * See {@link AuthAlgorithm} for descriptions of the values.
331 * Defaults to automatic selection.
332 */
333 public BitSet allowedAuthAlgorithms;
334 /**
335 * The set of pairwise ciphers for WPA supported by this configuration.
336 * See {@link PairwiseCipher} for descriptions of the values.
337 * Defaults to CCMP TKIP.
338 */
339 public BitSet allowedPairwiseCiphers;
340 /**
341 * The set of group ciphers supported by this configuration.
342 * See {@link GroupCipher} for descriptions of the values.
343 * Defaults to CCMP TKIP WEP104 WEP40.
344 */
345 public BitSet allowedGroupCiphers;
Irfan Sheriff9b813192013-01-11 14:03:55 -0800346 /**
Irfan Sheriff26d00762013-02-05 09:44:12 -0800347 * The enterprise configuration details specifying the EAP method,
348 * certificates and other settings associated with the EAP.
Irfan Sheriff9b813192013-01-11 14:03:55 -0800349 */
350 public WifiEnterpriseConfig enterpriseConfig;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800351
Jaewan Kim67897972014-04-07 09:01:24 +0000352 /**
Vinit Deshpandeb21d2482015-02-02 10:50:36 -0800353 * Fully qualified domain name of a passpoint configuration
354 */
355 public String FQDN;
356
357 /**
Vinit Deshpandea0d929e2015-06-12 15:18:44 -0700358 * Name of passpoint credential provider
Vinit Deshpandeb21d2482015-02-02 10:50:36 -0800359 */
360 public String providerFriendlyName;
361
362 /**
Vinit Deshpandea0d929e2015-06-12 15:18:44 -0700363 * Roaming Consortium Id list for passpoint credential; identifies a set of networks where
364 * passpoint credential will be considered valid
Vinit Deshpandeb21d2482015-02-02 10:50:36 -0800365 */
Vinit Deshpande7226c8f2015-06-30 13:43:02 -0700366 public long[] roamingConsortiumIds;
Vinit Deshpandeb21d2482015-02-02 10:50:36 -0800367
368 /**
Jaewan Kim67897972014-04-07 09:01:24 +0000369 * @hide
Bartosz Fabianowski6fb07562016-01-12 15:43:19 +0100370 * This network configuration is visible to and usable by other users on the
371 * same device.
372 */
373 public boolean shared;
374
375 /**
376 * @hide
Jaewan Kim67897972014-04-07 09:01:24 +0000377 */
Jaewan Kim63461552014-03-10 17:10:51 +0900378 private IpConfiguration mIpConfiguration;
Jaewan Kim67897972014-04-07 09:01:24 +0000379
380 /**
381 * @hide
vandwalle7c3606c2014-03-31 19:12:07 -0700382 * dhcp server MAC address if known
383 */
384 public String dhcpServer;
385
386 /**
387 * @hide
388 * default Gateway MAC address if known
389 */
390 public String defaultGwMacAddress;
391
392 /**
393 * @hide
vandwalle3a74e2ef2014-05-21 21:21:00 -0700394 * last failure
395 */
396 public String lastFailure;
397
398 /**
399 * @hide
vandwalleec3e9802014-11-07 17:29:24 -0800400 * last time we connected, this configuration had validated internet access
vandwalle448e2082014-09-05 00:01:24 -0700401 */
vandwalleec3e9802014-11-07 17:29:24 -0800402 public boolean validatedInternetAccess;
vandwalle448e2082014-09-05 00:01:24 -0700403
404 /**
405 * @hide
Glen Kuhneb6cd6fa2016-02-10 15:08:33 -0800406 * The number of beacon intervals between Delivery Traffic Indication Maps (DTIM)
407 * This value is populated from scan results that contain Beacon Frames, which are infrequent.
408 * The value is not guaranteed to be set or current (Although it SHOULDNT change once set)
409 * Valid values are from 1 - 255. Initialized here as 0, use this to check if set.
410 */
411 public int dtimInterval = 0;
412
413 /**
414 * @hide
vandwalle8f135482014-05-30 14:29:49 -0700415 * Uid of app creating the configuration
416 */
Chelsea Derrickadae06b2014-07-16 12:53:40 -0700417 @SystemApi
vandwalle8f135482014-05-30 14:29:49 -0700418 public int creatorUid;
419
420 /**
421 * @hide
422 * Uid of last app issuing a connection related command
423 */
424 public int lastConnectUid;
425
426 /**
427 * @hide
428 * Uid of last app modifying the configuration
429 */
Chelsea Derrickeb8f3292014-07-24 12:50:40 -0700430 @SystemApi
vandwalle8f135482014-05-30 14:29:49 -0700431 public int lastUpdateUid;
432
433 /**
434 * @hide
Sky Faber3e3857c2014-09-22 13:54:18 -0700435 * Universal name for app creating the configuration
436 * see {#link {@link PackageManager#getNameForUid(int)}
437 */
438 @SystemApi
439 public String creatorName;
440
441 /**
442 * @hide
443 * Universal name for app updating the configuration
444 * see {#link {@link PackageManager#getNameForUid(int)}
445 */
446 @SystemApi
447 public String lastUpdateName;
448
449 /**
450 * @hide
Sky Faber3e3857c2014-09-22 13:54:18 -0700451 * Status of user approval for connection
452 */
453 public int userApproved = USER_UNSPECIFIED;
454
vandwalle2ab90892014-06-02 15:30:39 -0700455 /** The Below RSSI thresholds are used to configure AutoJoin
456 * - GOOD/LOW/BAD thresholds are used so as to calculate link score
vandwalle2e93c38f2014-09-13 12:53:26 -0700457 * - UNWANTED_SOFT are used by the blacklisting logic so as to handle
458 * the unwanted network message coming from CS
459 * - UNBLACKLIST thresholds are used so as to tweak the speed at which
460 * the network is unblacklisted (i.e. if
vandwalle2ab90892014-06-02 15:30:39 -0700461 * it is seen with good RSSI, it is blacklisted faster)
vandwalle2e93c38f2014-09-13 12:53:26 -0700462 * - INITIAL_AUTOJOIN_ATTEMPT, used to determine how close from
463 * the network we need to be before autojoin kicks in
vandwalle2ab90892014-06-02 15:30:39 -0700464 */
vandwalle7c3606c2014-03-31 19:12:07 -0700465 /** @hide **/
466 public static int INVALID_RSSI = -127;
467
468 /**
469 * @hide
470 * A summary of the RSSI and Band status for that configuration
471 * This is used as a temporary value by the auto-join controller
472 */
Vinit Deshpande6f6c7812015-03-27 11:40:17 -0700473 public static final class Visibility {
vandwalle7c3606c2014-03-31 19:12:07 -0700474 public int rssi5; // strongest 5GHz RSSI
475 public int rssi24; // strongest 2.4GHz RSSI
476 public int num5; // number of BSSIDs on 5GHz
477 public int num24; // number of BSSIDs on 2.4GHz
vandwallee26bc8f2014-09-10 01:32:09 -0700478 public long age5; // timestamp of the strongest 5GHz BSSID (last time it was seen)
479 public long age24; // timestamp of the strongest 2.4GHz BSSID (last time it was seen)
480 public String BSSID24;
481 public String BSSID5;
vandwalle72e1d3f2014-12-15 15:41:34 -0800482 public int score; // Debug only, indicate last score used for autojoin/cell-handover
483 public int currentNetworkBoost; // Debug only, indicate boost applied to RSSI if current
484 public int bandPreferenceBoost; // Debug only, indicate boost applied to RSSI if current
485 public int lastChoiceBoost; // Debug only, indicate last choice applied to this configuration
486 public String lastChoiceConfig; // Debug only, indicate last choice applied to this configuration
vandwalle5fb7bf52014-05-21 15:20:59 -0700487
488 public Visibility() {
vandwalle7c3606c2014-03-31 19:12:07 -0700489 rssi5 = INVALID_RSSI;
490 rssi24 = INVALID_RSSI;
491 }
vandwalle5fb7bf52014-05-21 15:20:59 -0700492
493 public Visibility(Visibility source) {
vandwalle7c3606c2014-03-31 19:12:07 -0700494 rssi5 = source.rssi5;
495 rssi24 = source.rssi24;
496 age24 = source.age24;
497 age5 = source.age5;
498 num24 = source.num24;
499 num5 = source.num5;
vandwallee26bc8f2014-09-10 01:32:09 -0700500 BSSID5 = source.BSSID5;
501 BSSID24 = source.BSSID24;
vandwalle7c3606c2014-03-31 19:12:07 -0700502 }
vandwalle5fb7bf52014-05-21 15:20:59 -0700503
504 @Override
505 public String toString() {
506 StringBuilder sbuf = new StringBuilder();
507 sbuf.append("[");
508 if (rssi24 > INVALID_RSSI) {
509 sbuf.append(Integer.toString(rssi24));
510 sbuf.append(",");
511 sbuf.append(Integer.toString(num24));
vandwallee26bc8f2014-09-10 01:32:09 -0700512 if (BSSID24 != null) sbuf.append(",").append(BSSID24);
vandwalle5fb7bf52014-05-21 15:20:59 -0700513 }
vandwalle72e1d3f2014-12-15 15:41:34 -0800514 sbuf.append("; ");
vandwalle5fb7bf52014-05-21 15:20:59 -0700515 if (rssi5 > INVALID_RSSI) {
516 sbuf.append(Integer.toString(rssi5));
517 sbuf.append(",");
518 sbuf.append(Integer.toString(num5));
vandwallee26bc8f2014-09-10 01:32:09 -0700519 if (BSSID5 != null) sbuf.append(",").append(BSSID5);
vandwalle5fb7bf52014-05-21 15:20:59 -0700520 }
vandwalle72e1d3f2014-12-15 15:41:34 -0800521 if (score != 0) {
522 sbuf.append("; ").append(score);
523 sbuf.append(", ").append(currentNetworkBoost);
524 sbuf.append(", ").append(bandPreferenceBoost);
525 if (lastChoiceConfig != null) {
526 sbuf.append(", ").append(lastChoiceBoost);
527 sbuf.append(", ").append(lastChoiceConfig);
528 }
529 }
vandwalle5fb7bf52014-05-21 15:20:59 -0700530 sbuf.append("]");
531 return sbuf.toString();
532 }
vandwalle7c3606c2014-03-31 19:12:07 -0700533 }
534
535 /** @hide
536 * Cache the visibility status of this configuration.
537 * Visibility can change at any time depending on scan results availability.
538 * Owner of the WifiConfiguration is responsible to set this field based on
539 * recent scan results.
540 ***/
541 public Visibility visibility;
542
543 /** @hide
544 * calculate and set Visibility for that configuration.
545 *
546 * age in milliseconds: we will consider only ScanResults that are more recent,
547 * i.e. younger.
548 ***/
Vinit Deshpande6f6c7812015-03-27 11:40:17 -0700549 public void setVisibility(Visibility status) {
vandwalle7c3606c2014-03-31 19:12:07 -0700550 visibility = status;
vandwalle7c3606c2014-03-31 19:12:07 -0700551 }
552
Sky Faber3e3857c2014-09-22 13:54:18 -0700553 // States for the userApproved field
554 /**
555 * @hide
556 * User hasn't specified if connection is okay
557 */
558 public static final int USER_UNSPECIFIED = 0;
559 /**
560 * @hide
561 * User has approved this for connection
562 */
563 public static final int USER_APPROVED = 1;
564 /**
565 * @hide
566 * User has banned this from connection
567 */
568 public static final int USER_BANNED = 2;
569 /**
570 * @hide
571 * Waiting for user input
572 */
573 public static final int USER_PENDING = 3;
574
vandwalle7c3606c2014-03-31 19:12:07 -0700575 /**
576 * @hide
vandwalleec3e9802014-11-07 17:29:24 -0800577 * Number of reports indicating no Internet Access
578 */
579 public int numNoInternetAccessReports;
580
581 /**
582 * @hide
Pierre Vandwalleced1a652015-06-16 13:55:44 -0700583 * For debug: date at which the config was last updated
584 */
585 public String updateTime;
586
587 /**
588 * @hide
589 * For debug: date at which the config was last updated
590 */
591 public String creationTime;
592
593 /**
594 * @hide
vandwalleec3e9802014-11-07 17:29:24 -0800595 * The WiFi configuration is considered to have no internet access for purpose of autojoining
596 * if there has been a report of it having no internet access, and, it never have had
597 * internet access in the past.
598 */
599 public boolean hasNoInternetAccess() {
600 return numNoInternetAccessReports > 0 && !validatedInternetAccess;
601 }
602
603 /**
Lorenzo Colitti1248dd32015-04-06 17:26:10 +0900604 * The WiFi configuration is expected not to have Internet access (e.g., a wireless printer, a
605 * Chromecast hotspot, etc.). This will be set if the user explicitly confirms a connection to
606 * this configuration and selects "don't ask again".
607 * @hide
608 */
609 public boolean noInternetAccessExpected;
610
611 /**
vandwalleec3e9802014-11-07 17:29:24 -0800612 * @hide
vandwalle154b2cf2014-07-23 16:03:43 -0700613 * Last time the system was connected to this configuration.
vandwalle111fa022014-06-10 20:47:58 -0700614 */
615 public long lastConnected;
616
617 /**
618 * @hide
vandwalle154b2cf2014-07-23 16:03:43 -0700619 * Last time the system tried to connect and failed.
620 */
621 public long lastConnectionFailure;
622
623 /**
624 * @hide
vandwalle8650c032015-01-11 11:57:01 -0800625 * Last time the system tried to roam and failed because of authentication failure or DHCP
626 * RENEW failure.
627 */
628 public long lastRoamingFailure;
629
630 /** @hide */
631 public static int ROAMING_FAILURE_IP_CONFIG = 1;
632 /** @hide */
633 public static int ROAMING_FAILURE_AUTH_FAILURE = 2;
634
635 /**
636 * @hide
637 * Initial amount of time this Wifi configuration gets blacklisted for network switching
638 * because of roaming failure
639 */
640 public long roamingFailureBlackListTimeMilli = 1000;
641
642 /**
643 * @hide
644 * Last roaming failure reason code
645 */
646 public int lastRoamingFailureReason;
647
648 /**
649 * @hide
vandwalle154b2cf2014-07-23 16:03:43 -0700650 * Last time the system was disconnected to this configuration.
vandwalle111fa022014-06-10 20:47:58 -0700651 */
652 public long lastDisconnected;
vandwalle2ab90892014-06-02 15:30:39 -0700653
vandwalle7c3606c2014-03-31 19:12:07 -0700654 /**
vandwallee50869d2014-05-13 13:08:44 -0700655 * Set if the configuration was self added by the framework
vandwalle8f135482014-05-30 14:29:49 -0700656 * This boolean is cleared if we get a connect/save/ update or
657 * any wifiManager command that indicate the user interacted with the configuration
658 * since we will now consider that the configuration belong to him.
vandwallee50869d2014-05-13 13:08:44 -0700659 * @hide
660 */
661 public boolean selfAdded;
662
663 /**
vandwalle8f135482014-05-30 14:29:49 -0700664 * Set if the configuration was self added by the framework
665 * This boolean is set once and never cleared. It is used
666 * so as we never loose track of who created the
667 * configuration in the first place.
668 * @hide
669 */
670 public boolean didSelfAdd;
671
672 /**
vandwalle154b2cf2014-07-23 16:03:43 -0700673 * Peer WifiConfiguration this WifiConfiguration was added for
vandwalle2d0f71e2014-06-01 14:58:07 -0700674 * @hide
675 */
676 public String peerWifiConfiguration;
677
678 /**
vandwalle7c3606c2014-03-31 19:12:07 -0700679 * @hide
680 * Indicate that a WifiConfiguration is temporary and should not be saved
681 * nor considered by AutoJoin.
682 */
683 public boolean ephemeral;
684
685 /**
686 * @hide
Jeremy Joslinf0c9b8c2016-03-17 10:10:32 -0700687 * A hint about whether or not the network represented by this WifiConfiguration
688 * is metered.
689 */
690 public boolean meteredHint;
691
692 /**
693 * @hide
vandwalle154b2cf2014-07-23 16:03:43 -0700694 * Number of time the scorer overrode a the priority based choice, when comparing two
695 * WifiConfigurations, note that since comparing WifiConfiguration happens very often
696 * potentially at every scan, this number might become very large, even on an idle
697 * system.
698 */
699 @SystemApi
700 public int numScorerOverride;
701
702 /**
703 * @hide
704 * Number of time the scorer overrode a the priority based choice, and the comparison
705 * triggered a network switch
706 */
707 @SystemApi
708 public int numScorerOverrideAndSwitchedNetwork;
709
710 /**
711 * @hide
vandwalle4eeecb22014-07-25 17:10:56 -0700712 * Number of time we associated to this configuration.
713 */
714 @SystemApi
715 public int numAssociation;
716
vandwalle448e2082014-09-05 00:01:24 -0700717 /**
718 * @hide
719 * Number of time user disabled WiFi while associated to this configuration with Low RSSI.
720 */
721 public int numUserTriggeredWifiDisableLowRSSI;
722
723 /**
724 * @hide
725 * Number of time user disabled WiFi while associated to this configuration with Bad RSSI.
726 */
727 public int numUserTriggeredWifiDisableBadRSSI;
728
729 /**
730 * @hide
731 * Number of time user disabled WiFi while associated to this configuration
732 * and RSSI was not HIGH.
733 */
734 public int numUserTriggeredWifiDisableNotHighRSSI;
735
736 /**
737 * @hide
738 * Number of ticks associated to this configuration with Low RSSI.
739 */
740 public int numTicksAtLowRSSI;
741
742 /**
743 * @hide
744 * Number of ticks associated to this configuration with Bad RSSI.
745 */
746 public int numTicksAtBadRSSI;
747
748 /**
749 * @hide
750 * Number of ticks associated to this configuration
751 * and RSSI was not HIGH.
752 */
753 public int numTicksAtNotHighRSSI;
754 /**
755 * @hide
756 * Number of time user (WifiManager) triggered association to this configuration.
757 * TODO: count this only for Wifi Settings uuid, so as to not count 3rd party apps
758 */
759 public int numUserTriggeredJoinAttempts;
vandwalle4eeecb22014-07-25 17:10:56 -0700760
xinhe8d106782015-12-01 14:44:37 -0800761 /** @hide
762 * Boost given to RSSI on a home network for the purpose of calculating the score
763 * This adds stickiness to home networks, as defined by:
764 * - less than 4 known BSSIDs
765 * - PSK only
766 * - TODO: add a test to verify that all BSSIDs are behind same gateway
767 ***/
768 public static final int HOME_NETWORK_RSSI_BOOST = 5;
769
770 /**
771 * @hide
772 * This class is used to contain all the information and API used for quality network selection
773 */
774 public static class NetworkSelectionStatus {
775 /**
776 * Quality Network Selection Status enable, temporary disabled, permanently disabled
777 */
778 /**
779 * This network is allowed to join Quality Network Selection
780 */
781 public static final int NETWORK_SELECTION_ENABLED = 0;
782 /**
783 * network was temporary disabled. Can be re-enabled after a time period expire
784 */
785 public static final int NETWORK_SELECTION_TEMPORARY_DISABLED = 1;
786 /**
787 * network was permanently disabled.
788 */
789 public static final int NETWORK_SELECTION_PERMANENTLY_DISABLED = 2;
790 /**
791 * Maximum Network selection status
792 */
793 public static final int NETWORK_SELECTION_STATUS_MAX = 3;
794
795 /**
796 * Quality network selection status String (for debug purpose). Use Quality network
797 * selection status value as index to extec the corresponding debug string
798 */
799 private static final String[] QUALITY_NETWORK_SELECTION_STATUS = {
xinhe90a38412016-01-20 10:52:50 -0800800 "NETWORK_SELECTION_ENABLED",
801 "NETWORK_SELECTION_TEMPORARY_DISABLED",
xinhe8d106782015-12-01 14:44:37 -0800802 "NETWORK_SELECTION_PERMANENTLY_DISABLED"};
803
804 //Quality Network disabled reasons
805 /**
806 * Default value. Means not disabled
807 */
808 public static final int NETWORK_SELECTION_ENABLE = 0;
809 /**
810 * This network is disabled because higher layer (>2) network is bad
811 */
812 public static final int DISABLED_BAD_LINK = 1;
813 /**
814 * This network is disabled because multiple association rejects
815 */
816 public static final int DISABLED_ASSOCIATION_REJECTION = 2;
817 /**
818 * This network is disabled because multiple authentication failure
819 */
820 public static final int DISABLED_AUTHENTICATION_FAILURE = 3;
821 /**
822 * This network is disabled because multiple DHCP failure
823 */
824 public static final int DISABLED_DHCP_FAILURE = 4;
825 /**
826 * This network is disabled because of security network but no credentials
827 */
828 public static final int DISABLED_DNS_FAILURE = 5;
829 /**
830 * This network is disabled because EAP-TLS failure
831 */
832 public static final int DISABLED_TLS_VERSION_MISMATCH = 6;
833 /**
834 * This network is disabled due to WifiManager disable it explicitly
835 */
836 public static final int DISABLED_AUTHENTICATION_NO_CREDENTIALS = 7;
837 /**
838 * This network is disabled because no Internet connected and user do not want
839 */
840 public static final int DISABLED_NO_INTERNET = 8;
841 /**
842 * This network is disabled due to WifiManager disable it explicitly
843 */
844 public static final int DISABLED_BY_WIFI_MANAGER = 9;
845 /**
846 * This Maximum disable reason value
847 */
848 public static final int NETWORK_SELECTION_DISABLED_MAX = 10;
849
850 /**
851 * Quality network selection disable reason String (for debug purpose)
852 */
853 private static final String[] QUALITY_NETWORK_SELECTION_DISABLE_REASON = {
xinhe90a38412016-01-20 10:52:50 -0800854 "NETWORK_SELECTION_ENABLE",
855 "NETWORK_SELECTION_DISABLED_BAD_LINK",
xinhe8d106782015-12-01 14:44:37 -0800856 "NETWORK_SELECTION_DISABLED_ASSOCIATION_REJECTION ",
857 "NETWORK_SELECTION_DISABLED_AUTHENTICATION_FAILURE",
858 "NETWORK_SELECTION_DISABLED_DHCP_FAILURE",
xinhe90a38412016-01-20 10:52:50 -0800859 "NETWORK_SELECTION_DISABLED_DNS_FAILURE",
860 "NETWORK_SELECTION_DISABLED_TLS_VERSION",
xinhe8d106782015-12-01 14:44:37 -0800861 "NETWORK_SELECTION_DISABLED_AUTHENTICATION_NO_CREDENTIALS",
xinhe90a38412016-01-20 10:52:50 -0800862 "NETWORK_SELECTION_DISABLED_NO_INTERNET",
xinhe8d106782015-12-01 14:44:37 -0800863 "NETWORK_SELECTION_DISABLED_BY_WIFI_MANAGER"};
864
865 /**
866 * Invalid time stamp for network selection disable
867 */
868 public static final long INVALID_NETWORK_SELECTION_DISABLE_TIMESTAMP = -1L;
869
xinhe584dc6b2016-01-26 10:32:03 -0800870 /**
871 * This constant indicates the current configuration has connect choice set
872 */
873 private static final int CONNECT_CHOICE_EXISTS = 1;
874
875 /**
876 * This constant indicates the current configuration does not have connect choice set
877 */
878 private static final int CONNECT_CHOICE_NOT_EXISTS = -1;
879
xinhe8d106782015-12-01 14:44:37 -0800880 // fields for QualityNetwork Selection
881 /**
882 * Network selection status, should be in one of three status: enable, temporaily disabled
883 * or permanently disabled
884 */
885 private int mStatus;
886
887 /**
888 * Reason for disable this network
889 */
890 private int mNetworkSelectionDisableReason;
891
892 /**
893 * Last time we temporarily disabled the configuration
894 */
895 private long mTemporarilyDisabledTimestamp = INVALID_NETWORK_SELECTION_DISABLE_TIMESTAMP;
896
897 /**
898 * counter for each Network selection disable reason
899 */
900 private int[] mNetworkSeclectionDisableCounter = new int[NETWORK_SELECTION_DISABLED_MAX];
901
902 /**
xinhe584dc6b2016-01-26 10:32:03 -0800903 * Connect Choice over this configuration
904 *
905 * When current wifi configuration is visible to the user but user explicitly choose to
906 * connect to another network X, the another networks X's configure key will be stored here.
907 * We will consider user has a preference of X over this network. And in the future,
908 * network selection will always give X a higher preference over this configuration.
909 * configKey is : "SSID"-WEP-WPA_PSK-WPA_EAP
910 */
911 private String mConnectChoice;
912
913 /**
914 * The system timestamp when we records the connectChoice. This value is obtained from
915 * System.currentTimeMillis
916 */
917 private long mConnectChoiceTimestamp = INVALID_NETWORK_SELECTION_DISABLE_TIMESTAMP;
918
919 /**
920 * Used to cache the temporary candidate during the network selection procedure. It will be
921 * kept updating once a new scan result has a higher score than current one
922 */
923 private ScanResult mCandidate;
924
925 /**
926 * Used to cache the score of the current temporary candidate during the network
927 * selection procedure.
928 */
929 private int mCandidateScore;
930
931 /**
932 * Indicate whether this network is visible in latest Qualified Network Selection. This
933 * means there is scan result found related to this Configuration and meet the minimum
934 * requirement. The saved network need not join latest Qualified Network Selection. For
935 * example, it is disabled. True means network is visible in latest Qualified Network
936 * Selection and false means network is invisible
937 */
938 private boolean mSeenInLastQualifiedNetworkSelection;
939
940 /**
Rebecca Silbersteincd7167d2016-03-25 17:35:58 -0700941 * Boolean indicating if we have ever successfully connected to this network.
942 *
943 * This value will be set to true upon a successful connection.
944 * This value will be set to false if a previous value was not stored in the config or if
945 * the credentials are updated (ex. a password change).
946 */
947 private boolean mHasEverConnected;
948
949 /**
xinhe584dc6b2016-01-26 10:32:03 -0800950 * set whether this network is visible in latest Qualified Network Selection
951 * @param seen value set to candidate
952 */
953 public void setSeenInLastQualifiedNetworkSelection(boolean seen) {
954 mSeenInLastQualifiedNetworkSelection = seen;
955 }
956
957 /**
958 * get whether this network is visible in latest Qualified Network Selection
959 * @return returns true -- network is visible in latest Qualified Network Selection
960 * false -- network is invisible in latest Qualified Network Selection
961 */
962 public boolean getSeenInLastQualifiedNetworkSelection() {
963 return mSeenInLastQualifiedNetworkSelection;
964 }
965 /**
966 * set the temporary candidate of current network selection procedure
967 * @param scanCandidate {@link ScanResult} the candidate set to mCandidate
968 */
969 public void setCandidate(ScanResult scanCandidate) {
970 mCandidate = scanCandidate;
971 }
972
973 /**
974 * get the temporary candidate of current network selection procedure
975 * @return returns {@link ScanResult} temporary candidate of current network selection
976 * procedure
977 */
978 public ScanResult getCandidate() {
979 return mCandidate;
980 }
981
982 /**
983 * set the score of the temporary candidate of current network selection procedure
984 * @param score value set to mCandidateScore
985 */
986 public void setCandidateScore(int score) {
987 mCandidateScore = score;
988 }
989
990 /**
991 * get the score of the temporary candidate of current network selection procedure
992 * @return returns score of the temporary candidate of current network selection procedure
993 */
994 public int getCandidateScore() {
995 return mCandidateScore;
996 }
997
998 /**
999 * get user preferred choice over this configuration
1000 *@return returns configKey of user preferred choice over this configuration
1001 */
1002 public String getConnectChoice() {
1003 return mConnectChoice;
1004 }
1005
1006 /**
1007 * set user preferred choice over this configuration
1008 * @param newConnectChoice, the configKey of user preferred choice over this configuration
1009 */
1010 public void setConnectChoice(String newConnectChoice) {
1011 mConnectChoice = newConnectChoice;
1012 }
1013
1014 /**
1015 * get the timeStamp when user select a choice over this configuration
1016 * @return returns when current connectChoice is set (time from System.currentTimeMillis)
1017 */
1018 public long getConnectChoiceTimestamp() {
1019 return mConnectChoiceTimestamp;
1020 }
1021
1022 /**
1023 * set the timeStamp when user select a choice over this configuration
1024 * @param timeStamp, the timestamp set to connectChoiceTimestamp, expected timestamp should
1025 * be obtained from System.currentTimeMillis
1026 */
1027 public void setConnectChoiceTimestamp(long timeStamp) {
1028 mConnectChoiceTimestamp = timeStamp;
1029 }
1030
1031 /**
1032 * get current Quality network selection status
1033 * @return returns current Quality network selection status in String (for debug purpose)
xinhe8d106782015-12-01 14:44:37 -08001034 */
1035 public String getNetworkStatusString() {
1036 return QUALITY_NETWORK_SELECTION_STATUS[mStatus];
1037 }
1038
Rebecca Silbersteincd7167d2016-03-25 17:35:58 -07001039 public void setHasEverConnected(boolean value) {
1040 mHasEverConnected = value;
1041 }
1042
1043 public boolean getHasEverConnected() {
1044 return mHasEverConnected;
1045 }
1046
1047 private NetworkSelectionStatus() {
1048 // previously stored configs will not have this parameter, so we default to false.
1049 mHasEverConnected = false;
1050 };
xinhe8d106782015-12-01 14:44:37 -08001051
1052 /**
1053 * @param reason specific error reason
1054 * @return corresponding network disable reason String (for debug purpose)
1055 */
1056 public static String getNetworkDisableReasonString(int reason) {
1057 if (reason >= NETWORK_SELECTION_ENABLE && reason < NETWORK_SELECTION_DISABLED_MAX) {
1058 return QUALITY_NETWORK_SELECTION_DISABLE_REASON[reason];
1059 } else {
1060 return null;
1061 }
1062 }
1063 /**
xinhe584dc6b2016-01-26 10:32:03 -08001064 * get current network disable reason
xinhe8d106782015-12-01 14:44:37 -08001065 * @return current network disable reason in String (for debug purpose)
1066 */
1067 public String getNetworkDisableReasonString() {
1068 return QUALITY_NETWORK_SELECTION_DISABLE_REASON[mNetworkSelectionDisableReason];
1069 }
1070
1071 /**
1072 * get current network network selection status
xinhe584dc6b2016-01-26 10:32:03 -08001073 * @return return current network network selection status
xinhe8d106782015-12-01 14:44:37 -08001074 */
1075 public int getNetworkSelectionStatus() {
1076 return mStatus;
1077 }
1078 /**
1079 * @return whether current network is enabled to join network selection
1080 */
1081 public boolean isNetworkEnabled() {
1082 return mStatus == NETWORK_SELECTION_ENABLED;
1083 }
1084
1085 /**
1086 * @return whether current network is temporary disabled
1087 */
1088 public boolean isNetworkTemporaryDisabled() {
1089 return mStatus == NETWORK_SELECTION_TEMPORARY_DISABLED;
1090 }
1091
1092 /**
xinhe584dc6b2016-01-26 10:32:03 -08001093 * @return returns whether current network is permanently disabled
xinhe8d106782015-12-01 14:44:37 -08001094 */
1095 public boolean isNetworkPermanentlyDisabled() {
1096 return mStatus == NETWORK_SELECTION_PERMANENTLY_DISABLED;
1097 }
xinhe584dc6b2016-01-26 10:32:03 -08001098
xinhe8d106782015-12-01 14:44:37 -08001099 /**
xinhe584dc6b2016-01-26 10:32:03 -08001100 * set current networ work selection status
xinhe8d106782015-12-01 14:44:37 -08001101 * @param status network selection status to set
1102 */
1103 public void setNetworkSelectionStatus(int status) {
1104 if (status >= 0 && status < NETWORK_SELECTION_STATUS_MAX) {
1105 mStatus = status;
1106 }
1107 }
xinhe584dc6b2016-01-26 10:32:03 -08001108
xinhe8d106782015-12-01 14:44:37 -08001109 /**
xinhe584dc6b2016-01-26 10:32:03 -08001110 * @return returns current network's disable reason
xinhe8d106782015-12-01 14:44:37 -08001111 */
1112 public int getNetworkSelectionDisableReason() {
1113 return mNetworkSelectionDisableReason;
1114 }
1115
1116 /**
xinhe584dc6b2016-01-26 10:32:03 -08001117 * set Network disable reason
xinhe8d106782015-12-01 14:44:37 -08001118 * @param reason Network disable reason
1119 */
1120 public void setNetworkSelectionDisableReason(int reason) {
1121 if (reason >= 0 && reason < NETWORK_SELECTION_DISABLED_MAX) {
1122 mNetworkSelectionDisableReason = reason;
1123 } else {
1124 throw new IllegalArgumentException("Illegal reason value: " + reason);
1125 }
1126 }
xinhe584dc6b2016-01-26 10:32:03 -08001127
xinhe8d106782015-12-01 14:44:37 -08001128 /**
xinhe584dc6b2016-01-26 10:32:03 -08001129 * check whether network is disabled by this reason
1130 * @param reason a specific disable reason
1131 * @return true -- network is disabled for this reason
1132 * false -- network is not disabled for this reason
xinhe8d106782015-12-01 14:44:37 -08001133 */
1134 public boolean isDisabledByReason(int reason) {
1135 return mNetworkSelectionDisableReason == reason;
1136 }
xinhe584dc6b2016-01-26 10:32:03 -08001137
xinhe8d106782015-12-01 14:44:37 -08001138 /**
1139 * @param timeStamp Set when current network is disabled in millisecond since January 1,
1140 * 1970 00:00:00.0 UTC
1141 */
1142 public void setDisableTime(long timeStamp) {
1143 mTemporarilyDisabledTimestamp = timeStamp;
1144 }
1145
1146 /**
xinhe584dc6b2016-01-26 10:32:03 -08001147 * @return returns when current network is disabled in millisecond since January 1,
xinhe8d106782015-12-01 14:44:37 -08001148 * 1970 00:00:00.0 UTC
1149 */
1150 public long getDisableTime() {
1151 return mTemporarilyDisabledTimestamp;
1152 }
1153
1154 /**
xinhe584dc6b2016-01-26 10:32:03 -08001155 * get the disable counter of a specific reason
xinhe8d106782015-12-01 14:44:37 -08001156 * @param reason specific failure reason
1157 * @exception throw IllegalArgumentException for illegal input
1158 * @return counter number for specific error reason.
1159 */
1160 public int getDisableReasonCounter(int reason) {
1161 if (reason >= NETWORK_SELECTION_ENABLE && reason < NETWORK_SELECTION_DISABLED_MAX) {
1162 return mNetworkSeclectionDisableCounter[reason];
1163 } else {
1164 throw new IllegalArgumentException("Illegal reason value: " + reason);
1165 }
1166 }
1167
1168 /**
1169 * set the counter of a specific failure reason
1170 * @param reason reason for disable error
1171 * @param value the counter value for this specific reason
1172 * @exception throw IllegalArgumentException for illegal input
1173 */
1174 public void setDisableReasonCounter(int reason, int value) {
1175 if (reason >= NETWORK_SELECTION_ENABLE && reason < NETWORK_SELECTION_DISABLED_MAX) {
1176 mNetworkSeclectionDisableCounter[reason] = value;
1177 } else {
1178 throw new IllegalArgumentException("Illegal reason value: " + reason);
1179 }
1180 }
1181
1182 /**
1183 * increment the counter of a specific failure reason
1184 * @param reason a specific failure reason
1185 * @exception throw IllegalArgumentException for illegal input
1186 */
1187 public void incrementDisableReasonCounter(int reason) {
1188 if (reason >= NETWORK_SELECTION_ENABLE && reason < NETWORK_SELECTION_DISABLED_MAX) {
1189 mNetworkSeclectionDisableCounter[reason]++;
1190 } else {
1191 throw new IllegalArgumentException("Illegal reason value: " + reason);
1192 }
1193 }
xinhe584dc6b2016-01-26 10:32:03 -08001194
xinhe8d106782015-12-01 14:44:37 -08001195 /**
1196 * clear the counter of a specific failure reason
1197 * @hide
1198 * @param reason a specific failure reason
1199 * @exception throw IllegalArgumentException for illegal input
1200 */
1201 public void clearDisableReasonCounter(int reason) {
1202 if (reason >= NETWORK_SELECTION_ENABLE && reason < NETWORK_SELECTION_DISABLED_MAX) {
1203 mNetworkSeclectionDisableCounter[reason] = NETWORK_SELECTION_ENABLE;
1204 } else {
1205 throw new IllegalArgumentException("Illegal reason value: " + reason);
1206 }
1207 }
xinhe584dc6b2016-01-26 10:32:03 -08001208
xinhe8d106782015-12-01 14:44:37 -08001209 /**
1210 * clear all the failure reason counters
1211 */
1212 public void clearDisableReasonCounter() {
1213 Arrays.fill(mNetworkSeclectionDisableCounter, NETWORK_SELECTION_ENABLE);
1214 }
1215
1216 /**
1217 * BSSID for connection to this network (through network selection procedure)
1218 */
1219 private String mNetworkSelectionBSSID;
1220
1221 /**
1222 * get current network Selection BSSID
1223 * @return current network Selection BSSID
1224 */
1225 public String getNetworkSelectionBSSID() {
1226 return mNetworkSelectionBSSID;
1227 }
1228
1229 /**
1230 * set network Selection BSSID
1231 * @param bssid The target BSSID for assocaition
1232 */
1233 public void setNetworkSelectionBSSID(String bssid) {
1234 mNetworkSelectionBSSID = bssid;
1235 }
1236
1237 public void copy(NetworkSelectionStatus source) {
1238 mStatus = source.mStatus;
1239 mNetworkSelectionDisableReason = source.mNetworkSelectionDisableReason;
1240 for (int index = NETWORK_SELECTION_ENABLE; index < NETWORK_SELECTION_DISABLED_MAX;
1241 index++) {
1242 mNetworkSeclectionDisableCounter[index] =
1243 source.mNetworkSeclectionDisableCounter[index];
1244 }
1245 mTemporarilyDisabledTimestamp = source.mTemporarilyDisabledTimestamp;
1246 mNetworkSelectionBSSID = source.mNetworkSelectionBSSID;
xinhe584dc6b2016-01-26 10:32:03 -08001247 setConnectChoice(source.getConnectChoice());
1248 setConnectChoiceTimestamp(source.getConnectChoiceTimestamp());
Rebecca Silbersteincd7167d2016-03-25 17:35:58 -07001249 setHasEverConnected(source.getHasEverConnected());
xinhe8d106782015-12-01 14:44:37 -08001250 }
1251
1252 public void writeToParcel(Parcel dest) {
1253 dest.writeInt(getNetworkSelectionStatus());
1254 dest.writeInt(getNetworkSelectionDisableReason());
1255 for (int index = NETWORK_SELECTION_ENABLE; index < NETWORK_SELECTION_DISABLED_MAX;
1256 index++) {
1257 dest.writeInt(getDisableReasonCounter(index));
1258 }
1259 dest.writeLong(getDisableTime());
1260 dest.writeString(getNetworkSelectionBSSID());
xinhe584dc6b2016-01-26 10:32:03 -08001261 if (getConnectChoice() != null) {
1262 dest.writeInt(CONNECT_CHOICE_EXISTS);
1263 dest.writeString(getConnectChoice());
1264 dest.writeLong(getConnectChoiceTimestamp());
1265 } else {
1266 dest.writeInt(CONNECT_CHOICE_NOT_EXISTS);
1267 }
Rebecca Silbersteincd7167d2016-03-25 17:35:58 -07001268 dest.writeInt(getHasEverConnected() ? 1 : 0);
xinhe8d106782015-12-01 14:44:37 -08001269 }
1270
1271 public void readFromParcel(Parcel in) {
1272 setNetworkSelectionStatus(in.readInt());
1273 setNetworkSelectionDisableReason(in.readInt());
1274 for (int index = NETWORK_SELECTION_ENABLE; index < NETWORK_SELECTION_DISABLED_MAX;
1275 index++) {
1276 setDisableReasonCounter(index, in.readInt());
1277 }
1278 setDisableTime(in.readLong());
1279 setNetworkSelectionBSSID(in.readString());
xinhe584dc6b2016-01-26 10:32:03 -08001280 if (in.readInt() == CONNECT_CHOICE_EXISTS) {
1281 setConnectChoice(in.readString());
1282 setConnectChoiceTimestamp(in.readLong());
1283 } else {
1284 setConnectChoice(null);
1285 setConnectChoiceTimestamp(INVALID_NETWORK_SELECTION_DISABLE_TIMESTAMP);
1286 }
Rebecca Silbersteincd7167d2016-03-25 17:35:58 -07001287 setHasEverConnected(in.readInt() != 0);
xinhe8d106782015-12-01 14:44:37 -08001288 }
1289 }
1290
1291 /**
1292 * @hide
1293 * network selection related member
1294 */
1295 private final NetworkSelectionStatus mNetworkSelectionStatus = new NetworkSelectionStatus();
1296
1297 /**
1298 * @hide
1299 * @return network selection status
1300 */
1301 public NetworkSelectionStatus getNetworkSelectionStatus() {
1302 return mNetworkSelectionStatus;
1303 }
vandwalle7c3606c2014-03-31 19:12:07 -07001304 /**
1305 * @hide
1306 * Linked Configurations: represent the set of Wificonfigurations that are equivalent
1307 * regarding roaming and auto-joining.
1308 * The linked configuration may or may not have same SSID, and may or may not have same
1309 * credentials.
1310 * For instance, linked configurations will have same defaultGwMacAddress or same dhcp server.
1311 */
1312 public HashMap<String, Integer> linkedConfigurations;
1313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001314 public WifiConfiguration() {
Irfan Sheriff5ee89802010-09-16 17:53:34 -07001315 networkId = INVALID_NETWORK_ID;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001316 SSID = null;
1317 BSSID = null;
Yuhao Zheng8a9eb812014-05-27 10:35:02 -07001318 FQDN = null;
Vinit Deshpande7226c8f2015-06-30 13:43:02 -07001319 roamingConsortiumIds = new long[0];
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001320 priority = 0;
1321 hiddenSSID = false;
1322 allowedKeyManagement = new BitSet();
1323 allowedProtocols = new BitSet();
1324 allowedAuthAlgorithms = new BitSet();
1325 allowedPairwiseCiphers = new BitSet();
1326 allowedGroupCiphers = new BitSet();
1327 wepKeys = new String[4];
Irfan Sheriff9b813192013-01-11 14:03:55 -08001328 for (int i = 0; i < wepKeys.length; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001329 wepKeys[i] = null;
Chung-yih Wang43374762009-09-16 14:28:42 +08001330 }
Irfan Sheriff9b813192013-01-11 14:03:55 -08001331 enterpriseConfig = new WifiEnterpriseConfig();
vandwallee50869d2014-05-13 13:08:44 -07001332 selfAdded = false;
vandwalle8f135482014-05-30 14:29:49 -07001333 didSelfAdd = false;
vandwallee50869d2014-05-13 13:08:44 -07001334 ephemeral = false;
Jeremy Joslinf0c9b8c2016-03-17 10:10:32 -07001335 meteredHint = false;
vandwalleec3e9802014-11-07 17:29:24 -08001336 validatedInternetAccess = false;
Jaewan Kim63461552014-03-10 17:10:51 +09001337 mIpConfiguration = new IpConfiguration();
Sky Faber3e3857c2014-09-22 13:54:18 -07001338 lastUpdateUid = -1;
1339 creatorUid = -1;
Bartosz Fabianowski6fb07562016-01-12 15:43:19 +01001340 shared = true;
Glen Kuhneb6cd6fa2016-02-10 15:08:33 -08001341 dtimInterval = 0;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001342 }
1343
Vinit Deshapnde10652a92013-09-09 16:24:36 -07001344 /**
Vinit Deshpande2522c832015-03-12 17:04:35 -07001345 * Identify if this configuration represents a passpoint network
1346 */
1347 public boolean isPasspoint() {
Vinit Deshpandead25bb82015-03-18 17:00:30 -07001348 return !TextUtils.isEmpty(FQDN)
Vinit Deshpande2522c832015-03-12 17:04:35 -07001349 && !TextUtils.isEmpty(providerFriendlyName)
1350 && enterpriseConfig != null
1351 && enterpriseConfig.getEapMethod() != WifiEnterpriseConfig.Eap.NONE;
1352 }
1353
1354 /**
vandwalle111fa022014-06-10 20:47:58 -07001355 * Helper function, identify if a configuration is linked
1356 * @hide
1357 */
1358 public boolean isLinked(WifiConfiguration config) {
xinhe8d106782015-12-01 14:44:37 -08001359 if (config != null) {
1360 if (config.linkedConfigurations != null && linkedConfigurations != null) {
1361 if (config.linkedConfigurations.get(configKey()) != null
1362 && linkedConfigurations.get(config.configKey()) != null) {
1363 return true;
1364 }
vandwalle111fa022014-06-10 20:47:58 -07001365 }
1366 }
1367 return false;
vandwalle7c3606c2014-03-31 19:12:07 -07001368 }
1369
1370 /**
Sky Faberc55cd102014-09-19 18:21:35 -07001371 * Helper function, idenfity if a configuration should be treated as an enterprise network
1372 * @hide
1373 */
1374 public boolean isEnterprise() {
1375 return allowedKeyManagement.get(KeyMgmt.WPA_EAP) ||
1376 allowedKeyManagement.get(KeyMgmt.IEEE8021X);
1377 }
1378
Isaac Levy8dc6a1b2011-07-27 08:00:03 -07001379 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001380 public String toString() {
Isaac Levy8dc6a1b2011-07-27 08:00:03 -07001381 StringBuilder sbuf = new StringBuilder();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001382 if (this.status == WifiConfiguration.Status.CURRENT) {
1383 sbuf.append("* ");
1384 } else if (this.status == WifiConfiguration.Status.DISABLED) {
vandwalle63edd982014-10-06 15:04:07 -07001385 sbuf.append("- DSBLE ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001386 }
1387 sbuf.append("ID: ").append(this.networkId).append(" SSID: ").append(this.SSID).
Vinit Deshpandeb21d2482015-02-02 10:50:36 -08001388 append(" PROVIDER-NAME: ").append(this.providerFriendlyName).
xinhe8d106782015-12-01 14:44:37 -08001389 append(" BSSID: ").append(this.BSSID).append(" FQDN: ").append(this.FQDN)
1390 .append(" PRIO: ").append(this.priority)
mukesh agrawale2399382016-03-02 16:33:33 -08001391 .append(" HIDDEN: ").append(this.hiddenSSID)
xinhe8d106782015-12-01 14:44:37 -08001392 .append('\n');
1393
1394
1395 sbuf.append(" NetworkSelectionStatus ")
1396 .append(mNetworkSelectionStatus.getNetworkStatusString() + "\n");
1397 if (mNetworkSelectionStatus.getNetworkSelectionDisableReason() > 0) {
1398 sbuf.append(" mNetworkSelectionDisableReason ")
1399 .append(mNetworkSelectionStatus.getNetworkDisableReasonString() + "\n");
1400
1401 for (int index = mNetworkSelectionStatus.NETWORK_SELECTION_ENABLE;
1402 index < mNetworkSelectionStatus.NETWORK_SELECTION_DISABLED_MAX; index++) {
1403 if (mNetworkSelectionStatus.getDisableReasonCounter(index) != 0) {
1404 sbuf.append(NetworkSelectionStatus.getNetworkDisableReasonString(index)
1405 + " counter:" + mNetworkSelectionStatus.getDisableReasonCounter(index)
1406 + "\n");
1407 }
1408 }
vandwalle16a40cc2014-07-28 20:26:58 -07001409 }
xinhe584dc6b2016-01-26 10:32:03 -08001410 if (mNetworkSelectionStatus.getConnectChoice() != null) {
1411 sbuf.append(" connect choice: ").append(mNetworkSelectionStatus.getConnectChoice());
1412 sbuf.append(" connect choice set time: ").append(mNetworkSelectionStatus
1413 .getConnectChoiceTimestamp());
1414 }
Rebecca Silbersteincd7167d2016-03-25 17:35:58 -07001415 sbuf.append(" hasEverConnected: ")
1416 .append(mNetworkSelectionStatus.getHasEverConnected()).append("\n");
xinhe8d106782015-12-01 14:44:37 -08001417
Mike Lockwood05610302014-09-24 13:51:40 -07001418 if (this.numAssociation > 0) {
1419 sbuf.append(" numAssociation ").append(this.numAssociation).append("\n");
vandwalle16a40cc2014-07-28 20:26:58 -07001420 }
vandwalleec3e9802014-11-07 17:29:24 -08001421 if (this.numNoInternetAccessReports > 0) {
1422 sbuf.append(" numNoInternetAccessReports ");
1423 sbuf.append(this.numNoInternetAccessReports).append("\n");
1424 }
Pierre Vandwalleced1a652015-06-16 13:55:44 -07001425 if (this.updateTime != null) {
Pierre Vandwalleedbedd22015-07-01 12:48:26 -07001426 sbuf.append("update ").append(this.updateTime).append("\n");
Pierre Vandwalleced1a652015-06-16 13:55:44 -07001427 }
1428 if (this.creationTime != null) {
Pierre Vandwalleedbedd22015-07-01 12:48:26 -07001429 sbuf.append("creation").append(this.creationTime).append("\n");
Pierre Vandwalleced1a652015-06-16 13:55:44 -07001430 }
vandwalle94fe7e92014-09-11 18:41:23 -07001431 if (this.didSelfAdd) sbuf.append(" didSelfAdd");
1432 if (this.selfAdded) sbuf.append(" selfAdded");
vandwalleec3e9802014-11-07 17:29:24 -08001433 if (this.validatedInternetAccess) sbuf.append(" validatedInternetAccess");
Jeff Davidson8faf2a22014-10-06 16:16:35 -07001434 if (this.ephemeral) sbuf.append(" ephemeral");
Jeremy Joslinf0c9b8c2016-03-17 10:10:32 -07001435 if (this.meteredHint) sbuf.append(" meteredHint");
1436 if (this.didSelfAdd || this.selfAdded || this.validatedInternetAccess
1437 || this.ephemeral || this.meteredHint) {
vandwalle16a40cc2014-07-28 20:26:58 -07001438 sbuf.append("\n");
1439 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001440 sbuf.append(" KeyMgmt:");
1441 for (int k = 0; k < this.allowedKeyManagement.size(); k++) {
1442 if (this.allowedKeyManagement.get(k)) {
1443 sbuf.append(" ");
1444 if (k < KeyMgmt.strings.length) {
1445 sbuf.append(KeyMgmt.strings[k]);
1446 } else {
1447 sbuf.append("??");
1448 }
1449 }
1450 }
1451 sbuf.append(" Protocols:");
1452 for (int p = 0; p < this.allowedProtocols.size(); p++) {
1453 if (this.allowedProtocols.get(p)) {
1454 sbuf.append(" ");
1455 if (p < Protocol.strings.length) {
1456 sbuf.append(Protocol.strings[p]);
1457 } else {
1458 sbuf.append("??");
1459 }
1460 }
1461 }
1462 sbuf.append('\n');
1463 sbuf.append(" AuthAlgorithms:");
1464 for (int a = 0; a < this.allowedAuthAlgorithms.size(); a++) {
1465 if (this.allowedAuthAlgorithms.get(a)) {
1466 sbuf.append(" ");
1467 if (a < AuthAlgorithm.strings.length) {
1468 sbuf.append(AuthAlgorithm.strings[a]);
1469 } else {
1470 sbuf.append("??");
1471 }
1472 }
1473 }
1474 sbuf.append('\n');
1475 sbuf.append(" PairwiseCiphers:");
1476 for (int pc = 0; pc < this.allowedPairwiseCiphers.size(); pc++) {
1477 if (this.allowedPairwiseCiphers.get(pc)) {
1478 sbuf.append(" ");
1479 if (pc < PairwiseCipher.strings.length) {
1480 sbuf.append(PairwiseCipher.strings[pc]);
1481 } else {
1482 sbuf.append("??");
1483 }
1484 }
1485 }
1486 sbuf.append('\n');
1487 sbuf.append(" GroupCiphers:");
1488 for (int gc = 0; gc < this.allowedGroupCiphers.size(); gc++) {
1489 if (this.allowedGroupCiphers.get(gc)) {
1490 sbuf.append(" ");
1491 if (gc < GroupCipher.strings.length) {
1492 sbuf.append(GroupCipher.strings[gc]);
1493 } else {
1494 sbuf.append("??");
1495 }
1496 }
1497 }
Chung-yih Wang5069cc72009-06-03 17:33:47 +08001498 sbuf.append('\n').append(" PSK: ");
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001499 if (this.preSharedKey != null) {
Chung-yih Wang5069cc72009-06-03 17:33:47 +08001500 sbuf.append('*');
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001501 }
vandwalle94fe7e92014-09-11 18:41:23 -07001502 sbuf.append("\nEnterprise config:\n");
Irfan Sheriff9b813192013-01-11 14:03:55 -08001503 sbuf.append(enterpriseConfig);
Irfan Sheriff9b813192013-01-11 14:03:55 -08001504
vandwalle94fe7e92014-09-11 18:41:23 -07001505 sbuf.append("IP config:\n");
Jaewan Kim63461552014-03-10 17:10:51 +09001506 sbuf.append(mIpConfiguration.toString());
Irfan Sheriff128ceca2010-09-22 16:09:46 -07001507
xinhe8d106782015-12-01 14:44:37 -08001508 if (mNetworkSelectionStatus.getNetworkSelectionBSSID() != null) {
1509 sbuf.append(" networkSelectionBSSID="
1510 + mNetworkSelectionStatus.getNetworkSelectionBSSID());
1511 }
vandwalle94fe7e92014-09-11 18:41:23 -07001512 long now_ms = System.currentTimeMillis();
xinhe8d106782015-12-01 14:44:37 -08001513 if (mNetworkSelectionStatus.getDisableTime() != NetworkSelectionStatus
1514 .INVALID_NETWORK_SELECTION_DISABLE_TIMESTAMP) {
vandwalle94fe7e92014-09-11 18:41:23 -07001515 sbuf.append('\n');
xinhe8d106782015-12-01 14:44:37 -08001516 long diff = now_ms - mNetworkSelectionStatus.getDisableTime();
vandwalle2ab90892014-06-02 15:30:39 -07001517 if (diff <= 0) {
vandwalle94fe7e92014-09-11 18:41:23 -07001518 sbuf.append(" blackListed since <incorrect>");
vandwalle2ab90892014-06-02 15:30:39 -07001519 } else {
Ritesh Reddyaeb4c062016-01-26 19:40:48 +00001520 sbuf.append(" blackListed: ").append(Long.toString(diff / 1000)).append("sec ");
vandwalle94fe7e92014-09-11 18:41:23 -07001521 }
1522 }
Ritesh Reddyaeb4c062016-01-26 19:40:48 +00001523 if (creatorUid != 0) sbuf.append(" cuid=" + creatorUid);
Sky Faber3e3857c2014-09-22 13:54:18 -07001524 if (creatorName != null) sbuf.append(" cname=" + creatorName);
1525 if (lastUpdateUid != 0) sbuf.append(" luid=" + lastUpdateUid);
1526 if (lastUpdateName != null) sbuf.append(" lname=" + lastUpdateName);
Lorenzo Colitti1ac50cb2015-04-06 17:19:19 +09001527 sbuf.append(" lcuid=" + lastConnectUid);
1528 sbuf.append(" userApproved=" + userApprovedAsString(userApproved));
1529 sbuf.append(" noInternetAccessExpected=" + noInternetAccessExpected);
Lorenzo Colitti1248dd32015-04-06 17:26:10 +09001530 sbuf.append(" ");
Sky Faber3e3857c2014-09-22 13:54:18 -07001531
vandwalle94fe7e92014-09-11 18:41:23 -07001532 if (this.lastConnected != 0) {
1533 sbuf.append('\n');
1534 long diff = now_ms - this.lastConnected;
1535 if (diff <= 0) {
1536 sbuf.append("lastConnected since <incorrect>");
1537 } else {
Ritesh Reddyaeb4c062016-01-26 19:40:48 +00001538 sbuf.append("lastConnected: ").append(Long.toString(diff / 1000)).append("sec ");
vandwalle94fe7e92014-09-11 18:41:23 -07001539 }
1540 }
1541 if (this.lastConnectionFailure != 0) {
1542 sbuf.append('\n');
1543 long diff = now_ms - this.lastConnectionFailure;
1544 if (diff <= 0) {
Pierre Vandwalle5ddc65b2015-05-20 15:15:31 -07001545 sbuf.append("lastConnectionFailure since <incorrect> ");
vandwalle94fe7e92014-09-11 18:41:23 -07001546 } else {
Ritesh Reddyaeb4c062016-01-26 19:40:48 +00001547 sbuf.append("lastConnectionFailure: ").append(Long.toString(diff / 1000));
1548 sbuf.append("sec ");
vandwalle2ab90892014-06-02 15:30:39 -07001549 }
1550 }
vandwalle8650c032015-01-11 11:57:01 -08001551 if (this.lastRoamingFailure != 0) {
1552 sbuf.append('\n');
1553 long diff = now_ms - this.lastRoamingFailure;
1554 if (diff <= 0) {
Pierre Vandwalle5ddc65b2015-05-20 15:15:31 -07001555 sbuf.append("lastRoamingFailure since <incorrect> ");
vandwalle8650c032015-01-11 11:57:01 -08001556 } else {
Ritesh Reddyaeb4c062016-01-26 19:40:48 +00001557 sbuf.append("lastRoamingFailure: ").append(Long.toString(diff / 1000));
1558 sbuf.append("sec ");
vandwalle8650c032015-01-11 11:57:01 -08001559 }
1560 }
1561 sbuf.append("roamingFailureBlackListTimeMilli: ").
1562 append(Long.toString(this.roamingFailureBlackListTimeMilli));
vandwalle448e2082014-09-05 00:01:24 -07001563 sbuf.append('\n');
1564 if (this.linkedConfigurations != null) {
Ritesh Reddyaeb4c062016-01-26 19:40:48 +00001565 for (String key : this.linkedConfigurations.keySet()) {
vandwalle448e2082014-09-05 00:01:24 -07001566 sbuf.append(" linked: ").append(key);
1567 sbuf.append('\n');
1568 }
1569 }
vandwalle94fe7e92014-09-11 18:41:23 -07001570 sbuf.append("triggeredLow: ").append(this.numUserTriggeredWifiDisableLowRSSI);
1571 sbuf.append(" triggeredBad: ").append(this.numUserTriggeredWifiDisableBadRSSI);
1572 sbuf.append(" triggeredNotHigh: ").append(this.numUserTriggeredWifiDisableNotHighRSSI);
vandwalle448e2082014-09-05 00:01:24 -07001573 sbuf.append('\n');
vandwalle94fe7e92014-09-11 18:41:23 -07001574 sbuf.append("ticksLow: ").append(this.numTicksAtLowRSSI);
1575 sbuf.append(" ticksBad: ").append(this.numTicksAtBadRSSI);
1576 sbuf.append(" ticksNotHigh: ").append(this.numTicksAtNotHighRSSI);
vandwalle448e2082014-09-05 00:01:24 -07001577 sbuf.append('\n');
vandwalle94fe7e92014-09-11 18:41:23 -07001578 sbuf.append("triggeredJoin: ").append(this.numUserTriggeredJoinAttempts);
1579 sbuf.append('\n');
vandwalle8f135482014-05-30 14:29:49 -07001580
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001581 return sbuf.toString();
1582 }
1583
Irfan Sheriffb6deeed2012-09-05 10:46:24 -07001584 /** {@hide} */
1585 public String getPrintableSsid() {
1586 if (SSID == null) return "";
1587 final int length = SSID.length();
1588 if (length > 2 && (SSID.charAt(0) == '"') && SSID.charAt(length - 1) == '"') {
1589 return SSID.substring(1, length - 1);
1590 }
1591
1592 /** The ascii-encoded string format is P"<ascii-encoded-string>"
1593 * The decoding is implemented in the supplicant for a newly configured
1594 * network.
1595 */
1596 if (length > 3 && (SSID.charAt(0) == 'P') && (SSID.charAt(1) == '"') &&
1597 (SSID.charAt(length-1) == '"')) {
1598 WifiSsid wifiSsid = WifiSsid.createFromAsciiEncoded(
1599 SSID.substring(2, length - 1));
1600 return wifiSsid.toString();
1601 }
1602 return SSID;
1603 }
1604
Sky Faber3e3857c2014-09-22 13:54:18 -07001605 /** @hide **/
1606 public static String userApprovedAsString(int userApproved) {
1607 switch (userApproved) {
1608 case USER_APPROVED:
1609 return "USER_APPROVED";
1610 case USER_BANNED:
1611 return "USER_BANNED";
1612 case USER_UNSPECIFIED:
1613 return "USER_UNSPECIFIED";
1614 default:
1615 return "INVALID";
1616 }
1617 }
1618
Irfan Sheriff26d00762013-02-05 09:44:12 -08001619 /**
1620 * Get an identifier for associating credentials with this config
1621 * @param current configuration contains values for additional fields
1622 * that are not part of this configuration. Used
1623 * when a config with some fields is passed by an application.
1624 * @throws IllegalStateException if config is invalid for key id generation
1625 * @hide
1626 */
Vinit Deshapndeffadfb92013-12-06 15:12:41 -08001627 public String getKeyIdForCredentials(WifiConfiguration current) {
Irfan Sheriff26d00762013-02-05 09:44:12 -08001628 String keyMgmt = null;
1629
1630 try {
1631 // Get current config details for fields that are not initialized
1632 if (TextUtils.isEmpty(SSID)) SSID = current.SSID;
1633 if (allowedKeyManagement.cardinality() == 0) {
1634 allowedKeyManagement = current.allowedKeyManagement;
1635 }
1636 if (allowedKeyManagement.get(KeyMgmt.WPA_EAP)) {
1637 keyMgmt = KeyMgmt.strings[KeyMgmt.WPA_EAP];
1638 }
1639 if (allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
1640 keyMgmt += KeyMgmt.strings[KeyMgmt.IEEE8021X];
1641 }
1642
1643 if (TextUtils.isEmpty(keyMgmt)) {
1644 throw new IllegalStateException("Not an EAP network");
1645 }
1646
1647 return trimStringForKeyId(SSID) + "_" + keyMgmt + "_" +
1648 trimStringForKeyId(enterpriseConfig.getKeyId(current != null ?
1649 current.enterpriseConfig : null));
1650 } catch (NullPointerException e) {
1651 throw new IllegalStateException("Invalid config details");
1652 }
1653 }
1654
1655 private String trimStringForKeyId(String string) {
1656 // Remove quotes and spaces
1657 return string.replace("\"", "").replace(" ", "");
1658 }
1659
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001660 private static BitSet readBitSet(Parcel src) {
1661 int cardinality = src.readInt();
1662
1663 BitSet set = new BitSet();
Irfan Sheriff9b813192013-01-11 14:03:55 -08001664 for (int i = 0; i < cardinality; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001665 set.set(src.readInt());
Irfan Sheriff9b813192013-01-11 14:03:55 -08001666 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001667
1668 return set;
1669 }
1670
1671 private static void writeBitSet(Parcel dest, BitSet set) {
1672 int nextSetBit = -1;
1673
1674 dest.writeInt(set.cardinality());
1675
Irfan Sheriff9b813192013-01-11 14:03:55 -08001676 while ((nextSetBit = set.nextSetBit(nextSetBit + 1)) != -1) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001677 dest.writeInt(nextSetBit);
Irfan Sheriff9b813192013-01-11 14:03:55 -08001678 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001679 }
1680
Irfan Sheriffec8d23a2011-02-16 17:00:33 -08001681 /** @hide */
1682 public int getAuthType() {
Jan Nordqvistd4928832015-06-01 16:14:55 -07001683 if (allowedKeyManagement.cardinality() > 1) {
1684 throw new IllegalStateException("More than one auth type set");
Irfan Sheriff26d00762013-02-05 09:44:12 -08001685 }
Irfan Sheriffec8d23a2011-02-16 17:00:33 -08001686 if (allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
1687 return KeyMgmt.WPA_PSK;
1688 } else if (allowedKeyManagement.get(KeyMgmt.WPA2_PSK)) {
1689 return KeyMgmt.WPA2_PSK;
1690 } else if (allowedKeyManagement.get(KeyMgmt.WPA_EAP)) {
1691 return KeyMgmt.WPA_EAP;
1692 } else if (allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
1693 return KeyMgmt.IEEE8021X;
1694 }
1695 return KeyMgmt.NONE;
1696 }
1697
vandwalle7c3606c2014-03-31 19:12:07 -07001698 /* @hide
1699 * Cache the config key, this seems useful as a speed up since a lot of
1700 * lookups in the config store are done and based on this key.
1701 */
1702 String mCachedConfigKey;
1703
1704 /** @hide
1705 * return the string used to calculate the hash in WifiConfigStore
1706 * and uniquely identify this WifiConfiguration
1707 */
1708 public String configKey(boolean allowCached) {
1709 String key;
1710 if (allowCached && mCachedConfigKey != null) {
1711 key = mCachedConfigKey;
Vinit Deshpandeb21d2482015-02-02 10:50:36 -08001712 } else if (providerFriendlyName != null) {
1713 key = FQDN + KeyMgmt.strings[KeyMgmt.WPA_EAP];
Bartosz Fabianowski6fb07562016-01-12 15:43:19 +01001714 if (!shared) {
1715 key += "-" + Integer.toString(UserHandle.getUserId(creatorUid));
1716 }
vandwalle7c3606c2014-03-31 19:12:07 -07001717 } else {
Lorenzo Colitti8e1e34a2014-09-30 18:30:04 +09001718 if (allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
1719 key = SSID + KeyMgmt.strings[KeyMgmt.WPA_PSK];
1720 } else if (allowedKeyManagement.get(KeyMgmt.WPA_EAP) ||
1721 allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
1722 key = SSID + KeyMgmt.strings[KeyMgmt.WPA_EAP];
1723 } else if (wepKeys[0] != null) {
1724 key = SSID + "WEP";
1725 } else {
1726 key = SSID + KeyMgmt.strings[KeyMgmt.NONE];
vandwalle7c3606c2014-03-31 19:12:07 -07001727 }
Bartosz Fabianowski6fb07562016-01-12 15:43:19 +01001728 if (!shared) {
1729 key += "-" + Integer.toString(UserHandle.getUserId(creatorUid));
1730 }
vandwalle7c3606c2014-03-31 19:12:07 -07001731 mCachedConfigKey = key;
1732 }
1733 return key;
1734 }
1735
1736 /** @hide
1737 * get configKey, force calculating the config string
1738 */
1739 public String configKey() {
1740 return configKey(false);
1741 }
1742
Jaewan Kim63461552014-03-10 17:10:51 +09001743 /** @hide */
1744 public IpConfiguration getIpConfiguration() {
1745 return mIpConfiguration;
1746 }
1747
1748 /** @hide */
1749 public void setIpConfiguration(IpConfiguration ipConfiguration) {
1750 mIpConfiguration = ipConfiguration;
1751 }
1752
1753 /** @hide */
Lorenzo Colitti0a82e802014-07-31 00:48:01 +09001754 public StaticIpConfiguration getStaticIpConfiguration() {
1755 return mIpConfiguration.getStaticIpConfiguration();
Jaewan Kim63461552014-03-10 17:10:51 +09001756 }
1757
1758 /** @hide */
Lorenzo Colitti0a82e802014-07-31 00:48:01 +09001759 public void setStaticIpConfiguration(StaticIpConfiguration staticIpConfiguration) {
1760 mIpConfiguration.setStaticIpConfiguration(staticIpConfiguration);
Jaewan Kim63461552014-03-10 17:10:51 +09001761 }
1762
1763 /** @hide */
1764 public IpConfiguration.IpAssignment getIpAssignment() {
1765 return mIpConfiguration.ipAssignment;
1766 }
1767
1768 /** @hide */
1769 public void setIpAssignment(IpConfiguration.IpAssignment ipAssignment) {
1770 mIpConfiguration.ipAssignment = ipAssignment;
1771 }
1772
1773 /** @hide */
1774 public IpConfiguration.ProxySettings getProxySettings() {
1775 return mIpConfiguration.proxySettings;
1776 }
1777
1778 /** @hide */
1779 public void setProxySettings(IpConfiguration.ProxySettings proxySettings) {
1780 mIpConfiguration.proxySettings = proxySettings;
1781 }
1782
1783 /** @hide */
Lorenzo Colitti0a82e802014-07-31 00:48:01 +09001784 public ProxyInfo getHttpProxy() {
1785 return mIpConfiguration.httpProxy;
1786 }
1787
1788 /** @hide */
1789 public void setHttpProxy(ProxyInfo httpProxy) {
1790 mIpConfiguration.httpProxy = httpProxy;
1791 }
1792
1793 /** @hide */
Jaewan Kim63461552014-03-10 17:10:51 +09001794 public void setProxy(ProxySettings settings, ProxyInfo proxy) {
1795 mIpConfiguration.proxySettings = settings;
Lorenzo Colitti0a82e802014-07-31 00:48:01 +09001796 mIpConfiguration.httpProxy = proxy;
Jaewan Kim63461552014-03-10 17:10:51 +09001797 }
1798
vandwalle13f48ff2014-05-15 14:25:18 -07001799 /** Implement the Parcelable interface {@hide} */
Jaewan Kim67897972014-04-07 09:01:24 +00001800 public int describeContents() {
1801 return 0;
1802 }
1803
Bartosz Fabianowski6fb07562016-01-12 15:43:19 +01001804 /** @hide */
Vinit Deshpandea772f0c2016-01-27 19:05:24 -08001805 public void setPasspointManagementObjectTree(String passpointManagementObjectTree) {
1806 mPasspointManagementObjectTree = passpointManagementObjectTree;
1807 }
1808
1809 /** @hide */
1810 public String getMoTree() {
1811 return mPasspointManagementObjectTree;
1812 }
1813
Irfan Sheriff128ceca2010-09-22 16:09:46 -07001814 /** copy constructor {@hide} */
1815 public WifiConfiguration(WifiConfiguration source) {
1816 if (source != null) {
1817 networkId = source.networkId;
1818 status = source.status;
1819 SSID = source.SSID;
1820 BSSID = source.BSSID;
Yuhao Zheng8a9eb812014-05-27 10:35:02 -07001821 FQDN = source.FQDN;
Vinit Deshpandea0d929e2015-06-12 15:18:44 -07001822 roamingConsortiumIds = source.roamingConsortiumIds.clone();
Vinit Deshpandeb21d2482015-02-02 10:50:36 -08001823 providerFriendlyName = source.providerFriendlyName;
Irfan Sheriff128ceca2010-09-22 16:09:46 -07001824 preSharedKey = source.preSharedKey;
Irfan Sheriff9e6222f2010-08-23 10:41:11 -07001825
xinhe8d106782015-12-01 14:44:37 -08001826 mNetworkSelectionStatus.copy(source.getNetworkSelectionStatus());
xinhea0be0fb2015-01-07 17:57:38 -08001827 apBand = source.apBand;
1828 apChannel = source.apChannel;
1829
Irfan Sheriff128ceca2010-09-22 16:09:46 -07001830 wepKeys = new String[4];
Irfan Sheriff9b813192013-01-11 14:03:55 -08001831 for (int i = 0; i < wepKeys.length; i++) {
Irfan Sheriff128ceca2010-09-22 16:09:46 -07001832 wepKeys[i] = source.wepKeys[i];
Irfan Sheriff9b813192013-01-11 14:03:55 -08001833 }
Irfan Sheriff9e6222f2010-08-23 10:41:11 -07001834
Irfan Sheriff128ceca2010-09-22 16:09:46 -07001835 wepTxKeyIndex = source.wepTxKeyIndex;
1836 priority = source.priority;
1837 hiddenSSID = source.hiddenSSID;
1838 allowedKeyManagement = (BitSet) source.allowedKeyManagement.clone();
1839 allowedProtocols = (BitSet) source.allowedProtocols.clone();
1840 allowedAuthAlgorithms = (BitSet) source.allowedAuthAlgorithms.clone();
1841 allowedPairwiseCiphers = (BitSet) source.allowedPairwiseCiphers.clone();
1842 allowedGroupCiphers = (BitSet) source.allowedGroupCiphers.clone();
Irfan Sheriff9b813192013-01-11 14:03:55 -08001843 enterpriseConfig = new WifiEnterpriseConfig(source.enterpriseConfig);
Jaewan Kim67897972014-04-07 09:01:24 +00001844
vandwalle7c3606c2014-03-31 19:12:07 -07001845 defaultGwMacAddress = source.defaultGwMacAddress;
1846
Jaewan Kim63461552014-03-10 17:10:51 +09001847 mIpConfiguration = new IpConfiguration(source.mIpConfiguration);
1848
vandwalle7c3606c2014-03-31 19:12:07 -07001849 if ((source.linkedConfigurations != null)
1850 && (source.linkedConfigurations.size() > 0)) {
1851 linkedConfigurations = new HashMap<String, Integer>();
1852 linkedConfigurations.putAll(source.linkedConfigurations);
1853 }
1854 mCachedConfigKey = null; //force null configKey
vandwallee50869d2014-05-13 13:08:44 -07001855 selfAdded = source.selfAdded;
vandwalleec3e9802014-11-07 17:29:24 -08001856 validatedInternetAccess = source.validatedInternetAccess;
Jeff Davidson8faf2a22014-10-06 16:16:35 -07001857 ephemeral = source.ephemeral;
Jeremy Joslinf0c9b8c2016-03-17 10:10:32 -07001858 meteredHint = source.meteredHint;
vandwalle7c3606c2014-03-31 19:12:07 -07001859 if (source.visibility != null) {
1860 visibility = new Visibility(source.visibility);
1861 }
vandwalle3a74e2ef2014-05-21 21:21:00 -07001862
1863 lastFailure = source.lastFailure;
vandwalle8f135482014-05-30 14:29:49 -07001864 didSelfAdd = source.didSelfAdd;
1865 lastConnectUid = source.lastConnectUid;
1866 lastUpdateUid = source.lastUpdateUid;
1867 creatorUid = source.creatorUid;
Sky Faber3e3857c2014-09-22 13:54:18 -07001868 creatorName = source.creatorName;
1869 lastUpdateName = source.lastUpdateName;
vandwalle2d0f71e2014-06-01 14:58:07 -07001870 peerWifiConfiguration = source.peerWifiConfiguration;
xinhe8d106782015-12-01 14:44:37 -08001871
vandwalle111fa022014-06-10 20:47:58 -07001872 lastConnected = source.lastConnected;
1873 lastDisconnected = source.lastDisconnected;
vandwalle154b2cf2014-07-23 16:03:43 -07001874 lastConnectionFailure = source.lastConnectionFailure;
vandwalle8650c032015-01-11 11:57:01 -08001875 lastRoamingFailure = source.lastRoamingFailure;
1876 lastRoamingFailureReason = source.lastRoamingFailureReason;
1877 roamingFailureBlackListTimeMilli = source.roamingFailureBlackListTimeMilli;
vandwalle154b2cf2014-07-23 16:03:43 -07001878 numScorerOverride = source.numScorerOverride;
1879 numScorerOverrideAndSwitchedNetwork = source.numScorerOverrideAndSwitchedNetwork;
vandwalle4eeecb22014-07-25 17:10:56 -07001880 numAssociation = source.numAssociation;
vandwalle448e2082014-09-05 00:01:24 -07001881 numUserTriggeredWifiDisableLowRSSI = source.numUserTriggeredWifiDisableLowRSSI;
1882 numUserTriggeredWifiDisableBadRSSI = source.numUserTriggeredWifiDisableBadRSSI;
1883 numUserTriggeredWifiDisableNotHighRSSI = source.numUserTriggeredWifiDisableNotHighRSSI;
1884 numTicksAtLowRSSI = source.numTicksAtLowRSSI;
1885 numTicksAtBadRSSI = source.numTicksAtBadRSSI;
1886 numTicksAtNotHighRSSI = source.numTicksAtNotHighRSSI;
1887 numUserTriggeredJoinAttempts = source.numUserTriggeredJoinAttempts;
Sky Faber3e3857c2014-09-22 13:54:18 -07001888 userApproved = source.userApproved;
vandwalleec3e9802014-11-07 17:29:24 -08001889 numNoInternetAccessReports = source.numNoInternetAccessReports;
Lorenzo Colitti1248dd32015-04-06 17:26:10 +09001890 noInternetAccessExpected = source.noInternetAccessExpected;
Pierre Vandwalleced1a652015-06-16 13:55:44 -07001891 creationTime = source.creationTime;
1892 updateTime = source.updateTime;
Bartosz Fabianowski6fb07562016-01-12 15:43:19 +01001893 shared = source.shared;
Jaewan Kim63461552014-03-10 17:10:51 +09001894 }
Irfan Sheriff9e6222f2010-08-23 10:41:11 -07001895 }
1896
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001897 /** Implement the Parcelable interface {@hide} */
Jaewan Kim63461552014-03-10 17:10:51 +09001898 @Override
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001899 public void writeToParcel(Parcel dest, int flags) {
1900 dest.writeInt(networkId);
1901 dest.writeInt(status);
xinhe8d106782015-12-01 14:44:37 -08001902 mNetworkSelectionStatus.writeToParcel(dest);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001903 dest.writeString(SSID);
1904 dest.writeString(BSSID);
xinhea0be0fb2015-01-07 17:57:38 -08001905 dest.writeInt(apBand);
1906 dest.writeInt(apChannel);
Yuhao Zheng8a9eb812014-05-27 10:35:02 -07001907 dest.writeString(FQDN);
Vinit Deshpandeb21d2482015-02-02 10:50:36 -08001908 dest.writeString(providerFriendlyName);
Vinit Deshpandea0d929e2015-06-12 15:18:44 -07001909 dest.writeInt(roamingConsortiumIds.length);
Vinit Deshpande7226c8f2015-06-30 13:43:02 -07001910 for (long roamingConsortiumId : roamingConsortiumIds) {
Vinit Deshpandeb21d2482015-02-02 10:50:36 -08001911 dest.writeLong(roamingConsortiumId);
1912 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001913 dest.writeString(preSharedKey);
Irfan Sheriff9b813192013-01-11 14:03:55 -08001914 for (String wepKey : wepKeys) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001915 dest.writeString(wepKey);
Irfan Sheriff9b813192013-01-11 14:03:55 -08001916 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001917 dest.writeInt(wepTxKeyIndex);
1918 dest.writeInt(priority);
1919 dest.writeInt(hiddenSSID ? 1 : 0);
Yuhao Zheng5f9385f2014-06-30 15:32:08 -07001920 dest.writeInt(requirePMF ? 1 : 0);
1921 dest.writeString(updateIdentifier);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001922
1923 writeBitSet(dest, allowedKeyManagement);
1924 writeBitSet(dest, allowedProtocols);
1925 writeBitSet(dest, allowedAuthAlgorithms);
1926 writeBitSet(dest, allowedPairwiseCiphers);
1927 writeBitSet(dest, allowedGroupCiphers);
Chung-yih Wang43374762009-09-16 14:28:42 +08001928
Irfan Sheriff9b813192013-01-11 14:03:55 -08001929 dest.writeParcelable(enterpriseConfig, flags);
Jaewan Kim67897972014-04-07 09:01:24 +00001930
Jaewan Kim63461552014-03-10 17:10:51 +09001931 dest.writeParcelable(mIpConfiguration, flags);
vandwalle7c3606c2014-03-31 19:12:07 -07001932 dest.writeString(dhcpServer);
1933 dest.writeString(defaultGwMacAddress);
vandwallee50869d2014-05-13 13:08:44 -07001934 dest.writeInt(selfAdded ? 1 : 0);
vandwalle8f135482014-05-30 14:29:49 -07001935 dest.writeInt(didSelfAdd ? 1 : 0);
vandwalleec3e9802014-11-07 17:29:24 -08001936 dest.writeInt(validatedInternetAccess ? 1 : 0);
Jeff Davidson8faf2a22014-10-06 16:16:35 -07001937 dest.writeInt(ephemeral ? 1 : 0);
Jeremy Joslinf0c9b8c2016-03-17 10:10:32 -07001938 dest.writeInt(meteredHint ? 1 : 0);
vandwalle8f135482014-05-30 14:29:49 -07001939 dest.writeInt(creatorUid);
1940 dest.writeInt(lastConnectUid);
1941 dest.writeInt(lastUpdateUid);
Sky Faber3e3857c2014-09-22 13:54:18 -07001942 dest.writeString(creatorName);
1943 dest.writeString(lastUpdateName);
vandwalle154b2cf2014-07-23 16:03:43 -07001944 dest.writeLong(lastConnectionFailure);
vandwalle8650c032015-01-11 11:57:01 -08001945 dest.writeLong(lastRoamingFailure);
1946 dest.writeInt(lastRoamingFailureReason);
1947 dest.writeLong(roamingFailureBlackListTimeMilli);
vandwalle154b2cf2014-07-23 16:03:43 -07001948 dest.writeInt(numScorerOverride);
1949 dest.writeInt(numScorerOverrideAndSwitchedNetwork);
vandwalle4eeecb22014-07-25 17:10:56 -07001950 dest.writeInt(numAssociation);
vandwalle448e2082014-09-05 00:01:24 -07001951 dest.writeInt(numUserTriggeredWifiDisableLowRSSI);
1952 dest.writeInt(numUserTriggeredWifiDisableBadRSSI);
1953 dest.writeInt(numUserTriggeredWifiDisableNotHighRSSI);
1954 dest.writeInt(numTicksAtLowRSSI);
1955 dest.writeInt(numTicksAtBadRSSI);
1956 dest.writeInt(numTicksAtNotHighRSSI);
1957 dest.writeInt(numUserTriggeredJoinAttempts);
Sky Faber3e3857c2014-09-22 13:54:18 -07001958 dest.writeInt(userApproved);
vandwalleec3e9802014-11-07 17:29:24 -08001959 dest.writeInt(numNoInternetAccessReports);
Lorenzo Colitti1248dd32015-04-06 17:26:10 +09001960 dest.writeInt(noInternetAccessExpected ? 1 : 0);
Bartosz Fabianowski6fb07562016-01-12 15:43:19 +01001961 dest.writeInt(shared ? 1 : 0);
Vinit Deshpandea772f0c2016-01-27 19:05:24 -08001962 dest.writeString(mPasspointManagementObjectTree);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001963 }
1964
1965 /** Implement the Parcelable interface {@hide} */
1966 public static final Creator<WifiConfiguration> CREATOR =
1967 new Creator<WifiConfiguration>() {
1968 public WifiConfiguration createFromParcel(Parcel in) {
1969 WifiConfiguration config = new WifiConfiguration();
1970 config.networkId = in.readInt();
1971 config.status = in.readInt();
xinhe8d106782015-12-01 14:44:37 -08001972 config.mNetworkSelectionStatus.readFromParcel(in);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001973 config.SSID = in.readString();
1974 config.BSSID = in.readString();
xinhea0be0fb2015-01-07 17:57:38 -08001975 config.apBand = in.readInt();
1976 config.apChannel = in.readInt();
Yuhao Zheng8a9eb812014-05-27 10:35:02 -07001977 config.FQDN = in.readString();
Vinit Deshpandeb21d2482015-02-02 10:50:36 -08001978 config.providerFriendlyName = in.readString();
1979 int numRoamingConsortiumIds = in.readInt();
Vinit Deshpande7226c8f2015-06-30 13:43:02 -07001980 config.roamingConsortiumIds = new long[numRoamingConsortiumIds];
Vinit Deshpandeb21d2482015-02-02 10:50:36 -08001981 for (int i = 0; i < numRoamingConsortiumIds; i++) {
Vinit Deshpandea0d929e2015-06-12 15:18:44 -07001982 config.roamingConsortiumIds[i] = in.readLong();
Vinit Deshpandeb21d2482015-02-02 10:50:36 -08001983 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001984 config.preSharedKey = in.readString();
Irfan Sheriff9b813192013-01-11 14:03:55 -08001985 for (int i = 0; i < config.wepKeys.length; i++) {
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001986 config.wepKeys[i] = in.readString();
Irfan Sheriff9b813192013-01-11 14:03:55 -08001987 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001988 config.wepTxKeyIndex = in.readInt();
1989 config.priority = in.readInt();
1990 config.hiddenSSID = in.readInt() != 0;
Yuhao Zheng5f9385f2014-06-30 15:32:08 -07001991 config.requirePMF = in.readInt() != 0;
1992 config.updateIdentifier = in.readString();
1993
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001994 config.allowedKeyManagement = readBitSet(in);
1995 config.allowedProtocols = readBitSet(in);
1996 config.allowedAuthAlgorithms = readBitSet(in);
1997 config.allowedPairwiseCiphers = readBitSet(in);
1998 config.allowedGroupCiphers = readBitSet(in);
Chung-yih Wang43374762009-09-16 14:28:42 +08001999
Irfan Sheriff9b813192013-01-11 14:03:55 -08002000 config.enterpriseConfig = in.readParcelable(null);
Jaewan Kim63461552014-03-10 17:10:51 +09002001 config.mIpConfiguration = in.readParcelable(null);
vandwalle7c3606c2014-03-31 19:12:07 -07002002 config.dhcpServer = in.readString();
2003 config.defaultGwMacAddress = in.readString();
vandwallee50869d2014-05-13 13:08:44 -07002004 config.selfAdded = in.readInt() != 0;
vandwalle8f135482014-05-30 14:29:49 -07002005 config.didSelfAdd = in.readInt() != 0;
vandwalleec3e9802014-11-07 17:29:24 -08002006 config.validatedInternetAccess = in.readInt() != 0;
Jeff Davidson8faf2a22014-10-06 16:16:35 -07002007 config.ephemeral = in.readInt() != 0;
Jeremy Joslinf0c9b8c2016-03-17 10:10:32 -07002008 config.meteredHint = in.readInt() != 0;
vandwalle8f135482014-05-30 14:29:49 -07002009 config.creatorUid = in.readInt();
2010 config.lastConnectUid = in.readInt();
2011 config.lastUpdateUid = in.readInt();
Sky Faber3e3857c2014-09-22 13:54:18 -07002012 config.creatorName = in.readString();
2013 config.lastUpdateName = in.readString();
vandwalle154b2cf2014-07-23 16:03:43 -07002014 config.lastConnectionFailure = in.readLong();
vandwalle8650c032015-01-11 11:57:01 -08002015 config.lastRoamingFailure = in.readLong();
2016 config.lastRoamingFailureReason = in.readInt();
2017 config.roamingFailureBlackListTimeMilli = in.readLong();
vandwalle154b2cf2014-07-23 16:03:43 -07002018 config.numScorerOverride = in.readInt();
2019 config.numScorerOverrideAndSwitchedNetwork = in.readInt();
vandwalle4eeecb22014-07-25 17:10:56 -07002020 config.numAssociation = in.readInt();
vandwalle448e2082014-09-05 00:01:24 -07002021 config.numUserTriggeredWifiDisableLowRSSI = in.readInt();
2022 config.numUserTriggeredWifiDisableBadRSSI = in.readInt();
2023 config.numUserTriggeredWifiDisableNotHighRSSI = in.readInt();
2024 config.numTicksAtLowRSSI = in.readInt();
2025 config.numTicksAtBadRSSI = in.readInt();
2026 config.numTicksAtNotHighRSSI = in.readInt();
2027 config.numUserTriggeredJoinAttempts = in.readInt();
Sky Faber3e3857c2014-09-22 13:54:18 -07002028 config.userApproved = in.readInt();
vandwalleec3e9802014-11-07 17:29:24 -08002029 config.numNoInternetAccessReports = in.readInt();
Lorenzo Colitti1248dd32015-04-06 17:26:10 +09002030 config.noInternetAccessExpected = in.readInt() != 0;
Bartosz Fabianowski6fb07562016-01-12 15:43:19 +01002031 config.shared = in.readInt() != 0;
Vinit Deshpandea772f0c2016-01-27 19:05:24 -08002032 config.mPasspointManagementObjectTree = in.readString();
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08002033 return config;
2034 }
2035
2036 public WifiConfiguration[] newArray(int size) {
2037 return new WifiConfiguration[size];
2038 }
2039 };
Ritesh Reddyaeb4c062016-01-26 19:40:48 +00002040
2041 /**
2042 * Serializes the object for backup
2043 * @hide
2044 */
2045 public byte[] getBytesForBackup() throws IOException {
2046 ByteArrayOutputStream baos = new ByteArrayOutputStream();
2047 DataOutputStream out = new DataOutputStream(baos);
2048
2049 out.writeInt(BACKUP_VERSION);
2050 BackupUtils.writeString(out, SSID);
2051 out.writeInt(apBand);
2052 out.writeInt(apChannel);
2053 BackupUtils.writeString(out, preSharedKey);
2054 out.writeInt(getAuthType());
2055 return baos.toByteArray();
2056 }
2057
2058 /**
2059 * Deserializes a byte array into the WiFiConfiguration Object
2060 * @hide
2061 */
2062 public static WifiConfiguration getWifiConfigFromBackup(DataInputStream in) throws IOException,
2063 BackupUtils.BadVersionException {
2064 WifiConfiguration config = new WifiConfiguration();
2065 int version = in.readInt();
2066 if (version < 1 || version > BACKUP_VERSION) {
2067 throw new BackupUtils.BadVersionException("Unknown Backup Serialization Version");
2068 }
2069
2070 if (version == 1) return null; // Version 1 is a bad dataset.
2071
2072 config.SSID = BackupUtils.readString(in);
2073 config.apBand = in.readInt();
2074 config.apChannel = in.readInt();
2075 config.preSharedKey = BackupUtils.readString(in);
2076 config.allowedKeyManagement.set(in.readInt());
2077 return config;
2078 }
Glen Kuhneb6cd6fa2016-02-10 15:08:33 -08002079}