diff options
author | Randy Pan <zpan@google.com> | 2017-03-15 22:18:24 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2017-03-15 22:18:24 +0000 |
commit | 1df53b3ec09d8bd1713b55167ebe283bd1c1a9e9 (patch) | |
tree | e75fa9f16877f25c724a14b298feb45eeb122584 | |
parent | ffe8694d14621b679ef06ca2679cf55462b33ea8 (diff) | |
parent | 915a3782e33684562dff8a0897d1446227301b75 (diff) |
Merge "Schedule a scan immediately when disconnected"
-rw-r--r-- | service/java/com/android/server/wifi/WifiConnectivityManager.java | 5 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java | 77 |
2 files changed, 66 insertions, 16 deletions
diff --git a/service/java/com/android/server/wifi/WifiConnectivityManager.java b/service/java/com/android/server/wifi/WifiConnectivityManager.java index 179da0f14..4ae3a96a2 100644 --- a/service/java/com/android/server/wifi/WifiConnectivityManager.java +++ b/service/java/com/android/server/wifi/WifiConnectivityManager.java @@ -948,9 +948,10 @@ public class WifiConnectivityManager { if (mWifiState == WIFI_STATE_DISCONNECTED) { mLastConnectionAttemptBssid = null; scheduleWatchdogTimer(); + startConnectivityScan(SCAN_IMMEDIATELY); + } else { + startConnectivityScan(SCAN_ON_SCHEDULE); } - - startConnectivityScan(SCAN_ON_SCHEDULE); } /** diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index 56af3fbb9..39fa247bf 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -703,14 +703,14 @@ public class WifiConnectivityManagerTest { } /** - * When screen on trigger two connection state change events back to back to - * verify that the minium scan interval is enforced. + * When screen on trigger a disconnected state change event then a connected state + * change event back to back to verify that the minium scan interval is enforced. * * Expected behavior: WifiConnectivityManager start the second periodic single * scan PERIODIC_SCAN_INTERVAL_MS after the first one. */ @Test - public void checkMinimumPeriodicScanIntervalWhenScreenOn() { + public void checkMinimumPeriodicScanIntervalWhenScreenOnAndConnected() { long currentTimeStamp = CURRENT_SYSTEM_TIME_MS; when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); @@ -720,30 +720,79 @@ public class WifiConnectivityManagerTest { // Wait for MAX_PERIODIC_SCAN_INTERVAL_MS so that any impact triggered // by screen state change can settle currentTimeStamp += WifiConnectivityManager.MAX_PERIODIC_SCAN_INTERVAL_MS; - long firstScanTimeStamp = currentTimeStamp; + long scanForDisconnectedTimeStamp = currentTimeStamp; + when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); + + // Set WiFi to disconnected state which triggers a scan immediately + mWifiConnectivityManager.handleConnectionStateChanged( + WifiConnectivityManager.WIFI_STATE_DISCONNECTED); + verify(mWifiScanner, times(1)).startScan(anyObject(), anyObject(), anyObject()); + + // Set up time stamp for when entering CONNECTED state + currentTimeStamp += 2000; + when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); + + // Set WiFi to connected state to trigger its periodic scan + mWifiConnectivityManager.handleConnectionStateChanged( + WifiConnectivityManager.WIFI_STATE_CONNECTED); + + // The very first scan triggered for connected state is actually via the alarm timer + // and it obeys the minimum scan interval + long firstScanForConnectedTimeStamp = mAlarmManager + .getTriggerTimeMillis(WifiConnectivityManager.PERIODIC_SCAN_TIMER_TAG); + + // Verify that the first scan for connected state is scheduled PERIODIC_SCAN_INTERVAL_MS + // after the scan for disconnected state + assertEquals(firstScanForConnectedTimeStamp, scanForDisconnectedTimeStamp + + WifiConnectivityManager.PERIODIC_SCAN_INTERVAL_MS); + } + + /** + * When screen on trigger a connected state change event then a disconnected state + * change event back to back to verify that a scan is fired immediately for the + * disconnected state change event. + * + * Expected behavior: WifiConnectivityManager directly starts the periodic immediately + * for the disconnected state change event. The second scan for disconnected state is + * via alarm timer. + */ + @Test + public void scanImmediatelyWhenScreenOnAndDisconnected() { + long currentTimeStamp = CURRENT_SYSTEM_TIME_MS; + when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); + + // Set screen to ON + mWifiConnectivityManager.handleScreenStateChanged(true); + + // Wait for MAX_PERIODIC_SCAN_INTERVAL_MS so that any impact triggered + // by screen state change can settle + currentTimeStamp += WifiConnectivityManager.MAX_PERIODIC_SCAN_INTERVAL_MS; + long scanForConnectedTimeStamp = currentTimeStamp; when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); // Set WiFi to connected state to trigger the periodic scan mWifiConnectivityManager.handleConnectionStateChanged( WifiConnectivityManager.WIFI_STATE_CONNECTED); + verify(mWifiScanner, times(1)).startScan(anyObject(), anyObject(), anyObject()); - // Set the second scan attempt time stamp. + // Set up the time stamp for when entering DISCONNECTED state currentTimeStamp += 2000; + long enteringDisconnectedStateTimeStamp = currentTimeStamp; when(mClock.getElapsedSinceBootMillis()).thenReturn(currentTimeStamp); - // Set WiFi to disconnected state to trigger another periodic scan + // Set WiFi to disconnected state to trigger its periodic scan mWifiConnectivityManager.handleConnectionStateChanged( WifiConnectivityManager.WIFI_STATE_DISCONNECTED); - // Get the second periodic scan actual time stamp - long secondScanTimeStamp = mAlarmManager - .getTriggerTimeMillis(WifiConnectivityManager.PERIODIC_SCAN_TIMER_TAG); - - // Verify that the second scan is scheduled PERIODIC_SCAN_INTERVAL_MS after the - // very first scan. - assertEquals(secondScanTimeStamp, firstScanTimeStamp - + WifiConnectivityManager.PERIODIC_SCAN_INTERVAL_MS); + // Verify the very first scan for DISCONNECTED state is fired immediately + verify(mWifiScanner, times(2)).startScan(anyObject(), anyObject(), anyObject()); + long secondScanForDisconnectedTimeStamp = mAlarmManager + .getTriggerTimeMillis(WifiConnectivityManager.PERIODIC_SCAN_TIMER_TAG); + // Verify that the second scan is scheduled PERIODIC_SCAN_INTERVAL_MS after + // entering DISCONNECTED state. + assertEquals(secondScanForDisconnectedTimeStamp, enteringDisconnectedStateTimeStamp + + WifiConnectivityManager.PERIODIC_SCAN_INTERVAL_MS); } /** |