Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0f711f86 authored by Sundeep Ghuman's avatar Sundeep Ghuman
Browse files

Remove use of forceUpdate.

Now that WifiTracker correctly handles eviction of stale scan results
only after scanning has resumed, it is no longer necessary to
conditionally fetch APs on app resumption.

Fix broken test.

Bug: 68030053
Test: runtest --path
tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java

Change-Id: Ib4c8d6e53cf760fcb5f00069da40c578171c09f4
parent e5020950
Loading
Loading
Loading
Loading
+1 −27
Original line number Diff line number Diff line
@@ -352,32 +352,6 @@ public class WifiSettings extends RestrictedSettingsFragment
        getPreferenceScreen().removeAll();
    }

    /**
     * Only update the AP list if there are not any APs currently shown.
     *
     * <p>Thus forceUpdate will only be called during cold start or when toggling between wifi on
     * and off. In other use cases, the previous APs will remain until the next update is received
     * from {@link WifiTracker}.
     */
    private void conditionallyForceUpdateAPs() {
        if (mAccessPointsPreferenceCategory.getPreferenceCount() > 0
                && mAccessPointsPreferenceCategory.getPreference(0) instanceof
                        AccessPointPreference) {
            // Make sure we don't update due to callbacks initiated by sticky broadcasts in
            // WifiTracker.
            Log.d(TAG, "Did not force update APs due to existing APs displayed");
            getView().removeCallbacks(mUpdateAccessPointsRunnable);
            return;
        }
        setProgressBarVisible(true);
        mWifiTracker.forceUpdate();
        if (isVerboseLoggingEnabled()) {
            Log.i(TAG, "WifiSettings force update APs: " + mWifiTracker.getAccessPoints());
        }
        getView().removeCallbacks(mUpdateAccessPointsRunnable);
        updateAccessPointPreferences();
    }

    /**
     * @return new WifiEnabler or null (as overridden by WifiSettingsForSetupWizard)
     */
@@ -682,7 +656,7 @@ public class WifiSettings extends RestrictedSettingsFragment
        final int wifiState = mWifiManager.getWifiState();
        switch (wifiState) {
            case WifiManager.WIFI_STATE_ENABLED:
                conditionallyForceUpdateAPs();
                updateAccessPointPreferences();
                break;

            case WifiManager.WIFI_STATE_ENABLING:
+3 −23
Original line number Diff line number Diff line
@@ -51,6 +51,7 @@ import android.support.test.rule.ActivityTestRule;
import android.support.test.runner.AndroidJUnit4;

import com.android.settings.Settings.WifiSettingsActivity;
import com.android.settingslib.utils.ThreadUtils;
import com.android.settingslib.wifi.AccessPoint;
import com.android.settingslib.wifi.TestAccessPointBuilder;
import com.android.settingslib.wifi.WifiTracker;
@@ -260,26 +261,6 @@ public class WifiSettingsUiTest {
                matches(isDisplayed()));
    }

    @Test
    public void resumingAp_shouldNotForceUpdateWhenExistingAPsAreListed() {
        setWifiState(WifiManager.WIFI_STATE_ENABLED);
        setupConnectedAccessPoint();
        when(mWifiTracker.isConnected()).thenReturn(true);

        launchActivity();

        onView(withText(resourceString(WIFI_DISPLAY_STATUS_CONNECTED))).check(
                matches(isDisplayed()));
        verify(mWifiTracker).forceUpdate();

        Activity activity = mActivityRule.getActivity();
        activity.finish();
        getInstrumentation().waitForIdleSync();

        getInstrumentation().callActivityOnStart(activity);
        verify(mWifiTracker, atMost(1)).forceUpdate();
    }

    @Test
    public void changingSecurityStateOnApShouldNotCauseMultipleListItems() {
        setWifiState(WifiManager.WIFI_STATE_ENABLED);
@@ -305,10 +286,10 @@ public class WifiSettingsUiTest {

        onView(withText(TEST_SSID)).check(matches(isDisplayed()));

        mWifiListener.onAccessPointsChanged();
        ThreadUtils.postOnMainThread(() -> mWifiListener.onAccessPointsChanged());
        onView(withText(TEST_SSID)).check(matches(isDisplayed()));

        mWifiListener.onAccessPointsChanged();
        ThreadUtils.postOnMainThread(() -> mWifiListener.onAccessPointsChanged());
        onView(withText(TEST_SSID)).check(matches(isDisplayed()));
    }

@@ -367,7 +348,6 @@ public class WifiSettingsUiTest {

        launchActivity();

        verify(mWifiTracker, atMost(1)).forceUpdate();
        verify(mWifiTracker, times(1)).getAccessPoints();
        onView(withText(WIFI_DISPLAY_STATUS_CONNECTED)).check(matches(isDisplayed()));