summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/WifiConnectivityManager.java1
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java44
2 files changed, 45 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java
index ad5a8f26c..2ce0bc024 100644
--- a/service/java/com/android/server/wifi/WifiConnectivityManager.java
+++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java
@@ -1847,6 +1847,7 @@ public class WifiConnectivityManager {
if (!mWifiEnabled) return;
localLog("forceConnectivityScan in request of " + workSource);
+ clearConnectionAttemptTimeStamps();
mWaitForFullBandScanResults = true;
startForcedSingleScan(true, workSource);
}
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()