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

Commit f5d02aa7 authored by Stephen Chen's avatar Stephen Chen
Browse files

Fix Disallow config Wi-Fi message for AFW Do mode.

Correctly displays the custom message set by the Test DPC tool
for devices in AFW Do mode.

This change also fixes an issue where when Wi-Fi is disabled, the
disabled message is not shown instantly on Settings app start.

Bug: 37134344
Bug: 37911257
Test: runtest --path
packages/apps/Settings/tests/unit/src/com/android/settings/wifi/WifiSettingsUiTest.java
for off message testing, manual inspection using the Test DPC tool, and
verifying Guest mode behavior.

Change-Id: I61e48f605d75cb5665461536beeedcb32f6aa7f9
parent ad597344
Loading
Loading
Loading
Loading
+21 −10
Original line number Diff line number Diff line
@@ -128,6 +128,13 @@ public class WifiSettings extends RestrictedSettingsFragment
    private WifiManager.ActionListener mSaveListener;
    private WifiManager.ActionListener mForgetListener;

    /**
     * The state of {@link #isUiRestricted()} at {@link #onCreate(Bundle)}}. This is neccesary to
     * ensure that behavior is consistent if {@link #isUiRestricted()} changes. It could be changed
     * by the Test DPC tool in AFW mode.
     */
    private boolean mIsRestricted;

    private WifiEnabler mWifiEnabler;
    // An access point being editted is stored here.
    private AccessPoint mSelectedAccessPoint;
@@ -214,10 +221,7 @@ public class WifiSettings extends RestrictedSettingsFragment

        mUserBadgeCache = new AccessPointPreference.UserBadgeCache(getPackageManager());

        if (isUiRestricted()) {
            getPreferenceScreen().removePreference(mAdditionalSettingsPreferenceCategory);
            addMessagePreference(R.string.wifi_empty_list_user_restricted);
        }
        mIsRestricted = isUiRestricted();

        mBgThread = new HandlerThread(TAG, Process.THREAD_PRIORITY_BACKGROUND);
        mBgThread.start();
@@ -339,9 +343,15 @@ public class WifiSettings extends RestrictedSettingsFragment

        mWifiTracker.startTracking();

        if (!isUiRestricted() && mWifiManager.isWifiEnabled()) {
            forceUpdateAPs();
        if (mIsRestricted) {
            if (!isUiRestrictedByOnlyAdmin()) {
                getEmptyTextView().setText(R.string.wifi_empty_list_user_restricted);
            }
            getPreferenceScreen().removeAll();
            return;
        }

        onWifiStateChanged(mWifiManager.getWifiState());
    }

    private void forceUpdateAPs() {
@@ -418,7 +428,9 @@ public class WifiSettings extends RestrictedSettingsFragment
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // If the user is not allowed to configure wifi, do not handle menu selections.
        if (isUiRestricted()) return false;
        if (mIsRestricted) {
            return false;
        }

        switch (item.getItemId()) {
            case MENU_ID_WPS_PBC:
@@ -651,7 +663,7 @@ public class WifiSettings extends RestrictedSettingsFragment
     */
    private void updateAccessPointsDelayed() {
        // Safeguard from some delayed event handling
        if (getActivity() != null && !isUiRestricted() && mWifiManager.isWifiEnabled()) {
        if (getActivity() != null && !mIsRestricted && mWifiManager.isWifiEnabled()) {
            setProgressBarVisible(true);
            getView().postDelayed(mUpdateAccessPointsRunnable, 300 /* delay milliseconds */);
        }
@@ -660,7 +672,7 @@ public class WifiSettings extends RestrictedSettingsFragment
    /** Called when the state of Wifi has changed. */
    @Override
    public void onWifiStateChanged(int state) {
        if (isUiRestricted()) {
        if (mIsRestricted) {
            return;
        }

@@ -700,7 +712,6 @@ public class WifiSettings extends RestrictedSettingsFragment
        changeNextButtonState(mWifiTracker.isConnected());
    }


    private void updateAccessPointPreferences() {
        // in case state has changed
        if (!mWifiManager.isWifiEnabled()) {