From 0f41a6a3df4a2cedcad60324d91e1fffc968cfbb Mon Sep 17 00:00:00 2001 From: Stephen Chen Date: Tue, 18 Jul 2017 11:43:39 -0700 Subject: ONA: Track screen state in WifiNotificationController. The Open Networks Available notification should not be shown when the screen is off. Bug: 38460614 Bug: 37357441 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Change-Id: I445f95a624009f492c3abd8a9f815706e221ea44 --- .../server/wifi/WifiConnectivityManagerTest.java | 14 +++++++++++ .../wifi/WifiNotificationControllerTest.java | 28 ++++++++++++++++++++++ 2 files changed, 42 insertions(+) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java index 11e220e7f..bdb6b14ed 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConnectivityManagerTest.java @@ -678,6 +678,20 @@ public class WifiConnectivityManagerTest { verify(mWifiNotificationController).clearPendingNotification(true /* isRepeatDelayReset */); } + /** + * Verify that the ONA controller tracks screen state changes. + */ + @Test + public void openNetworkNotificationControllerTracksScreenStateChanges() { + mWifiConnectivityManager.handleScreenStateChanged(false); + + verify(mWifiNotificationController).handleScreenStateChanged(false); + + mWifiConnectivityManager.handleScreenStateChanged(true); + + verify(mWifiNotificationController).handleScreenStateChanged(true); + } + /** * Verify that scan interval for screen on and wifi disconnected scenario * is in the exponential backoff fashion. diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNotificationControllerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNotificationControllerTest.java index 9aa5ee938..27055a885 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiNotificationControllerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiNotificationControllerTest.java @@ -70,6 +70,7 @@ public class WifiNotificationControllerTest { mNotificationController = new WifiNotificationController( mContext, mock_looper.getLooper(), mFrameworkFacade, mock(Notification.Builder.class)); + mNotificationController.handleScreenStateChanged(true); } private List createOpenScanResults() { @@ -114,6 +115,21 @@ public class WifiNotificationControllerTest { verify(mNotificationManager).cancelAsUser(any(), anyInt(), any()); } + /** + * When a notification is showing, screen is off, and scan results with no open networks are + * handled, the notification is cleared. + */ + @Test + public void handleScanResults_notificationShown_screenOff_emptyList_notificationCleared() { + mNotificationController.handleScanResults(createOpenScanResults()); + + verify(mNotificationManager).notifyAsUser(any(), anyInt(), any(), any()); + + mNotificationController.handleScreenStateChanged(false); + mNotificationController.handleScanResults(new ArrayList<>()); + + verify(mNotificationManager).cancelAsUser(any(), anyInt(), any()); + } /** * If notification is showing, do not post another notification. @@ -152,6 +168,18 @@ public class WifiNotificationControllerTest { verify(mNotificationManager, never()).cancelAsUser(any(), anyInt(), any()); } + /** + * When screen is off and notification is not displayed, notification is not posted on handling + * new scan results with open networks. + */ + @Test + public void screenOff_handleScanResults_notificationNotDisplayed() { + mNotificationController.handleScreenStateChanged(false); + mNotificationController.handleScanResults(createOpenScanResults()); + + verify(mNotificationManager, never()).notifyAsUser(any(), anyInt(), any(), any()); + } + /** Verifies that {@link UserManager#DISALLOW_CONFIG_WIFI} disables the feature. */ @Test public void userHasDisallowConfigWifiRestriction_notificationNotDisplayed() { -- cgit v1.2.3