diff options
author | Roshan Pius <rpius@google.com> | 2020-05-28 05:12:35 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2020-05-28 05:12:35 +0000 |
commit | 1641120374e0f8a35ccac637c7ac8cdbfe18b701 (patch) | |
tree | a729531bf5b79b80b837b2db849fe5748c204aa8 | |
parent | f063f352bed64650293b5ba890fb6141e3f463b6 (diff) | |
parent | e297c3c30defae364fa601c299c0af313caf06f5 (diff) |
Merge "WifiWakeup: Ignore wakeup start if no saved networks or suggestions" into rvc-dev am: c5d1fad63f am: e297c3c30d
Change-Id: I969ffc73553f83cddade0405dbef72f48600afd1
-rw-r--r-- | service/java/com/android/server/wifi/WakeupController.java | 4 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java | 22 |
2 files changed, 22 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/WakeupController.java b/service/java/com/android/server/wifi/WakeupController.java index b003b74b9..d9882dbf3 100644 --- a/service/java/com/android/server/wifi/WakeupController.java +++ b/service/java/com/android/server/wifi/WakeupController.java @@ -240,6 +240,10 @@ public class WakeupController { */ public void start() { Log.d(TAG, "start()"); + if (getGoodSavedNetworksAndSuggestions().isEmpty()) { + Log.i(TAG, "Ignore wakeup start since there are no good networks."); + return; + } mWifiInjector.getWifiScanner().registerScanListener( new HandlerExecutor(mHandler), mScanListener); diff --git a/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java b/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java index ed2ccce5e..9824c5b23 100644 --- a/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WakeupControllerTest.java @@ -103,6 +103,10 @@ public class WakeupControllerTest extends WifiBaseTest { .thenReturn(new int[]{DFS_CHANNEL_FREQ}); when(mWifiSettingsStore.handleWifiToggled(anyBoolean())).thenReturn(true); + // Saved network needed to start wake. + WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork(); + openNetwork.getNetworkSelectionStatus().setHasEverConnected(true); + when(mWifiConfigManager.getSavedNetworks(anyInt())).thenReturn(Arrays.asList(openNetwork)); mLooper = new TestLooper(); @@ -255,6 +259,19 @@ public class WakeupControllerTest extends WifiBaseTest { verify(mWifiWakeMetrics, never()).recordStartEvent(anyInt()); } + + /** + * Verify that start does not set the wakeup lock when feature is disabled. + */ + @Test + public void startDoesNotSetWakeupLockWhenNoSavedNetworksOrSuggestions() { + when(mWifiConfigManager.getSavedNetworks(anyInt())).thenReturn(Collections.emptyList()); + initializeWakeupController(false /* enabled */); + mWakeupController.start(); + verify(mWakeupLock, never()).setLock(any()); + verify(mWifiWakeMetrics, never()).recordStartEvent(anyInt()); + } + /** * If the controller is already active, verify that start() is ignored and no setup is done. */ @@ -537,8 +554,7 @@ public class WakeupControllerTest extends WifiBaseTest { */ @Test public void onResultsUpdatesWakeupLockWithOnlySavedNetworks() { - // no saved configs - when(mWifiConfigManager.getSavedNetworks(anyInt())).thenReturn(Collections.emptyList()); + // no matching saved configs initializeWakeupController(true /* enabled */); mWakeupController.start(); @@ -713,7 +729,6 @@ public class WakeupControllerTest extends WifiBaseTest { when(mClock.getElapsedSinceBootMillis()).thenReturn(0L, (long) (0.8 * WakeupController.LAST_DISCONNECT_TIMEOUT_MILLIS)); ScanResultMatchInfo matchInfo = ScanResultMatchInfo.fromScanResult(mTestScanResult); - when(mWifiConfigManager.getSavedNetworks(anyInt())).thenReturn(Collections.emptyList()); when(mWifiScanner.getSingleScanResults()).thenReturn(Collections.emptyList()); initializeWakeupController(true); @@ -739,7 +754,6 @@ public class WakeupControllerTest extends WifiBaseTest { when(mClock.getElapsedSinceBootMillis()).thenReturn(0L, (long) (1.2 * WakeupController.LAST_DISCONNECT_TIMEOUT_MILLIS)); ScanResultMatchInfo matchInfo = ScanResultMatchInfo.fromScanResult(mTestScanResult); - when(mWifiConfigManager.getSavedNetworks(anyInt())).thenReturn(Collections.emptyList()); when(mWifiScanner.getSingleScanResults()).thenReturn(Collections.emptyList()); initializeWakeupController(true); |