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

Commit 46721efd authored by Arc Wang's avatar Arc Wang
Browse files

[Wi-Fi] Support intent extra "wifi_enable_next_on_connect" in WifiSettings2

This is a similar code merge of ag/489459.

Bug: 143328194
Test: make RunSettingsRoboTests ROBOTEST_FILTER=WifiSettings2Test
Change-Id: I666b3293f00aa1822a6fdcc3760ae19d27019597
parent 19747ba3
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -142,6 +142,13 @@ public class WifiSettings2 extends RestrictedSettingsFragment
    private String mDialogWifiEntryKey;
    private WifiEntry mDialogWifiEntry;

    // This boolean extra specifies whether to enable the Next button when connected. Used by
    // account creation outside of setup wizard.
    private static final String EXTRA_ENABLE_NEXT_ON_CONNECT = "wifi_enable_next_on_connect";

    // Enable the Next button when a Wi-Fi network is connected.
    private boolean mEnableNextOnConnection;

    private static boolean isVerboseLoggingEnabled() {
        return WifiPickerTracker.isVerboseLoggingEnabled();
    }
@@ -329,6 +336,11 @@ public class WifiSettings2 extends RestrictedSettingsFragment
                }
            }
        }

        // If we're supposed to enable/disable the Next button based on our current connection
        // state, start it off in the right state.
        final Intent intent = getActivity().getIntent();
        mEnableNextOnConnection = intent.getBooleanExtra(EXTRA_ENABLE_NEXT_ON_CONNECT, false);
    }

    @Override
@@ -384,6 +396,8 @@ public class WifiSettings2 extends RestrictedSettingsFragment
        if (mWifiEnabler != null) {
            mWifiEnabler.resume(activity);
        }

        changeNextButtonState(mWifiPickerTracker.getConnectedWifiEntry() != null);
    }

    @Override
@@ -626,6 +640,7 @@ public class WifiSettings2 extends RestrictedSettingsFragment
    @Override
    public void onWifiEntriesChanged() {
        updateWifiEntryPreferencesDelayed();
        changeNextButtonState(mWifiPickerTracker.getConnectedWifiEntry() != null);
    }

    @Override
@@ -882,6 +897,19 @@ public class WifiSettings2 extends RestrictedSettingsFragment
        return R.string.help_url_wifi;
    }

    /**
     * Renames/replaces "Next" button when appropriate. "Next" button usually exists in
     * Wi-Fi setup screens, not in usual wifi settings screen.
     *
     * @param enabled true when the device is connected to a wifi network.
     */
    @VisibleForTesting
    void changeNextButtonState(boolean enabled) {
        if (mEnableNextOnConnection && hasNextButton()) {
            getNextButton().setEnabled(enabled);
        }
    }

    @Override
    public void onForget(WifiDialog2 dialog) {
        forget(mDialogWifiEntry);
+8 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.settings.wifi;
import static com.google.common.truth.Truth.assertThat;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
@@ -278,4 +279,11 @@ public class WifiSettings2Test {
        verify(menu).add(anyInt(), eq(WifiSettings2.MENU_ID_FORGET), anyInt(), anyInt());
        verify(menu).add(anyInt(), eq(WifiSettings2.MENU_ID_DISCONNECT), anyInt(), anyInt());
    }

    @Test
    public void onWifiEntriesChanged_shouldChangeNextButtonState() {
        mWifiSettings2.onWifiEntriesChanged();

        verify(mWifiSettings2).changeNextButtonState(anyBoolean());
    }
}