diff options
author | Oscar Shu <xshu@google.com> | 2020-02-10 18:09:26 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-02-10 18:09:26 +0000 |
commit | ed3462deff78af1f557b7f2675061aadddea7496 (patch) | |
tree | f285d1c0eeca606d6e443de08fbb6dbc7389e0cc | |
parent | 4e064770c7408b07d500415c6b723e1a5cda922c (diff) | |
parent | 0c3faa4a375a7dce1da1d5d3899efba118a7bda0 (diff) |
Merge "Shorten block duration at low RSSI"
6 files changed, 157 insertions, 51 deletions
diff --git a/service/java/com/android/server/wifi/BssidBlocklistMonitor.java b/service/java/com/android/server/wifi/BssidBlocklistMonitor.java index 623e63a67..4a1d2882f 100644 --- a/service/java/com/android/server/wifi/BssidBlocklistMonitor.java +++ b/service/java/com/android/server/wifi/BssidBlocklistMonitor.java @@ -134,20 +134,14 @@ public class BssidBlocklistMonitor { * @param failureStreak should be greater or equal to 0. * @return duration to block the BSSID in milliseconds */ - private long getBlocklistDurationWithExponentialBackoff(int failureStreak) { - int maxBlocklistDurationMs = mContext.getResources().getInteger( - R.integer.config_wifiBssidBlocklistMonitorMaxBlockDurationMs); - if (failureStreak > mContext.getResources().getInteger( - R.integer.config_wifiBssidBlocklistMonitorFailureStreakCap)) { - return maxBlocklistDurationMs; - } - int baseBlocklistDurationMs = mContext.getResources().getInteger( - R.integer.config_wifiBssidBlocklistMonitorBaseBlockDurationMs); + private long getBlocklistDurationWithExponentialBackoff(int failureStreak, + int baseBlocklistDurationMs) { + failureStreak = Math.min(failureStreak, mContext.getResources().getInteger( + R.integer.config_wifiBssidBlocklistMonitorFailureStreakCap)); if (failureStreak < 1) { return baseBlocklistDurationMs; } - long duration = (long) (Math.pow(2.0, (double) failureStreak) * baseBlocklistDurationMs); - return Math.min(maxBlocklistDurationMs, duration); + return (long) (Math.pow(2.0, (double) failureStreak) * baseBlocklistDurationMs); } /** @@ -271,7 +265,7 @@ public class BssidBlocklistMonitor { } private boolean handleBssidConnectionFailureInternal(String bssid, String ssid, - @FailureReason int reasonCode) { + @FailureReason int reasonCode, boolean isLowRssi) { BssidStatus entry = incrementFailureCountForBssid(bssid, ssid, reasonCode); int failureThreshold = getFailureThresholdForReason(reasonCode); int currentStreak = mWifiScoreCard.getBssidBlocklistStreak(ssid, bssid, reasonCode); @@ -281,7 +275,15 @@ public class BssidBlocklistMonitor { if (shouldWaitForWatchdogToTriggerFirst(bssid, reasonCode)) { return false; } - addToBlocklist(entry, getBlocklistDurationWithExponentialBackoff(currentStreak), + int baseBlockDurationMs = mContext.getResources().getInteger( + R.integer.config_wifiBssidBlocklistMonitorBaseBlockDurationMs); + if ((reasonCode == REASON_ASSOCIATION_TIMEOUT + || reasonCode == REASON_ABNORMAL_DISCONNECT) && isLowRssi) { + baseBlockDurationMs = mContext.getResources().getInteger( + R.integer.config_wifiBssidBlocklistMonitorBaseLowRssiBlockDurationMs); + } + addToBlocklist(entry, + getBlocklistDurationWithExponentialBackoff(currentStreak, baseBlockDurationMs), false, getFailureReasonString(reasonCode)); mWifiScoreCard.incrementBssidBlocklistStreak(ssid, bssid, reasonCode); return true; @@ -294,7 +296,7 @@ public class BssidBlocklistMonitor { * @return True if the blocklist has been modified. */ public boolean handleBssidConnectionFailure(String bssid, String ssid, - @FailureReason int reasonCode) { + @FailureReason int reasonCode, boolean isLowRssi) { if (!isValidNetworkAndFailureReason(bssid, ssid, reasonCode)) { return false; } @@ -307,7 +309,7 @@ public class BssidBlocklistMonitor { return false; } } - return handleBssidConnectionFailureInternal(bssid, ssid, reasonCode); + return handleBssidConnectionFailureInternal(bssid, ssid, reasonCode, isLowRssi); } /** diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java index 28409c36e..49dc4ff70 100644 --- a/service/java/com/android/server/wifi/ClientModeImpl.java +++ b/service/java/com/android/server/wifi/ClientModeImpl.java @@ -2814,8 +2814,18 @@ public class ClientModeImpl extends StateMachine { bssidBlocklistMonitorReason); } if (bssidBlocklistMonitorReason != -1) { + int networkId = (configuration == null) ? WifiConfiguration.INVALID_NETWORK_ID + : configuration.networkId; + ScanDetailCache scanDetailCache = + mWifiConfigManager.getScanDetailCacheForNetwork(networkId); + boolean isLowRssi = false; + int rssi = mWifiConfigManager.findScanRssi(networkId, SCAN_RSSI_VALID_TIME_MS); + int sufficientRssi = getSufficientRssi(networkId, bssid); + if (rssi != WifiInfo.INVALID_RSSI && sufficientRssi != WifiInfo.INVALID_RSSI) { + isLowRssi = rssi < sufficientRssi; + } mBssidBlocklistMonitor.handleBssidConnectionFailure(bssid, ssid, - bssidBlocklistMonitorReason); + bssidBlocklistMonitorReason, isLowRssi); } } @@ -2841,6 +2851,22 @@ public class ClientModeImpl extends StateMachine { handleConnectionAttemptEndForDiagnostics(level2FailureCode); } + /** + * Returns the sufficient RSSI for the frequency that this network is last seen on. + */ + private int getSufficientRssi(int networkId, String bssid) { + ScanDetailCache scanDetailCache = + mWifiConfigManager.getScanDetailCacheForNetwork(networkId); + if (scanDetailCache == null) { + return WifiInfo.INVALID_RSSI; + } + ScanResult scanResult = scanDetailCache.getScanResult(bssid); + if (scanResult == null) { + return WifiInfo.INVALID_RSSI; + } + return mWifiInjector.getScoringParams().getSufficientRssi(scanResult.frequency); + } + private int convertToBssidBlocklistMonitorFailureReason( int level2FailureCode, int failureReason) { switch (level2FailureCode) { @@ -5114,10 +5140,14 @@ public class ClientModeImpl extends StateMachine { config.networkId, DISABLED_NO_INTERNET_TEMPORARY); } + int rssi = mWifiInfo.getRssi(); + int sufficientRssi = mWifiInjector.getScoringParams() + .getSufficientRssi(mWifiInfo.getFrequency()); + boolean isLowRssi = rssi < sufficientRssi; mBssidBlocklistMonitor.handleBssidConnectionFailure( mLastBssid, config.SSID, - BssidBlocklistMonitor - .REASON_NETWORK_VALIDATION_FAILURE); + BssidBlocklistMonitor.REASON_NETWORK_VALIDATION_FAILURE, + isLowRssi); mWifiScoreCard.noteValidationFailure(mWifiInfo); } } @@ -5172,9 +5202,13 @@ public class ClientModeImpl extends StateMachine { boolean localGen = message.arg1 == 1; if (!localGen) { // ignore disconnects initiated by wpa_supplicant. mWifiScoreCard.noteNonlocalDisconnect(message.arg2); + int rssi = mWifiInfo.getRssi(); + int sufficientRssi = mWifiInjector.getScoringParams() + .getSufficientRssi(mWifiInfo.getFrequency()); + boolean isLowRssi = rssi < sufficientRssi; mBssidBlocklistMonitor.handleBssidConnectionFailure(mWifiInfo.getBSSID(), mWifiInfo.getSSID(), - BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT); + BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT, isLowRssi); } config = getCurrentWifiConfiguration(); diff --git a/service/res/values/config.xml b/service/res/values/config.xml index 9e3edf077..d836289b3 100644 --- a/service/res/values/config.xml +++ b/service/res/values/config.xml @@ -317,18 +317,26 @@ <!-- Base duration to block a BSSID after consecutive failures happen. (default = 5 mins) The blocklist duration is increased exponentially for a BSSID that consecutively gets added to the blocklist. - ie. 5/10/20/40/... up to the upper limit defined by config_wifiBssidBlocklistMonitorMaxBlockDurationMs --> + ie. 5/10/20/40/80/160/320/640 minutes - capped at 640 minutes because the default for + config_wifiBssidBlocklistMonitorFailureStreakCap is set to 7--> <integer translatable="false" name="config_wifiBssidBlocklistMonitorBaseBlockDurationMs"> 300000 </integer> + <!-- Base block duration for a failure at low RSSI (less than the sufficient RSSI) used for + ASSOCIATION_TIMEOUT, ABNORMAL_DISCONNECT, and NETWORK_VALIDATION failures. The block duration + for a BSSID that keeps failing will grow exponentially to the this base duration. + ie. 0.5/1/2/4/8/16/32/64 minutes - capped at 64 minutes because the default for + config_wifiBssidBlocklistMonitorFailureStreakCap is set to 7. + This value should be configured to be less than config_wifiBssidBlocklistMonitorBaseBlockDurationMs --> + <integer translatable="false" name="config_wifiBssidBlocklistMonitorBaseLowRssiBlockDurationMs"> 30000 </integer> + <!-- The failure streak is the number of times a BSSID consecutively gets blocked without ever successfully connecting in between, and is used to calculate the exponentially growing blocklist time. - Any BSSID with failure streak greater than the failure streak cap will be blocked for - config_wifiBssidBlocklistMonitorMaxBlockDurationMs. --> + The config_wifiBssidBlocklistMonitorFailureStreakCap controls how many times the block duration + could exponentially grow when a BSSID keeps failing. + ie. A value of 0 means BSSIDs are always blocked for the flat base duration defined by + config_wifiBssidBlocklistMonitorBaseBlockDurationMs and config_wifiBssidBlocklistMonitorBaseLowRssiBlockDurationMs. --> <integer translatable="false" name="config_wifiBssidBlocklistMonitorFailureStreakCap"> 7 </integer> - <!-- The maximum duration to block a BSSID (default = 18 hours) --> - <integer translatable="false" name="config_wifiBssidBlocklistMonitorMaxBlockDurationMs"> 64800000 </integer> - <!-- If a non-locally generated disconnect happens within this time window after association, then count it as a failure with reason code REASON_ABNORMAL_DISCONNECT (default = 30 seconds) --> <integer translatable="false" name="config_wifiBssidBlocklistAbnormalDisconnectTimeWindowMs"> 30000 </integer> diff --git a/service/res/values/overlayable.xml b/service/res/values/overlayable.xml index 33df3947f..552fa184e 100644 --- a/service/res/values/overlayable.xml +++ b/service/res/values/overlayable.xml @@ -104,8 +104,8 @@ <item type="integer" name="config_wifiBssidBlocklistMonitorDhcpFailureThreshold" /> <item type="integer" name="config_wifiBssidBlocklistMonitorAbnormalDisconnectThreshold" /> <item type="integer" name="config_wifiBssidBlocklistMonitorBaseBlockDurationMs" /> + <item type="integer" name="config_wifiBssidBlocklistMonitorBaseLowRssiBlockDurationMs" /> <item type="integer" name="config_wifiBssidBlocklistMonitorFailureStreakCap" /> - <item type="integer" name="config_wifiBssidBlocklistMonitorMaxBlockDurationMs" /> <item type="integer" name="config_wifiBssidBlocklistAbnormalDisconnectTimeWindowMs" /> <item type="bool" name="config_wifiScanHiddenNetworksScanOnlyMode" /> <item type="integer" name="config_wifiHardwareSoftapMaxClientCount" /> diff --git a/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java b/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java index 30fab35ab..00afa91f1 100644 --- a/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java +++ b/tests/wifitests/src/com/android/server/wifi/BssidBlocklistMonitorTest.java @@ -50,7 +50,7 @@ public class BssidBlocklistMonitorTest { private static final int TEST_L2_FAILURE = BssidBlocklistMonitor.REASON_ASSOCIATION_REJECTION; private static final int TEST_DHCP_FAILURE = BssidBlocklistMonitor.REASON_DHCP_FAILURE; private static final long BASE_BLOCKLIST_DURATION = TimeUnit.MINUTES.toMillis(5); // 5 minutes - private static final long MAX_BLOCKLIST_DURATION = TimeUnit.HOURS.toMillis(18); // 18 hours + private static final long BASE_LOW_RSSI_BLOCKLIST_DURATION = TimeUnit.SECONDS.toMillis(30); private static final long ABNORMAL_DISCONNECT_TIME_WINDOW_MS = TimeUnit.SECONDS.toMillis(30); private static final long ABNORMAL_DISCONNECT_RESET_TIME_MS = TimeUnit.HOURS.toMillis(3); private static final int FAILURE_STREAK_CAP = 7; @@ -87,10 +87,11 @@ public class BssidBlocklistMonitorTest { when(mWifiConnectivityHelper.getMaxNumBlacklistBssid()) .thenReturn(TEST_NUM_MAX_FIRMWARE_SUPPORT_BSSIDS); mResources = new MockResources(); - mResources.setInteger(R.integer.config_wifiBssidBlocklistMonitorMaxBlockDurationMs, - (int) MAX_BLOCKLIST_DURATION); mResources.setInteger(R.integer.config_wifiBssidBlocklistMonitorBaseBlockDurationMs, (int) BASE_BLOCKLIST_DURATION); + mResources.setInteger( + R.integer.config_wifiBssidBlocklistMonitorBaseLowRssiBlockDurationMs, + (int) BASE_LOW_RSSI_BLOCKLIST_DURATION); mResources.setInteger(R.integer.config_wifiBssidBlocklistMonitorFailureStreakCap, FAILURE_STREAK_CAP); mResources.setInteger(R.integer.config_wifiBssidBlocklistAbnormalDisconnectTimeWindowMs, @@ -128,7 +129,7 @@ public class BssidBlocklistMonitorTest { private void verifyAddTestBssidToBlocklist() { mBssidBlocklistMonitor.handleBssidConnectionFailure( TEST_BSSID_1, TEST_SSID_1, - BssidBlocklistMonitor.REASON_AP_UNABLE_TO_HANDLE_NEW_STA); + BssidBlocklistMonitor.REASON_AP_UNABLE_TO_HANDLE_NEW_STA, false); assertTrue(mBssidBlocklistMonitor.updateAndGetBssidBlocklist().contains(TEST_BSSID_1)); } @@ -136,12 +137,12 @@ public class BssidBlocklistMonitorTest { private void verifyAddMultipleBssidsToBlocklist() { when(mClock.getWallClockMillis()).thenReturn(0L); mBssidBlocklistMonitor.handleBssidConnectionFailure(TEST_BSSID_1, - TEST_SSID_1, BssidBlocklistMonitor.REASON_AP_UNABLE_TO_HANDLE_NEW_STA); + TEST_SSID_1, BssidBlocklistMonitor.REASON_AP_UNABLE_TO_HANDLE_NEW_STA, false); when(mClock.getWallClockMillis()).thenReturn(1L); mBssidBlocklistMonitor.handleBssidConnectionFailure(TEST_BSSID_2, - TEST_SSID_1, BssidBlocklistMonitor.REASON_AP_UNABLE_TO_HANDLE_NEW_STA); + TEST_SSID_1, BssidBlocklistMonitor.REASON_AP_UNABLE_TO_HANDLE_NEW_STA, false); mBssidBlocklistMonitor.handleBssidConnectionFailure(TEST_BSSID_3, - TEST_SSID_2, BssidBlocklistMonitor.REASON_AP_UNABLE_TO_HANDLE_NEW_STA); + TEST_SSID_2, BssidBlocklistMonitor.REASON_AP_UNABLE_TO_HANDLE_NEW_STA, false); // Verify that we have 3 BSSIDs in the blocklist. Set<String> bssidList = mBssidBlocklistMonitor.updateAndGetBssidBlocklist(); @@ -158,7 +159,7 @@ public class BssidBlocklistMonitorTest { private void handleBssidConnectionFailureMultipleTimes(String bssid, String ssid, int reason, int times) { for (int i = 0; i < times; i++) { - mBssidBlocklistMonitor.handleBssidConnectionFailure(bssid, ssid, reason); + mBssidBlocklistMonitor.handleBssidConnectionFailure(bssid, ssid, reason, false); } } @@ -191,6 +192,22 @@ public class BssidBlocklistMonitorTest { } /** + * Verify that a BSSID is blocked for a shorter time if the failure reason is association + * timeout and the RSSI is low. + */ + @Test + public void testAssociationTimeoutAtLowRssi() { + for (int i = 0; i < NUM_FAILURES_TO_BLOCKLIST; i++) { + mBssidBlocklistMonitor.handleBssidConnectionFailure(TEST_BSSID_1, TEST_SSID_1, + BssidBlocklistMonitor.REASON_ASSOCIATION_TIMEOUT, true); + } + when(mClock.getWallClockMillis()).thenReturn(BASE_LOW_RSSI_BLOCKLIST_DURATION); + assertEquals(1, mBssidBlocklistMonitor.updateAndGetBssidBlocklist().size()); + when(mClock.getWallClockMillis()).thenReturn(BASE_LOW_RSSI_BLOCKLIST_DURATION + 1); + assertEquals(0, mBssidBlocklistMonitor.updateAndGetBssidBlocklist().size()); + } + + /** * Verify that when adding a AP that had already been failing (therefore has a blocklist * streak), we are setting the blocklist duration using an exponential backoff technique. */ @@ -198,6 +215,7 @@ public class BssidBlocklistMonitorTest { public void testBssidIsRemoveFromBlocklistAfterTimoutExponentialBackoff() { verifyAddTestBssidToBlocklist(); int multiplier = 2; + long duration = 0; for (int i = 1; i <= FAILURE_STREAK_CAP; i++) { when(mWifiScoreCard.getBssidBlocklistStreak(anyString(), anyString(), anyInt())) .thenReturn(i); @@ -206,7 +224,7 @@ public class BssidBlocklistMonitorTest { // calculate the expected blocklist duration then verify that timeout happens // exactly after the duration. - long duration = multiplier * BASE_BLOCKLIST_DURATION; + duration = multiplier * BASE_BLOCKLIST_DURATION; when(mClock.getWallClockMillis()).thenReturn(duration); assertTrue(mBssidBlocklistMonitor.updateAndGetBssidBlocklist().contains(TEST_BSSID_1)); when(mClock.getWallClockMillis()).thenReturn(duration + 1); @@ -215,14 +233,14 @@ public class BssidBlocklistMonitorTest { multiplier *= 2; } - // finally verify that the timout is capped at some max value + // finally verify that the timout is capped by the FAILURE_STREAK_CAP when(mWifiScoreCard.getBssidBlocklistStreak(anyString(), anyString(), anyInt())) .thenReturn(FAILURE_STREAK_CAP + 1); when(mClock.getWallClockMillis()).thenReturn(0L); verifyAddTestBssidToBlocklist(); - when(mClock.getWallClockMillis()).thenReturn(MAX_BLOCKLIST_DURATION); + when(mClock.getWallClockMillis()).thenReturn(duration); assertTrue(mBssidBlocklistMonitor.updateAndGetBssidBlocklist().contains(TEST_BSSID_1)); - when(mClock.getWallClockMillis()).thenReturn(MAX_BLOCKLIST_DURATION + 1); + when(mClock.getWallClockMillis()).thenReturn(duration + 1); assertEquals(0, mBssidBlocklistMonitor.updateAndGetBssidBlocklist().size()); } @@ -261,7 +279,7 @@ public class BssidBlocklistMonitorTest { .thenReturn(0L); when(mClock.getWallClockMillis()).thenReturn(ABNORMAL_DISCONNECT_TIME_WINDOW_MS + 1); assertFalse(mBssidBlocklistMonitor.handleBssidConnectionFailure(TEST_BSSID_1, TEST_SSID_1, - BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT)); + BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT, false)); verify(mWifiScoreCard, never()).incrementBssidBlocklistStreak(TEST_SSID_1, TEST_BSSID_1, BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT); @@ -269,7 +287,7 @@ public class BssidBlocklistMonitorTest { // added to blocklist. when(mClock.getWallClockMillis()).thenReturn(ABNORMAL_DISCONNECT_TIME_WINDOW_MS); assertTrue(mBssidBlocklistMonitor.handleBssidConnectionFailure(TEST_BSSID_1, TEST_SSID_1, - BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT)); + BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT, false)); verify(mWifiScoreCard).incrementBssidBlocklistStreak(TEST_SSID_1, TEST_BSSID_1, BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT); } @@ -283,7 +301,7 @@ public class BssidBlocklistMonitorTest { when(mWifiScoreCard.getBssidBlocklistStreak(anyString(), anyString(), anyInt())) .thenReturn(1); assertTrue(mBssidBlocklistMonitor.handleBssidConnectionFailure( - TEST_BSSID_1, TEST_SSID_1, TEST_L2_FAILURE)); + TEST_BSSID_1, TEST_SSID_1, TEST_L2_FAILURE, false)); assertTrue(mBssidBlocklistMonitor.updateAndGetBssidBlocklist().contains(TEST_BSSID_1)); } @@ -524,7 +542,7 @@ public class BssidBlocklistMonitorTest { for (int i = 0; i < 10; i++) { when(mClock.getWallClockMillis()).thenReturn((long) i); mBssidBlocklistMonitor.handleBssidConnectionFailure(bssid + i, - TEST_SSID_1, BssidBlocklistMonitor.REASON_AP_UNABLE_TO_HANDLE_NEW_STA); + TEST_SSID_1, BssidBlocklistMonitor.REASON_AP_UNABLE_TO_HANDLE_NEW_STA, false); // This will build a List of BSSIDs starting from the latest added ones that is at // most size |TEST_NUM_MAX_FIRMWARE_SUPPORT_BSSIDS|. diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java index c9788ddcb..89286e7e8 100644 --- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java @@ -1582,9 +1582,9 @@ public class ClientModeImplTest extends WifiBaseTest { verify(mWifiLastResortWatchdog, times(2)).noteConnectionFailureAndTriggerIfNeeded( sSSID, sBSSID, WifiLastResortWatchdog.FAILURE_CODE_DHCP); verify(mBssidBlocklistMonitor, times(2)).handleBssidConnectionFailure(sBSSID, - sSSID, BssidBlocklistMonitor.REASON_DHCP_FAILURE); + sSSID, BssidBlocklistMonitor.REASON_DHCP_FAILURE, false); verify(mBssidBlocklistMonitor, times(2)).handleBssidConnectionFailure(sBSSID, sSSID, - BssidBlocklistMonitor.REASON_DHCP_FAILURE); + BssidBlocklistMonitor.REASON_DHCP_FAILURE, false); verify(mBssidBlocklistMonitor, never()).handleDhcpProvisioningSuccess(sBSSID, sSSID); verify(mBssidBlocklistMonitor, never()).handleNetworkValidationSuccess(sBSSID, sSSID); } @@ -2922,11 +2922,45 @@ public class ClientModeImplTest extends WifiBaseTest { */ @Test public void testAbnormalDisconnectNotifiesBssidBlocklistMonitor() throws Exception { + // trigger RSSI poll to update WifiInfo + mCmi.enableRssiPolling(true); + WifiLinkLayerStats llStats = new WifiLinkLayerStats(); + llStats.txmpdu_be = 1000; + llStats.rxmpdu_bk = 2000; + WifiCondManager.SignalPollResult signalPollResult = new WifiCondManager.SignalPollResult( + TEST_RSSI, 65, 54, sFreq); + when(mWifiNative.getWifiLinkLayerStats(any())).thenReturn(llStats); + when(mWifiNative.signalPoll(any())).thenReturn(signalPollResult); + connect(); + mLooper.dispatchAll(); mCmi.sendMessage(WifiMonitor.NETWORK_DISCONNECTION_EVENT, 0, 0, sBSSID); mLooper.dispatchAll(); + + verify(mBssidBlocklistMonitor).handleBssidConnectionFailure(sBSSID, sSSID, + BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT, false); + } + + /** + * Verify that ClientModeImpl notifies BssidBlocklistMonitor correctly when the RSSI is + * too low. + */ + @Test + public void testNotifiesBssidBlocklistMonitorLowRssi() throws Exception { + initializeAndAddNetworkAndVerifySuccess(); + mCmi.sendMessage(ClientModeImpl.CMD_START_CONNECT, FRAMEWORK_NETWORK_ID, 0, sBSSID); + mCmi.sendMessage(WifiMonitor.ASSOCIATION_REJECTION_EVENT, 1, 0, sBSSID); + when(mWifiConfigManager.findScanRssi(eq(FRAMEWORK_NETWORK_ID), anyInt())).thenReturn(-80); + when(mWifiConfigManager.getScanDetailCacheForNetwork(FRAMEWORK_NETWORK_ID)) + .thenReturn(mScanDetailCache); + when(mScanDetailCache.getScanDetail(sBSSID)).thenReturn( + getGoogleGuestScanDetail(-80, sBSSID, sFreq)); + when(mScanDetailCache.getScanResult(sBSSID)).thenReturn( + getGoogleGuestScanDetail(-80, sBSSID, sFreq).getScanResult()); + mLooper.dispatchAll(); + verify(mBssidBlocklistMonitor).handleBssidConnectionFailure(sBSSID, sSSID, - BssidBlocklistMonitor.REASON_ABNORMAL_DISCONNECT); + BssidBlocklistMonitor.REASON_ASSOCIATION_TIMEOUT, true); } /** @@ -2945,7 +2979,7 @@ public class ClientModeImplTest extends WifiBaseTest { verify(mWifiLastResortWatchdog, never()).noteConnectionFailureAndTriggerIfNeeded( anyString(), anyString(), anyInt()); verify(mBssidBlocklistMonitor).handleBssidConnectionFailure(sBSSID, sSSID, - BssidBlocklistMonitor.REASON_AP_UNABLE_TO_HANDLE_NEW_STA); + BssidBlocklistMonitor.REASON_AP_UNABLE_TO_HANDLE_NEW_STA, false); } /** @@ -2962,7 +2996,7 @@ public class ClientModeImplTest extends WifiBaseTest { verify(mWifiLastResortWatchdog).noteConnectionFailureAndTriggerIfNeeded( anyString(), anyString(), anyInt()); verify(mBssidBlocklistMonitor).handleBssidConnectionFailure(sBSSID, sSSID, - BssidBlocklistMonitor.REASON_ASSOCIATION_REJECTION); + BssidBlocklistMonitor.REASON_ASSOCIATION_REJECTION, false); } /** @@ -2983,7 +3017,7 @@ public class ClientModeImplTest extends WifiBaseTest { verify(mWifiLastResortWatchdog, never()).noteConnectionFailureAndTriggerIfNeeded( anyString(), anyString(), anyInt()); verify(mBssidBlocklistMonitor).handleBssidConnectionFailure(sBSSID, sSSID, - BssidBlocklistMonitor.REASON_WRONG_PASSWORD); + BssidBlocklistMonitor.REASON_WRONG_PASSWORD, false); } /** @@ -3004,7 +3038,7 @@ public class ClientModeImplTest extends WifiBaseTest { verify(mWifiLastResortWatchdog, never()).noteConnectionFailureAndTriggerIfNeeded( anyString(), anyString(), anyInt()); verify(mBssidBlocklistMonitor).handleBssidConnectionFailure(sBSSID, sSSID, - BssidBlocklistMonitor.REASON_EAP_FAILURE); + BssidBlocklistMonitor.REASON_EAP_FAILURE, false); } /** @@ -3024,7 +3058,7 @@ public class ClientModeImplTest extends WifiBaseTest { verify(mWifiLastResortWatchdog).noteConnectionFailureAndTriggerIfNeeded( anyString(), anyString(), anyInt()); verify(mBssidBlocklistMonitor).handleBssidConnectionFailure(sBSSID, sSSID, - BssidBlocklistMonitor.REASON_AUTHENTICATION_FAILURE); + BssidBlocklistMonitor.REASON_AUTHENTICATION_FAILURE, false); } /** @@ -3290,6 +3324,16 @@ public class ClientModeImplTest extends WifiBaseTest { */ @Test public void verifyAutoConnectedNetworkWithInternetValidationFailure() throws Exception { + // Setup RSSI poll to update WifiInfo with low RSSI + mCmi.enableRssiPolling(true); + WifiLinkLayerStats llStats = new WifiLinkLayerStats(); + llStats.txmpdu_be = 1000; + llStats.rxmpdu_bk = 2000; + WifiCondManager.SignalPollResult signalPollResult = new WifiCondManager.SignalPollResult( + RSSI_THRESHOLD_BREACH_MIN, 65, 54, sFreq); + when(mWifiNative.getWifiLinkLayerStats(any())).thenReturn(llStats); + when(mWifiNative.signalPoll(any())).thenReturn(signalPollResult); + // Simulate the first connection. connect(); ArgumentCaptor<Messenger> messengerCaptor = ArgumentCaptor.forClass(Messenger.class); @@ -3318,7 +3362,7 @@ public class ClientModeImplTest extends WifiBaseTest { verify(mWifiConfigManager).updateNetworkSelectionStatus( FRAMEWORK_NETWORK_ID, DISABLED_NO_INTERNET_TEMPORARY); verify(mBssidBlocklistMonitor).handleBssidConnectionFailure(sBSSID, sSSID, - BssidBlocklistMonitor.REASON_NETWORK_VALIDATION_FAILURE); + BssidBlocklistMonitor.REASON_NETWORK_VALIDATION_FAILURE, true); verify(mWifiScoreCard).noteValidationFailure(any()); } |