From 45bb3a1a77d0c548b5112ea7bfce48bab7361a07 Mon Sep 17 00:00:00 2001 From: Sundeep Ghuman Date: Fri, 21 Jul 2017 15:20:21 -0700 Subject: [PATCH] onConnectedChanged should not update access points In WifiSettings, invocation of onConnectedChanged should not update access points. This is controller by another callback, onAccessPointsChanged. Furthermore, this is fired before any changes have even been made to the AccessPoints. This is exacerbating a problem where old scan results are not shown in the WifiPicker, or sometimes the platform does not return any scan results. Bug: b/38212080 Test: runtest --path packages/apps/Settings/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java Change-Id: Ibbc067d9952525b4edd85389996509e9b17bb1bd --- .../android/settings/wifi/WifiSettings.java | 4 +--- .../settings/wifi/WifiSettingsUiTest.java | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/com/android/settings/wifi/WifiSettings.java b/src/com/android/settings/wifi/WifiSettings.java index 166a8ac87f5..2885e11925b 100644 --- a/src/com/android/settings/wifi/WifiSettings.java +++ b/src/com/android/settings/wifi/WifiSettings.java @@ -734,12 +734,10 @@ public class WifiSettings extends RestrictedSettingsFragment } /** - * Called when the connection state of wifi has changed and isConnected - * should be called to get the updated state. + * Called when the connection state of wifi has changed. */ @Override public void onConnectedChanged() { - updateAccessPointsDelayed(); changeNextButtonState(mWifiTracker.isConnected()); } diff --git a/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java b/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java index cbd9546c229..e44a5966bfe 100644 --- a/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java +++ b/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java @@ -31,6 +31,7 @@ import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.startsWith; import static org.mockito.Mockito.atMost; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -359,4 +360,23 @@ public class WifiSettingsUiTest { onView(withId(resourceId(ID, PASSWORD_LAYOUT))).check(matches(isDisplayed())); onView(withId(resourceId(ID, PASSWORD))).check(matches(isDisplayed())); } + + public void onConnectedChanged_shouldNotFetchAPs() { + setWifiState(WifiManager.WIFI_STATE_ENABLED); + when(mWifiTracker.isConnected()).thenReturn(true); + + launchActivity(); + + verify(mWifiTracker, atMost(1)).forceUpdate(); + verify(mWifiTracker, times(1)).getAccessPoints(); + onView(withText(WIFI_DISPLAY_STATUS_CONNECTED)).check(matches(isDisplayed())); + + // Invoke onConnectedChanged + when(mWifiTracker.isConnected()).thenReturn(false); + mWifiListener.onConnectedChanged(); + + // Verify no additional call to getAccessPoints + getInstrumentation().waitForIdleSync(); + verify(mWifiTracker, times(1)).getAccessPoints(); + } }