diff options
author | Roshan Pius <rpius@google.com> | 2020-06-02 10:14:00 -0700 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2020-06-02 10:19:09 -0700 |
commit | 40a6a0e1fb3efb62b81e24b30820c9ffa778b206 (patch) | |
tree | 16ce768161cdadaa6953d071a288e8fecbed2a3e /tests | |
parent | 6b61b75021ae98eab575dbcf9ccd244d0a821a1e (diff) |
WifiConnectivityManager: Reset connection limiter on force scan
Bug: 156708458
Test: atest com.android.server.wifi
Change-Id: Ia7f82e382e3764892287f4358eda280de2bea3cb
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index 7bf21fb27..ba1c4f976 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -607,6 +607,50 @@ public class WifiConnectivityManagerTest extends WifiBaseTest { } /** + * Multiple back to back connection attempts after a force connectivity scan should not be rate + * limited. + * + * Expected behavior: WifiConnectivityManager calls ClientModeImpl.startConnectToNetwork() + * with the expected candidate network ID and BSSID for only the expected number of times within + * the given interval. + */ + @Test + public void connectionAttemptNotRateLimitedWhenScreenOffForceConnectivityScan() { + int maxAttemptRate = WifiConnectivityManager.MAX_CONNECTION_ATTEMPTS_RATE; + int timeInterval = WifiConnectivityManager.MAX_CONNECTION_ATTEMPTS_TIME_INTERVAL_MS; + int numAttempts = 0; + int connectionAttemptIntervals = timeInterval / maxAttemptRate; + + mWifiConnectivityManager.handleScreenStateChanged(false); + + // First attempt the max rate number of connections within the rate interval. + long currentTimeStamp = 0; + for (int attempt = 0; attempt < maxAttemptRate; attempt++) { + currentTimeStamp += connectionAttemptIntervals; + when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); + // Set WiFi to disconnected state to trigger PNO scan + mWifiConnectivityManager.handleConnectionStateChanged( + WifiConnectivityManager.WIFI_STATE_DISCONNECTED); + numAttempts++; + } + + mWifiConnectivityManager.forceConnectivityScan(new WorkSource()); + + for (int attempt = 0; attempt < maxAttemptRate; attempt++) { + currentTimeStamp += connectionAttemptIntervals; + when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); + // Set WiFi to disconnected state to trigger PNO scan + mWifiConnectivityManager.handleConnectionStateChanged( + WifiConnectivityManager.WIFI_STATE_DISCONNECTED); + numAttempts++; + } + + // Verify that all the connection attempts went through + verify(mClientModeImpl, times(numAttempts)).startConnectToNetwork( + CANDIDATE_NETWORK_ID, Process.WIFI_UID, CANDIDATE_BSSID); + } + + /** * Multiple back to back connection attempts after a user selection should not be rate limited. * * Expected behavior: WifiConnectivityManager calls ClientModeImpl.startConnectToNetwork() |