Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package com.android.settingslib.wifi; |
| 18 | |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 19 | import android.annotation.IntDef; |
Sundeep Ghuman | bb39991 | 2018-01-29 18:31:15 -0800 | [diff] [blame] | 20 | import android.annotation.MainThread; |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 21 | import android.annotation.Nullable; |
Jason Monk | 6980d12 | 2015-06-15 10:07:55 -0400 | [diff] [blame] | 22 | import android.app.AppGlobals; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 23 | import android.content.Context; |
Jason Monk | 6980d12 | 2015-06-15 10:07:55 -0400 | [diff] [blame] | 24 | import android.content.pm.ApplicationInfo; |
| 25 | import android.content.pm.IPackageManager; |
| 26 | import android.content.pm.PackageManager; |
Sanket Padawe | 7094d22 | 2015-05-01 16:55:00 -0700 | [diff] [blame] | 27 | import android.net.ConnectivityManager; |
Sanket Padawe | 7094d22 | 2015-05-01 16:55:00 -0700 | [diff] [blame] | 28 | import android.net.NetworkCapabilities; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 29 | import android.net.NetworkInfo; |
| 30 | import android.net.NetworkInfo.DetailedState; |
| 31 | import android.net.NetworkInfo.State; |
Sundeep Ghuman | a28050a | 2017-07-12 22:09:25 -0700 | [diff] [blame] | 32 | import android.net.NetworkKey; |
Stephen Chen | 36dd5cf1 | 2017-03-20 13:27:51 -0700 | [diff] [blame] | 33 | import android.net.NetworkScoreManager; |
| 34 | import android.net.NetworkScorerAppData; |
Sundeep Ghuman | 5519b7b | 2016-12-14 17:53:31 -0800 | [diff] [blame] | 35 | import android.net.ScoredNetwork; |
Sanket Padawe | 7094d22 | 2015-05-01 16:55:00 -0700 | [diff] [blame] | 36 | import android.net.wifi.IWifiManager; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 37 | import android.net.wifi.ScanResult; |
| 38 | import android.net.wifi.WifiConfiguration; |
| 39 | import android.net.wifi.WifiConfiguration.KeyMgmt; |
Peter Qiu | 280581b | 2017-07-24 14:18:56 -0700 | [diff] [blame] | 40 | import android.net.wifi.WifiEnterpriseConfig; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 41 | import android.net.wifi.WifiInfo; |
| 42 | import android.net.wifi.WifiManager; |
Sundeep Ghuman | 5519b7b | 2016-12-14 17:53:31 -0800 | [diff] [blame] | 43 | import android.net.wifi.WifiNetworkScoreCache; |
Quang Luong | 9051dfd | 2018-12-12 12:49:24 -0800 | [diff] [blame] | 44 | import android.net.wifi.hotspot2.OsuProvider; |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 45 | import android.net.wifi.hotspot2.PasspointConfiguration; |
Quang Luong | 4d19484 | 2018-12-18 16:59:49 -0800 | [diff] [blame] | 46 | import android.net.wifi.hotspot2.ProvisioningCallback; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 47 | import android.os.Bundle; |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 48 | import android.os.Parcelable; |
Sanket Padawe | 7094d22 | 2015-05-01 16:55:00 -0700 | [diff] [blame] | 49 | import android.os.RemoteException; |
| 50 | import android.os.ServiceManager; |
Mitchell Wills | 18af493 | 2016-08-10 13:49:21 -0700 | [diff] [blame] | 51 | import android.os.SystemClock; |
Jason Monk | 6980d12 | 2015-06-15 10:07:55 -0400 | [diff] [blame] | 52 | import android.os.UserHandle; |
Jason Monk | 6980d12 | 2015-06-15 10:07:55 -0400 | [diff] [blame] | 53 | import android.text.TextUtils; |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 54 | import android.util.ArraySet; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 55 | import android.util.Log; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 56 | |
Fan Zhang | f7802ea | 2018-08-28 15:15:19 -0700 | [diff] [blame] | 57 | import androidx.annotation.NonNull; |
| 58 | |
Sundeep Ghuman | 54bdcfa | 2017-03-08 19:52:05 -0800 | [diff] [blame] | 59 | import com.android.internal.annotations.VisibleForTesting; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 60 | import com.android.settingslib.R; |
Sundeep Ghuman | bb39991 | 2018-01-29 18:31:15 -0800 | [diff] [blame] | 61 | import com.android.settingslib.utils.ThreadUtils; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 62 | |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 63 | import java.lang.annotation.Retention; |
| 64 | import java.lang.annotation.RetentionPolicy; |
Vinit Deshpande | fcd4612 | 2015-06-11 18:22:23 -0700 | [diff] [blame] | 65 | import java.util.ArrayList; |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 66 | import java.util.Collection; |
Eric Schwarzenbach | 0b8700f | 2017-07-25 14:32:21 -0700 | [diff] [blame] | 67 | import java.util.HashMap; |
Mitchell Wills | 18af493 | 2016-08-10 13:49:21 -0700 | [diff] [blame] | 68 | import java.util.Iterator; |
Eric Schwarzenbach | 0b8700f | 2017-07-25 14:32:21 -0700 | [diff] [blame] | 69 | import java.util.Map; |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 70 | import java.util.Set; |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 71 | import java.util.concurrent.atomic.AtomicInteger; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 72 | |
Sundeep Ghuman | bb39991 | 2018-01-29 18:31:15 -0800 | [diff] [blame] | 73 | /** |
| 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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 81 | public 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 Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 104 | /** The key which identifies this AccessPoint grouping. */ |
| 105 | private String mKey; |
| 106 | |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 107 | @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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 131 | |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 132 | /** The underlying set of scan results comprising this AccessPoint. */ |
| 133 | private final ArraySet<ScanResult> mScanResults = new ArraySet<>(); |
Eric Schwarzenbach | 0b8700f | 2017-07-25 14:32:21 -0700 | [diff] [blame] | 134 | |
Sundeep Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 135 | /** |
| 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 Ghuman | fedf461 | 2017-08-15 15:47:18 -0700 | [diff] [blame] | 141 | private final Map<String, TimestampedScoredNetwork> mScoredNetworkCache = new HashMap<>(); |
| 142 | |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 143 | static final String KEY_NETWORKINFO = "key_networkinfo"; |
| 144 | static final String KEY_WIFIINFO = "key_wifiinfo"; |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 145 | static final String KEY_SSID = "key_ssid"; |
| 146 | static final String KEY_SECURITY = "key_security"; |
Sundeep Ghuman | a28050a | 2017-07-12 22:09:25 -0700 | [diff] [blame] | 147 | static final String KEY_SPEED = "key_speed"; |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 148 | static final String KEY_PSKTYPE = "key_psktype"; |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 149 | static final String KEY_SCANRESULTS = "key_scanresults"; |
Sundeep Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 150 | static final String KEY_SCOREDNETWORKCACHE = "key_scorednetworkcache"; |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 151 | static final String KEY_CONFIG = "key_config"; |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 152 | static final String KEY_FQDN = "key_fqdn"; |
| 153 | static final String KEY_PROVIDER_FRIENDLY_NAME = "key_provider_friendly_name"; |
Peter Qiu | 280581b | 2017-07-24 14:18:56 -0700 | [diff] [blame] | 154 | 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 Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 157 | static final AtomicInteger sLastId = new AtomicInteger(0); |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 158 | |
Maurice Lam | 7cdbe19 | 2018-11-13 13:52:50 -0800 | [diff] [blame] | 159 | /* |
| 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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 163 | */ |
| 164 | public static final int SECURITY_NONE = 0; |
Hai Shalom | 9effa64 | 2018-11-12 11:43:52 -0800 | [diff] [blame] | 165 | 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 Shalom | aa6f920 | 2018-10-16 14:30:02 -0700 | [diff] [blame] | 170 | public static final int SECURITY_EAP_SUITE_B = 6; |
Hai Shalom | 828b13c | 2018-11-13 16:43:14 -0800 | [diff] [blame] | 171 | public static final int SECURITY_MAX_VAL = 7; // Has to be the last |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 172 | |
| 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 Ghuman | aaa8a1b | 2017-03-13 14:40:56 -0700 | [diff] [blame] | 178 | /** |
| 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 Mantler | a0e03dd | 2016-01-27 15:57:03 -0800 | [diff] [blame] | 184 | |
Sundeep Ghuman | aaa8a1b | 2017-03-13 14:40:56 -0700 | [diff] [blame] | 185 | public static final int UNREACHABLE_RSSI = Integer.MIN_VALUE; |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 186 | |
Quang Luong | 9051dfd | 2018-12-12 12:49:24 -0800 | [diff] [blame] | 187 | 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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 191 | private final Context mContext; |
| 192 | |
| 193 | private String ssid; |
Jason Monk | 60a82ff | 2016-02-25 13:55:03 -0500 | [diff] [blame] | 194 | private String bssid; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 195 | private int security; |
| 196 | private int networkId = WifiConfiguration.INVALID_NETWORK_ID; |
| 197 | |
| 198 | private int pskType = PSK_UNKNOWN; |
| 199 | |
| 200 | private WifiConfiguration mConfig; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 201 | |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 202 | private int mRssi = UNREACHABLE_RSSI; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 203 | |
| 204 | private WifiInfo mInfo; |
| 205 | private NetworkInfo mNetworkInfo; |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 206 | AccessPointListener mAccessPointListener; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 207 | |
| 208 | private Object mTag; |
| 209 | |
Sundeep Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 210 | @Speed private int mSpeed = Speed.NONE; |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 211 | private boolean mIsScoredNetworkMetered = false; |
Sundeep Ghuman | 5519b7b | 2016-12-14 17:53:31 -0800 | [diff] [blame] | 212 | |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 213 | /** |
| 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 Qiu | 280581b | 2017-07-24 14:18:56 -0700 | [diff] [blame] | 220 | private boolean mIsCarrierAp = false; |
Quang Luong | 9051dfd | 2018-12-12 12:49:24 -0800 | [diff] [blame] | 221 | |
| 222 | private OsuProvider mOsuProvider; |
Quang Luong | 8d40a8e | 2019-01-02 16:25:38 -0800 | [diff] [blame] | 223 | |
| 224 | private String mOsuStatus; |
| 225 | private String mOsuFailure; |
| 226 | private boolean mOsuProvisioningComplete = false; |
| 227 | |
Peter Qiu | 280581b | 2017-07-24 14:18:56 -0700 | [diff] [blame] | 228 | /** |
| 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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 234 | public AccessPoint(Context context, Bundle savedState) { |
| 235 | mContext = context; |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 236 | |
| 237 | if (savedState.containsKey(KEY_CONFIG)) { |
| 238 | mConfig = savedState.getParcelable(KEY_CONFIG); |
| 239 | } |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 240 | if (mConfig != null) { |
| 241 | loadConfig(mConfig); |
| 242 | } |
Vinit Deshpande | fcd4612 | 2015-06-11 18:22:23 -0700 | [diff] [blame] | 243 | 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 Ghuman | a28050a | 2017-07-12 22:09:25 -0700 | [diff] [blame] | 249 | if (savedState.containsKey(KEY_SPEED)) { |
| 250 | mSpeed = savedState.getInt(KEY_SPEED); |
| 251 | } |
Vinit Deshpande | fcd4612 | 2015-06-11 18:22:23 -0700 | [diff] [blame] | 252 | if (savedState.containsKey(KEY_PSKTYPE)) { |
| 253 | pskType = savedState.getInt(KEY_PSKTYPE); |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 254 | } |
Sundeep Ghuman | a28050a | 2017-07-12 22:09:25 -0700 | [diff] [blame] | 255 | mInfo = savedState.getParcelable(KEY_WIFIINFO); |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 256 | if (savedState.containsKey(KEY_NETWORKINFO)) { |
| 257 | mNetworkInfo = savedState.getParcelable(KEY_NETWORKINFO); |
| 258 | } |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 259 | 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 Deshpande | fcd4612 | 2015-06-11 18:22:23 -0700 | [diff] [blame] | 264 | } |
| 265 | } |
Sundeep Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 266 | if (savedState.containsKey(KEY_SCOREDNETWORKCACHE)) { |
Sundeep Ghuman | fedf461 | 2017-08-15 15:47:18 -0700 | [diff] [blame] | 267 | ArrayList<TimestampedScoredNetwork> scoredNetworkArrayList = |
Sundeep Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 268 | savedState.getParcelableArrayList(KEY_SCOREDNETWORKCACHE); |
Sundeep Ghuman | fedf461 | 2017-08-15 15:47:18 -0700 | [diff] [blame] | 269 | for (TimestampedScoredNetwork timedScore : scoredNetworkArrayList) { |
| 270 | mScoredNetworkCache.put(timedScore.getScore().networkKey.wifiKey.bssid, timedScore); |
Sundeep Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 271 | } |
| 272 | } |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 273 | 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 Qiu | 280581b | 2017-07-24 14:18:56 -0700 | [diff] [blame] | 279 | 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 Wills | 5a42db2 | 2015-08-03 09:46:08 -0700 | [diff] [blame] | 288 | update(mConfig, mInfo, mNetworkInfo); |
Sundeep Ghuman | d1e4492 | 2017-08-07 11:21:38 -0700 | [diff] [blame] | 289 | |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 290 | // Calculate required fields |
| 291 | updateKey(); |
Sundeep Ghuman | 54bdcfa | 2017-03-08 19:52:05 -0800 | [diff] [blame] | 292 | updateRssi(); |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 293 | } |
| 294 | |
Quang Luong | 9051dfd | 2018-12-12 12:49:24 -0800 | [diff] [blame] | 295 | /** |
| 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 Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 302 | public AccessPoint(Context context, WifiConfiguration config) { |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 303 | mContext = context; |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 304 | loadConfig(config); |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 305 | } |
| 306 | |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 307 | /** |
| 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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 312 | mContext = context; |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 313 | mFqdn = config.getHomeSp().getFqdn(); |
| 314 | mProviderFriendlyName = config.getHomeSp().getFriendlyName(); |
Quang Luong | 9051dfd | 2018-12-12 12:49:24 -0800 | [diff] [blame] | 315 | } |
| 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 Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 328 | } |
| 329 | |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 330 | AccessPoint(Context context, Collection<ScanResult> results) { |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 331 | mContext = context; |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 332 | |
| 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 Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 355 | @VisibleForTesting void loadConfig(WifiConfiguration config) { |
| 356 | ssid = (config.SSID == null ? "" : removeDoubleQuotes(config.SSID)); |
| 357 | bssid = config.BSSID; |
| 358 | security = getSecurity(config); |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 359 | networkId = config.networkId; |
| 360 | mConfig = config; |
Quang Luong | 7054e92 | 2018-12-07 16:44:18 -0800 | [diff] [blame] | 361 | updateKey(); |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 362 | } |
| 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 Luong | 7054e92 | 2018-12-07 16:44:18 -0800 | [diff] [blame] | 367 | if (isPasspoint()) { |
Quang Luong | ac1026e | 2019-01-02 17:37:01 -0800 | [diff] [blame^] | 368 | mKey = getKey(mConfig); |
Quang Luong | 9051dfd | 2018-12-12 12:49:24 -0800 | [diff] [blame] | 369 | } else if (isOsuProvider()) { |
Quang Luong | ac1026e | 2019-01-02 17:37:01 -0800 | [diff] [blame^] | 370 | mKey = getKey(mOsuProvider); |
Quang Luong | 9051dfd | 2018-12-12 12:49:24 -0800 | [diff] [blame] | 371 | } else { // Non-Passpoint AP |
Quang Luong | ac1026e | 2019-01-02 17:37:01 -0800 | [diff] [blame^] | 372 | mKey = getKey(getSsidStr(), getBssid(), getSecurity()); |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 373 | } |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 374 | } |
| 375 | |
Ajay Nadathur | d7b689a | 2016-08-31 15:07:56 -0700 | [diff] [blame] | 376 | /** |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 377 | * 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 Schwarzenbach | f4f3842b | 2017-07-17 16:45:04 -0700 | [diff] [blame] | 384 | * 4. Network speed value |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 385 | * 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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 391 | @Override |
Tony Mantler | a0e03dd | 2016-01-27 15:57:03 -0800 | [diff] [blame] | 392 | public int compareTo(@NonNull AccessPoint other) { |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 393 | // 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 Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 398 | if (isReachable() && !other.isReachable()) return -1; |
| 399 | if (!isReachable() && other.isReachable()) return 1; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 400 | |
Sundeep Ghuman | 05c41e2 | 2017-02-01 13:27:56 -0800 | [diff] [blame] | 401 | // Configured (saved) one goes before unconfigured one. |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 402 | if (isSaved() && !other.isSaved()) return -1; |
| 403 | if (!isSaved() && other.isSaved()) return 1; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 404 | |
Sundeep Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 405 | // Faster speeds go before slower speeds - but only if visible change in speed label |
Eric Schwarzenbach | f4f3842b | 2017-07-17 16:45:04 -0700 | [diff] [blame] | 406 | if (getSpeed() != other.getSpeed()) { |
| 407 | return other.getSpeed() - getSpeed(); |
Sundeep Ghuman | 05c41e2 | 2017-02-01 13:27:56 -0800 | [diff] [blame] | 408 | } |
| 409 | |
Tony Mantler | a0e03dd | 2016-01-27 15:57:03 -0800 | [diff] [blame] | 410 | // Sort by signal strength, bucketed by level |
| 411 | int difference = WifiManager.calculateSignalLevel(other.mRssi, SIGNAL_LEVELS) |
| 412 | - WifiManager.calculateSignalLevel(mRssi, SIGNAL_LEVELS); |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 413 | if (difference != 0) { |
| 414 | return difference; |
| 415 | } |
Sundeep Ghuman | d44b8e4 | 2017-06-21 21:40:06 -0700 | [diff] [blame] | 416 | |
Quang Luong | 9051dfd | 2018-12-12 12:49:24 -0800 | [diff] [blame] | 417 | // Sort by title. |
| 418 | difference = getTitle().compareToIgnoreCase(other.getTitle()); |
Sundeep Ghuman | d44b8e4 | 2017-06-21 21:40:06 -0700 | [diff] [blame] | 419 | 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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 425 | } |
| 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 Ghuman | 2b48990 | 2017-02-22 18:17:29 -0800 | [diff] [blame] | 447 | if (bssid != null) { |
| 448 | builder.append(":").append(bssid); |
| 449 | } |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 450 | 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 Shalom | aa6f920 | 2018-10-16 14:30:02 -0700 | [diff] [blame] | 462 | if ((security != SECURITY_NONE) && (security != SECURITY_OWE)) { |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 463 | builder.append(',').append(securityToString(security, pskType)); |
| 464 | } |
Sundeep Ghuman | 2b48990 | 2017-02-22 18:17:29 -0800 | [diff] [blame] | 465 | builder.append(",level=").append(getLevel()); |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 466 | if (mSpeed != Speed.NONE) { |
Sundeep Ghuman | 55adc6b | 2017-06-05 16:46:59 -0700 | [diff] [blame] | 467 | builder.append(",speed=").append(mSpeed); |
Sundeep Ghuman | 8920e9c | 2017-04-27 16:16:41 -0700 | [diff] [blame] | 468 | } |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 469 | builder.append(",metered=").append(isMetered()); |
Sundeep Ghuman | 5519b7b | 2016-12-14 17:53:31 -0800 | [diff] [blame] | 470 | |
Sundeep Ghuman | c0cf848 | 2018-01-26 18:23:34 -0800 | [diff] [blame] | 471 | if (isVerboseLoggingEnabled()) { |
Sundeep Ghuman | db9b94c | 2017-09-06 11:46:21 -0700 | [diff] [blame] | 472 | builder.append(",rssi=").append(mRssi); |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 473 | builder.append(",scan cache size=").append(mScanResults.size()); |
Sundeep Ghuman | db9b94c | 2017-09-06 11:46:21 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 476 | return builder.append(')').toString(); |
| 477 | } |
| 478 | |
Sundeep Ghuman | 5519b7b | 2016-12-14 17:53:31 -0800 | [diff] [blame] | 479 | /** |
Sundeep Ghuman | 55adc6b | 2017-06-05 16:46:59 -0700 | [diff] [blame] | 480 | * Updates the AccessPoint rankingScore, metering, and speed, returning true if the data has |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 481 | * changed. |
| 482 | * |
Sundeep Ghuman | 9bb85d3 | 2017-08-28 17:04:16 -0700 | [diff] [blame] | 483 | * @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 Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 487 | */ |
Sundeep Ghuman | 9bb85d3 | 2017-08-28 17:04:16 -0700 | [diff] [blame] | 488 | boolean update( |
| 489 | WifiNetworkScoreCache scoreCache, |
| 490 | boolean scoringUiEnabled, |
| 491 | long maxScoreCacheAgeMillis) { |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 492 | boolean scoreChanged = false; |
| 493 | if (scoringUiEnabled) { |
Sundeep Ghuman | 9bb85d3 | 2017-08-28 17:04:16 -0700 | [diff] [blame] | 494 | scoreChanged = updateScores(scoreCache, maxScoreCacheAgeMillis); |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 495 | } |
| 496 | return updateMetered(scoreCache) || scoreChanged; |
| 497 | } |
| 498 | |
| 499 | /** |
Sundeep Ghuman | 55adc6b | 2017-06-05 16:46:59 -0700 | [diff] [blame] | 500 | * Updates the AccessPoint rankingScore and speed, returning true if the data has changed. |
Sundeep Ghuman | 5519b7b | 2016-12-14 17:53:31 -0800 | [diff] [blame] | 501 | * |
Sundeep Ghuman | 9bb85d3 | 2017-08-28 17:04:16 -0700 | [diff] [blame] | 502 | * <p>Any cached {@link TimestampedScoredNetwork} objects older than the given max age in millis |
| 503 | * will be removed when this method is invoked. |
Sundeep Ghuman | fedf461 | 2017-08-15 15:47:18 -0700 | [diff] [blame] | 504 | * |
Sundeep Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 505 | * <p>Precondition: {@link #mRssi} is up to date before invoking this method. |
| 506 | * |
Sundeep Ghuman | 9bb85d3 | 2017-08-28 17:04:16 -0700 | [diff] [blame] | 507 | * @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 Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 511 | * @return true if the set speed has changed |
Sundeep Ghuman | 5519b7b | 2016-12-14 17:53:31 -0800 | [diff] [blame] | 512 | */ |
Sundeep Ghuman | 9bb85d3 | 2017-08-28 17:04:16 -0700 | [diff] [blame] | 513 | private boolean updateScores(WifiNetworkScoreCache scoreCache, long maxScoreCacheAgeMillis) { |
Sundeep Ghuman | fedf461 | 2017-08-15 15:47:18 -0700 | [diff] [blame] | 514 | long nowMillis = SystemClock.elapsedRealtime(); |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 515 | for (ScanResult result : mScanResults) { |
Eric Schwarzenbach | 0b8700f | 2017-07-25 14:32:21 -0700 | [diff] [blame] | 516 | ScoredNetwork score = scoreCache.getScoredNetwork(result); |
| 517 | if (score == null) { |
| 518 | continue; |
| 519 | } |
Sundeep Ghuman | fedf461 | 2017-08-15 15:47:18 -0700 | [diff] [blame] | 520 | 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 Schwarzenbach | 0b8700f | 2017-07-25 14:32:21 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Sundeep Ghuman | fedf461 | 2017-08-15 15:47:18 -0700 | [diff] [blame] | 530 | // Remove old cached networks |
Sundeep Ghuman | 9bb85d3 | 2017-08-28 17:04:16 -0700 | [diff] [blame] | 531 | long evictionCutoff = nowMillis - maxScoreCacheAgeMillis; |
Sundeep Ghuman | fedf461 | 2017-08-15 15:47:18 -0700 | [diff] [blame] | 532 | Iterator<TimestampedScoredNetwork> iterator = mScoredNetworkCache.values().iterator(); |
| 533 | iterator.forEachRemaining(timestampedScoredNetwork -> { |
| 534 | if (timestampedScoredNetwork.getUpdatedTimestampMillis() < evictionCutoff) { |
| 535 | iterator.remove(); |
| 536 | } |
| 537 | }); |
| 538 | |
Sundeep Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 539 | 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 Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 549 | boolean changed = oldSpeed != mSpeed; |
Sundeep Ghuman | c0cf848 | 2018-01-26 18:23:34 -0800 | [diff] [blame] | 550 | if(isVerboseLoggingEnabled() && changed) { |
Sundeep Ghuman | a28050a | 2017-07-12 22:09:25 -0700 | [diff] [blame] | 551 | Log.i(TAG, String.format("%s: Set speed to %d", ssid, mSpeed)); |
Sundeep Ghuman | 5519b7b | 2016-12-14 17:53:31 -0800 | [diff] [blame] | 552 | } |
Sundeep Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 553 | return changed; |
| 554 | } |
Sundeep Ghuman | 5519b7b | 2016-12-14 17:53:31 -0800 | [diff] [blame] | 555 | |
Sundeep Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 556 | /** 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 Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 562 | 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 Ghuman | a782569 | 2017-08-23 15:53:00 -0700 | [diff] [blame] | 567 | // 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 Ghuman | fedf461 | 2017-08-15 15:47:18 -0700 | [diff] [blame] | 571 | int count = 0; |
| 572 | int totalSpeed = 0; |
| 573 | for (TimestampedScoredNetwork timedScore : mScoredNetworkCache.values()) { |
| 574 | int speed = timedScore.getScore().calculateBadge(mRssi); |
Sundeep Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 575 | if (speed != Speed.NONE) { |
| 576 | count++; |
| 577 | totalSpeed += speed; |
| 578 | } |
| 579 | } |
| 580 | int speed = count == 0 ? Speed.NONE : totalSpeed / count; |
Sundeep Ghuman | c0cf848 | 2018-01-26 18:23:34 -0800 | [diff] [blame] | 581 | if (isVerboseLoggingEnabled()) { |
Sundeep Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 582 | Log.i(TAG, String.format("%s generated fallback speed is: %d", getSsidStr(), speed)); |
| 583 | } |
| 584 | return roundToClosestSpeedEnum(speed); |
Sundeep Ghuman | 5519b7b | 2016-12-14 17:53:31 -0800 | [diff] [blame] | 585 | } |
| 586 | |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 587 | /** |
| 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 Ghuman | a28050a | 2017-07-12 22:09:25 -0700 | [diff] [blame] | 594 | |
| 595 | if (isActive() && mInfo != null) { |
Eric Schwarzenbach | 733ea26 | 2017-08-08 10:28:21 -0700 | [diff] [blame] | 596 | NetworkKey key = NetworkKey.createFromWifiInfo(mInfo); |
Sundeep Ghuman | a28050a | 2017-07-12 22:09:25 -0700 | [diff] [blame] | 597 | ScoredNetwork score = scoreCache.getScoredNetwork(key); |
| 598 | if (score != null) { |
| 599 | mIsScoredNetworkMetered |= score.meteredHint; |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 600 | } |
Sundeep Ghuman | a28050a | 2017-07-12 22:09:25 -0700 | [diff] [blame] | 601 | } else { |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 602 | for (ScanResult result : mScanResults) { |
Sundeep Ghuman | a28050a | 2017-07-12 22:09:25 -0700 | [diff] [blame] | 603 | ScoredNetwork score = scoreCache.getScoredNetwork(result); |
| 604 | if (score == null) { |
| 605 | continue; |
| 606 | } |
| 607 | mIsScoredNetworkMetered |= score.meteredHint; |
| 608 | } |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 609 | } |
| 610 | return oldMetering == mIsScoredNetworkMetered; |
| 611 | } |
| 612 | |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 613 | public static String getKey(ScanResult result) { |
Quang Luong | ac1026e | 2019-01-02 17:37:01 -0800 | [diff] [blame^] | 614 | return getKey(result.SSID, result.BSSID, getSecurity(result)); |
Mitchell Wills | 18af493 | 2016-08-10 13:49:21 -0700 | [diff] [blame] | 615 | } |
| 616 | |
Quang Luong | ac1026e | 2019-01-02 17:37:01 -0800 | [diff] [blame^] | 617 | /** |
| 618 | * Returns the AccessPoint key for a WifiConfiguration. |
| 619 | * This will return a special Passpoint key if the config is for Passpoint. |
| 620 | */ |
Sundeep Ghuman | 0d492e8 | 2018-01-26 12:45:02 -0800 | [diff] [blame] | 621 | public static String getKey(WifiConfiguration config) { |
Quang Luong | 7054e92 | 2018-12-07 16:44:18 -0800 | [diff] [blame] | 622 | if (config.isPasspoint()) { |
Quang Luong | ac1026e | 2019-01-02 17:37:01 -0800 | [diff] [blame^] | 623 | return new StringBuilder() |
| 624 | .append(KEY_PREFIX_FQDN) |
| 625 | .append(config.FQDN).toString(); |
Sundeep Ghuman | 0d492e8 | 2018-01-26 12:45:02 -0800 | [diff] [blame] | 626 | } else { |
Quang Luong | ac1026e | 2019-01-02 17:37:01 -0800 | [diff] [blame^] | 627 | return getKey(config.SSID, config.BSSID, getSecurity(config)); |
Sundeep Ghuman | 0d492e8 | 2018-01-26 12:45:02 -0800 | [diff] [blame] | 628 | } |
Quang Luong | ac1026e | 2019-01-02 17:37:01 -0800 | [diff] [blame^] | 629 | } |
Sundeep Ghuman | 0d492e8 | 2018-01-26 12:45:02 -0800 | [diff] [blame] | 630 | |
Quang Luong | ac1026e | 2019-01-02 17:37:01 -0800 | [diff] [blame^] | 631 | /** |
| 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 Ghuman | 0d492e8 | 2018-01-26 12:45:02 -0800 | [diff] [blame] | 654 | return builder.toString(); |
| 655 | } |
| 656 | |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 657 | public String getKey() { |
| 658 | return mKey; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | public boolean matches(WifiConfiguration config) { |
Quang Luong | 7054e92 | 2018-12-07 16:44:18 -0800 | [diff] [blame] | 662 | if (config.isPasspoint()) { |
| 663 | return (isPasspoint() && config.FQDN.equals(mConfig.FQDN)); |
Bartosz Fabianowski | 6fb0756 | 2016-01-12 15:43:19 +0100 | [diff] [blame] | 664 | } else { |
Quang Luong | 7054e92 | 2018-12-07 16:44:18 -0800 | [diff] [blame] | 665 | // Normal non-Passpoint network |
Bartosz Fabianowski | 6fb0756 | 2016-01-12 15:43:19 +0100 | [diff] [blame] | 666 | return ssid.equals(removeDoubleQuotes(config.SSID)) |
| 667 | && security == getSecurity(config) |
| 668 | && (mConfig == null || mConfig.shared == config.shared); |
| 669 | } |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 670 | } |
| 671 | |
| 672 | public WifiConfiguration getConfig() { |
| 673 | return mConfig; |
| 674 | } |
| 675 | |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 676 | public String getPasspointFqdn() { |
| 677 | return mFqdn; |
| 678 | } |
| 679 | |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 680 | public void clearConfig() { |
| 681 | mConfig = null; |
| 682 | networkId = WifiConfiguration.INVALID_NETWORK_ID; |
| 683 | } |
| 684 | |
| 685 | public WifiInfo getInfo() { |
| 686 | return mInfo; |
| 687 | } |
| 688 | |
Sundeep Ghuman | aaa8a1b | 2017-03-13 14:40:56 -0700 | [diff] [blame] | 689 | /** |
| 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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 695 | public int getLevel() { |
Tony Mantler | a0e03dd | 2016-01-27 15:57:03 -0800 | [diff] [blame] | 696 | return WifiManager.calculateSignalLevel(mRssi, SIGNAL_LEVELS); |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 697 | } |
| 698 | |
Vinit Deshpande | fcd4612 | 2015-06-11 18:22:23 -0700 | [diff] [blame] | 699 | public int getRssi() { |
Sundeep Ghuman | 54bdcfa | 2017-03-08 19:52:05 -0800 | [diff] [blame] | 700 | return mRssi; |
| 701 | } |
| 702 | |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 703 | /** |
| 704 | * Returns the underlying scan result set. |
| 705 | * |
| 706 | * <p>Callers should not modify this set. |
| 707 | */ |
| 708 | public Set<ScanResult> getScanResults() { return mScanResults; } |
jackqdyulei | 9ee9b39 | 2017-12-22 11:31:49 -0800 | [diff] [blame] | 709 | |
| 710 | public Map<String, TimestampedScoredNetwork> getScoredNetworkCache() { |
| 711 | return mScoredNetworkCache; |
| 712 | } |
| 713 | |
Sundeep Ghuman | 54bdcfa | 2017-03-08 19:52:05 -0800 | [diff] [blame] | 714 | /** |
| 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 Ghuman | ce78a5f | 2017-03-15 19:06:14 -0700 | [diff] [blame] | 719 | * 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 Ghuman | 54bdcfa | 2017-03-08 19:52:05 -0800 | [diff] [blame] | 722 | */ |
| 723 | private void updateRssi() { |
Sundeep Ghuman | 54bdcfa | 2017-03-08 19:52:05 -0800 | [diff] [blame] | 724 | if (this.isActive()) { |
| 725 | return; |
| 726 | } |
| 727 | |
| 728 | int rssi = UNREACHABLE_RSSI; |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 729 | for (ScanResult result : mScanResults) { |
Vinit Deshpande | fcd4612 | 2015-06-11 18:22:23 -0700 | [diff] [blame] | 730 | if (result.level > rssi) { |
| 731 | rssi = result.level; |
| 732 | } |
| 733 | } |
| 734 | |
Sundeep Ghuman | ce78a5f | 2017-03-15 19:06:14 -0700 | [diff] [blame] | 735 | if (rssi != UNREACHABLE_RSSI && mRssi != UNREACHABLE_RSSI) { |
| 736 | mRssi = (mRssi + rssi) / 2; // half-life previous value |
| 737 | } else { |
| 738 | mRssi = rssi; |
| 739 | } |
Vinit Deshpande | fcd4612 | 2015-06-11 18:22:23 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 742 | /** |
Jeff Sharkey | 43d2a17 | 2017-07-12 10:50:42 -0600 | [diff] [blame] | 743 | * Returns if the network should be considered metered. |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 744 | */ |
| 745 | public boolean isMetered() { |
| 746 | return mIsScoredNetworkMetered |
Jeff Sharkey | 43d2a17 | 2017-07-12 10:50:42 -0600 | [diff] [blame] | 747 | || WifiConfiguration.isMetered(mConfig, mInfo); |
Stephen Chen | 21f6868 | 2017-04-04 13:23:31 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 750 | 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 Hatano | 2bde6e7 | 2017-05-30 18:38:56 +0900 | [diff] [blame] | 760 | if (isPasspoint() || isPasspointConfig()) { |
Sanket Padawe | 194cce6 | 2015-07-10 10:53:31 -0700 | [diff] [blame] | 761 | return concise ? context.getString(R.string.wifi_security_short_eap) : |
| 762 | context.getString(R.string.wifi_security_eap); |
Sanket Padawe | d187880 | 2015-05-12 10:27:19 -0700 | [diff] [blame] | 763 | } |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 764 | 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 Shalom | aa6f920 | 2018-10-16 14:30:02 -0700 | [diff] [blame] | 768 | 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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 771 | 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 Shalom | aa6f920 | 2018-10-16 14:30:02 -0700 | [diff] [blame] | 790 | 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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 796 | case SECURITY_NONE: |
| 797 | default: |
| 798 | return concise ? "" : context.getString(R.string.wifi_security_none); |
| 799 | } |
| 800 | } |
| 801 | |
Jason Monk | 6980d12 | 2015-06-15 10:07:55 -0400 | [diff] [blame] | 802 | public String getSsidStr() { |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 803 | return ssid; |
| 804 | } |
| 805 | |
Jason Monk | 60a82ff | 2016-02-25 13:55:03 -0500 | [diff] [blame] | 806 | public String getBssid() { |
| 807 | return bssid; |
| 808 | } |
| 809 | |
Jason Monk | 6980d12 | 2015-06-15 10:07:55 -0400 | [diff] [blame] | 810 | public CharSequence getSsid() { |
pastychang | a2998fc | 2018-06-26 13:37:34 +0800 | [diff] [blame] | 811 | return ssid; |
Jason Monk | 6980d12 | 2015-06-15 10:07:55 -0400 | [diff] [blame] | 812 | } |
| 813 | |
Vinit Deshpande | dcf00c9 | 2015-04-15 18:32:09 -0700 | [diff] [blame] | 814 | public String getConfigName() { |
| 815 | if (mConfig != null && mConfig.isPasspoint()) { |
| 816 | return mConfig.providerFriendlyName; |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 817 | } else if (mFqdn != null) { |
| 818 | return mProviderFriendlyName; |
Vinit Deshpande | dcf00c9 | 2015-04-15 18:32:09 -0700 | [diff] [blame] | 819 | } else { |
| 820 | return ssid; |
| 821 | } |
| 822 | } |
| 823 | |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 824 | public DetailedState getDetailedState() { |
Fan Zhang | 6acb766 | 2016-10-17 12:40:03 -0700 | [diff] [blame] | 825 | if (mNetworkInfo != null) { |
| 826 | return mNetworkInfo.getDetailedState(); |
| 827 | } |
| 828 | Log.w(TAG, "NetworkInfo is null, cannot return detailed state"); |
| 829 | return null; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 830 | } |
| 831 | |
Peter Qiu | 280581b | 2017-07-24 14:18:56 -0700 | [diff] [blame] | 832 | 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 Deshpande | dcf00c9 | 2015-04-15 18:32:09 -0700 | [diff] [blame] | 844 | public String getSavedNetworkSummary() { |
Fan Zhang | 51365c3 | 2016-09-20 12:22:18 -0700 | [diff] [blame] | 845 | WifiConfiguration config = mConfig; |
| 846 | if (config != null) { |
Sanket Padawe | 56cfbfb | 2015-05-05 20:10:46 -0700 | [diff] [blame] | 847 | PackageManager pm = mContext.getPackageManager(); |
| 848 | String systemName = pm.getNameForUid(android.os.Process.SYSTEM_UID); |
Fan Zhang | 51365c3 | 2016-09-20 12:22:18 -0700 | [diff] [blame] | 849 | int userId = UserHandle.getUserId(config.creatorUid); |
Sanket Padawe | 56cfbfb | 2015-05-05 20:10:46 -0700 | [diff] [blame] | 850 | ApplicationInfo appInfo = null; |
Fan Zhang | 51365c3 | 2016-09-20 12:22:18 -0700 | [diff] [blame] | 851 | if (config.creatorName != null && config.creatorName.equals(systemName)) { |
Sanket Padawe | 56cfbfb | 2015-05-05 20:10:46 -0700 | [diff] [blame] | 852 | appInfo = mContext.getApplicationInfo(); |
| 853 | } else { |
| 854 | try { |
| 855 | IPackageManager ipm = AppGlobals.getPackageManager(); |
Fan Zhang | 51365c3 | 2016-09-20 12:22:18 -0700 | [diff] [blame] | 856 | appInfo = ipm.getApplicationInfo(config.creatorName, 0 /* flags */, userId); |
Sanket Padawe | 56cfbfb | 2015-05-05 20:10:46 -0700 | [diff] [blame] | 857 | } 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 Deshpande | dcf00c9 | 2015-04-15 18:32:09 -0700 | [diff] [blame] | 866 | } |
Sanket Padawe | 56cfbfb | 2015-05-05 20:10:46 -0700 | [diff] [blame] | 867 | return ""; |
Vinit Deshpande | dcf00c9 | 2015-04-15 18:32:09 -0700 | [diff] [blame] | 868 | } |
| 869 | |
Quang Luong | 7054e92 | 2018-12-07 16:44:18 -0800 | [diff] [blame] | 870 | /** |
| 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 Luong | 9051dfd | 2018-12-12 12:49:24 -0800 | [diff] [blame] | 876 | } else if (isOsuProvider()) { |
| 877 | return mOsuProvider.getFriendlyName(); |
Quang Luong | 7054e92 | 2018-12-07 16:44:18 -0800 | [diff] [blame] | 878 | } else { |
| 879 | return getSsidStr(); |
| 880 | } |
| 881 | } |
| 882 | |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 883 | public String getSummary() { |
Quang Luong | 19bae88c | 2018-12-14 16:05:05 -0800 | [diff] [blame] | 884 | return getSettingsSummary(); |
Vinit Deshpande | dcf00c9 | 2015-04-15 18:32:09 -0700 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | public String getSettingsSummary() { |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 888 | // Update to new summary |
| 889 | StringBuilder summary = new StringBuilder(); |
| 890 | |
Quang Luong | 19bae88c | 2018-12-14 16:05:05 -0800 | [diff] [blame] | 891 | if (isActive()) { |
| 892 | if (isPasspoint()) { |
| 893 | // This is the active connection on passpoint |
Quang Luong | 0a3edf0 | 2018-12-17 14:50:58 -0800 | [diff] [blame] | 894 | summary.append(getSummary(mContext, ssid, getDetailedState(), |
Quang Luong | 19bae88c | 2018-12-14 16:05:05 -0800 | [diff] [blame] | 895 | 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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 905 | } |
Quang Luong | 19bae88c | 2018-12-14 16:05:05 -0800 | [diff] [blame] | 906 | } 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 Kuhne | 446afac | 2017-06-22 16:02:33 -0700 | [diff] [blame] | 918 | break; |
Quang Luong | 19bae88c | 2018-12-14 16:05:05 -0800 | [diff] [blame] | 919 | case WifiConfiguration.NetworkSelectionStatus.DISABLED_BY_WRONG_PASSWORD: |
| 920 | summary.append(mContext.getString(R.string.wifi_check_password_try_again)); |
Glen Kuhne | 446afac | 2017-06-22 16:02:33 -0700 | [diff] [blame] | 921 | break; |
Quang Luong | 19bae88c | 2018-12-14 16:05:05 -0800 | [diff] [blame] | 922 | 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 Luong | 02d8174 | 2018-12-17 16:09:45 -0800 | [diff] [blame] | 936 | } else if (isOsuProvider()) { |
Quang Luong | 8d40a8e | 2019-01-02 16:25:38 -0800 | [diff] [blame] | 937 | 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 Luong | 19bae88c | 2018-12-14 16:05:05 -0800 | [diff] [blame] | 946 | } 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 Kuhne | 446afac | 2017-06-22 16:02:33 -0700 | [diff] [blame] | 961 | } |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 962 | } |
| 963 | } |
| 964 | |
Quang Luong | 19bae88c | 2018-12-14 16:05:05 -0800 | [diff] [blame] | 965 | |
| 966 | |
Sundeep Ghuman | c0cf848 | 2018-01-26 18:23:34 -0800 | [diff] [blame] | 967 | if (isVerboseLoggingEnabled()) { |
Quang Luong | 19bae88c | 2018-12-14 16:05:05 -0800 | [diff] [blame] | 968 | summary.append(WifiUtils.buildLoggingSummary(this, mConfig)); |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 969 | } |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 970 | |
Quang Luong | 19bae88c | 2018-12-14 16:05:05 -0800 | [diff] [blame] | 971 | if (mConfig != null && (WifiUtils.isMeteredOverridden(mConfig) || mConfig.meteredHint)) { |
Salvador Martinez | 6f6fe75 | 2018-03-21 16:33:53 -0700 | [diff] [blame] | 972 | return mContext.getResources().getString( |
| 973 | R.string.preference_summary_default_combination, |
Quang Luong | 19bae88c | 2018-12-14 16:05:05 -0800 | [diff] [blame] | 974 | WifiUtils.getMeteredLabel(mContext, mConfig), |
Salvador Martinez | 6f6fe75 | 2018-03-21 16:33:53 -0700 | [diff] [blame] | 975 | summary.toString()); |
| 976 | } |
| 977 | |
Eric Schwarzenbach | f4f3842b | 2017-07-17 16:45:04 -0700 | [diff] [blame] | 978 | // 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 Ghuman | d3171ca | 2017-07-12 23:02:24 -0700 | [diff] [blame] | 981 | return mContext.getResources().getString( |
| 982 | R.string.preference_summary_default_combination, |
| 983 | getSpeedLabel(), |
| 984 | summary.toString()); |
Eric Schwarzenbach | f4f3842b | 2017-07-17 16:45:04 -0700 | [diff] [blame] | 985 | } else if (getSpeedLabel() != null) { |
| 986 | return getSpeedLabel(); |
Sundeep Ghuman | d3171ca | 2017-07-12 23:02:24 -0700 | [diff] [blame] | 987 | } else { |
| 988 | return summary.toString(); |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 989 | } |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 990 | } |
| 991 | |
| 992 | /** |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 993 | * 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 Kalele | c7a38ef | 2015-06-25 13:55:33 -0700 | [diff] [blame] | 1008 | return mInfo != null && mInfo.isEphemeral() && |
| 1009 | mNetworkInfo != null && mNetworkInfo.getState() != State.DISCONNECTED; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1010 | } |
| 1011 | |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 1012 | /** |
| 1013 | * Return true if this AccessPoint represents a Passpoint AP. |
| 1014 | */ |
Vinit Deshpande | 5b7352c | 2015-07-09 16:53:12 -0700 | [diff] [blame] | 1015 | public boolean isPasspoint() { |
| 1016 | return mConfig != null && mConfig.isPasspoint(); |
| 1017 | } |
| 1018 | |
Mitchell Wills | 5a42db2 | 2015-08-03 09:46:08 -0700 | [diff] [blame] | 1019 | /** |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 1020 | * Return true if this AccessPoint represents a Passpoint provider configuration. |
| 1021 | */ |
| 1022 | public boolean isPasspointConfig() { |
| 1023 | return mFqdn != null; |
| 1024 | } |
| 1025 | |
| 1026 | /** |
Quang Luong | 9051dfd | 2018-12-12 12:49:24 -0800 | [diff] [blame] | 1027 | * Return true if this AccessPoint represents an OSU Provider. |
| 1028 | */ |
| 1029 | public boolean isOsuProvider() { |
| 1030 | return mOsuProvider != null; |
| 1031 | } |
| 1032 | |
| 1033 | /** |
Quang Luong | 4d19484 | 2018-12-18 16:59:49 -0800 | [diff] [blame] | 1034 | * 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 Wills | 5a42db2 | 2015-08-03 09:46:08 -0700 | [diff] [blame] | 1045 | * 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 Deshpande | 5b7352c | 2015-07-09 16:53:12 -0700 | [diff] [blame] | 1050 | if (isPasspoint() == false && networkId != WifiConfiguration.INVALID_NETWORK_ID) { |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1051 | return networkId == info.getNetworkId(); |
Mitchell Wills | 5a42db2 | 2015-08-03 09:46:08 -0700 | [diff] [blame] | 1052 | } else if (config != null) { |
| 1053 | return matches(config); |
| 1054 | } |
| 1055 | else { |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1056 | // 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 Shalom | aa6f920 | 2018-10-16 14:30:02 -0700 | [diff] [blame] | 1080 | if ((security != SECURITY_NONE) && (security != SECURITY_OWE)) { |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1081 | throw new IllegalStateException(); |
Hai Shalom | aa6f920 | 2018-10-16 14:30:02 -0700 | [diff] [blame] | 1082 | } |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1083 | if (mConfig != null) |
| 1084 | return; |
| 1085 | mConfig = new WifiConfiguration(); |
| 1086 | mConfig.SSID = AccessPoint.convertToQuotedString(ssid); |
Hai Shalom | aa6f920 | 2018-10-16 14:30:02 -0700 | [diff] [blame] | 1087 | |
| 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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1094 | } |
| 1095 | |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1096 | public void saveWifiState(Bundle savedState) { |
Vinit Deshpande | fcd4612 | 2015-06-11 18:22:23 -0700 | [diff] [blame] | 1097 | if (ssid != null) savedState.putString(KEY_SSID, getSsidStr()); |
| 1098 | savedState.putInt(KEY_SECURITY, security); |
Sundeep Ghuman | a28050a | 2017-07-12 22:09:25 -0700 | [diff] [blame] | 1099 | savedState.putInt(KEY_SPEED, mSpeed); |
Vinit Deshpande | fcd4612 | 2015-06-11 18:22:23 -0700 | [diff] [blame] | 1100 | savedState.putInt(KEY_PSKTYPE, pskType); |
| 1101 | if (mConfig != null) savedState.putParcelable(KEY_CONFIG, mConfig); |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1102 | savedState.putParcelable(KEY_WIFIINFO, mInfo); |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 1103 | savedState.putParcelableArray(KEY_SCANRESULTS, |
| 1104 | mScanResults.toArray(new Parcelable[mScanResults.size()])); |
Sundeep Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 1105 | savedState.putParcelableArrayList(KEY_SCOREDNETWORKCACHE, |
| 1106 | new ArrayList<>(mScoredNetworkCache.values())); |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1107 | if (mNetworkInfo != null) { |
| 1108 | savedState.putParcelable(KEY_NETWORKINFO, mNetworkInfo); |
| 1109 | } |
Peter Qiu | ced37db | 2017-03-14 15:51:22 -0700 | [diff] [blame] | 1110 | if (mFqdn != null) { |
| 1111 | savedState.putString(KEY_FQDN, mFqdn); |
| 1112 | } |
| 1113 | if (mProviderFriendlyName != null) { |
| 1114 | savedState.putString(KEY_PROVIDER_FRIENDLY_NAME, mProviderFriendlyName); |
| 1115 | } |
Peter Qiu | 280581b | 2017-07-24 14:18:56 -0700 | [diff] [blame] | 1116 | savedState.putBoolean(KEY_IS_CARRIER_AP, mIsCarrierAp); |
| 1117 | savedState.putInt(KEY_CARRIER_AP_EAP_TYPE, mCarrierApEapType); |
| 1118 | savedState.putString(KEY_CARRIER_NAME, mCarrierName); |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1119 | } |
| 1120 | |
| 1121 | public void setListener(AccessPointListener listener) { |
| 1122 | mAccessPointListener = listener; |
| 1123 | } |
| 1124 | |
Sundeep Ghuman | d1e4492 | 2017-08-07 11:21:38 -0700 | [diff] [blame] | 1125 | /** |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 1126 | * Sets {@link #mScanResults} to the given collection. |
Sundeep Ghuman | d1e4492 | 2017-08-07 11:21:38 -0700 | [diff] [blame] | 1127 | * |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 1128 | * @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 Ghuman | d1e4492 | 2017-08-07 11:21:38 -0700 | [diff] [blame] | 1130 | */ |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 1131 | void setScanResults(Collection<ScanResult> scanResults) { |
Sundeep Ghuman | 54bdcfa | 2017-03-08 19:52:05 -0800 | [diff] [blame] | 1132 | |
Quang Luong | 7054e92 | 2018-12-07 16:44:18 -0800 | [diff] [blame] | 1133 | // Validate scan results are for current AP only by matching SSID/BSSID |
Quang Luong | 9051dfd | 2018-12-12 12:49:24 -0800 | [diff] [blame] | 1134 | // Passpoint networks are not bound to a specific SSID/BSSID, so skip this for passpoint. |
| 1135 | if (!isPasspoint() && !isOsuProvider()) { |
Quang Luong | 7054e92 | 2018-12-07 16:44:18 -0800 | [diff] [blame] | 1136 | 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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1145 | } |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 1146 | } |
| 1147 | |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 1148 | 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 Ghuman | 5d14fd7 | 2018-02-15 14:49:15 -0800 | [diff] [blame] | 1158 | ThreadUtils.postOnMainThread(() -> { |
| 1159 | if (mAccessPointListener != null) { |
| 1160 | mAccessPointListener.onLevelChanged(this); |
| 1161 | } |
| 1162 | }); |
| 1163 | |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 1164 | } |
| 1165 | |
Sundeep Ghuman | 5d14fd7 | 2018-02-15 14:49:15 -0800 | [diff] [blame] | 1166 | ThreadUtils.postOnMainThread(() -> { |
| 1167 | if (mAccessPointListener != null) { |
| 1168 | mAccessPointListener.onAccessPointChanged(this); |
| 1169 | } |
| 1170 | }); |
Sundeep Ghuman | 04f7f34 | 2018-01-23 19:18:31 -0800 | [diff] [blame] | 1171 | |
| 1172 | if (!scanResults.isEmpty()) { |
| 1173 | ScanResult result = scanResults.iterator().next(); |
| 1174 | |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1175 | // This flag only comes from scans, is not easily saved in config |
| 1176 | if (security == SECURITY_PSK) { |
| 1177 | pskType = getPskType(result); |
| 1178 | } |
Vinit Deshpande | fcd4612 | 2015-06-11 18:22:23 -0700 | [diff] [blame] | 1179 | |
Peter Qiu | 280581b | 2017-07-24 14:18:56 -0700 | [diff] [blame] | 1180 | // 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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1185 | } |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1186 | } |
| 1187 | |
Quang Luong | 9051dfd | 2018-12-12 12:49:24 -0800 | [diff] [blame] | 1188 | /** |
| 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 Ghuman | d911da3 | 2017-07-05 20:06:05 -0700 | [diff] [blame] | 1199 | public boolean update( |
| 1200 | @Nullable WifiConfiguration config, WifiInfo info, NetworkInfo networkInfo) { |
Sundeep Ghuman | db9b94c | 2017-09-06 11:46:21 -0700 | [diff] [blame] | 1201 | |
Sundeep Ghuman | 8c79288 | 2017-04-04 17:23:29 -0700 | [diff] [blame] | 1202 | boolean updated = false; |
| 1203 | final int oldLevel = getLevel(); |
Mitchell Wills | 5a42db2 | 2015-08-03 09:46:08 -0700 | [diff] [blame] | 1204 | if (info != null && isInfoForThisAccessPoint(config, info)) { |
Sundeep Ghuman | 8c79288 | 2017-04-04 17:23:29 -0700 | [diff] [blame] | 1205 | updated = (mInfo == null); |
Sundeep Ghuman | f4d3302 | 2017-06-05 19:47:36 -0700 | [diff] [blame] | 1206 | 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 Kuhne | d38708c | 2017-07-19 14:53:34 -0700 | [diff] [blame] | 1212 | if (mRssi != info.getRssi() && info.getRssi() != WifiInfo.INVALID_RSSI) { |
Sundeep Ghuman | 8c79288 | 2017-04-04 17:23:29 -0700 | [diff] [blame] | 1213 | mRssi = info.getRssi(); |
| 1214 | updated = true; |
Sundeep Ghuman | 5c5cd7a | 2017-05-03 12:45:44 -0700 | [diff] [blame] | 1215 | } else if (mNetworkInfo != null && networkInfo != null |
| 1216 | && mNetworkInfo.getDetailedState() != networkInfo.getDetailedState()) { |
Sundeep Ghuman | 96a5357 | 2017-04-20 21:25:41 -0700 | [diff] [blame] | 1217 | updated = true; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1218 | } |
Sundeep Ghuman | 8c79288 | 2017-04-04 17:23:29 -0700 | [diff] [blame] | 1219 | mInfo = info; |
Sundeep Ghuman | 8c79288 | 2017-04-04 17:23:29 -0700 | [diff] [blame] | 1220 | mNetworkInfo = networkInfo; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1221 | } else if (mInfo != null) { |
Sundeep Ghuman | 8c79288 | 2017-04-04 17:23:29 -0700 | [diff] [blame] | 1222 | updated = true; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1223 | mInfo = null; |
| 1224 | mNetworkInfo = null; |
Sundeep Ghuman | 8c79288 | 2017-04-04 17:23:29 -0700 | [diff] [blame] | 1225 | } |
| 1226 | if (updated && mAccessPointListener != null) { |
Sundeep Ghuman | 5d14fd7 | 2018-02-15 14:49:15 -0800 | [diff] [blame] | 1227 | ThreadUtils.postOnMainThread(() -> { |
| 1228 | if (mAccessPointListener != null) { |
| 1229 | mAccessPointListener.onAccessPointChanged(this); |
| 1230 | } |
| 1231 | }); |
Sundeep Ghuman | 8c79288 | 2017-04-04 17:23:29 -0700 | [diff] [blame] | 1232 | |
| 1233 | if (oldLevel != getLevel() /* current level */) { |
Sundeep Ghuman | 5d14fd7 | 2018-02-15 14:49:15 -0800 | [diff] [blame] | 1234 | ThreadUtils.postOnMainThread(() -> { |
| 1235 | if (mAccessPointListener != null) { |
| 1236 | mAccessPointListener.onLevelChanged(this); |
| 1237 | } |
| 1238 | }); |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1239 | } |
| 1240 | } |
Sundeep Ghuman | db9b94c | 2017-09-06 11:46:21 -0700 | [diff] [blame] | 1241 | |
Sundeep Ghuman | 8c79288 | 2017-04-04 17:23:29 -0700 | [diff] [blame] | 1242 | return updated; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1243 | } |
| 1244 | |
Sundeep Ghuman | d911da3 | 2017-07-05 20:06:05 -0700 | [diff] [blame] | 1245 | void update(@Nullable WifiConfiguration config) { |
Vinit Deshpande | fc40600 | 2015-04-15 18:10:55 -0700 | [diff] [blame] | 1246 | mConfig = config; |
Quang Luong | 7054e92 | 2018-12-07 16:44:18 -0800 | [diff] [blame] | 1247 | if (mConfig != null) { |
| 1248 | ssid = removeDoubleQuotes(mConfig.SSID); |
| 1249 | } |
Sundeep Ghuman | d911da3 | 2017-07-05 20:06:05 -0700 | [diff] [blame] | 1250 | networkId = config != null ? config.networkId : WifiConfiguration.INVALID_NETWORK_ID; |
Sundeep Ghuman | 5d14fd7 | 2018-02-15 14:49:15 -0800 | [diff] [blame] | 1251 | ThreadUtils.postOnMainThread(() -> { |
| 1252 | if (mAccessPointListener != null) { |
| 1253 | mAccessPointListener.onAccessPointChanged(this); |
| 1254 | } |
| 1255 | }); |
Vinit Deshpande | fc40600 | 2015-04-15 18:10:55 -0700 | [diff] [blame] | 1256 | } |
Shirish Kalele | c7a38ef | 2015-06-25 13:55:33 -0700 | [diff] [blame] | 1257 | |
Sundeep Ghuman | 54bdcfa | 2017-03-08 19:52:05 -0800 | [diff] [blame] | 1258 | @VisibleForTesting |
Sanket Padawe | 0775a98 | 2015-08-19 14:57:46 -0700 | [diff] [blame] | 1259 | void setRssi(int rssi) { |
| 1260 | mRssi = rssi; |
| 1261 | } |
| 1262 | |
Sundeep Ghuman | 54bdcfa | 2017-03-08 19:52:05 -0800 | [diff] [blame] | 1263 | /** Sets the rssi to {@link #UNREACHABLE_RSSI}. */ |
| 1264 | void setUnreachable() { |
| 1265 | setRssi(AccessPoint.UNREACHABLE_RSSI); |
| 1266 | } |
| 1267 | |
Sundeep Ghuman | 55adc6b | 2017-06-05 16:46:59 -0700 | [diff] [blame] | 1268 | int getSpeed() { return mSpeed;} |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 1269 | |
| 1270 | @Nullable |
| 1271 | String getSpeedLabel() { |
Eric Schwarzenbach | 0b8700f | 2017-07-25 14:32:21 -0700 | [diff] [blame] | 1272 | return getSpeedLabel(mSpeed); |
| 1273 | } |
| 1274 | |
| 1275 | @Nullable |
Sundeep Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 1276 | @Speed |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 1277 | private static int roundToClosestSpeedEnum(int speed) { |
Sundeep Ghuman | be3a74c | 2017-08-01 17:50:59 -0700 | [diff] [blame] | 1278 | 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 |
jackqdyulei | 9ee9b39 | 2017-12-22 11:31:49 -0800 | [diff] [blame] | 1292 | String getSpeedLabel(@Speed int speed) { |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 1293 | return getSpeedLabel(mContext, speed); |
| 1294 | } |
| 1295 | |
| 1296 | private static String getSpeedLabel(Context context, int speed) { |
Eric Schwarzenbach | 0b8700f | 2017-07-25 14:32:21 -0700 | [diff] [blame] | 1297 | switch (speed) { |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 1298 | case Speed.VERY_FAST: |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 1299 | return context.getString(R.string.speed_label_very_fast); |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 1300 | case Speed.FAST: |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 1301 | return context.getString(R.string.speed_label_fast); |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 1302 | case Speed.MODERATE: |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 1303 | return context.getString(R.string.speed_label_okay); |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 1304 | case Speed.SLOW: |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 1305 | return context.getString(R.string.speed_label_slow); |
Sundeep Ghuman | 53200ed | 2017-06-21 16:54:36 -0700 | [diff] [blame] | 1306 | case Speed.NONE: |
Sundeep Ghuman | 271e5de | 2017-05-30 14:11:39 -0700 | [diff] [blame] | 1307 | default: |
| 1308 | return null; |
| 1309 | } |
Sundeep Ghuman | 5519b7b | 2016-12-14 17:53:31 -0800 | [diff] [blame] | 1310 | } |
| 1311 | |
Amin Shaikh | e74dbdd | 2018-03-09 16:05:30 -0500 | [diff] [blame] | 1312 | /** 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 Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 1318 | /** Return true if the current RSSI is reachable, and false otherwise. */ |
Sundeep Ghuman | aaa8a1b | 2017-03-13 14:40:56 -0700 | [diff] [blame] | 1319 | public boolean isReachable() { |
Dave Schaefer | 9853743 | 2017-02-08 11:26:08 -0800 | [diff] [blame] | 1320 | return mRssi != UNREACHABLE_RSSI; |
| 1321 | } |
| 1322 | |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1323 | public static String getSummary(Context context, String ssid, DetailedState state, |
Vinit Deshpande | fc40600 | 2015-04-15 18:10:55 -0700 | [diff] [blame] | 1324 | boolean isEphemeral, String passpointProvider) { |
Quang Luong | 0a3edf0 | 2018-12-17 14:50:58 -0800 | [diff] [blame] | 1325 | if (state == DetailedState.CONNECTED) { |
| 1326 | if (!TextUtils.isEmpty(passpointProvider)) { |
Vinit Deshpande | dcf00c9 | 2015-04-15 18:32:09 -0700 | [diff] [blame] | 1327 | // Special case for connected + passpoint networks. |
Quang Luong | 0a3edf0 | 2018-12-17 14:50:58 -0800 | [diff] [blame] | 1328 | String format = context.getString(R.string.ssid_by_passpoint_provider); |
| 1329 | return String.format(format, ssid, passpointProvider); |
Vinit Deshpande | dcf00c9 | 2015-04-15 18:32:09 -0700 | [diff] [blame] | 1330 | } else if (isEphemeral) { |
Vinit Deshpande | fc40600 | 2015-04-15 18:10:55 -0700 | [diff] [blame] | 1331 | // Special case for connected + ephemeral networks. |
Stephen Chen | 36dd5cf1 | 2017-03-20 13:27:51 -0700 | [diff] [blame] | 1332 | 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 Deshpande | fc40600 | 2015-04-15 18:10:55 -0700 | [diff] [blame] | 1341 | } |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1342 | } |
| 1343 | |
Sanket Padawe | 7094d22 | 2015-05-01 16:55:00 -0700 | [diff] [blame] | 1344 | // 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 Colitti | 1317e04 | 2016-12-13 13:30:07 +0900 | [diff] [blame] | 1350 | NetworkCapabilities nc = null; |
Sanket Padawe | 7094d22 | 2015-05-01 16:55:00 -0700 | [diff] [blame] | 1351 | |
| 1352 | try { |
Lorenzo Colitti | 1317e04 | 2016-12-13 13:30:07 +0900 | [diff] [blame] | 1353 | nc = cm.getNetworkCapabilities(wifiManager.getCurrentNetwork()); |
| 1354 | } catch (RemoteException e) {} |
| 1355 | |
| 1356 | if (nc != null) { |
| 1357 | if (nc.hasCapability(nc.NET_CAPABILITY_CAPTIVE_PORTAL)) { |
Maurice Lam | 7f6fc86 | 2017-07-12 16:43:49 -0700 | [diff] [blame] | 1358 | int id = context.getResources() |
| 1359 | .getIdentifier("network_available_sign_in", "string", "android"); |
| 1360 | return context.getString(id); |
Lorenzo Colitti | 1317e04 | 2016-12-13 13:30:07 +0900 | [diff] [blame] | 1361 | } else if (!nc.hasCapability(NetworkCapabilities.NET_CAPABILITY_VALIDATED)) { |
| 1362 | return context.getString(R.string.wifi_connected_no_internet); |
| 1363 | } |
Sanket Padawe | 7094d22 | 2015-05-01 16:55:00 -0700 | [diff] [blame] | 1364 | } |
| 1365 | } |
Fan Zhang | 6acb766 | 2016-10-17 12:40:03 -0700 | [diff] [blame] | 1366 | if (state == null) { |
| 1367 | Log.w(TAG, "state is null, returning empty summary"); |
| 1368 | return ""; |
| 1369 | } |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1370 | 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 Padawe | 3e9e5fa | 2015-05-28 10:41:14 -0700 | [diff] [blame] | 1375 | return ""; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1376 | } |
| 1377 | return String.format(formats[index], ssid); |
| 1378 | } |
| 1379 | |
| 1380 | public static String getSummary(Context context, DetailedState state, boolean isEphemeral) { |
Vinit Deshpande | fc40600 | 2015-04-15 18:10:55 -0700 | [diff] [blame] | 1381 | 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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1387 | } |
| 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 Shalom | aa6f920 | 2018-10-16 14:30:02 -0700 | [diff] [blame] | 1411 | } else if (result.capabilities.contains("SAE")) { |
| 1412 | return SECURITY_SAE; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1413 | } else if (result.capabilities.contains("PSK")) { |
| 1414 | return SECURITY_PSK; |
Hai Shalom | aa6f920 | 2018-10-16 14:30:02 -0700 | [diff] [blame] | 1415 | } else if (result.capabilities.contains("EAP_SUITE_B_192")) { |
| 1416 | return SECURITY_EAP_SUITE_B; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1417 | } else if (result.capabilities.contains("EAP")) { |
| 1418 | return SECURITY_EAP; |
Hai Shalom | aa6f920 | 2018-10-16 14:30:02 -0700 | [diff] [blame] | 1419 | } else if (result.capabilities.contains("OWE")) { |
| 1420 | return SECURITY_OWE; |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1421 | } |
Hai Shalom | aa6f920 | 2018-10-16 14:30:02 -0700 | [diff] [blame] | 1422 | |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1423 | return SECURITY_NONE; |
| 1424 | } |
| 1425 | |
| 1426 | static int getSecurity(WifiConfiguration config) { |
Hai Shalom | aa6f920 | 2018-10-16 14:30:02 -0700 | [diff] [blame] | 1427 | if (config.allowedKeyManagement.get(KeyMgmt.SAE)) { |
| 1428 | return SECURITY_SAE; |
| 1429 | } |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1430 | if (config.allowedKeyManagement.get(KeyMgmt.WPA_PSK)) { |
| 1431 | return SECURITY_PSK; |
| 1432 | } |
Hai Shalom | aa6f920 | 2018-10-16 14:30:02 -0700 | [diff] [blame] | 1433 | if (config.allowedKeyManagement.get(KeyMgmt.SUITE_B_192)) { |
| 1434 | return SECURITY_EAP_SUITE_B; |
| 1435 | } |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1436 | if (config.allowedKeyManagement.get(KeyMgmt.WPA_EAP) || |
| 1437 | config.allowedKeyManagement.get(KeyMgmt.IEEE8021X)) { |
| 1438 | return SECURITY_EAP; |
| 1439 | } |
Hai Shalom | aa6f920 | 2018-10-16 14:30:02 -0700 | [diff] [blame] | 1440 | if (config.allowedKeyManagement.get(KeyMgmt.OWE)) { |
| 1441 | return SECURITY_OWE; |
| 1442 | } |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1443 | 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 Shalom | aa6f920 | 2018-10-16 14:30:02 -0700 | [diff] [blame] | 1460 | } 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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1466 | } |
| 1467 | return "NONE"; |
| 1468 | } |
| 1469 | |
| 1470 | static String removeDoubleQuotes(String string) { |
Jason Monk | 2b51cc3 | 2015-05-13 11:07:53 -0400 | [diff] [blame] | 1471 | if (TextUtils.isEmpty(string)) { |
| 1472 | return ""; |
| 1473 | } |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1474 | 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 Ghuman | bb39991 | 2018-01-29 18:31:15 -0800 | [diff] [blame] | 1482 | /** |
| 1483 | * Callbacks relaying changes to the AccessPoint representation. |
| 1484 | * |
| 1485 | * <p>All methods are invoked on the Main Thread. |
| 1486 | */ |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1487 | public interface AccessPointListener { |
Sundeep Ghuman | bb39991 | 2018-01-29 18:31:15 -0800 | [diff] [blame] | 1488 | /** |
| 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 Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1517 | } |
Sundeep Ghuman | c0cf848 | 2018-01-26 18:23:34 -0800 | [diff] [blame] | 1518 | |
| 1519 | private static boolean isVerboseLoggingEnabled() { |
| 1520 | return WifiTracker.sVerboseLogging || Log.isLoggable(TAG, Log.VERBOSE); |
| 1521 | } |
Quang Luong | 4d19484 | 2018-12-18 16:59:49 -0800 | [diff] [blame] | 1522 | |
| 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 Luong | 8d40a8e | 2019-01-02 16:25:38 -0800 | [diff] [blame] | 1532 | 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 Luong | 4d19484 | 2018-12-18 16:59:49 -0800 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | @Override |
| 1625 | @MainThread public void onProvisioningStatus(int status) { |
Quang Luong | 8d40a8e | 2019-01-02 16:25:38 -0800 | [diff] [blame] | 1626 | 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 Luong | 4d19484 | 2018-12-18 16:59:49 -0800 | [diff] [blame] | 1682 | } |
| 1683 | } |
Jason Monk | d52356a | 2015-01-28 10:40:41 -0500 | [diff] [blame] | 1684 | } |