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

Commit bc1cf7e2 authored by Eric Schwarzenbach's avatar Eric Schwarzenbach
Browse files

Make only the "Add Network" WifiDialog fullscreen.

Fixes an issue where other instances of WifiDialog were being launched
fullscreen. Creates static methods for creating fullscreen and modal
WifiDialogs to make the style more explicit.

Bug: 63889135
Test: make -j40 RunSettingsRoboTests
Change-Id: I2200b5d7f817b9f69a6abb73bf2c04ea24556d19
parent bd429f42
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -174,10 +174,9 @@ public class SavedAccessPointsWifiSettings extends SettingsPreferenceFragment
                }
                mSelectedAccessPoint = mDlgAccessPoint;

                mDialog = new WifiDialog(getActivity(), this, mDlgAccessPoint,
                        WifiConfigUiBase.MODE_VIEW, true /* hide the submit button */);
                mDialog = WifiDialog.createModal(getActivity(), this, mDlgAccessPoint,
                        WifiConfigUiBase.MODE_VIEW);
                return mDialog;

        }
        return super.onCreateDialog(dialogId);
    }
+21 −10
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import com.android.settings.R;
import com.android.settingslib.RestrictedLockUtils;
import com.android.settingslib.wifi.AccessPoint;

// TODO(b/64069122) Have this extend a dialogfragment to handle the fullscreen launch case.
class WifiDialog extends AlertDialog implements WifiConfigUiBase, DialogInterface.OnClickListener {

    public interface WifiDialogListener {
@@ -45,21 +46,31 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase, DialogInterfac
    private WifiConfigController mController;
    private boolean mHideSubmitButton;

    public WifiDialog(Context context, WifiDialogListener listener, AccessPoint accessPoint,
            int mode, boolean hideSubmitButton) {
        this(context, listener, accessPoint, mode);
        mHideSubmitButton = hideSubmitButton;

    /** Creates a WifiDialog with fullscreen style. It displays in fullscreen mode. */
    public static WifiDialog createFullscreen(Context context, WifiDialogListener listener,
            AccessPoint accessPoint, int mode) {
        return new WifiDialog(context, listener, accessPoint, mode,
                R.style.Theme_Settings_NoActionBar, false /* hideSubmitButton */);
    }

    /**
     * Creates a WifiDialog with no additional style. It displays as a dialog above the current
     * view.
     */
    public static WifiDialog createModal(Context context, WifiDialogListener listener,
            AccessPoint accessPoint, int mode) {
        return new WifiDialog(context, listener, accessPoint, mode, 0 /* style */,
                mode == WifiConfigUiBase.MODE_VIEW /* hideSubmitButton*/);
    }

    public WifiDialog(Context context, WifiDialogListener listener, AccessPoint accessPoint,
            int mode) {
        // conditionally sets the theme to fullscreen dialog for "Add Network"
        super(context,
                mode == WifiConfigUiBase.MODE_CONNECT ? R.style.Theme_Settings_NoActionBar : 0);
    /* package */ WifiDialog(Context context, WifiDialogListener listener, AccessPoint accessPoint,
        int mode, int style, boolean hideSubmitButton) {
        super(context, style);
        mMode = mode;
        mListener = listener;
        mAccessPoint = accessPoint;
        mHideSubmitButton = false;
        mHideSubmitButton = hideSubmitButton;
    }

    @Override
+1 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ public class WifiDialogActivity extends Activity implements WifiDialog.WifiDialo
            accessPoint = new AccessPoint(this, accessPointState);
        }

        WifiDialog dialog = new WifiDialog(this, this, accessPoint, WifiConfigUiBase.MODE_CONNECT);
        WifiDialog dialog = WifiDialog.createModal(this, this, accessPoint, WifiConfigUiBase.MODE_CONNECT);
        dialog.show();
        dialog.setOnDismissListener(this);
    }
+13 −10
Original line number Diff line number Diff line
@@ -626,20 +626,23 @@ public class WifiSettings extends RestrictedSettingsFragment
    public Dialog onCreateDialog(int dialogId) {
        switch (dialogId) {
            case WIFI_DIALOG_ID:
                AccessPoint ap = mDlgAccessPoint; // For manual launch
                if (ap == null) { // For re-launch from saved state
                    if (mAccessPointSavedState != null) {
                        ap = new AccessPoint(getActivity(), mAccessPointSavedState);
                        // For repeated orientation changes
                        mDlgAccessPoint = ap;
                if (mDlgAccessPoint == null && mAccessPointSavedState == null) {
                    // add new network
                    mDialog = WifiDialog
                            .createFullscreen(getActivity(), this, mDlgAccessPoint, mDialogMode);
                } else {
                    // modify network
                    if (mDlgAccessPoint == null) {
                        // restore AP from save state
                        mDlgAccessPoint = new AccessPoint(getActivity(), mAccessPointSavedState);
                        // Reset the saved access point data
                        mAccessPointSavedState = null;
                    }
                    mDialog = WifiDialog
                            .createModal(getActivity(), this, mDlgAccessPoint, mDialogMode);
                }
                // If it's null, fine, it's for Add Network
                mSelectedAccessPoint = ap;
                mDialog = new WifiDialog(getActivity(), this, ap, mDialogMode,
                        /* no hide submit/connect */ false);

                mSelectedAccessPoint = mDlgAccessPoint;
                return mDialog;
            case WPS_PBC_DIALOG_ID:
                return new WpsDialog(getActivity(), WpsInfo.PBC);
+64 −0
Original line number Diff line number Diff line
package com.android.settings.wifi;

import static com.google.common.truth.Truth.assertThat;

import android.content.Context;

import com.android.settings.R;
import com.android.settings.TestConfig;
import com.android.settings.testutils.SettingsRobolectricTestRunner;
import com.android.settings.testutils.shadow.ShadowEntityHeaderController;

import com.android.settings.wifi.WifiDialog.WifiDialogListener;
import com.android.settingslib.wifi.AccessPoint;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;


@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
        shadows = ShadowEntityHeaderController.class)
public class WifiDialogTest {
    @Mock private AccessPoint mockAccessPoint;

    private Context mContext = RuntimeEnvironment.application;

    private WifiDialogListener mListener = new WifiDialogListener() {
        @Override
        public void onForget(WifiDialog dialog) {
        }

        @Override
        public void onSubmit(WifiDialog dialog) {
        }
    };

    @Before
    public void setUp() {
        MockitoAnnotations.initMocks(this);
    }

    @Test
    public void createFullscreen_setsFullscreenTheme() {
        WifiDialog fullscreen = WifiDialog.createFullscreen(mContext, mListener, mockAccessPoint,
                WifiConfigUiBase.MODE_CONNECT);
        assertThat(fullscreen.getContext().getThemeResId())
                .isEqualTo(R.style.Theme_Settings_NoActionBar);
    }

    @Test
    public void createModal_usesDefaultTheme() {
        WifiDialog modal = WifiDialog
                .createModal(mContext, mListener, mockAccessPoint, WifiConfigUiBase.MODE_CONNECT);

        WifiDialog wifiDialog = new WifiDialog(mContext, mListener, mockAccessPoint,
                WifiConfigUiBase.MODE_CONNECT, 0 /* style */, false /* hideSubmitButton */);
        assertThat(modal.getContext().getThemeResId())
                .isEqualTo(wifiDialog.getContext().getThemeResId());
    }
}