blob: 78f8a7287db183830bbd94546241ecfb0dc3c6c1 [file] [log] [blame]
Jason Monkd52356a2015-01-28 10:40:41 -05001/*
2 * Copyright (C) 2015 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 com.android.settingslib.wifi;
18
Sundeep Ghuman53200ed2017-06-21 16:54:36 -070019import android.annotation.IntDef;
Sundeep Ghumanbb399912018-01-29 18:31:15 -080020import android.annotation.MainThread;
Sundeep Ghuman271e5de2017-05-30 14:11:39 -070021import android.annotation.Nullable;
Jason Monk6980d122015-06-15 10:07:55 -040022import android.app.AppGlobals;
Jason Monkd52356a2015-01-28 10:40:41 -050023import android.content.Context;
Jason Monk6980d122015-06-15 10:07:55 -040024import android.content.pm.ApplicationInfo;
25import android.content.pm.IPackageManager;
26import android.content.pm.PackageManager;
Sanket Padawe7094d222015-05-01 16:55:00 -070027import android.net.ConnectivityManager;
Sanket Padawe7094d222015-05-01 16:55:00 -070028import android.net.NetworkCapabilities;
Jason Monkd52356a2015-01-28 10:40:41 -050029import android.net.NetworkInfo;
30import android.net.NetworkInfo.DetailedState;
31import android.net.NetworkInfo.State;
Sundeep Ghumana28050a2017-07-12 22:09:25 -070032import android.net.NetworkKey;
Stephen Chen36dd5cf12017-03-20 13:27:51 -070033import android.net.NetworkScoreManager;
34import android.net.NetworkScorerAppData;
Sundeep Ghuman5519b7b2016-12-14 17:53:31 -080035import android.net.ScoredNetwork;
Sanket Padawe7094d222015-05-01 16:55:00 -070036import android.net.wifi.IWifiManager;
Jason Monkd52356a2015-01-28 10:40:41 -050037import android.net.wifi.ScanResult;
38import android.net.wifi.WifiConfiguration;
39import android.net.wifi.WifiConfiguration.KeyMgmt;
Peter Qiu280581b2017-07-24 14:18:56 -070040import android.net.wifi.WifiEnterpriseConfig;
Jason Monkd52356a2015-01-28 10:40:41 -050041import android.net.wifi.WifiInfo;
42import android.net.wifi.WifiManager;
Sundeep Ghuman5519b7b2016-12-14 17:53:31 -080043import android.net.wifi.WifiNetworkScoreCache;
Quang Luong9051dfd2018-12-12 12:49:24 -080044import android.net.wifi.hotspot2.OsuProvider;
Peter Qiuced37db2017-03-14 15:51:22 -070045import android.net.wifi.hotspot2.PasspointConfiguration;
Quang Luong4d194842018-12-18 16:59:49 -080046import android.net.wifi.hotspot2.ProvisioningCallback;
Jason Monkd52356a2015-01-28 10:40:41 -050047import android.os.Bundle;
Sundeep Ghuman04f7f342018-01-23 19:18:31 -080048import android.os.Parcelable;
Sanket Padawe7094d222015-05-01 16:55:00 -070049import android.os.RemoteException;
50import android.os.ServiceManager;
Mitchell Wills18af4932016-08-10 13:49:21 -070051import android.os.SystemClock;
Jason Monk6980d122015-06-15 10:07:55 -040052import android.os.UserHandle;
Jason Monk6980d122015-06-15 10:07:55 -040053import android.text.TextUtils;
Sundeep Ghuman04f7f342018-01-23 19:18:31 -080054import android.util.ArraySet;
Jason Monkd52356a2015-01-28 10:40:41 -050055import android.util.Log;
Jason Monkd52356a2015-01-28 10:40:41 -050056
Fan Zhangf7802ea2018-08-28 15:15:19 -070057import androidx.annotation.NonNull;
58
Sundeep Ghuman54bdcfa2017-03-08 19:52:05 -080059import com.android.internal.annotations.VisibleForTesting;
Jason Monkd52356a2015-01-28 10:40:41 -050060import com.android.settingslib.R;
Sundeep Ghumanbb399912018-01-29 18:31:15 -080061import com.android.settingslib.utils.ThreadUtils;
Jason Monkd52356a2015-01-28 10:40:41 -050062
Sundeep Ghuman53200ed2017-06-21 16:54:36 -070063import java.lang.annotation.Retention;
64import java.lang.annotation.RetentionPolicy;
Vinit Deshpandefcd46122015-06-11 18:22:23 -070065import java.util.ArrayList;
Sundeep Ghuman04f7f342018-01-23 19:18:31 -080066import java.util.Collection;
Eric Schwarzenbach0b8700f2017-07-25 14:32:21 -070067import java.util.HashMap;
Mitchell Wills18af4932016-08-10 13:49:21 -070068import java.util.Iterator;
Eric Schwarzenbach0b8700f2017-07-25 14:32:21 -070069import java.util.Map;
Sundeep Ghuman04f7f342018-01-23 19:18:31 -080070import java.util.Set;
Ajay Nadathurd7b689a2016-08-31 15:07:56 -070071import java.util.concurrent.atomic.AtomicInteger;
Jason Monkd52356a2015-01-28 10:40:41 -050072
Sundeep Ghumanbb399912018-01-29 18:31:15 -080073/**
74 * Represents a selectable Wifi Network for use in various wifi selection menus backed by
75 * {@link WifiTracker}.
76 *
77 * <p>An AccessPoint, which would be more fittingly named "WifiNetwork", is an aggregation of
78 * {@link ScanResult ScanResults} along with pertinent metadata (e.g. current connection info,
79 * network scores) required to successfully render the network to the user.
80 */
Jason Monkd52356a2015-01-28 10:40:41 -050081public class AccessPoint implements Comparable<AccessPoint> {
82 static final String TAG = "SettingsLib.AccessPoint";
83
84 /**
85 * Lower bound on the 2.4 GHz (802.11b/g/n) WLAN channels
86 */
87 public static final int LOWER_FREQ_24GHZ = 2400;
88
89 /**
90 * Upper bound on the 2.4 GHz (802.11b/g/n) WLAN channels
91 */
92 public static final int HIGHER_FREQ_24GHZ = 2500;
93
94 /**
95 * Lower bound on the 5.0 GHz (802.11a/h/j/n/ac) WLAN channels
96 */
97 public static final int LOWER_FREQ_5GHZ = 4900;
98
99 /**
100 * Upper bound on the 5.0 GHz (802.11a/h/j/n/ac) WLAN channels
101 */
102 public static final int HIGHER_FREQ_5GHZ = 5900;
103
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800104 /** The key which identifies this AccessPoint grouping. */
105 private String mKey;
106
Sundeep Ghuman53200ed2017-06-21 16:54:36 -0700107 @IntDef({Speed.NONE, Speed.SLOW, Speed.MODERATE, Speed.FAST, Speed.VERY_FAST})
108 @Retention(RetentionPolicy.SOURCE)
109 public @interface Speed {
110 /**
111 * Constant value representing an unlabeled / unscored network.
112 */
113 int NONE = 0;
114 /**
115 * Constant value representing a slow speed network connection.
116 */
117 int SLOW = 5;
118 /**
119 * Constant value representing a medium speed network connection.
120 */
121 int MODERATE = 10;
122 /**
123 * Constant value representing a fast speed network connection.
124 */
125 int FAST = 20;
126 /**
127 * Constant value representing a very fast speed network connection.
128 */
129 int VERY_FAST = 30;
130 }
Jason Monkd52356a2015-01-28 10:40:41 -0500131
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800132 /** The underlying set of scan results comprising this AccessPoint. */
133 private final ArraySet<ScanResult> mScanResults = new ArraySet<>();
Eric Schwarzenbach0b8700f2017-07-25 14:32:21 -0700134
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -0700135 /**
136 * Map of BSSIDs to scored networks for individual bssids.
137 *
138 * <p>This cache should not be evicted with scan results, as the values here are used to
139 * generate a fallback in the absence of scores for the visible APs.
140 */
Sundeep Ghumanfedf4612017-08-15 15:47:18 -0700141 private final Map<String, TimestampedScoredNetwork> mScoredNetworkCache = new HashMap<>();
142
Dave Schaefer98537432017-02-08 11:26:08 -0800143 static final String KEY_NETWORKINFO = "key_networkinfo";
144 static final String KEY_WIFIINFO = "key_wifiinfo";
Dave Schaefer98537432017-02-08 11:26:08 -0800145 static final String KEY_SSID = "key_ssid";
146 static final String KEY_SECURITY = "key_security";
Sundeep Ghumana28050a2017-07-12 22:09:25 -0700147 static final String KEY_SPEED = "key_speed";
Dave Schaefer98537432017-02-08 11:26:08 -0800148 static final String KEY_PSKTYPE = "key_psktype";
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800149 static final String KEY_SCANRESULTS = "key_scanresults";
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -0700150 static final String KEY_SCOREDNETWORKCACHE = "key_scorednetworkcache";
Dave Schaefer98537432017-02-08 11:26:08 -0800151 static final String KEY_CONFIG = "key_config";
Peter Qiuced37db2017-03-14 15:51:22 -0700152 static final String KEY_FQDN = "key_fqdn";
153 static final String KEY_PROVIDER_FRIENDLY_NAME = "key_provider_friendly_name";
Peter Qiu280581b2017-07-24 14:18:56 -0700154 static final String KEY_IS_CARRIER_AP = "key_is_carrier_ap";
155 static final String KEY_CARRIER_AP_EAP_TYPE = "key_carrier_ap_eap_type";
156 static final String KEY_CARRIER_NAME = "key_carrier_name";
Dave Schaefer98537432017-02-08 11:26:08 -0800157 static final AtomicInteger sLastId = new AtomicInteger(0);
Jason Monkd52356a2015-01-28 10:40:41 -0500158
Maurice Lam7cdbe192018-11-13 13:52:50 -0800159 /*
160 * NOTE: These constants for security and PSK types are saved to the bundle in saveWifiState,
161 * and sent across IPC. The numeric values should remain stable, otherwise the changes will need
162 * to be synced with other unbundled users of this library.
Jason Monkd52356a2015-01-28 10:40:41 -0500163 */
164 public static final int SECURITY_NONE = 0;
Hai Shalom9effa642018-11-12 11:43:52 -0800165 public static final int SECURITY_WEP = 1;
166 public static final int SECURITY_PSK = 2;
167 public static final int SECURITY_EAP = 3;
168 public static final int SECURITY_OWE = 4;
169 public static final int SECURITY_SAE = 5;
Hai Shalomaa6f9202018-10-16 14:30:02 -0700170 public static final int SECURITY_EAP_SUITE_B = 6;
Hai Shalom828b13c2018-11-13 16:43:14 -0800171 public static final int SECURITY_MAX_VAL = 7; // Has to be the last
Jason Monkd52356a2015-01-28 10:40:41 -0500172
173 private static final int PSK_UNKNOWN = 0;
174 private static final int PSK_WPA = 1;
175 private static final int PSK_WPA2 = 2;
176 private static final int PSK_WPA_WPA2 = 3;
177
Sundeep Ghumanaaa8a1b2017-03-13 14:40:56 -0700178 /**
179 * The number of distinct wifi levels.
180 *
181 * <p>Must keep in sync with {@link R.array.wifi_signal} and {@link WifiManager#RSSI_LEVELS}.
182 */
183 public static final int SIGNAL_LEVELS = 5;
Tony Mantlera0e03dd2016-01-27 15:57:03 -0800184
Sundeep Ghumanaaa8a1b2017-03-13 14:40:56 -0700185 public static final int UNREACHABLE_RSSI = Integer.MIN_VALUE;
Dave Schaefer98537432017-02-08 11:26:08 -0800186
Quang Luong9051dfd2018-12-12 12:49:24 -0800187 public static final String KEY_PREFIX_AP = "AP:";
188 public static final String KEY_PREFIX_FQDN = "FQDN:";
189 public static final String KEY_PREFIX_OSU = "OSU:";
190
Jason Monkd52356a2015-01-28 10:40:41 -0500191 private final Context mContext;
192
193 private String ssid;
Jason Monk60a82ff2016-02-25 13:55:03 -0500194 private String bssid;
Jason Monkd52356a2015-01-28 10:40:41 -0500195 private int security;
196 private int networkId = WifiConfiguration.INVALID_NETWORK_ID;
197
198 private int pskType = PSK_UNKNOWN;
199
200 private WifiConfiguration mConfig;
Jason Monkd52356a2015-01-28 10:40:41 -0500201
Dave Schaefer98537432017-02-08 11:26:08 -0800202 private int mRssi = UNREACHABLE_RSSI;
Jason Monkd52356a2015-01-28 10:40:41 -0500203
204 private WifiInfo mInfo;
205 private NetworkInfo mNetworkInfo;
Ajay Nadathurd7b689a2016-08-31 15:07:56 -0700206 AccessPointListener mAccessPointListener;
Jason Monkd52356a2015-01-28 10:40:41 -0500207
208 private Object mTag;
209
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -0700210 @Speed private int mSpeed = Speed.NONE;
Stephen Chen21f68682017-04-04 13:23:31 -0700211 private boolean mIsScoredNetworkMetered = false;
Sundeep Ghuman5519b7b2016-12-14 17:53:31 -0800212
Peter Qiuced37db2017-03-14 15:51:22 -0700213 /**
214 * Information associated with the {@link PasspointConfiguration}. Only maintaining
215 * the relevant info to preserve spaces.
216 */
217 private String mFqdn;
218 private String mProviderFriendlyName;
219
Peter Qiu280581b2017-07-24 14:18:56 -0700220 private boolean mIsCarrierAp = false;
Quang Luong9051dfd2018-12-12 12:49:24 -0800221
222 private OsuProvider mOsuProvider;
Quang Luong8d40a8e2019-01-02 16:25:38 -0800223
224 private String mOsuStatus;
225 private String mOsuFailure;
226 private boolean mOsuProvisioningComplete = false;
227
Peter Qiu280581b2017-07-24 14:18:56 -0700228 /**
229 * The EAP type {@link WifiEnterpriseConfig.Eap} associated with this AP if it is a carrier AP.
230 */
231 private int mCarrierApEapType = WifiEnterpriseConfig.Eap.NONE;
232 private String mCarrierName = null;
233
Jason Monkd52356a2015-01-28 10:40:41 -0500234 public AccessPoint(Context context, Bundle savedState) {
235 mContext = context;
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800236
237 if (savedState.containsKey(KEY_CONFIG)) {
238 mConfig = savedState.getParcelable(KEY_CONFIG);
239 }
Jason Monkd52356a2015-01-28 10:40:41 -0500240 if (mConfig != null) {
241 loadConfig(mConfig);
242 }
Vinit Deshpandefcd46122015-06-11 18:22:23 -0700243 if (savedState.containsKey(KEY_SSID)) {
244 ssid = savedState.getString(KEY_SSID);
245 }
246 if (savedState.containsKey(KEY_SECURITY)) {
247 security = savedState.getInt(KEY_SECURITY);
248 }
Sundeep Ghumana28050a2017-07-12 22:09:25 -0700249 if (savedState.containsKey(KEY_SPEED)) {
250 mSpeed = savedState.getInt(KEY_SPEED);
251 }
Vinit Deshpandefcd46122015-06-11 18:22:23 -0700252 if (savedState.containsKey(KEY_PSKTYPE)) {
253 pskType = savedState.getInt(KEY_PSKTYPE);
Jason Monkd52356a2015-01-28 10:40:41 -0500254 }
Sundeep Ghumana28050a2017-07-12 22:09:25 -0700255 mInfo = savedState.getParcelable(KEY_WIFIINFO);
Jason Monkd52356a2015-01-28 10:40:41 -0500256 if (savedState.containsKey(KEY_NETWORKINFO)) {
257 mNetworkInfo = savedState.getParcelable(KEY_NETWORKINFO);
258 }
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800259 if (savedState.containsKey(KEY_SCANRESULTS)) {
260 Parcelable[] scanResults = savedState.getParcelableArray(KEY_SCANRESULTS);
261 mScanResults.clear();
262 for (Parcelable result : scanResults) {
263 mScanResults.add((ScanResult) result);
Vinit Deshpandefcd46122015-06-11 18:22:23 -0700264 }
265 }
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -0700266 if (savedState.containsKey(KEY_SCOREDNETWORKCACHE)) {
Sundeep Ghumanfedf4612017-08-15 15:47:18 -0700267 ArrayList<TimestampedScoredNetwork> scoredNetworkArrayList =
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -0700268 savedState.getParcelableArrayList(KEY_SCOREDNETWORKCACHE);
Sundeep Ghumanfedf4612017-08-15 15:47:18 -0700269 for (TimestampedScoredNetwork timedScore : scoredNetworkArrayList) {
270 mScoredNetworkCache.put(timedScore.getScore().networkKey.wifiKey.bssid, timedScore);
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -0700271 }
272 }
Peter Qiuced37db2017-03-14 15:51:22 -0700273 if (savedState.containsKey(KEY_FQDN)) {
274 mFqdn = savedState.getString(KEY_FQDN);
275 }
276 if (savedState.containsKey(KEY_PROVIDER_FRIENDLY_NAME)) {
277 mProviderFriendlyName = savedState.getString(KEY_PROVIDER_FRIENDLY_NAME);
278 }
Peter Qiu280581b2017-07-24 14:18:56 -0700279 if (savedState.containsKey(KEY_IS_CARRIER_AP)) {
280 mIsCarrierAp = savedState.getBoolean(KEY_IS_CARRIER_AP);
281 }
282 if (savedState.containsKey(KEY_CARRIER_AP_EAP_TYPE)) {
283 mCarrierApEapType = savedState.getInt(KEY_CARRIER_AP_EAP_TYPE);
284 }
285 if (savedState.containsKey(KEY_CARRIER_NAME)) {
286 mCarrierName = savedState.getString(KEY_CARRIER_NAME);
287 }
Mitchell Wills5a42db22015-08-03 09:46:08 -0700288 update(mConfig, mInfo, mNetworkInfo);
Sundeep Ghumand1e44922017-08-07 11:21:38 -0700289
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800290 // Calculate required fields
291 updateKey();
Sundeep Ghuman54bdcfa2017-03-08 19:52:05 -0800292 updateRssi();
Jason Monkd52356a2015-01-28 10:40:41 -0500293 }
294
Quang Luong9051dfd2018-12-12 12:49:24 -0800295 /**
296 * Creates an AccessPoint with only a WifiConfiguration. This is used for the saved networks
297 * page.
298 *
299 * Passpoint Credential AccessPoints should be created with this.
300 * Make sure to call setScanResults after constructing with this.
301 */
Peter Qiuced37db2017-03-14 15:51:22 -0700302 public AccessPoint(Context context, WifiConfiguration config) {
Jason Monkd52356a2015-01-28 10:40:41 -0500303 mContext = context;
Peter Qiuced37db2017-03-14 15:51:22 -0700304 loadConfig(config);
Jason Monkd52356a2015-01-28 10:40:41 -0500305 }
306
Peter Qiuced37db2017-03-14 15:51:22 -0700307 /**
308 * Initialize an AccessPoint object for a {@link PasspointConfiguration}. This is mainly
309 * used by "Saved Networks" page for managing the saved {@link PasspointConfiguration}.
310 */
311 public AccessPoint(Context context, PasspointConfiguration config) {
Jason Monkd52356a2015-01-28 10:40:41 -0500312 mContext = context;
Peter Qiuced37db2017-03-14 15:51:22 -0700313 mFqdn = config.getHomeSp().getFqdn();
314 mProviderFriendlyName = config.getHomeSp().getFriendlyName();
Quang Luong9051dfd2018-12-12 12:49:24 -0800315 }
316
317 /**
318 * Initialize an AccessPoint object for a Passpoint OSU Provider.
319 * Make sure to call setScanResults after constructing with this.
320 */
321 public AccessPoint(Context context, OsuProvider provider) {
322 mContext = context;
323 mOsuProvider = provider;
324 mRssi = 1;
325 // TODO: This placeholder SSID is here to avoid null pointer exceptions.
326 ssid = "<OsuProvider AP SSID goes here>";
327 updateKey();
Ajay Nadathurd7b689a2016-08-31 15:07:56 -0700328 }
329
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800330 AccessPoint(Context context, Collection<ScanResult> results) {
Peter Qiuced37db2017-03-14 15:51:22 -0700331 mContext = context;
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800332
333 if (results.isEmpty()) {
334 throw new IllegalArgumentException("Cannot construct with an empty ScanResult list");
335 }
336 mScanResults.addAll(results);
337
338 // Information derived from scan results
339 ScanResult firstResult = results.iterator().next();
340 ssid = firstResult.SSID;
341 bssid = firstResult.BSSID;
342 security = getSecurity(firstResult);
343 if (security == SECURITY_PSK) {
344 pskType = getPskType(firstResult);
345 }
346 updateKey();
347 updateRssi();
348
349 // Passpoint Info
350 mIsCarrierAp = firstResult.isCarrierAp;
351 mCarrierApEapType = firstResult.carrierApEapType;
352 mCarrierName = firstResult.carrierName;
Peter Qiuced37db2017-03-14 15:51:22 -0700353 }
354
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800355 @VisibleForTesting void loadConfig(WifiConfiguration config) {
356 ssid = (config.SSID == null ? "" : removeDoubleQuotes(config.SSID));
357 bssid = config.BSSID;
358 security = getSecurity(config);
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800359 networkId = config.networkId;
360 mConfig = config;
Quang Luong7054e922018-12-07 16:44:18 -0800361 updateKey();
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800362 }
363
364 /** Updates {@link #mKey} and should only called upon object creation/initialization. */
365 private void updateKey() {
366 // TODO(sghuman): Consolidate Key logic on ScanResultMatchInfo
Quang Luong7054e922018-12-07 16:44:18 -0800367 if (isPasspoint()) {
Quang Luongac1026e2019-01-02 17:37:01 -0800368 mKey = getKey(mConfig);
Quang Luong9051dfd2018-12-12 12:49:24 -0800369 } else if (isOsuProvider()) {
Quang Luongac1026e2019-01-02 17:37:01 -0800370 mKey = getKey(mOsuProvider);
Quang Luong9051dfd2018-12-12 12:49:24 -0800371 } else { // Non-Passpoint AP
Quang Luongac1026e2019-01-02 17:37:01 -0800372 mKey = getKey(getSsidStr(), getBssid(), getSecurity());
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800373 }
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800374 }
375
Ajay Nadathurd7b689a2016-08-31 15:07:56 -0700376 /**
Dave Schaefer98537432017-02-08 11:26:08 -0800377 * Returns a negative integer, zero, or a positive integer if this AccessPoint is less than,
378 * equal to, or greater than the other AccessPoint.
379 *
380 * Sort order rules for AccessPoints:
381 * 1. Active before inactive
382 * 2. Reachable before unreachable
383 * 3. Saved before unsaved
Eric Schwarzenbachf4f3842b2017-07-17 16:45:04 -0700384 * 4. Network speed value
Dave Schaefer98537432017-02-08 11:26:08 -0800385 * 5. Stronger signal before weaker signal
386 * 6. SSID alphabetically
387 *
388 * Note that AccessPoints with a signal are usually also Reachable,
389 * and will thus appear before unreachable saved AccessPoints.
390 */
Jason Monkd52356a2015-01-28 10:40:41 -0500391 @Override
Tony Mantlera0e03dd2016-01-27 15:57:03 -0800392 public int compareTo(@NonNull AccessPoint other) {
Jason Monkd52356a2015-01-28 10:40:41 -0500393 // Active one goes first.
394 if (isActive() && !other.isActive()) return -1;
395 if (!isActive() && other.isActive()) return 1;
396
397 // Reachable one goes before unreachable one.
Dave Schaefer98537432017-02-08 11:26:08 -0800398 if (isReachable() && !other.isReachable()) return -1;
399 if (!isReachable() && other.isReachable()) return 1;
Jason Monkd52356a2015-01-28 10:40:41 -0500400
Sundeep Ghuman05c41e22017-02-01 13:27:56 -0800401 // Configured (saved) one goes before unconfigured one.
Dave Schaefer98537432017-02-08 11:26:08 -0800402 if (isSaved() && !other.isSaved()) return -1;
403 if (!isSaved() && other.isSaved()) return 1;
Jason Monkd52356a2015-01-28 10:40:41 -0500404
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -0700405 // Faster speeds go before slower speeds - but only if visible change in speed label
Eric Schwarzenbachf4f3842b2017-07-17 16:45:04 -0700406 if (getSpeed() != other.getSpeed()) {
407 return other.getSpeed() - getSpeed();
Sundeep Ghuman05c41e22017-02-01 13:27:56 -0800408 }
409
Tony Mantlera0e03dd2016-01-27 15:57:03 -0800410 // Sort by signal strength, bucketed by level
411 int difference = WifiManager.calculateSignalLevel(other.mRssi, SIGNAL_LEVELS)
412 - WifiManager.calculateSignalLevel(mRssi, SIGNAL_LEVELS);
Jason Monkd52356a2015-01-28 10:40:41 -0500413 if (difference != 0) {
414 return difference;
415 }
Sundeep Ghumand44b8e42017-06-21 21:40:06 -0700416
Quang Luong9051dfd2018-12-12 12:49:24 -0800417 // Sort by title.
418 difference = getTitle().compareToIgnoreCase(other.getTitle());
Sundeep Ghumand44b8e42017-06-21 21:40:06 -0700419 if (difference != 0) {
420 return difference;
421 }
422
423 // Do a case sensitive comparison to distinguish SSIDs that differ in case only
424 return getSsidStr().compareTo(other.getSsidStr());
Jason Monkd52356a2015-01-28 10:40:41 -0500425 }
426
427 @Override
428 public boolean equals(Object other) {
429 if (!(other instanceof AccessPoint)) return false;
430 return (this.compareTo((AccessPoint) other) == 0);
431 }
432
433 @Override
434 public int hashCode() {
435 int result = 0;
436 if (mInfo != null) result += 13 * mInfo.hashCode();
437 result += 19 * mRssi;
438 result += 23 * networkId;
439 result += 29 * ssid.hashCode();
440 return result;
441 }
442
443 @Override
444 public String toString() {
445 StringBuilder builder = new StringBuilder().append("AccessPoint(")
446 .append(ssid);
Sundeep Ghuman2b489902017-02-22 18:17:29 -0800447 if (bssid != null) {
448 builder.append(":").append(bssid);
449 }
Jason Monkd52356a2015-01-28 10:40:41 -0500450 if (isSaved()) {
451 builder.append(',').append("saved");
452 }
453 if (isActive()) {
454 builder.append(',').append("active");
455 }
456 if (isEphemeral()) {
457 builder.append(',').append("ephemeral");
458 }
459 if (isConnectable()) {
460 builder.append(',').append("connectable");
461 }
Hai Shalomaa6f9202018-10-16 14:30:02 -0700462 if ((security != SECURITY_NONE) && (security != SECURITY_OWE)) {
Jason Monkd52356a2015-01-28 10:40:41 -0500463 builder.append(',').append(securityToString(security, pskType));
464 }
Sundeep Ghuman2b489902017-02-22 18:17:29 -0800465 builder.append(",level=").append(getLevel());
Sundeep Ghuman53200ed2017-06-21 16:54:36 -0700466 if (mSpeed != Speed.NONE) {
Sundeep Ghuman55adc6b2017-06-05 16:46:59 -0700467 builder.append(",speed=").append(mSpeed);
Sundeep Ghuman8920e9c2017-04-27 16:16:41 -0700468 }
Stephen Chen21f68682017-04-04 13:23:31 -0700469 builder.append(",metered=").append(isMetered());
Sundeep Ghuman5519b7b2016-12-14 17:53:31 -0800470
Sundeep Ghumanc0cf8482018-01-26 18:23:34 -0800471 if (isVerboseLoggingEnabled()) {
Sundeep Ghumandb9b94c2017-09-06 11:46:21 -0700472 builder.append(",rssi=").append(mRssi);
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800473 builder.append(",scan cache size=").append(mScanResults.size());
Sundeep Ghumandb9b94c2017-09-06 11:46:21 -0700474 }
475
Jason Monkd52356a2015-01-28 10:40:41 -0500476 return builder.append(')').toString();
477 }
478
Sundeep Ghuman5519b7b2016-12-14 17:53:31 -0800479 /**
Sundeep Ghuman55adc6b2017-06-05 16:46:59 -0700480 * Updates the AccessPoint rankingScore, metering, and speed, returning true if the data has
Stephen Chen21f68682017-04-04 13:23:31 -0700481 * changed.
482 *
Sundeep Ghuman9bb85d32017-08-28 17:04:16 -0700483 * @param scoreCache The score cache to use to retrieve scores
484 * @param scoringUiEnabled Whether to show scoring and badging UI
485 * @param maxScoreCacheAgeMillis the maximum age in milliseconds of scores to consider when
486 * generating speed labels
Stephen Chen21f68682017-04-04 13:23:31 -0700487 */
Sundeep Ghuman9bb85d32017-08-28 17:04:16 -0700488 boolean update(
489 WifiNetworkScoreCache scoreCache,
490 boolean scoringUiEnabled,
491 long maxScoreCacheAgeMillis) {
Stephen Chen21f68682017-04-04 13:23:31 -0700492 boolean scoreChanged = false;
493 if (scoringUiEnabled) {
Sundeep Ghuman9bb85d32017-08-28 17:04:16 -0700494 scoreChanged = updateScores(scoreCache, maxScoreCacheAgeMillis);
Stephen Chen21f68682017-04-04 13:23:31 -0700495 }
496 return updateMetered(scoreCache) || scoreChanged;
497 }
498
499 /**
Sundeep Ghuman55adc6b2017-06-05 16:46:59 -0700500 * Updates the AccessPoint rankingScore and speed, returning true if the data has changed.
Sundeep Ghuman5519b7b2016-12-14 17:53:31 -0800501 *
Sundeep Ghuman9bb85d32017-08-28 17:04:16 -0700502 * <p>Any cached {@link TimestampedScoredNetwork} objects older than the given max age in millis
503 * will be removed when this method is invoked.
Sundeep Ghumanfedf4612017-08-15 15:47:18 -0700504 *
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -0700505 * <p>Precondition: {@link #mRssi} is up to date before invoking this method.
506 *
Sundeep Ghuman9bb85d32017-08-28 17:04:16 -0700507 * @param scoreCache The score cache to use to retrieve scores
508 * @param maxScoreCacheAgeMillis the maximum age in milliseconds of scores to consider when
509 * generating speed labels
510 *
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -0700511 * @return true if the set speed has changed
Sundeep Ghuman5519b7b2016-12-14 17:53:31 -0800512 */
Sundeep Ghuman9bb85d32017-08-28 17:04:16 -0700513 private boolean updateScores(WifiNetworkScoreCache scoreCache, long maxScoreCacheAgeMillis) {
Sundeep Ghumanfedf4612017-08-15 15:47:18 -0700514 long nowMillis = SystemClock.elapsedRealtime();
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800515 for (ScanResult result : mScanResults) {
Eric Schwarzenbach0b8700f2017-07-25 14:32:21 -0700516 ScoredNetwork score = scoreCache.getScoredNetwork(result);
517 if (score == null) {
518 continue;
519 }
Sundeep Ghumanfedf4612017-08-15 15:47:18 -0700520 TimestampedScoredNetwork timedScore = mScoredNetworkCache.get(result.BSSID);
521 if (timedScore == null) {
522 mScoredNetworkCache.put(
523 result.BSSID, new TimestampedScoredNetwork(score, nowMillis));
524 } else {
525 // Update data since the has been seen in the score cache
526 timedScore.update(score, nowMillis);
527 }
Eric Schwarzenbach0b8700f2017-07-25 14:32:21 -0700528 }
529
Sundeep Ghumanfedf4612017-08-15 15:47:18 -0700530 // Remove old cached networks
Sundeep Ghuman9bb85d32017-08-28 17:04:16 -0700531 long evictionCutoff = nowMillis - maxScoreCacheAgeMillis;
Sundeep Ghumanfedf4612017-08-15 15:47:18 -0700532 Iterator<TimestampedScoredNetwork> iterator = mScoredNetworkCache.values().iterator();
533 iterator.forEachRemaining(timestampedScoredNetwork -> {
534 if (timestampedScoredNetwork.getUpdatedTimestampMillis() < evictionCutoff) {
535 iterator.remove();
536 }
537 });
538
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -0700539 return updateSpeed();
540 }
541
542 /**
543 * Updates the internal speed, returning true if the update resulted in a speed label change.
544 */
545 private boolean updateSpeed() {
546 int oldSpeed = mSpeed;
547 mSpeed = generateAverageSpeedForSsid();
548
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -0700549 boolean changed = oldSpeed != mSpeed;
Sundeep Ghumanc0cf8482018-01-26 18:23:34 -0800550 if(isVerboseLoggingEnabled() && changed) {
Sundeep Ghumana28050a2017-07-12 22:09:25 -0700551 Log.i(TAG, String.format("%s: Set speed to %d", ssid, mSpeed));
Sundeep Ghuman5519b7b2016-12-14 17:53:31 -0800552 }
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -0700553 return changed;
554 }
Sundeep Ghuman5519b7b2016-12-14 17:53:31 -0800555
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -0700556 /** Creates a speed value for the current {@link #mRssi} by averaging all non zero badges. */
557 @Speed private int generateAverageSpeedForSsid() {
558 if (mScoredNetworkCache.isEmpty()) {
559 return Speed.NONE;
560 }
561
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -0700562 if (Log.isLoggable(TAG, Log.DEBUG)) {
563 Log.d(TAG, String.format("Generating fallbackspeed for %s using cache: %s",
564 getSsidStr(), mScoredNetworkCache));
565 }
566
Sundeep Ghumana7825692017-08-23 15:53:00 -0700567 // TODO(b/63073866): If flickering issues persist, consider mapping using getLevel rather
568 // than specific rssi value so score doesn't change without a visible wifi bar change. This
569 // issue is likely to be more evident for the active AP whose RSSI value is not half-lifed.
570
Sundeep Ghumanfedf4612017-08-15 15:47:18 -0700571 int count = 0;
572 int totalSpeed = 0;
573 for (TimestampedScoredNetwork timedScore : mScoredNetworkCache.values()) {
574 int speed = timedScore.getScore().calculateBadge(mRssi);
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -0700575 if (speed != Speed.NONE) {
576 count++;
577 totalSpeed += speed;
578 }
579 }
580 int speed = count == 0 ? Speed.NONE : totalSpeed / count;
Sundeep Ghumanc0cf8482018-01-26 18:23:34 -0800581 if (isVerboseLoggingEnabled()) {
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -0700582 Log.i(TAG, String.format("%s generated fallback speed is: %d", getSsidStr(), speed));
583 }
584 return roundToClosestSpeedEnum(speed);
Sundeep Ghuman5519b7b2016-12-14 17:53:31 -0800585 }
586
Stephen Chen21f68682017-04-04 13:23:31 -0700587 /**
588 * Updates the AccessPoint's metering based on {@link ScoredNetwork#meteredHint}, returning
589 * true if the metering changed.
590 */
591 private boolean updateMetered(WifiNetworkScoreCache scoreCache) {
592 boolean oldMetering = mIsScoredNetworkMetered;
593 mIsScoredNetworkMetered = false;
Sundeep Ghumana28050a2017-07-12 22:09:25 -0700594
595 if (isActive() && mInfo != null) {
Eric Schwarzenbach733ea262017-08-08 10:28:21 -0700596 NetworkKey key = NetworkKey.createFromWifiInfo(mInfo);
Sundeep Ghumana28050a2017-07-12 22:09:25 -0700597 ScoredNetwork score = scoreCache.getScoredNetwork(key);
598 if (score != null) {
599 mIsScoredNetworkMetered |= score.meteredHint;
Stephen Chen21f68682017-04-04 13:23:31 -0700600 }
Sundeep Ghumana28050a2017-07-12 22:09:25 -0700601 } else {
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800602 for (ScanResult result : mScanResults) {
Sundeep Ghumana28050a2017-07-12 22:09:25 -0700603 ScoredNetwork score = scoreCache.getScoredNetwork(result);
604 if (score == null) {
605 continue;
606 }
607 mIsScoredNetworkMetered |= score.meteredHint;
608 }
Stephen Chen21f68682017-04-04 13:23:31 -0700609 }
610 return oldMetering == mIsScoredNetworkMetered;
611 }
612
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800613 public static String getKey(ScanResult result) {
Quang Luongac1026e2019-01-02 17:37:01 -0800614 return getKey(result.SSID, result.BSSID, getSecurity(result));
Mitchell Wills18af4932016-08-10 13:49:21 -0700615 }
616
Quang Luongac1026e2019-01-02 17:37:01 -0800617 /**
618 * Returns the AccessPoint key for a WifiConfiguration.
619 * This will return a special Passpoint key if the config is for Passpoint.
620 */
Sundeep Ghuman0d492e82018-01-26 12:45:02 -0800621 public static String getKey(WifiConfiguration config) {
Quang Luong7054e922018-12-07 16:44:18 -0800622 if (config.isPasspoint()) {
Quang Luongac1026e2019-01-02 17:37:01 -0800623 return new StringBuilder()
624 .append(KEY_PREFIX_FQDN)
625 .append(config.FQDN).toString();
Sundeep Ghuman0d492e82018-01-26 12:45:02 -0800626 } else {
Quang Luongac1026e2019-01-02 17:37:01 -0800627 return getKey(config.SSID, config.BSSID, getSecurity(config));
Sundeep Ghuman0d492e82018-01-26 12:45:02 -0800628 }
Quang Luongac1026e2019-01-02 17:37:01 -0800629 }
Sundeep Ghuman0d492e82018-01-26 12:45:02 -0800630
Quang Luongac1026e2019-01-02 17:37:01 -0800631 /**
632 * Returns the AccessPoint key corresponding to the OsuProvider.
633 */
634 public static String getKey(OsuProvider provider) {
635 return new StringBuilder()
636 .append(KEY_PREFIX_OSU)
637 .append(provider.getOsuSsid())
638 .append(',')
639 .append(provider.getServerUri()).toString();
640 }
641
642 /**
643 * Returns the AccessPoint key for a normal non-Passpoint network by ssid/bssid and security.
644 */
645 private static String getKey(String ssid, String bssid, int security) {
646 StringBuilder builder = new StringBuilder();
647 builder.append(KEY_PREFIX_AP);
648 if (TextUtils.isEmpty(ssid)) {
649 builder.append(bssid);
650 } else {
651 builder.append(ssid);
652 }
653 builder.append(',').append(security);
Sundeep Ghuman0d492e82018-01-26 12:45:02 -0800654 return builder.toString();
655 }
656
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800657 public String getKey() {
658 return mKey;
Jason Monkd52356a2015-01-28 10:40:41 -0500659 }
660
661 public boolean matches(WifiConfiguration config) {
Quang Luong7054e922018-12-07 16:44:18 -0800662 if (config.isPasspoint()) {
663 return (isPasspoint() && config.FQDN.equals(mConfig.FQDN));
Bartosz Fabianowski6fb07562016-01-12 15:43:19 +0100664 } else {
Quang Luong7054e922018-12-07 16:44:18 -0800665 // Normal non-Passpoint network
Bartosz Fabianowski6fb07562016-01-12 15:43:19 +0100666 return ssid.equals(removeDoubleQuotes(config.SSID))
667 && security == getSecurity(config)
668 && (mConfig == null || mConfig.shared == config.shared);
669 }
Jason Monkd52356a2015-01-28 10:40:41 -0500670 }
671
672 public WifiConfiguration getConfig() {
673 return mConfig;
674 }
675
Peter Qiuced37db2017-03-14 15:51:22 -0700676 public String getPasspointFqdn() {
677 return mFqdn;
678 }
679
Jason Monkd52356a2015-01-28 10:40:41 -0500680 public void clearConfig() {
681 mConfig = null;
682 networkId = WifiConfiguration.INVALID_NETWORK_ID;
683 }
684
685 public WifiInfo getInfo() {
686 return mInfo;
687 }
688
Sundeep Ghumanaaa8a1b2017-03-13 14:40:56 -0700689 /**
690 * Returns the number of levels to show for a Wifi icon, from 0 to {@link #SIGNAL_LEVELS}-1.
691 *
692 * <p>Use {@#isReachable()} to determine if an AccessPoint is in range, as this method will
693 * always return at least 0.
694 */
Jason Monkd52356a2015-01-28 10:40:41 -0500695 public int getLevel() {
Tony Mantlera0e03dd2016-01-27 15:57:03 -0800696 return WifiManager.calculateSignalLevel(mRssi, SIGNAL_LEVELS);
Jason Monkd52356a2015-01-28 10:40:41 -0500697 }
698
Vinit Deshpandefcd46122015-06-11 18:22:23 -0700699 public int getRssi() {
Sundeep Ghuman54bdcfa2017-03-08 19:52:05 -0800700 return mRssi;
701 }
702
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800703 /**
704 * Returns the underlying scan result set.
705 *
706 * <p>Callers should not modify this set.
707 */
708 public Set<ScanResult> getScanResults() { return mScanResults; }
jackqdyulei9ee9b392017-12-22 11:31:49 -0800709
710 public Map<String, TimestampedScoredNetwork> getScoredNetworkCache() {
711 return mScoredNetworkCache;
712 }
713
Sundeep Ghuman54bdcfa2017-03-08 19:52:05 -0800714 /**
715 * Updates {@link #mRssi}.
716 *
717 * <p>If the given connection is active, the existing value of {@link #mRssi} will be returned.
718 * If the given AccessPoint is not active, a value will be calculated from previous scan
Sundeep Ghumance78a5f2017-03-15 19:06:14 -0700719 * results, returning the best RSSI for all matching AccessPoints averaged with the previous
720 * value. If the access point is not connected and there are no scan results, the rssi will be
721 * set to {@link #UNREACHABLE_RSSI}.
Sundeep Ghuman54bdcfa2017-03-08 19:52:05 -0800722 */
723 private void updateRssi() {
Sundeep Ghuman54bdcfa2017-03-08 19:52:05 -0800724 if (this.isActive()) {
725 return;
726 }
727
728 int rssi = UNREACHABLE_RSSI;
Sundeep Ghuman04f7f342018-01-23 19:18:31 -0800729 for (ScanResult result : mScanResults) {
Vinit Deshpandefcd46122015-06-11 18:22:23 -0700730 if (result.level > rssi) {
731 rssi = result.level;
732 }
733 }
734
Sundeep Ghumance78a5f2017-03-15 19:06:14 -0700735 if (rssi != UNREACHABLE_RSSI && mRssi != UNREACHABLE_RSSI) {
736 mRssi = (mRssi + rssi) / 2; // half-life previous value
737 } else {
738 mRssi = rssi;
739 }
Vinit Deshpandefcd46122015-06-11 18:22:23 -0700740 }
741
Stephen Chen21f68682017-04-04 13:23:31 -0700742 /**
Jeff Sharkey43d2a172017-07-12 10:50:42 -0600743 * Returns if the network should be considered metered.
Stephen Chen21f68682017-04-04 13:23:31 -0700744 */
745 public boolean isMetered() {
746 return mIsScoredNetworkMetered
Jeff Sharkey43d2a172017-07-12 10:50:42 -0600747 || WifiConfiguration.isMetered(mConfig, mInfo);
Stephen Chen21f68682017-04-04 13:23:31 -0700748 }
749
Jason Monkd52356a2015-01-28 10:40:41 -0500750 public NetworkInfo getNetworkInfo() {
751 return mNetworkInfo;
752 }
753
754 public int getSecurity() {
755 return security;
756 }
757
758 public String getSecurityString(boolean concise) {
759 Context context = mContext;
Tomoharu Hatano2bde6e72017-05-30 18:38:56 +0900760 if (isPasspoint() || isPasspointConfig()) {
Sanket Padawe194cce62015-07-10 10:53:31 -0700761 return concise ? context.getString(R.string.wifi_security_short_eap) :
762 context.getString(R.string.wifi_security_eap);
Sanket Padawed1878802015-05-12 10:27:19 -0700763 }
Jason Monkd52356a2015-01-28 10:40:41 -0500764 switch(security) {
765 case SECURITY_EAP:
766 return concise ? context.getString(R.string.wifi_security_short_eap) :
767 context.getString(R.string.wifi_security_eap);
Hai Shalomaa6f9202018-10-16 14:30:02 -0700768 case SECURITY_EAP_SUITE_B:
769 return concise ? context.getString(R.string.wifi_security_short_eap_suiteb) :
770 context.getString(R.string.wifi_security_eap_suiteb);
Jason Monkd52356a2015-01-28 10:40:41 -0500771 case SECURITY_PSK:
772 switch (pskType) {
773 case PSK_WPA:
774 return concise ? context.getString(R.string.wifi_security_short_wpa) :
775 context.getString(R.string.wifi_security_wpa);
776 case PSK_WPA2:
777 return concise ? context.getString(R.string.wifi_security_short_wpa2) :
778 context.getString(R.string.wifi_security_wpa2);
779 case PSK_WPA_WPA2:
780 return concise ? context.getString(R.string.wifi_security_short_wpa_wpa2) :
781 context.getString(R.string.wifi_security_wpa_wpa2);
782 case PSK_UNKNOWN:
783 default:
784 return concise ? context.getString(R.string.wifi_security_short_psk_generic)
785 : context.getString(R.string.wifi_security_psk_generic);
786 }
787 case SECURITY_WEP:
788 return concise ? context.getString(R.string.wifi_security_short_wep) :
789 context.getString(R.string.wifi_security_wep);
Hai Shalomaa6f9202018-10-16 14:30:02 -0700790 case SECURITY_SAE:
791 return concise ? context.getString(R.string.wifi_security_short_sae) :
792 context.getString(R.string.wifi_security_sae);
793 case SECURITY_OWE:
794 return concise ? context.getString(R.string.wifi_security_short_owe) :
795 context.getString(R.string.wifi_security_owe);
Jason Monkd52356a2015-01-28 10:40:41 -0500796 case SECURITY_NONE:
797 default:
798 return concise ? "" : context.getString(R.string.wifi_security_none);
799 }
800 }
801
Jason Monk6980d122015-06-15 10:07:55 -0400802 public String getSsidStr() {
Jason Monkd52356a2015-01-28 10:40:41 -0500803 return ssid;
804 }
805
Jason Monk60a82ff2016-02-25 13:55:03 -0500806 public String getBssid() {
807 return bssid;
808 }
809
Jason Monk6980d122015-06-15 10:07:55 -0400810 public CharSequence getSsid() {
pastychanga2998fc2018-06-26 13:37:34 +0800811 return ssid;
Jason Monk6980d122015-06-15 10:07:55 -0400812 }
813
Vinit Deshpandedcf00c92015-04-15 18:32:09 -0700814 public String getConfigName() {
815 if (mConfig != null && mConfig.isPasspoint()) {
816 return mConfig.providerFriendlyName;
Peter Qiuced37db2017-03-14 15:51:22 -0700817 } else if (mFqdn != null) {
818 return mProviderFriendlyName;
Vinit Deshpandedcf00c92015-04-15 18:32:09 -0700819 } else {
820 return ssid;
821 }
822 }
823
Jason Monkd52356a2015-01-28 10:40:41 -0500824 public DetailedState getDetailedState() {
Fan Zhang6acb7662016-10-17 12:40:03 -0700825 if (mNetworkInfo != null) {
826 return mNetworkInfo.getDetailedState();
827 }
828 Log.w(TAG, "NetworkInfo is null, cannot return detailed state");
829 return null;
Jason Monkd52356a2015-01-28 10:40:41 -0500830 }
831
Peter Qiu280581b2017-07-24 14:18:56 -0700832 public boolean isCarrierAp() {
833 return mIsCarrierAp;
834 }
835
836 public int getCarrierApEapType() {
837 return mCarrierApEapType;
838 }
839
840 public String getCarrierName() {
841 return mCarrierName;
842 }
843
Vinit Deshpandedcf00c92015-04-15 18:32:09 -0700844 public String getSavedNetworkSummary() {
Fan Zhang51365c32016-09-20 12:22:18 -0700845 WifiConfiguration config = mConfig;
846 if (config != null) {
Sanket Padawe56cfbfb2015-05-05 20:10:46 -0700847 PackageManager pm = mContext.getPackageManager();
848 String systemName = pm.getNameForUid(android.os.Process.SYSTEM_UID);
Fan Zhang51365c32016-09-20 12:22:18 -0700849 int userId = UserHandle.getUserId(config.creatorUid);
Sanket Padawe56cfbfb2015-05-05 20:10:46 -0700850 ApplicationInfo appInfo = null;
Fan Zhang51365c32016-09-20 12:22:18 -0700851 if (config.creatorName != null && config.creatorName.equals(systemName)) {
Sanket Padawe56cfbfb2015-05-05 20:10:46 -0700852 appInfo = mContext.getApplicationInfo();
853 } else {
854 try {
855 IPackageManager ipm = AppGlobals.getPackageManager();
Fan Zhang51365c32016-09-20 12:22:18 -0700856 appInfo = ipm.getApplicationInfo(config.creatorName, 0 /* flags */, userId);
Sanket Padawe56cfbfb2015-05-05 20:10:46 -0700857 } catch (RemoteException rex) {
858 }
859 }
860 if (appInfo != null &&
861 !appInfo.packageName.equals(mContext.getString(R.string.settings_package)) &&
862 !appInfo.packageName.equals(
863 mContext.getString(R.string.certinstaller_package))) {
864 return mContext.getString(R.string.saved_network, appInfo.loadLabel(pm));
865 }
Vinit Deshpandedcf00c92015-04-15 18:32:09 -0700866 }
Sanket Padawe56cfbfb2015-05-05 20:10:46 -0700867 return "";
Vinit Deshpandedcf00c92015-04-15 18:32:09 -0700868 }
869
Quang Luong7054e922018-12-07 16:44:18 -0800870 /**
871 * Returns the display title for the AccessPoint, such as for an AccessPointPreference's title.
872 */
873 public String getTitle() {
874 if (isPasspoint()) {
875 return mConfig.providerFriendlyName;
Quang Luong9051dfd2018-12-12 12:49:24 -0800876 } else if (isOsuProvider()) {
877 return mOsuProvider.getFriendlyName();
Quang Luong7054e922018-12-07 16:44:18 -0800878 } else {
879 return getSsidStr();
880 }
881 }
882
Jason Monkd52356a2015-01-28 10:40:41 -0500883 public String getSummary() {
Quang Luong19bae88c2018-12-14 16:05:05 -0800884 return getSettingsSummary();
Vinit Deshpandedcf00c92015-04-15 18:32:09 -0700885 }
886
887 public String getSettingsSummary() {
Jason Monkd52356a2015-01-28 10:40:41 -0500888 // Update to new summary
889 StringBuilder summary = new StringBuilder();
890
Quang Luong19bae88c2018-12-14 16:05:05 -0800891 if (isActive()) {
892 if (isPasspoint()) {
893 // This is the active connection on passpoint
Quang Luong0a3edf02018-12-17 14:50:58 -0800894 summary.append(getSummary(mContext, ssid, getDetailedState(),
Quang Luong19bae88c2018-12-14 16:05:05 -0800895 false, mConfig.providerFriendlyName));
896 } else if (mConfig != null && getDetailedState() == DetailedState.CONNECTED
897 && mIsCarrierAp) {
898 // This is the active connection on a carrier AP
899 summary.append(String.format(mContext.getString(R.string.connected_via_carrier),
900 mCarrierName));
901 } else {
902 // This is the active connection on non-passpoint network
903 summary.append(getSummary(mContext, getDetailedState(),
904 mInfo != null && mInfo.isEphemeral()));
Jason Monkd52356a2015-01-28 10:40:41 -0500905 }
Quang Luong19bae88c2018-12-14 16:05:05 -0800906 } else { // not active
907 if (mConfig != null && mConfig.hasNoInternetAccess()) {
908 int messageID = mConfig.getNetworkSelectionStatus().isNetworkPermanentlyDisabled()
909 ? R.string.wifi_no_internet_no_reconnect
910 : R.string.wifi_no_internet;
911 summary.append(mContext.getString(messageID));
912 } else if (mConfig != null && !mConfig.getNetworkSelectionStatus().isNetworkEnabled()) {
913 WifiConfiguration.NetworkSelectionStatus networkStatus =
914 mConfig.getNetworkSelectionStatus();
915 switch (networkStatus.getNetworkSelectionDisableReason()) {
916 case WifiConfiguration.NetworkSelectionStatus.DISABLED_AUTHENTICATION_FAILURE:
917 summary.append(mContext.getString(R.string.wifi_disabled_password_failure));
Glen Kuhne446afac2017-06-22 16:02:33 -0700918 break;
Quang Luong19bae88c2018-12-14 16:05:05 -0800919 case WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD:
920 summary.append(mContext.getString(R.string.wifi_check_password_try_again));
Glen Kuhne446afac2017-06-22 16:02:33 -0700921 break;
Quang Luong19bae88c2018-12-14 16:05:05 -0800922 case WifiConfiguration.NetworkSelectionStatus.DISABLED_DHCP_FAILURE:
923 case WifiConfiguration.NetworkSelectionStatus.DISABLED_DNS_FAILURE:
924 summary.append(mContext.getString(R.string.wifi_disabled_network_failure));
925 break;
926 case WifiConfiguration.NetworkSelectionStatus.DISABLED_ASSOCIATION_REJECTION:
927 summary.append(mContext.getString(R.string.wifi_disabled_generic));
928 break;
929 }
930 } else if (mConfig != null && mConfig.getNetworkSelectionStatus().isNotRecommended()) {
931 summary.append(mContext.getString(
932 R.string.wifi_disabled_by_recommendation_provider));
933 } else if (mIsCarrierAp) {
934 summary.append(String.format(mContext.getString(
935 R.string.available_via_carrier), mCarrierName));
Quang Luong02d81742018-12-17 16:09:45 -0800936 } else if (isOsuProvider()) {
Quang Luong8d40a8e2019-01-02 16:25:38 -0800937 if (mOsuProvisioningComplete) {
938 summary.append(mContext.getString(R.string.osu_provisioning_complete));
939 } else if (mOsuFailure != null) {
940 summary.append(mOsuFailure);
941 } else if (mOsuStatus != null) {
942 summary.append(mOsuStatus);
943 } else {
944 summary.append(mContext.getString(R.string.tap_to_set_up));
945 }
Quang Luong19bae88c2018-12-14 16:05:05 -0800946 } else if (!isReachable()) { // Wifi out of range
947 summary.append(mContext.getString(R.string.wifi_not_in_range));
948 } else { // In range, not disabled.
949 if (mConfig != null) { // Is saved network
950 // Last attempt to connect to this failed. Show reason why
951 switch (mConfig.recentFailure.getAssociationStatus()) {
952 case WifiConfiguration.RecentFailure.STATUS_AP_UNABLE_TO_HANDLE_NEW_STA:
953 summary.append(mContext.getString(
954 R.string.wifi_ap_unable_to_handle_new_sta));
955 break;
956 default:
957 // "Saved"
958 summary.append(mContext.getString(R.string.wifi_remembered));
959 break;
960 }
Glen Kuhne446afac2017-06-22 16:02:33 -0700961 }
Jason Monkd52356a2015-01-28 10:40:41 -0500962 }
963 }
964
Quang Luong19bae88c2018-12-14 16:05:05 -0800965
966
Sundeep Ghumanc0cf8482018-01-26 18:23:34 -0800967 if (isVerboseLoggingEnabled()) {
Quang Luong19bae88c2018-12-14 16:05:05 -0800968 summary.append(WifiUtils.buildLoggingSummary(this, mConfig));
Jason Monkd52356a2015-01-28 10:40:41 -0500969 }
Sundeep Ghuman271e5de2017-05-30 14:11:39 -0700970
Quang Luong19bae88c2018-12-14 16:05:05 -0800971 if (mConfig != null && (WifiUtils.isMeteredOverridden(mConfig) || mConfig.meteredHint)) {
Salvador Martinez6f6fe752018-03-21 16:33:53 -0700972 return mContext.getResources().getString(
973 R.string.preference_summary_default_combination,
Quang Luong19bae88c2018-12-14 16:05:05 -0800974 WifiUtils.getMeteredLabel(mContext, mConfig),
Salvador Martinez6f6fe752018-03-21 16:33:53 -0700975 summary.toString());
976 }
977
Eric Schwarzenbachf4f3842b2017-07-17 16:45:04 -0700978 // If Speed label and summary are both present, use the preference combination to combine
979 // the two, else return the non-null one.
980 if (getSpeedLabel() != null && summary.length() != 0) {
Sundeep Ghumand3171ca2017-07-12 23:02:24 -0700981 return mContext.getResources().getString(
982 R.string.preference_summary_default_combination,
983 getSpeedLabel(),
984 summary.toString());
Eric Schwarzenbachf4f3842b2017-07-17 16:45:04 -0700985 } else if (getSpeedLabel() != null) {
986 return getSpeedLabel();
Sundeep Ghumand3171ca2017-07-12 23:02:24 -0700987 } else {
988 return summary.toString();
Sundeep Ghuman271e5de2017-05-30 14:11:39 -0700989 }
Jason Monkd52356a2015-01-28 10:40:41 -0500990 }
991
992 /**
Jason Monkd52356a2015-01-28 10:40:41 -0500993 * Return whether this is the active connection.
994 * For ephemeral connections (networkId is invalid), this returns false if the network is
995 * disconnected.
996 */
997 public boolean isActive() {
998 return mNetworkInfo != null &&
999 (networkId != WifiConfiguration.INVALID_NETWORK_ID ||
1000 mNetworkInfo.getState() != State.DISCONNECTED);
1001 }
1002
1003 public boolean isConnectable() {
1004 return getLevel() != -1 && getDetailedState() == null;
1005 }
1006
1007 public boolean isEphemeral() {
Shirish Kalelec7a38ef2015-06-25 13:55:33 -07001008 return mInfo != null && mInfo.isEphemeral() &&
1009 mNetworkInfo != null && mNetworkInfo.getState() != State.DISCONNECTED;
Jason Monkd52356a2015-01-28 10:40:41 -05001010 }
1011
Peter Qiuced37db2017-03-14 15:51:22 -07001012 /**
1013 * Return true if this AccessPoint represents a Passpoint AP.
1014 */
Vinit Deshpande5b7352c2015-07-09 16:53:12 -07001015 public boolean isPasspoint() {
1016 return mConfig != null && mConfig.isPasspoint();
1017 }
1018
Mitchell Wills5a42db22015-08-03 09:46:08 -07001019 /**
Peter Qiuced37db2017-03-14 15:51:22 -07001020 * Return true if this AccessPoint represents a Passpoint provider configuration.
1021 */
1022 public boolean isPasspointConfig() {
1023 return mFqdn != null;
1024 }
1025
1026 /**
Quang Luong9051dfd2018-12-12 12:49:24 -08001027 * Return true if this AccessPoint represents an OSU Provider.
1028 */
1029 public boolean isOsuProvider() {
1030 return mOsuProvider != null;
1031 }
1032
1033 /**
Quang Luong4d194842018-12-18 16:59:49 -08001034 * Starts the OSU Provisioning flow.
1035 */
1036 public void startOsuProvisioning() {
1037 mContext.getSystemService(WifiManager.class).startSubscriptionProvisioning(
1038 mOsuProvider,
1039 new AccessPointProvisioningCallback(),
1040 ThreadUtils.getUiThreadHandler()
1041 );
1042 }
1043
1044 /**
Mitchell Wills5a42db22015-08-03 09:46:08 -07001045 * Return whether the given {@link WifiInfo} is for this access point.
1046 * If the current AP does not have a network Id then the config is used to
1047 * match based on SSID and security.
1048 */
1049 private boolean isInfoForThisAccessPoint(WifiConfiguration config, WifiInfo info) {
Vinit Deshpande5b7352c2015-07-09 16:53:12 -07001050 if (isPasspoint() == false && networkId != WifiConfiguration.INVALID_NETWORK_ID) {
Jason Monkd52356a2015-01-28 10:40:41 -05001051 return networkId == info.getNetworkId();
Mitchell Wills5a42db22015-08-03 09:46:08 -07001052 } else if (config != null) {
1053 return matches(config);
1054 }
1055 else {
Jason Monkd52356a2015-01-28 10:40:41 -05001056 // Might be an ephemeral connection with no WifiConfiguration. Try matching on SSID.
1057 // (Note that we only do this if the WifiConfiguration explicitly equals INVALID).
1058 // TODO: Handle hex string SSIDs.
1059 return ssid.equals(removeDoubleQuotes(info.getSSID()));
1060 }
1061 }
1062
1063 public boolean isSaved() {
1064 return networkId != WifiConfiguration.INVALID_NETWORK_ID;
1065 }
1066
1067 public Object getTag() {
1068 return mTag;
1069 }
1070
1071 public void setTag(Object tag) {
1072 mTag = tag;
1073 }
1074
1075 /**
1076 * Generate and save a default wifiConfiguration with common values.
1077 * Can only be called for unsecured networks.
1078 */
1079 public void generateOpenNetworkConfig() {
Hai Shalomaa6f9202018-10-16 14:30:02 -07001080 if ((security != SECURITY_NONE) && (security != SECURITY_OWE)) {
Jason Monkd52356a2015-01-28 10:40:41 -05001081 throw new IllegalStateException();
Hai Shalomaa6f9202018-10-16 14:30:02 -07001082 }
Jason Monkd52356a2015-01-28 10:40:41 -05001083 if (mConfig != null)
1084 return;
1085 mConfig = new WifiConfiguration();
1086 mConfig.SSID = AccessPoint.convertToQuotedString(ssid);
Hai Shalomaa6f9202018-10-16 14:30:02 -07001087
1088 if (security == SECURITY_NONE) {
1089 mConfig.allowedKeyManagement.set(KeyMgmt.NONE);
1090 } else {
1091 mConfig.allowedKeyManagement.set(KeyMgmt.OWE);
1092 mConfig.requirePMF = true;
1093 }
Jason Monkd52356a2015-01-28 10:40:41 -05001094 }
1095
Jason Monkd52356a2015-01-28 10:40:41 -05001096 public void saveWifiState(Bundle savedState) {
Vinit Deshpandefcd46122015-06-11 18:22:23 -07001097 if (ssid != null) savedState.putString(KEY_SSID, getSsidStr());
1098 savedState.putInt(KEY_SECURITY, security);
Sundeep Ghumana28050a2017-07-12 22:09:25 -07001099 savedState.putInt(KEY_SPEED, mSpeed);
Vinit Deshpandefcd46122015-06-11 18:22:23 -07001100 savedState.putInt(KEY_PSKTYPE, pskType);
1101 if (mConfig != null) savedState.putParcelable(KEY_CONFIG, mConfig);
Jason Monkd52356a2015-01-28 10:40:41 -05001102 savedState.putParcelable(KEY_WIFIINFO, mInfo);
Sundeep Ghuman04f7f342018-01-23 19:18:31 -08001103 savedState.putParcelableArray(KEY_SCANRESULTS,
1104 mScanResults.toArray(new Parcelable[mScanResults.size()]));
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -07001105 savedState.putParcelableArrayList(KEY_SCOREDNETWORKCACHE,
1106 new ArrayList<>(mScoredNetworkCache.values()));
Jason Monkd52356a2015-01-28 10:40:41 -05001107 if (mNetworkInfo != null) {
1108 savedState.putParcelable(KEY_NETWORKINFO, mNetworkInfo);
1109 }
Peter Qiuced37db2017-03-14 15:51:22 -07001110 if (mFqdn != null) {
1111 savedState.putString(KEY_FQDN, mFqdn);
1112 }
1113 if (mProviderFriendlyName != null) {
1114 savedState.putString(KEY_PROVIDER_FRIENDLY_NAME, mProviderFriendlyName);
1115 }
Peter Qiu280581b2017-07-24 14:18:56 -07001116 savedState.putBoolean(KEY_IS_CARRIER_AP, mIsCarrierAp);
1117 savedState.putInt(KEY_CARRIER_AP_EAP_TYPE, mCarrierApEapType);
1118 savedState.putString(KEY_CARRIER_NAME, mCarrierName);
Jason Monkd52356a2015-01-28 10:40:41 -05001119 }
1120
1121 public void setListener(AccessPointListener listener) {
1122 mAccessPointListener = listener;
1123 }
1124
Sundeep Ghumand1e44922017-08-07 11:21:38 -07001125 /**
Sundeep Ghuman04f7f342018-01-23 19:18:31 -08001126 * Sets {@link #mScanResults} to the given collection.
Sundeep Ghumand1e44922017-08-07 11:21:38 -07001127 *
Sundeep Ghuman04f7f342018-01-23 19:18:31 -08001128 * @param scanResults a collection of scan results to add to the internal set
1129 * @throws IllegalArgumentException if any of the given ScanResults did not belong to this AP
Sundeep Ghumand1e44922017-08-07 11:21:38 -07001130 */
Sundeep Ghuman04f7f342018-01-23 19:18:31 -08001131 void setScanResults(Collection<ScanResult> scanResults) {
Sundeep Ghuman54bdcfa2017-03-08 19:52:05 -08001132
Quang Luong7054e922018-12-07 16:44:18 -08001133 // Validate scan results are for current AP only by matching SSID/BSSID
Quang Luong9051dfd2018-12-12 12:49:24 -08001134 // Passpoint networks are not bound to a specific SSID/BSSID, so skip this for passpoint.
1135 if (!isPasspoint() && !isOsuProvider()) {
Quang Luong7054e922018-12-07 16:44:18 -08001136 String key = getKey();
1137 for (ScanResult result : scanResults) {
1138 String scanResultKey = AccessPoint.getKey(result);
1139 if (!mKey.equals(scanResultKey)) {
1140 throw new IllegalArgumentException(
1141 String.format(
1142 "ScanResult %s\nkey of %s did not match current AP key %s",
1143 result, scanResultKey, key));
1144 }
Jason Monkd52356a2015-01-28 10:40:41 -05001145 }
Sundeep Ghuman04f7f342018-01-23 19:18:31 -08001146 }
1147
Sundeep Ghuman04f7f342018-01-23 19:18:31 -08001148 int oldLevel = getLevel();
1149 mScanResults.clear();
1150 mScanResults.addAll(scanResults);
1151 updateRssi();
1152 int newLevel = getLevel();
1153
1154 // If newLevel is 0, there will be no displayed Preference since the AP is unreachable
1155 if (newLevel > 0 && newLevel != oldLevel) {
1156 // Only update labels on visible rssi changes
1157 updateSpeed();
Sundeep Ghuman5d14fd72018-02-15 14:49:15 -08001158 ThreadUtils.postOnMainThread(() -> {
1159 if (mAccessPointListener != null) {
1160 mAccessPointListener.onLevelChanged(this);
1161 }
1162 });
1163
Sundeep Ghuman04f7f342018-01-23 19:18:31 -08001164 }
1165
Sundeep Ghuman5d14fd72018-02-15 14:49:15 -08001166 ThreadUtils.postOnMainThread(() -> {
1167 if (mAccessPointListener != null) {
1168 mAccessPointListener.onAccessPointChanged(this);
1169 }
1170 });
Sundeep Ghuman04f7f342018-01-23 19:18:31 -08001171
1172 if (!scanResults.isEmpty()) {
1173 ScanResult result = scanResults.iterator().next();
1174
Jason Monkd52356a2015-01-28 10:40:41 -05001175 // This flag only comes from scans, is not easily saved in config
1176 if (security == SECURITY_PSK) {
1177 pskType = getPskType(result);
1178 }
Vinit Deshpandefcd46122015-06-11 18:22:23 -07001179
Peter Qiu280581b2017-07-24 14:18:56 -07001180 // The carrier info in the ScanResult is set by the platform based on the SSID and will
1181 // always be the same for all matching scan results.
1182 mIsCarrierAp = result.isCarrierAp;
1183 mCarrierApEapType = result.carrierApEapType;
1184 mCarrierName = result.carrierName;
Jason Monkd52356a2015-01-28 10:40:41 -05001185 }
Jason Monkd52356a2015-01-28 10:40:41 -05001186 }
1187
Quang Luong9051dfd2018-12-12 12:49:24 -08001188 /**
1189 * Attempt to update the AccessPoint with the current connection info.
1190 * This is used to set an AccessPoint to the active one if the connection info matches, or
1191 * conversely to set an AccessPoint to inactive if the connection info does not match. The RSSI
1192 * is also updated upon a match. Listeners will be notified if an update occurred.
1193 *
1194 * This is called in {@link WifiTracker#updateAccessPoints} as well as in callbacks for handling
1195 * NETWORK_STATE_CHANGED_ACTION, RSSI_CHANGED_ACTION, and onCapabilitiesChanged in WifiTracker.
1196 *
1197 * Returns true if an update occurred.
1198 */
Sundeep Ghumand911da32017-07-05 20:06:05 -07001199 public boolean update(
1200 @Nullable WifiConfiguration config, WifiInfo info, NetworkInfo networkInfo) {
Sundeep Ghumandb9b94c2017-09-06 11:46:21 -07001201
Sundeep Ghuman8c792882017-04-04 17:23:29 -07001202 boolean updated = false;
1203 final int oldLevel = getLevel();
Mitchell Wills5a42db22015-08-03 09:46:08 -07001204 if (info != null && isInfoForThisAccessPoint(config, info)) {
Sundeep Ghuman8c792882017-04-04 17:23:29 -07001205 updated = (mInfo == null);
Sundeep Ghumanf4d33022017-06-05 19:47:36 -07001206 if (mConfig != config) {
1207 // We do not set updated = true as we do not want to increase the amount of sorting
1208 // and copying performed in WifiTracker at this time. If issues involving refresh
1209 // are still seen, we will investigate further.
1210 update(config); // Notifies the AccessPointListener of the change
1211 }
Glen Kuhned38708c2017-07-19 14:53:34 -07001212 if (mRssi != info.getRssi() && info.getRssi() != WifiInfo.INVALID_RSSI) {
Sundeep Ghuman8c792882017-04-04 17:23:29 -07001213 mRssi = info.getRssi();
1214 updated = true;
Sundeep Ghuman5c5cd7a2017-05-03 12:45:44 -07001215 } else if (mNetworkInfo != null && networkInfo != null
1216 && mNetworkInfo.getDetailedState() != networkInfo.getDetailedState()) {
Sundeep Ghuman96a53572017-04-20 21:25:41 -07001217 updated = true;
Jason Monkd52356a2015-01-28 10:40:41 -05001218 }
Sundeep Ghuman8c792882017-04-04 17:23:29 -07001219 mInfo = info;
Sundeep Ghuman8c792882017-04-04 17:23:29 -07001220 mNetworkInfo = networkInfo;
Jason Monkd52356a2015-01-28 10:40:41 -05001221 } else if (mInfo != null) {
Sundeep Ghuman8c792882017-04-04 17:23:29 -07001222 updated = true;
Jason Monkd52356a2015-01-28 10:40:41 -05001223 mInfo = null;
1224 mNetworkInfo = null;
Sundeep Ghuman8c792882017-04-04 17:23:29 -07001225 }
1226 if (updated && mAccessPointListener != null) {
Sundeep Ghuman5d14fd72018-02-15 14:49:15 -08001227 ThreadUtils.postOnMainThread(() -> {
1228 if (mAccessPointListener != null) {
1229 mAccessPointListener.onAccessPointChanged(this);
1230 }
1231 });
Sundeep Ghuman8c792882017-04-04 17:23:29 -07001232
1233 if (oldLevel != getLevel() /* current level */) {
Sundeep Ghuman5d14fd72018-02-15 14:49:15 -08001234 ThreadUtils.postOnMainThread(() -> {
1235 if (mAccessPointListener != null) {
1236 mAccessPointListener.onLevelChanged(this);
1237 }
1238 });
Jason Monkd52356a2015-01-28 10:40:41 -05001239 }
1240 }
Sundeep Ghumandb9b94c2017-09-06 11:46:21 -07001241
Sundeep Ghuman8c792882017-04-04 17:23:29 -07001242 return updated;
Jason Monkd52356a2015-01-28 10:40:41 -05001243 }
1244
Sundeep Ghumand911da32017-07-05 20:06:05 -07001245 void update(@Nullable WifiConfiguration config) {
Vinit Deshpandefc406002015-04-15 18:10:55 -07001246 mConfig = config;
Quang Luong7054e922018-12-07 16:44:18 -08001247 if (mConfig != null) {
1248 ssid = removeDoubleQuotes(mConfig.SSID);
1249 }
Sundeep Ghumand911da32017-07-05 20:06:05 -07001250 networkId = config != null ? config.networkId : WifiConfiguration.INVALID_NETWORK_ID;
Sundeep Ghuman5d14fd72018-02-15 14:49:15 -08001251 ThreadUtils.postOnMainThread(() -> {
1252 if (mAccessPointListener != null) {
1253 mAccessPointListener.onAccessPointChanged(this);
1254 }
1255 });
Vinit Deshpandefc406002015-04-15 18:10:55 -07001256 }
Shirish Kalelec7a38ef2015-06-25 13:55:33 -07001257
Sundeep Ghuman54bdcfa2017-03-08 19:52:05 -08001258 @VisibleForTesting
Sanket Padawe0775a982015-08-19 14:57:46 -07001259 void setRssi(int rssi) {
1260 mRssi = rssi;
1261 }
1262
Sundeep Ghuman54bdcfa2017-03-08 19:52:05 -08001263 /** Sets the rssi to {@link #UNREACHABLE_RSSI}. */
1264 void setUnreachable() {
1265 setRssi(AccessPoint.UNREACHABLE_RSSI);
1266 }
1267
Sundeep Ghuman55adc6b2017-06-05 16:46:59 -07001268 int getSpeed() { return mSpeed;}
Sundeep Ghuman271e5de2017-05-30 14:11:39 -07001269
1270 @Nullable
1271 String getSpeedLabel() {
Eric Schwarzenbach0b8700f2017-07-25 14:32:21 -07001272 return getSpeedLabel(mSpeed);
1273 }
1274
1275 @Nullable
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -07001276 @Speed
Amin Shaikhe74dbdd2018-03-09 16:05:30 -05001277 private static int roundToClosestSpeedEnum(int speed) {
Sundeep Ghumanbe3a74c2017-08-01 17:50:59 -07001278 if (speed < Speed.SLOW) {
1279 return Speed.NONE;
1280 } else if (speed < (Speed.SLOW + Speed.MODERATE) / 2) {
1281 return Speed.SLOW;
1282 } else if (speed < (Speed.MODERATE + Speed.FAST) / 2) {
1283 return Speed.MODERATE;
1284 } else if (speed < (Speed.FAST + Speed.VERY_FAST) / 2) {
1285 return Speed.FAST;
1286 } else {
1287 return Speed.VERY_FAST;
1288 }
1289 }
1290
1291 @Nullable
jackqdyulei9ee9b392017-12-22 11:31:49 -08001292 String getSpeedLabel(@Speed int speed) {
Amin Shaikhe74dbdd2018-03-09 16:05:30 -05001293 return getSpeedLabel(mContext, speed);
1294 }
1295
1296 private static String getSpeedLabel(Context context, int speed) {
Eric Schwarzenbach0b8700f2017-07-25 14:32:21 -07001297 switch (speed) {
Sundeep Ghuman53200ed2017-06-21 16:54:36 -07001298 case Speed.VERY_FAST:
Amin Shaikhe74dbdd2018-03-09 16:05:30 -05001299 return context.getString(R.string.speed_label_very_fast);
Sundeep Ghuman53200ed2017-06-21 16:54:36 -07001300 case Speed.FAST:
Amin Shaikhe74dbdd2018-03-09 16:05:30 -05001301 return context.getString(R.string.speed_label_fast);
Sundeep Ghuman53200ed2017-06-21 16:54:36 -07001302 case Speed.MODERATE:
Amin Shaikhe74dbdd2018-03-09 16:05:30 -05001303 return context.getString(R.string.speed_label_okay);
Sundeep Ghuman53200ed2017-06-21 16:54:36 -07001304 case Speed.SLOW:
Amin Shaikhe74dbdd2018-03-09 16:05:30 -05001305 return context.getString(R.string.speed_label_slow);
Sundeep Ghuman53200ed2017-06-21 16:54:36 -07001306 case Speed.NONE:
Sundeep Ghuman271e5de2017-05-30 14:11:39 -07001307 default:
1308 return null;
1309 }
Sundeep Ghuman5519b7b2016-12-14 17:53:31 -08001310 }
1311
Amin Shaikhe74dbdd2018-03-09 16:05:30 -05001312 /** Return the speed label for a {@link ScoredNetwork} at the specified {@code rssi} level. */
1313 @Nullable
1314 public static String getSpeedLabel(Context context, ScoredNetwork scoredNetwork, int rssi) {
1315 return getSpeedLabel(context, roundToClosestSpeedEnum(scoredNetwork.calculateBadge(rssi)));
1316 }
1317
Dave Schaefer98537432017-02-08 11:26:08 -08001318 /** Return true if the current RSSI is reachable, and false otherwise. */
Sundeep Ghumanaaa8a1b2017-03-13 14:40:56 -07001319 public boolean isReachable() {
Dave Schaefer98537432017-02-08 11:26:08 -08001320 return mRssi != UNREACHABLE_RSSI;
1321 }
1322
Jason Monkd52356a2015-01-28 10:40:41 -05001323 public static String getSummary(Context context, String ssid, DetailedState state,
Vinit Deshpandefc406002015-04-15 18:10:55 -07001324 boolean isEphemeral, String passpointProvider) {
Quang Luong0a3edf02018-12-17 14:50:58 -08001325 if (state == DetailedState.CONNECTED) {
1326 if (!TextUtils.isEmpty(passpointProvider)) {
Vinit Deshpandedcf00c92015-04-15 18:32:09 -07001327 // Special case for connected + passpoint networks.
Quang Luong0a3edf02018-12-17 14:50:58 -08001328 String format = context.getString(R.string.ssid_by_passpoint_provider);
1329 return String.format(format, ssid, passpointProvider);
Vinit Deshpandedcf00c92015-04-15 18:32:09 -07001330 } else if (isEphemeral) {
Vinit Deshpandefc406002015-04-15 18:10:55 -07001331 // Special case for connected + ephemeral networks.
Stephen Chen36dd5cf12017-03-20 13:27:51 -07001332 final NetworkScoreManager networkScoreManager = context.getSystemService(
1333 NetworkScoreManager.class);
1334 NetworkScorerAppData scorer = networkScoreManager.getActiveScorer();
1335 if (scorer != null && scorer.getRecommendationServiceLabel() != null) {
1336 String format = context.getString(R.string.connected_via_network_scorer);
1337 return String.format(format, scorer.getRecommendationServiceLabel());
1338 } else {
1339 return context.getString(R.string.connected_via_network_scorer_default);
1340 }
Vinit Deshpandefc406002015-04-15 18:10:55 -07001341 }
Jason Monkd52356a2015-01-28 10:40:41 -05001342 }
1343
Sanket Padawe7094d222015-05-01 16:55:00 -07001344 // Case when there is wifi connected without internet connectivity.
1345 final ConnectivityManager cm = (ConnectivityManager)
1346 context.getSystemService(Context.CONNECTIVITY_SERVICE);
1347 if (state == DetailedState.CONNECTED) {
1348 IWifiManager wifiManager = IWifiManager.Stub.asInterface(
1349 ServiceManager.getService(Context.WIFI_SERVICE));
Lorenzo Colitti1317e042016-12-13 13:30:07 +09001350 NetworkCapabilities nc = null;
Sanket Padawe7094d222015-05-01 16:55:00 -07001351
1352 try {
Lorenzo Colitti1317e042016-12-13 13:30:07 +09001353 nc = cm.getNetworkCapabilities(wifiManager.getCurrentNetwork());
1354 } catch (RemoteException e) {}
1355
1356 if (nc != null) {
1357 if (nc.hasCapability(nc.NET_CAPABILITY_CAPTIVE_PORTAL)) {
Maurice Lam7f6fc862017-07-12 16:43:49 -07001358 int id = context.getResources()
1359 .getIdentifier("network_available_sign_in", "string", "android");
1360 return context.getString(id);
Lorenzo Colitti1317e042016-12-13 13:30:07 +09001361 } else if (!nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)) {
1362 return context.getString(R.string.wifi_connected_no_internet);
1363 }
Sanket Padawe7094d222015-05-01 16:55:00 -07001364 }
1365 }
Fan Zhang6acb7662016-10-17 12:40:03 -07001366 if (state == null) {
1367 Log.w(TAG, "state is null, returning empty summary");
1368 return "";
1369 }
Jason Monkd52356a2015-01-28 10:40:41 -05001370 String[] formats = context.getResources().getStringArray((ssid == null)
1371 ? R.array.wifi_status : R.array.wifi_status_with_ssid);
1372 int index = state.ordinal();
1373
1374 if (index >= formats.length || formats[index].length() == 0) {
Sanket Padawe3e9e5fa2015-05-28 10:41:14 -07001375 return "";
Jason Monkd52356a2015-01-28 10:40:41 -05001376 }
1377 return String.format(formats[index], ssid);
1378 }
1379
1380 public static String getSummary(Context context, DetailedState state, boolean isEphemeral) {
Vinit Deshpandefc406002015-04-15 18:10:55 -07001381 return getSummary(context, null, state, isEphemeral, null);
1382 }
1383
1384 public static String getSummary(Context context, DetailedState state, boolean isEphemeral,
1385 String passpointProvider) {
1386 return getSummary(context, null, state, isEphemeral, passpointProvider);
Jason Monkd52356a2015-01-28 10:40:41 -05001387 }
1388
1389 public static String convertToQuotedString(String string) {
1390 return "\"" + string + "\"";
1391 }
1392
1393 private static int getPskType(ScanResult result) {
1394 boolean wpa = result.capabilities.contains("WPA-PSK");
1395 boolean wpa2 = result.capabilities.contains("WPA2-PSK");
1396 if (wpa2 && wpa) {
1397 return PSK_WPA_WPA2;
1398 } else if (wpa2) {
1399 return PSK_WPA2;
1400 } else if (wpa) {
1401 return PSK_WPA;
1402 } else {
1403 Log.w(TAG, "Received abnormal flag string: " + result.capabilities);
1404 return PSK_UNKNOWN;
1405 }
1406 }
1407
1408 private static int getSecurity(ScanResult result) {
1409 if (result.capabilities.contains("WEP")) {
1410 return SECURITY_WEP;
Hai Shalomaa6f9202018-10-16 14:30:02 -07001411 } else if (result.capabilities.contains("SAE")) {
1412 return SECURITY_SAE;
Jason Monkd52356a2015-01-28 10:40:41 -05001413 } else if (result.capabilities.contains("PSK")) {
1414 return SECURITY_PSK;
Hai Shalomaa6f9202018-10-16 14:30:02 -07001415 } else if (result.capabilities.contains("EAP_SUITE_B_192")) {
1416 return SECURITY_EAP_SUITE_B;
Jason Monkd52356a2015-01-28 10:40:41 -05001417 } else if (result.capabilities.contains("EAP")) {
1418 return SECURITY_EAP;
Hai Shalomaa6f9202018-10-16 14:30:02 -07001419 } else if (result.capabilities.contains("OWE")) {
1420 return SECURITY_OWE;
Jason Monkd52356a2015-01-28 10:40:41 -05001421 }
Hai Shalomaa6f9202018-10-16 14:30:02 -07001422
Jason Monkd52356a2015-01-28 10:40:41 -05001423 return SECURITY_NONE;
1424 }
1425
1426 static int getSecurity(WifiConfiguration config) {
Hai Shalomaa6f9202018-10-16 14:30:02 -07001427 if (config.allowedKeyManagement.get(KeyMgmt.SAE)) {
1428 return SECURITY_SAE;
1429 }
Jason Monkd52356a2015-01-28 10:40:41 -05001430 if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) {
1431 return SECURITY_PSK;
1432 }
Hai Shalomaa6f9202018-10-16 14:30:02 -07001433 if (config.allowedKeyManagement.get(KeyMgmt.SUITE_B_192)) {
1434 return SECURITY_EAP_SUITE_B;
1435 }
Jason Monkd52356a2015-01-28 10:40:41 -05001436 if (config.allowedKeyManagement.get(KeyMgmt.WPA_EAP) ||
1437 config.allowedKeyManagement.get(KeyMgmt.IEEE8021X)) {
1438 return SECURITY_EAP;
1439 }
Hai Shalomaa6f9202018-10-16 14:30:02 -07001440 if (config.allowedKeyManagement.get(KeyMgmt.OWE)) {
1441 return SECURITY_OWE;
1442 }
Jason Monkd52356a2015-01-28 10:40:41 -05001443 return (config.wepKeys[0] != null) ? SECURITY_WEP : SECURITY_NONE;
1444 }
1445
1446 public static String securityToString(int security, int pskType) {
1447 if (security == SECURITY_WEP) {
1448 return "WEP";
1449 } else if (security == SECURITY_PSK) {
1450 if (pskType == PSK_WPA) {
1451 return "WPA";
1452 } else if (pskType == PSK_WPA2) {
1453 return "WPA2";
1454 } else if (pskType == PSK_WPA_WPA2) {
1455 return "WPA_WPA2";
1456 }
1457 return "PSK";
1458 } else if (security == SECURITY_EAP) {
1459 return "EAP";
Hai Shalomaa6f9202018-10-16 14:30:02 -07001460 } else if (security == SECURITY_SAE) {
1461 return "SAE";
1462 } else if (security == SECURITY_EAP_SUITE_B) {
1463 return "SUITE_B";
1464 } else if (security == SECURITY_OWE) {
1465 return "OWE";
Jason Monkd52356a2015-01-28 10:40:41 -05001466 }
1467 return "NONE";
1468 }
1469
1470 static String removeDoubleQuotes(String string) {
Jason Monk2b51cc32015-05-13 11:07:53 -04001471 if (TextUtils.isEmpty(string)) {
1472 return "";
1473 }
Jason Monkd52356a2015-01-28 10:40:41 -05001474 int length = string.length();
1475 if ((length > 1) && (string.charAt(0) == '"')
1476 && (string.charAt(length - 1) == '"')) {
1477 return string.substring(1, length - 1);
1478 }
1479 return string;
1480 }
1481
Sundeep Ghumanbb399912018-01-29 18:31:15 -08001482 /**
1483 * Callbacks relaying changes to the AccessPoint representation.
1484 *
1485 * <p>All methods are invoked on the Main Thread.
1486 */
Jason Monkd52356a2015-01-28 10:40:41 -05001487 public interface AccessPointListener {
Sundeep Ghumanbb399912018-01-29 18:31:15 -08001488 /**
1489 * Indicates a change to the externally visible state of the AccessPoint trigger by an
1490 * update of ScanResults, saved configuration state, connection state, or score
1491 * (labels/metered) state.
1492 *
1493 * <p>Clients should refresh their view of the AccessPoint to match the updated state when
1494 * this is invoked. Overall this method is extraneous if clients are listening to
1495 * {@link WifiTracker.WifiListener#onAccessPointsChanged()} callbacks.
1496 *
1497 * <p>Examples of changes include signal strength, connection state, speed label, and
1498 * generally anything that would impact the summary string.
1499 *
1500 * @param accessPoint The accessPoint object the listener was registered on which has
1501 * changed
1502 */
1503 @MainThread void onAccessPointChanged(AccessPoint accessPoint);
1504
1505 /**
1506 * Indicates the "wifi pie signal level" has changed, retrieved via calls to
1507 * {@link AccessPoint#getLevel()}.
1508 *
1509 * <p>This call is a subset of {@link #onAccessPointChanged(AccessPoint)} , hence is also
1510 * extraneous if the client is already reacting to that or the
1511 * {@link WifiTracker.WifiListener#onAccessPointsChanged()} callbacks.
1512 *
1513 * @param accessPoint The accessPoint object the listener was registered on whose level has
1514 * changed
1515 */
1516 @MainThread void onLevelChanged(AccessPoint accessPoint);
Jason Monkd52356a2015-01-28 10:40:41 -05001517 }
Sundeep Ghumanc0cf8482018-01-26 18:23:34 -08001518
1519 private static boolean isVerboseLoggingEnabled() {
1520 return WifiTracker.sVerboseLogging || Log.isLoggable(TAG, Log.VERBOSE);
1521 }
Quang Luong4d194842018-12-18 16:59:49 -08001522
1523 /**
1524 * Callbacks relaying changes to the OSU provisioning status started in startOsuProvisioning().
1525 *
1526 * All methods are invoked on the Main Thread
1527 */
1528 private class AccessPointProvisioningCallback extends ProvisioningCallback {
1529 // TODO: Remove logs and implement summary changing logic for these provisioning callbacks.
1530 @Override
1531 @MainThread public void onProvisioningFailure(int status) {
Quang Luong8d40a8e2019-01-02 16:25:38 -08001532 switch (status) {
1533 case OSU_FAILURE_AP_CONNECTION:
1534 mOsuFailure = mContext.getString(R.string.osu_failure_ap_connection);
1535 break;
1536 case OSU_FAILURE_SERVER_URL_INVALID:
1537 mOsuFailure = mContext.getString(R.string.osu_failure_server_url_invalid);
1538 break;
1539 case OSU_FAILURE_SERVER_CONNECTION:
1540 mOsuFailure = mContext.getString(R.string.osu_failure_server_connection);
1541 break;
1542 case OSU_FAILURE_SERVER_VALIDATION:
1543 mOsuFailure = mContext.getString(R.string.osu_failure_server_validation);
1544 break;
1545 case OSU_FAILURE_SERVICE_PROVIDER_VERIFICATION:
1546 mOsuFailure = mContext.getString(
1547 R.string.osu_failure_service_provider_verification);
1548 break;
1549 case OSU_FAILURE_PROVISIONING_ABORTED:
1550 mOsuFailure = mContext.getString(R.string.osu_failure_provisioning_aborted);
1551 break;
1552 case OSU_FAILURE_PROVISIONING_NOT_AVAILABLE:
1553 mOsuFailure = mContext.getString(
1554 R.string.osu_failure_provisioning_not_available);
1555 break;
1556 case OSU_FAILURE_INVALID_SERVER_URL:
1557 mOsuFailure = mContext.getString(R.string.osu_failure_invalid_server_url);
1558 break;
1559 case OSU_FAILURE_UNEXPECTED_COMMAND_TYPE:
1560 mOsuFailure = mContext.getString(R.string.osu_failure_unexpected_command_type);
1561 break;
1562 case OSU_FAILURE_UNEXPECTED_SOAP_MESSAGE_TYPE:
1563 mOsuFailure = mContext.getString(
1564 R.string.osu_failure_unexpected_soap_message_type);
1565 break;
1566 case OSU_FAILURE_SOAP_MESSAGE_EXCHANGE:
1567 mOsuFailure = mContext.getString(R.string.osu_failure_soap_message_exchange);
1568 break;
1569 case OSU_FAILURE_START_REDIRECT_LISTENER:
1570 mOsuFailure = mContext.getString(R.string.osu_failure_start_redirect_listener);
1571 break;
1572 case OSU_FAILURE_TIMED_OUT_REDIRECT_LISTENER:
1573 mOsuFailure = mContext.getString(
1574 R.string.osu_failure_timed_out_redirect_listener);
1575 break;
1576 case OSU_FAILURE_NO_OSU_ACTIVITY_FOUND:
1577 mOsuFailure = mContext.getString(R.string.osu_failure_no_osu_activity_found);
1578 break;
1579 case OSU_FAILURE_UNEXPECTED_SOAP_MESSAGE_STATUS:
1580 mOsuFailure = mContext.getString(
1581 R.string.osu_failure_unexpected_soap_message_status);
1582 break;
1583 case OSU_FAILURE_NO_PPS_MO:
1584 mOsuFailure = mContext.getString(
1585 R.string.osu_failure_no_pps_mo);
1586 break;
1587 case OSU_FAILURE_NO_AAA_SERVER_TRUST_ROOT_NODE:
1588 mOsuFailure = mContext.getString(
1589 R.string.osu_failure_no_aaa_server_trust_root_node);
1590 break;
1591 case OSU_FAILURE_NO_REMEDIATION_SERVER_TRUST_ROOT_NODE:
1592 mOsuFailure = mContext.getString(
1593 R.string.osu_failure_no_remediation_server_trust_root_node);
1594 break;
1595 case OSU_FAILURE_NO_POLICY_SERVER_TRUST_ROOT_NODE:
1596 mOsuFailure = mContext.getString(
1597 R.string.osu_failure_no_policy_server_trust_root_node);
1598 break;
1599 case OSU_FAILURE_RETRIEVE_TRUST_ROOT_CERTIFICATES:
1600 mOsuFailure = mContext.getString(
1601 R.string.osu_failure_retrieve_trust_root_certificates);
1602 break;
1603 case OSU_FAILURE_NO_AAA_TRUST_ROOT_CERTIFICATE:
1604 mOsuFailure = mContext.getString(
1605 R.string.osu_failure_no_aaa_trust_root_certificate);
1606 break;
1607 case OSU_FAILURE_ADD_PASSPOINT_CONFIGURATION:
1608 mOsuFailure = mContext.getString(
1609 R.string.osu_failure_add_passpoint_configuration);
1610 break;
1611 case OSU_FAILURE_OSU_PROVIDER_NOT_FOUND:
1612 mOsuFailure = mContext.getString(R.string.osu_failure_osu_provider_not_found);
1613 break;
1614 }
1615 mOsuStatus = null;
1616 mOsuProvisioningComplete = false;
1617 ThreadUtils.postOnMainThread(() -> {
1618 if (mAccessPointListener != null) {
1619 mAccessPointListener.onAccessPointChanged(AccessPoint.this);
1620 }
1621 });
Quang Luong4d194842018-12-18 16:59:49 -08001622 }
1623
1624 @Override
1625 @MainThread public void onProvisioningStatus(int status) {
Quang Luong8d40a8e2019-01-02 16:25:38 -08001626 switch (status) {
1627 case OSU_STATUS_AP_CONNECTING:
1628 mOsuStatus = mContext.getString(R.string.osu_status_ap_connecting);
1629 break;
1630 case OSU_STATUS_AP_CONNECTED:
1631 mOsuStatus = mContext.getString(R.string.osu_status_ap_connected);
1632 break;
1633 case OSU_STATUS_SERVER_CONNECTING:
1634 mOsuStatus = mContext.getString(R.string.osu_status_server_connecting);
1635 break;
1636 case OSU_STATUS_SERVER_VALIDATED:
1637 mOsuStatus = mContext.getString(R.string.osu_status_server_validated);
1638 break;
1639 case OSU_STATUS_SERVER_CONNECTED:
1640 mOsuStatus = mContext.getString(R.string.osu_status_server_connected);
1641 break;
1642 case OSU_STATUS_INIT_SOAP_EXCHANGE:
1643 mOsuStatus = mContext.getString(R.string.osu_status_init_soap_exchange);
1644 break;
1645 case OSU_STATUS_WAITING_FOR_REDIRECT_RESPONSE:
1646 mOsuStatus = mContext.getString(
1647 R.string.osu_status_waiting_for_redirect_response);
1648 break;
1649 case OSU_STATUS_REDIRECT_RESPONSE_RECEIVED:
1650 mOsuStatus = mContext.getString(R.string.osu_status_redirect_response_received);
1651 break;
1652 case OSU_STATUS_SECOND_SOAP_EXCHANGE:
1653 mOsuStatus = mContext.getString(R.string.osu_status_second_soap_exchange);
1654 break;
1655 case OSU_STATUS_THIRD_SOAP_EXCHANGE:
1656 mOsuStatus = mContext.getString(R.string.osu_status_third_soap_exchange);
1657 break;
1658 case OSU_STATUS_RETRIEVING_TRUST_ROOT_CERTS:
1659 mOsuStatus = mContext.getString(
1660 R.string.osu_status_retrieving_trust_root_certs);
1661 break;
1662 }
1663 mOsuFailure = null;
1664 mOsuProvisioningComplete = false;
1665 ThreadUtils.postOnMainThread(() -> {
1666 if (mAccessPointListener != null) {
1667 mAccessPointListener.onAccessPointChanged(AccessPoint.this);
1668 }
1669 });
1670 }
1671
1672 @Override
1673 @MainThread public void onProvisioningComplete() {
1674 mOsuProvisioningComplete = true;
1675 mOsuFailure = null;
1676 mOsuStatus = null;
1677 ThreadUtils.postOnMainThread(() -> {
1678 if (mAccessPointListener != null) {
1679 mAccessPointListener.onAccessPointChanged(AccessPoint.this);
1680 }
1681 });
Quang Luong4d194842018-12-18 16:59:49 -08001682 }
1683 }
Jason Monkd52356a2015-01-28 10:40:41 -05001684}