1 /* 2 * Copyright (C) 2016 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.server.wifi; 18 19 import static com.android.server.wifi.WifiConfigurationTestUtil.SECURITY_NONE; 20 import static com.android.server.wifi.WifiConfigurationTestUtil.SECURITY_PSK; 21 22 import static org.junit.Assert.*; 23 import static org.mockito.Mockito.*; 24 25 import android.content.Context; 26 import android.content.res.Resources; 27 import android.net.wifi.ScanResult; 28 import android.net.wifi.WifiConfiguration; 29 import android.os.SystemClock; 30 import android.support.test.filters.SmallTest; 31 import android.util.LocalLog; 32 33 import com.android.internal.R; 34 import com.android.server.wifi.WifiNetworkSelectorTestUtil.ScanDetailsAndWifiConfigs; 35 36 import org.junit.After; 37 import org.junit.Before; 38 import org.junit.Test; 39 import org.mockito.Mock; 40 import org.mockito.MockitoAnnotations; 41 42 import java.util.List; 43 44 /** 45 * Unit tests for {@link com.android.server.wifi.SavedNetworkEvaluator}. 46 */ 47 @SmallTest 48 public class SavedNetworkEvaluatorTest { 49 50 /** Sets up test. */ 51 @Before 52 public void setUp() throws Exception { 53 MockitoAnnotations.initMocks(this); 54 setupContext(); 55 setupResource(); 56 setupWifiConfigManager(); 57 mLocalLog = new LocalLog(512); 58 59 when(mWifiConnectivityHelper.isFirmwareRoamingSupported()).thenReturn(false); 60 when(mClock.getElapsedSinceBootMillis()).thenReturn(SystemClock.elapsedRealtime()); 61 62 mThresholdMinimumRssi2G = mResource.getInteger( 63 R.integer.config_wifi_framework_wifi_score_bad_rssi_threshold_24GHz); 64 mThresholdMinimumRssi5G = mResource.getInteger( 65 R.integer.config_wifi_framework_wifi_score_bad_rssi_threshold_5GHz); 66 mThresholdQualifiedRssi2G = mResource.getInteger( 67 R.integer.config_wifi_framework_wifi_score_low_rssi_threshold_24GHz); 68 mThresholdQualifiedRssi5G = mResource.getInteger( 69 R.integer.config_wifi_framework_wifi_score_low_rssi_threshold_5GHz); 70 mThresholdSaturatedRssi2G = mResource.getInteger( 71 R.integer.config_wifi_framework_wifi_score_good_rssi_threshold_24GHz); 72 mThresholdSaturatedRssi5G = mResource.getInteger( 73 R.integer.config_wifi_framework_wifi_score_good_rssi_threshold_5GHz); 74 75 mSavedNetworkEvaluator = new SavedNetworkEvaluator(mContext, 76 new ScoringParams(mContext), mWifiConfigManager, 77 mClock, mLocalLog, mWifiConnectivityHelper); 78 } 79 80 /** Cleans up test. */ 81 @After 82 public void cleanup() { 83 validateMockitoUsage(); 84 } 85 86 private SavedNetworkEvaluator mSavedNetworkEvaluator; 87 @Mock private WifiConfigManager mWifiConfigManager; 88 @Mock private WifiConnectivityHelper mWifiConnectivityHelper; 89 @Mock private Context mContext; 90 @Mock private Resources mResource; 91 @Mock private Clock mClock; 92 private LocalLog mLocalLog; 93 private int mThresholdMinimumRssi2G; 94 private int mThresholdMinimumRssi5G; 95 private int mThresholdQualifiedRssi2G; 96 private int mThresholdQualifiedRssi5G; 97 private int mThresholdSaturatedRssi2G; 98 private int mThresholdSaturatedRssi5G; 99 100 private void setupContext() { 101 when(mContext.getResources()).thenReturn(mResource); 102 } 103 104 private void setupResource() { 105 when(mResource.getInteger( 106 R.integer.config_wifi_framework_wifi_score_good_rssi_threshold_5GHz)) 107 .thenReturn(-57); 108 when(mResource.getInteger( 109 R.integer.config_wifi_framework_wifi_score_good_rssi_threshold_24GHz)) 110 .thenReturn(-60); 111 when(mResource.getInteger( 112 R.integer.config_wifi_framework_wifi_score_low_rssi_threshold_5GHz)) 113 .thenReturn(-70); 114 when(mResource.getInteger( 115 R.integer.config_wifi_framework_wifi_score_low_rssi_threshold_24GHz)) 116 .thenReturn(-73); 117 when(mResource.getInteger( 118 R.integer.config_wifi_framework_wifi_score_bad_rssi_threshold_5GHz)) 119 .thenReturn(-82); 120 when(mResource.getInteger( 121 R.integer.config_wifi_framework_wifi_score_bad_rssi_threshold_24GHz)) 122 .thenReturn(-85); 123 when(mResource.getInteger( 124 R.integer.config_wifi_framework_RSSI_SCORE_SLOPE)) 125 .thenReturn(4); 126 when(mResource.getInteger( 127 R.integer.config_wifi_framework_RSSI_SCORE_OFFSET)) 128 .thenReturn(85); 129 when(mResource.getInteger( 130 R.integer.config_wifi_framework_SAME_BSSID_AWARD)) 131 .thenReturn(24); 132 when(mResource.getInteger( 133 R.integer.config_wifi_framework_SECURITY_AWARD)) 134 .thenReturn(80); 135 when(mResource.getInteger( 136 R.integer.config_wifi_framework_5GHz_preference_boost_factor)) 137 .thenReturn(16); 138 when(mResource.getInteger( 139 R.integer.config_wifi_framework_current_network_boost)) 140 .thenReturn(16); 141 } 142 143 private void setupWifiConfigManager() { 144 when(mWifiConfigManager.getLastSelectedNetwork()) 145 .thenReturn(WifiConfiguration.INVALID_NETWORK_ID); 146 } 147 148 /** 149 * Do not evaluate networks that {@link WifiConfiguration#useExternalScores}. 150 */ 151 @Test 152 public void ignoreNetworksIfUseExternalScores() { 153 String[] ssids = {"\"test1\"", "\"test2\""}; 154 String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"}; 155 int[] freqs = {2470, 2437}; 156 String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[WPA2-EAP-CCMP][ESS]"}; 157 int[] levels = {mThresholdQualifiedRssi2G + 8, mThresholdQualifiedRssi2G + 10}; 158 int[] securities = {SECURITY_PSK, SECURITY_PSK}; 159 160 ScanDetailsAndWifiConfigs scanDetailsAndConfigs = 161 WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, 162 freqs, caps, levels, securities, mWifiConfigManager, mClock); 163 List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); 164 WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); 165 for (WifiConfiguration wifiConfiguration : savedConfigs) { 166 wifiConfiguration.useExternalScores = true; 167 } 168 169 WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, 170 null, null, true, false, null); 171 172 assertNull(candidate); 173 } 174 175 /** 176 * Do not evaluate networks that {@link WifiConfiguration#isEphemeral}. 177 */ 178 @Test 179 public void ignoreEphemeralNetworks() { 180 String[] ssids = {"\"test1\"", "\"test2\""}; 181 String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"}; 182 int[] freqs = {2470, 2437}; 183 String[] caps = {"[ESS]", "[ESS]"}; 184 int[] levels = {mThresholdQualifiedRssi2G + 8, mThresholdQualifiedRssi2G + 10}; 185 int[] securities = {SECURITY_NONE, SECURITY_NONE}; 186 187 ScanDetailsAndWifiConfigs scanDetailsAndConfigs = 188 WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, 189 freqs, caps, levels, securities, mWifiConfigManager, mClock); 190 List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); 191 WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); 192 for (WifiConfiguration wifiConfiguration : savedConfigs) { 193 wifiConfiguration.ephemeral = true; 194 } 195 196 WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, 197 null, null, true, false, null); 198 199 assertNull(candidate); 200 } 201 202 /** 203 * Set the candidate {@link ScanResult} for all {@link WifiConfiguration}s regardless of 204 * whether they are secure saved, open saved, or {@link WifiConfiguration#useExternalScores}. 205 */ 206 @Test 207 public void setCandidateScanResultsForAllSavedNetworks() { 208 String[] ssids = {"\"test1\"", "\"test2\"", "\"test3\""}; 209 String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4", "6c:f3:7f:ae:8c:f5"}; 210 int[] freqs = {5200, 5220, 5240}; 211 String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[ESS]", "[WPA2-EAP-CCMP][ESS]"}; 212 int[] levels = 213 {mThresholdQualifiedRssi5G, mThresholdQualifiedRssi5G, mThresholdQualifiedRssi5G}; 214 int[] securities = {SECURITY_PSK, SECURITY_NONE, SECURITY_PSK}; 215 216 ScanDetailsAndWifiConfigs scanDetailsAndConfigs = 217 WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, 218 freqs, caps, levels, securities, mWifiConfigManager, mClock); 219 List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); 220 WifiConfiguration useExternalScoresConfig = scanDetailsAndConfigs.getWifiConfigs()[0]; 221 useExternalScoresConfig.useExternalScores = true; 222 WifiConfiguration openNetworkConfig = scanDetailsAndConfigs.getWifiConfigs()[1]; 223 WifiConfiguration secureNetworkConfig = scanDetailsAndConfigs.getWifiConfigs()[2]; 224 225 mSavedNetworkEvaluator.evaluateNetworks(scanDetails, null, null, true, false, null); 226 227 verify(mWifiConfigManager, atLeastOnce()).setNetworkCandidateScanResult( 228 eq(useExternalScoresConfig.networkId), 229 eq(scanDetails.get(0).getScanResult()), 230 anyInt()); 231 verify(mWifiConfigManager, atLeastOnce()).setNetworkCandidateScanResult( 232 eq(openNetworkConfig.networkId), 233 eq(scanDetails.get(1).getScanResult()), 234 anyInt()); 235 verify(mWifiConfigManager, atLeastOnce()).setNetworkCandidateScanResult( 236 eq(secureNetworkConfig.networkId), 237 eq(scanDetails.get(2).getScanResult()), 238 anyInt()); 239 } 240 241 /** 242 * Between two 2G networks, choose the one with stronger RSSI value if other conditions 243 * are the same and the RSSI values are not saturated. 244 */ 245 @Test 246 public void chooseStrongerRssi2GNetwork() { 247 String[] ssids = {"\"test1\"", "\"test2\""}; 248 String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"}; 249 int[] freqs = {2470, 2437}; 250 String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[WPA2-EAP-CCMP][ESS]"}; 251 int[] levels = {mThresholdQualifiedRssi2G + 8, mThresholdQualifiedRssi2G + 10}; 252 int[] securities = {SECURITY_PSK, SECURITY_PSK}; 253 254 ScanDetailsAndWifiConfigs scanDetailsAndConfigs = 255 WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, 256 freqs, caps, levels, securities, mWifiConfigManager, mClock); 257 List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); 258 WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); 259 260 WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, 261 null, null, true, false, null); 262 263 ScanResult chosenScanResult = scanDetails.get(1).getScanResult(); 264 WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate); 265 WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, 266 chosenScanResult, candidate); 267 } 268 269 /** 270 * Between two 5G networks, choose the one with stronger RSSI value if other conditions 271 * are the same and the RSSI values are not saturated. 272 */ 273 @Test 274 public void chooseStrongerRssi5GNetwork() { 275 String[] ssids = {"\"test1\"", "\"test2\""}; 276 String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"}; 277 int[] freqs = {5200, 5240}; 278 String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[WPA2-EAP-CCMP][ESS]"}; 279 int[] levels = {mThresholdQualifiedRssi5G + 8, mThresholdQualifiedRssi5G + 10}; 280 int[] securities = {SECURITY_PSK, SECURITY_PSK}; 281 282 ScanDetailsAndWifiConfigs scanDetailsAndConfigs = 283 WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, 284 freqs, caps, levels, securities, mWifiConfigManager, mClock); 285 List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); 286 WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); 287 288 WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, 289 null, null, true, false, null); 290 291 ScanResult chosenScanResult = scanDetails.get(1).getScanResult(); 292 WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate); 293 WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, 294 chosenScanResult, candidate); 295 } 296 297 /** 298 * Choose secure network over open network if other conditions are the same. 299 */ 300 @Test 301 public void chooseSecureNetworkOverOpenNetwork() { 302 String[] ssids = {"\"test1\"", "\"test2\""}; 303 String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"}; 304 int[] freqs = {5200, 5240}; 305 String[] caps = {"[ESS]", "[WPA2-EAP-CCMP][ESS]"}; 306 int[] levels = {mThresholdQualifiedRssi5G, mThresholdQualifiedRssi5G}; 307 int[] securities = {SECURITY_NONE, SECURITY_PSK}; 308 309 ScanDetailsAndWifiConfigs scanDetailsAndConfigs = 310 WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, 311 freqs, caps, levels, securities, mWifiConfigManager, mClock); 312 List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); 313 WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); 314 315 WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, 316 null, null, true, false, null); 317 318 ScanResult chosenScanResult = scanDetails.get(1).getScanResult(); 319 WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate); 320 WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, 321 chosenScanResult, candidate); 322 } 323 324 /** 325 * Choose 5G network over 2G network if other conditions are the same. 326 */ 327 @Test 328 public void choose5GNetworkOver2GNetwork() { 329 String[] ssids = {"\"test1\"", "\"test2\""}; 330 String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"}; 331 int[] freqs = {2437, 5240}; 332 String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[WPA2-EAP-CCMP][ESS]"}; 333 int[] levels = {mThresholdQualifiedRssi2G, mThresholdQualifiedRssi5G}; 334 int[] securities = {SECURITY_PSK, SECURITY_PSK}; 335 336 ScanDetailsAndWifiConfigs scanDetailsAndConfigs = 337 WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, 338 freqs, caps, levels, securities, mWifiConfigManager, mClock); 339 List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); 340 WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); 341 342 WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, 343 null, null, true, false, null); 344 345 ScanResult chosenScanResult = scanDetails.get(1).getScanResult(); 346 WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate); 347 WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, 348 chosenScanResult, candidate); 349 } 350 351 /** 352 * Verify that we stick to the currently connected network if the other one is 353 * just slightly better scored. 354 */ 355 @Test 356 public void stickToCurrentNetwork() { 357 String[] ssids = {"\"test1\"", "\"test2\""}; 358 String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"}; 359 int[] freqs = {5200, 5240}; 360 String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[WPA2-EAP-CCMP][ESS]"}; 361 // test2 has slightly stronger RSSI value than test1 362 int[] levels = {mThresholdMinimumRssi5G + 2, mThresholdMinimumRssi5G + 4}; 363 int[] securities = {SECURITY_PSK, SECURITY_PSK}; 364 365 ScanDetailsAndWifiConfigs scanDetailsAndConfigs = 366 WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, 367 freqs, caps, levels, securities, mWifiConfigManager, mClock); 368 List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); 369 WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); 370 371 // Simuluate we are connected to SSID test1 already. 372 WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, 373 savedConfigs[0], null, true, false, null); 374 375 // Even though test2 has higher RSSI value, test1 is chosen because of the 376 // currently connected network bonus. 377 ScanResult chosenScanResult = scanDetails.get(0).getScanResult(); 378 WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate); 379 WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, 380 chosenScanResult, candidate); 381 } 382 383 /** 384 * Verify that we stick to the currently connected BSSID if the other one is 385 * just slightly better scored. 386 */ 387 @Test 388 public void stickToCurrentBSSID() { 389 // Same SSID 390 String[] ssids = {"\"test1\"", "\"test1\""}; 391 String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"}; 392 int[] freqs = {5200, 5240}; 393 String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[WPA2-EAP-CCMP][ESS]"}; 394 // test2 has slightly stronger RSSI value than test1 395 int[] levels = {mThresholdMinimumRssi5G + 2, mThresholdMinimumRssi5G + 6}; 396 int[] securities = {SECURITY_PSK, SECURITY_PSK}; 397 398 ScanDetailsAndWifiConfigs scanDetailsAndConfigs = 399 WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, 400 freqs, caps, levels, securities, mWifiConfigManager, mClock); 401 List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); 402 WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); 403 404 // Simuluate we are connected to BSSID "6c:f3:7f:ae:8c:f3" already 405 WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, 406 null, bssids[0], true, false, null); 407 408 // Even though test2 has higher RSSI value, test1 is chosen because of the 409 // currently connected BSSID bonus. 410 ScanResult chosenScanResult = scanDetails.get(0).getScanResult(); 411 WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate); 412 } 413 414 /** 415 * Verify that the same BSSID award is applied to all the BSSIDs which are under the same 416 * network as the currently connected BSSID. 417 */ 418 @Test 419 public void currentBssidAwardForAllBssidsWithinTheSameNetworkWhenFirmwareRoamingSupported() { 420 // Three BSSIDs are carefully setup there: 421 // BSSID_0 and BSSID_1 have the same SSID and security type, so they are considered under 422 // the same 2.4 GHz network. BSSID_1 RSSI is stronger than BSSID_0. 423 // BSSID_2 is under a 5GHz network different from BSSID_0 and BSSID_1. Its RSSI is 424 // slightly stronger than BSSID_1. 425 // 426 // When firmware roaming is not supported, BSSID_2 has higher score than BSSID_0 and 427 // BSSID_1. 428 // When firmware roaming is suported, BSSID_1 has higher score than BSSID_2 because the 429 // same BSSID award is now applied to both BSSID_0 and BSSID_1. 430 String[] ssids = {"\"test1\"", "\"test1\"", "\"test2\""}; 431 String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4", "6c:f3:7f:ae:8c:f5"}; 432 int[] freqs = {2470, 2437, 5200}; 433 String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[WPA2-EAP-CCMP][ESS]", "[WPA2-EAP-CCMP][ESS]"}; 434 int[] levels = {mThresholdMinimumRssi2G + 2, mThresholdMinimumRssi2G + 5, 435 mThresholdMinimumRssi5G + 7}; 436 int[] securities = {SECURITY_PSK, SECURITY_PSK, SECURITY_PSK}; 437 438 ScanDetailsAndWifiConfigs scanDetailsAndConfigs = 439 WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, 440 freqs, caps, levels, securities, mWifiConfigManager, mClock); 441 List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); 442 WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); 443 444 // Firmware roaming is not supported. 445 when(mWifiConnectivityHelper.isFirmwareRoamingSupported()).thenReturn(false); 446 // Simuluate we are connected to BSSID_0 already. 447 WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, 448 savedConfigs[0], bssids[0], true, false, null); 449 // Verify that BSSID_2 is chosen. 450 ScanResult chosenScanResult = scanDetails.get(2).getScanResult(); 451 WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[2], candidate); 452 WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, 453 chosenScanResult, candidate); 454 455 // Firmware roaming is supported. 456 when(mWifiConnectivityHelper.isFirmwareRoamingSupported()).thenReturn(true); 457 // Simuluate we are connected to BSSID_0 already. 458 candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, 459 savedConfigs[0], bssids[0], true, false, null); 460 // Verify that BSSID_1 is chosen. 461 chosenScanResult = scanDetails.get(1).getScanResult(); 462 WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate); 463 WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, 464 chosenScanResult, candidate); 465 } 466 467 /** 468 * One 2.4GHz network and one 5GHz network have the same security type. Perform 469 * the following tests to verify that once across the RSSI saturation threshold 470 * stronger RSSI value doesn't increase network score. 471 * 472 * 1) Both 2.4GHz network and 5GHz network have the same RSSI value, 473 * mThresholdQualifiedRssi2G, which is below the saturation threshold. 5GHz 474 * network is chosen because of the 5G band award. 475 * 2) Bump up 2.4GHz network RSSI 20dBm higher. Verify that it helps the 2.4GHz network 476 * score and it gets chosen over the 5GHz network. 477 * 3) Bring both 2.4GHz network and 5GHz network RSSI value to mThresholdSaturatedRssi2G. 478 * Verify that 5GHz network is chosen because of the 5G band award. 479 * 4) Bump up 2.4GHz network RSSI to be 20dBm higher than mThresholdSaturatedRssi2G. 480 * Verify that the incresed RSSI doesn't help 2.4GHz network score and 5GHz network 481 * is still chosen. 482 */ 483 @Test 484 public void saturatedRssiAddsNoWeightToNetwork() { 485 String[] ssids = {"\"test1\"", "\"test2\""}; 486 String[] bssids = {"6c:f3:7f:ae:8c:f3", "6c:f3:7f:ae:8c:f4"}; 487 int[] freqs = {2437, 5400}; 488 String[] caps = {"[WPA2-EAP-CCMP][ESS]", "[WPA2-EAP-CCMP][ESS]"}; 489 int[] securities = {SECURITY_PSK, SECURITY_PSK}; 490 491 // 1) The RSSI of both networks is mThresholdQualifiedRssi2G 492 int[] levels = {mThresholdQualifiedRssi2G, mThresholdQualifiedRssi2G}; 493 ScanDetailsAndWifiConfigs scanDetailsAndConfigs = 494 WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, bssids, 495 freqs, caps, levels, securities, mWifiConfigManager, mClock); 496 List<ScanDetail> scanDetails = scanDetailsAndConfigs.getScanDetails(); 497 WifiConfiguration[] savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); 498 WifiConfiguration candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, 499 null, null, false, false, null); 500 // Verify that 5GHz network is chosen because of 5G band award 501 ScanResult chosenScanResult = scanDetails.get(1).getScanResult(); 502 WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate); 503 WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, 504 chosenScanResult, candidate); 505 506 // 2) Bump up 2.4GHz network RSSI by 20dBm. 507 levels[0] = mThresholdQualifiedRssi2G + 20; 508 scanDetailsAndConfigs = WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, 509 bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock); 510 scanDetails = scanDetailsAndConfigs.getScanDetails(); 511 savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); 512 candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, null, null, false, 513 false, null); 514 // Verify that 2.4GHz network is chosen because of much higher RSSI value 515 chosenScanResult = scanDetails.get(0).getScanResult(); 516 WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[0], candidate); 517 WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, 518 chosenScanResult, candidate); 519 520 // 3) Bring both 2.4GHz network and 5GHz network RSSI to mThresholdSaturatedRssi2G 521 levels[0] = levels[1] = mThresholdSaturatedRssi2G; 522 scanDetailsAndConfigs = WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, 523 bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock); 524 scanDetails = scanDetailsAndConfigs.getScanDetails(); 525 savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); 526 candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, null, null, false, 527 false, null); 528 // Verify that 5GHz network is chosen because of 5G band award 529 chosenScanResult = scanDetails.get(1).getScanResult(); 530 WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate); 531 WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, 532 chosenScanResult, candidate); 533 534 // 4) Bump 2.4GHz network RSSI to be 20dBm higher than mThresholdSaturatedRssi2G 535 levels[0] = mThresholdSaturatedRssi2G + 20; 536 scanDetailsAndConfigs = WifiNetworkSelectorTestUtil.setupScanDetailsAndConfigStore(ssids, 537 bssids, freqs, caps, levels, securities, mWifiConfigManager, mClock); 538 scanDetails = scanDetailsAndConfigs.getScanDetails(); 539 savedConfigs = scanDetailsAndConfigs.getWifiConfigs(); 540 candidate = mSavedNetworkEvaluator.evaluateNetworks(scanDetails, null, null, false, 541 false, null); 542 // Verify that the increased RSSI doesn't help 2.4GHz network and 5GHz network 543 // is still chosen 544 chosenScanResult = scanDetails.get(1).getScanResult(); 545 WifiConfigurationTestUtil.assertConfigurationEqual(savedConfigs[1], candidate); 546 WifiNetworkSelectorTestUtil.verifySelectedScanResult(mWifiConfigManager, 547 chosenScanResult, candidate); 548 } 549 } 550