diff options
author | David Su <dysu@google.com> | 2018-11-06 18:05:58 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2018-11-06 18:05:58 +0000 |
commit | 60f3e78cefae1f0d59de16e2744840571598350b (patch) | |
tree | 2e02709dd8ef7a98aa0211e1434413283b972faa /tests | |
parent | d2a20c1a3975668bc5aeab53a8f0daae6662366a (diff) | |
parent | f27f8fc96593d686ca8c71fa851635d50a47b549 (diff) |
Merge "Increased Wifi Wake consecutive missed scans to 5 and force add last disconnected network to Wakeup Lock."
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java | 57 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WakeupLockTest.java | 11 |
2 files changed, 62 insertions, 6 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java b/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java index 4d8f03481..d4c44c22c 100644 --- a/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java @@ -75,6 +75,7 @@ public class WakeupControllerTest { @Mock private WifiWakeMetrics mWifiWakeMetrics; @Mock private WifiController mWifiController; @Mock private WifiNative mWifiNative; + @Mock private Clock mClock; private TestLooper mLooper; private WakeupController mWakeupController; @@ -129,7 +130,8 @@ public class WakeupControllerTest { mWifiConfigStore, mWifiWakeMetrics, mWifiInjector, - mFrameworkFacade); + mFrameworkFacade, + mClock); ArgumentCaptor<WakeupConfigStoreData> captor = ArgumentCaptor.forClass(WakeupConfigStoreData.class); @@ -563,4 +565,57 @@ public class WakeupControllerTest { contentObserver.onChange(false /* selfChange */); verify(mWakeupOnboarding).setOnboarded(); } + + /** + * When Wifi disconnects from a network, and within LAST_DISCONNECT_TIMEOUT_MILLIS Wifi is + * disabled, then the last connected Wifi network should be added to the wakeup lock. + * + * This simulates when a Wifi network sporadically connects and disconnects. During the + * disconnected phase, the user forcibly disables Wifi to stop this intermittent behavior. Then, + * we should add the network to the wake lock to ensure Wifi Wake does not automatically + * reconnect to this network. + * + * Also verifies that after the above flow, when Wifi is re-enabled, then disabled again, the + * last connected network should be reset and no networks should be added to the wakeup lock. + */ + @Test + public void lastConnectedNetworkAddedToLock() { + when(mClock.getElapsedSinceBootMillis()).thenReturn(0L, + (long) (0.8 * WakeupController.LAST_DISCONNECT_TIMEOUT_MILLIS)); + ScanResultMatchInfo matchInfo = ScanResultMatchInfo.fromScanResult(mTestScanResult); + when(mWifiConfigManager.getSavedNetworks()).thenReturn(Collections.emptyList()); + when(mWifiScanner.getSingleScanResults()).thenReturn(Collections.emptyList()); + initializeWakeupController(true); + + mWakeupController.setLastDisconnectInfo(matchInfo); + mWakeupController.start(); + + verify(mWakeupLock).setLock(eq(Collections.singleton(matchInfo))); + + mWakeupController.stop(); + mWakeupController.reset(); + mWakeupController.start(); + + verify(mWakeupLock).setLock(eq(Collections.emptySet())); + } + + /** + * When Wifi disconnects from a network, and Wifi is disabled after more than + * LAST_DISCONNECT_TIMEOUT_MILLIS, the last connected Wifi network should not be added to the + * wakeup lock. + */ + @Test + public void expiredLastConnectedNetworkNotAddedToLock() { + when(mClock.getElapsedSinceBootMillis()).thenReturn(0L, + (long) (1.2 * WakeupController.LAST_DISCONNECT_TIMEOUT_MILLIS)); + ScanResultMatchInfo matchInfo = ScanResultMatchInfo.fromScanResult(mTestScanResult); + when(mWifiConfigManager.getSavedNetworks()).thenReturn(Collections.emptyList()); + when(mWifiScanner.getSingleScanResults()).thenReturn(Collections.emptyList()); + initializeWakeupController(true); + + mWakeupController.setLastDisconnectInfo(matchInfo); + mWakeupController.start(); + + verify(mWakeupLock).setLock(eq(Collections.emptySet())); + } } diff --git a/tests/wifitests/src/com/android/server/wifi/WakeupLockTest.java b/tests/wifitests/src/com/android/server/wifi/WakeupLockTest.java index 43605f484..8bd38e156 100644 --- a/tests/wifitests/src/com/android/server/wifi/WakeupLockTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WakeupLockTest.java @@ -105,10 +105,10 @@ public class WakeupLockTest { mWakeupLock.setLock(networks); assertFalse(mWakeupLock.isInitialized()); - mWakeupLock.update(networks); - assertFalse(mWakeupLock.isInitialized()); - mWakeupLock.update(networks); - assertFalse(mWakeupLock.isInitialized()); + for (int i = 0; i < WakeupLock.CONSECUTIVE_MISSED_SCANS_REQUIRED_TO_EVICT - 1; i++) { + mWakeupLock.update(networks); + assertFalse(mWakeupLock.isInitialized()); + } mWakeupLock.update(networks); assertTrue(mWakeupLock.isInitialized()); } @@ -283,7 +283,8 @@ public class WakeupLockTest { for (int i = 0; i < WakeupLock.CONSECUTIVE_MISSED_SCANS_REQUIRED_TO_EVICT; i++) { mWakeupLock.update(Collections.emptyList()); } - verify(mWifiWakeMetrics).recordUnlockEvent(3 /* numScans */); + verify(mWifiWakeMetrics).recordUnlockEvent( + WakeupLock.CONSECUTIVE_MISSED_SCANS_REQUIRED_TO_EVICT /* numScans */); } private void setLockAndInitializeByTimeout(Collection<ScanResultMatchInfo> networks) { |