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

Commit 22d441ac authored by Isaac Levy's avatar Isaac Levy
Browse files

Autojoin new unsecured networks without dialog

Unsaved, open wifi networks will connect on single click
without opening the connect dialog box

Change-Id: I71da155aa8b711309f0ed7eca4bd22a254db28c5
parent 78545348
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -358,4 +358,19 @@ class AccessPoint extends Preference {
            setSummary(summary.toString());
        }
    }

    /**
     * Generate and save a default wifiConfiguration with common values.
     * Can only be called for unsecured networks.
     * @hide
     */
    protected void generateOpenNetworkConfig() {
        if (security != SECURITY_NONE)
            throw new IllegalStateException();
        if (mConfig != null)
            return;
        mConfig = new WifiConfiguration();
        mConfig.SSID = AccessPoint.convertToQuotedString(ssid);
        mConfig.allowedKeyManagement.set(KeyMgmt.NONE);
    }
}
+12 −6
Original line number Diff line number Diff line
@@ -353,11 +353,9 @@ public class WifiSettings extends SettingsPreferenceFragment
                        mWifiManager.connectNetwork(mSelectedAccessPoint.networkId);
                    }
                } else if (mSelectedAccessPoint.security == AccessPoint.SECURITY_NONE) {
                    // Shortcut for open networks.
                    WifiConfiguration config = new WifiConfiguration();
                    config.SSID = AccessPoint.convertToQuotedString(mSelectedAccessPoint.ssid);
                    config.allowedKeyManagement.set(KeyMgmt.NONE);
                    mWifiManager.connectNetwork(config);
                    /** Bypass dialog for unsecured networks */
                    mSelectedAccessPoint.generateOpenNetworkConfig();
                    mWifiManager.connectNetwork(mSelectedAccessPoint.getConfig());
                } else {
                    showConfigUi(mSelectedAccessPoint, true);
                }
@@ -379,7 +377,14 @@ public class WifiSettings extends SettingsPreferenceFragment
    public boolean onPreferenceTreeClick(PreferenceScreen screen, Preference preference) {
        if (preference instanceof AccessPoint) {
            mSelectedAccessPoint = (AccessPoint) preference;
            /** Bypass dialog for unsecured, unsaved networks */
            if (mSelectedAccessPoint.security == AccessPoint.SECURITY_NONE &&
                    mSelectedAccessPoint.networkId == INVALID_NETWORK_ID) {
                mSelectedAccessPoint.generateOpenNetworkConfig();
                mWifiManager.connectNetwork(mSelectedAccessPoint.getConfig());
            } else {
                showConfigUi(mSelectedAccessPoint, false);
            }
        } else {
            return super.onPreferenceTreeClick(screen, preference);
        }
@@ -623,6 +628,7 @@ public class WifiSettings extends SettingsPreferenceFragment
        }

        void forceScan() {
            removeMessages(0);
            sendEmptyMessage(0);
        }