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

Commit 5814f085 authored by Bruno Randolf's avatar Bruno Randolf Committed by Gerrit Code Review
Browse files

Wifi: Enable IBSS options only if IBSS is supported

Show IBSS network options only if IBSS mode is supported by the Wifi driver.

This makes use of the new API isIbssSupported() of WifiManager. We have to be
careful to make the query only after we reached WIFI_STATE_ENABLED.

WifiSettingsForSetupWizardXL is left out because it does not handle these
states.

Change-Id: I072c5cc6ed36305806b469cf05c4786d22bfd418
parent 0f8d436d
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ public class WifiConfigController implements TextWatcher,
    private final AccessPoint mAccessPoint;

    private boolean mEdit;
    private boolean mIbssSupported;

    private TextView mSsidView;
    private CheckBox mIbssView;
@@ -142,7 +143,8 @@ public class WifiConfigController implements TextWatcher,
    }

    public WifiConfigController(
            WifiConfigUiBase parent, View view, AccessPoint accessPoint, boolean edit) {
            WifiConfigUiBase parent, View view, AccessPoint accessPoint, boolean edit,
            boolean ibssSupported) {
        mConfigUi = parent;
        mInXlSetupWizard = (parent instanceof WifiConfigUiForSetupWizardXL);

@@ -151,6 +153,7 @@ public class WifiConfigController implements TextWatcher,
        mAccessPointSecurity = (accessPoint == null) ? AccessPoint.SECURITY_NONE :
                accessPoint.security;
        mEdit = edit;
        mIbssSupported = ibssSupported;

        mTextViewChangedHandler = new Handler();
        final Context context = mConfigUi.getContext();
@@ -186,6 +189,8 @@ public class WifiConfigController implements TextWatcher,
            showProxyFields();
            mView.findViewById(R.id.wifi_advanced_toggle).setVisibility(View.VISIBLE);
            mView.findViewById(R.id.wifi_advanced_togglebox).setOnClickListener(this);

            if (mIbssSupported)
                mView.findViewById(R.id.wifi_ibss_toggle).setVisibility(View.VISIBLE);

            mConfigUi.setSubmitButton(context.getString(R.string.wifi_save));
+1 −1
Original line number Diff line number Diff line
@@ -68,7 +68,7 @@ public class WifiConfigUiForSetupWizardXL implements WifiConfigUiBase, OnFocusCh
        mInflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        mView = mInflater.inflate(R.layout.wifi_config_ui_for_setup_wizard, parent, true);
        mController = new WifiConfigController(this, mView, mAccessPoint, edit);
        mController = new WifiConfigController(this, mView, mAccessPoint, edit, false);

        mInputMethodManager = (InputMethodManager)
                activity.getSystemService(Context.INPUT_METHOD_SERVICE);
+4 −2
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase {
    static final int BUTTON_FORGET = DialogInterface.BUTTON_NEUTRAL;

    private final boolean mEdit;
    private final boolean mIbssSupported;
    private final DialogInterface.OnClickListener mListener;
    private final AccessPoint mAccessPoint;

@@ -37,9 +38,10 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase {
    private WifiConfigController mController;

    public WifiDialog(Context context, DialogInterface.OnClickListener listener,
            AccessPoint accessPoint, boolean edit) {
            AccessPoint accessPoint, boolean edit, boolean ibssSupported) {
        super(context, R.style.Theme_WifiDialog);
        mEdit = edit;
        mIbssSupported = ibssSupported;
        mListener = listener;
        mAccessPoint = accessPoint;
    }
@@ -54,7 +56,7 @@ class WifiDialog extends AlertDialog implements WifiConfigUiBase {
        mView = getLayoutInflater().inflate(R.layout.wifi_dialog, null);
        setView(mView);
        setInverseBackgroundForced(true);
        mController = new WifiConfigController(this, mView, mAccessPoint, mEdit);
        mController = new WifiConfigController(this, mView, mAccessPoint, mEdit, mIbssSupported);
        super.onCreate(savedInstanceState);
        /* During creation, the submit button can be unavailable to determine
         * visibility. Right after creation, update button visibility */
+10 −2
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ public class WifiSettings extends SettingsPreferenceFragment
    private WifiManager.ActionListener mSaveListener;
    private WifiManager.ActionListener mForgetListener;
    private boolean mP2pSupported;

    private boolean mIbssSupported;

    private WifiEnabler mWifiEnabler;
    // An access point being editted is stored here.
@@ -632,7 +632,7 @@ public class WifiSettings extends SettingsPreferenceFragment
                }
                // If it's still null, fine, it's for Add Network
                mSelectedAccessPoint = ap;
                mDialog = new WifiDialog(getActivity(), this, ap, mDlgEdit);
                mDialog = new WifiDialog(getActivity(), this, ap, mDlgEdit, mIbssSupported);
                return mDialog;
            case WPS_PBC_DIALOG_ID:
                return new WpsDialog(getActivity(), WpsInfo.PBC);
@@ -778,6 +778,11 @@ public class WifiSettings extends SettingsPreferenceFragment
                    continue;
                }

                // Ignore IBSS if chipset does not support them
                if (!mIbssSupported && result.capabilities.contains("[IBSS]")) {
                    continue;
                }

                boolean found = false;
                for (AccessPoint accessPoint : apMap.getAll(result.SSID)) {
                    if (accessPoint.update(result))
@@ -892,6 +897,9 @@ public class WifiSettings extends SettingsPreferenceFragment

        switch (state) {
            case WifiManager.WIFI_STATE_ENABLED:
                // this function only returns valid results in enabled state
                mIbssSupported = mWifiManager.isIbssSupported();

                mScanner.resume();
                return; // not break, to avoid the call to pause() below