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

Commit b3e96c52 authored by Irfan Sheriff's avatar Irfan Sheriff
Browse files

Fix connect & save of invalid networks

Ensure SSID is not null for a new network being added

Bug: 6411912
Change-Id: I26467810bf10b7325c04677c1d0e5ff1cfb4a09e
parent ca7086f5
Loading
Loading
Loading
Loading
+11 −26
Original line number Diff line number Diff line
@@ -194,31 +194,6 @@ class WifiConfigStore {
        }
    }

    /**
     * Selects the specified network config for connection. This involves
     * addition/update of the specified config, updating the priority of
     * all the networks and enabling the given network while disabling others.
     *
     * Selecting a network will leave the other networks disabled and
     * a call to enableAllNetworks() needs to be issued upon a connection
     * or a failure event from supplicant
     *
     * @param config The configuration details in WifiConfiguration
     * @return the networkId now associated with the specified configuration
     */
    int selectNetwork(WifiConfiguration config) {
        if (config != null) {
            NetworkUpdateResult result = addOrUpdateNetworkNative(config);
            int netId = result.getNetworkId();
            if (netId != INVALID_NETWORK_ID) {
                selectNetwork(netId);
            } else {
                loge("Failed to update network " + config);
            }
            return netId;
        }
        return INVALID_NETWORK_ID;
    }

    /**
     * Selects the specified network for connection. This involves
@@ -230,8 +205,11 @@ class WifiConfigStore {
     * or a failure event from supplicant
     *
     * @param netId network to select for connection
     * @return false if the network id is invalid
     */
    void selectNetwork(int netId) {
    boolean selectNetwork(int netId) {
        if (netId == INVALID_NETWORK_ID) return false;

        // Reset the priority of each network at start or if it goes too high.
        if (mLastPriority == -1 || mLastPriority > 1000000) {
            for(WifiConfiguration config : mConfiguredNetworks.values()) {
@@ -256,6 +234,7 @@ class WifiConfigStore {

       /* Avoid saving the config & sending a broadcast to prevent settings
        * from displaying a disabled list of networks */
        return true;
    }

    /**
@@ -265,6 +244,12 @@ class WifiConfigStore {
     * @return network update result
     */
    NetworkUpdateResult saveNetwork(WifiConfiguration config) {
        // A new network cannot have null SSID
        if (config == null || (config.networkId == INVALID_NETWORK_ID &&
                config.SSID == null)) {
            return new NetworkUpdateResult(INVALID_NETWORK_ID);
        }

        boolean newNetwork = (config.networkId == INVALID_NETWORK_ID);
        NetworkUpdateResult result = addOrUpdateNetworkNative(config);
        int netId = result.getNetworkId();
+16 −18
Original line number Diff line number Diff line
@@ -2855,35 +2855,33 @@ public class WifiStateMachine extends StateMachine {
                    mWifiNative.reassociate();
                    break;
                case WifiManager.CONNECT_NETWORK:
                    /* The connect message can contain a network id passed as arg1 on message or
                     * or a config passed as obj on message.
                     * For a new network, a config is passed to create and connect.
                     * For an existing network, a network id is passed
                     */
                    int netId = message.arg1;
                    WifiConfiguration config = (WifiConfiguration) message.obj;

                    /* We connect to a specific network by issuing a select
                     * to the WifiConfigStore. This enables the network,
                     * while disabling all other networks in the supplicant.
                     * Disabling a connected network will cause a disconnection
                     * from the network. A reconnectCommand() will then initiate
                     * a connection to the enabled network.
                     */
                    /* Save the network config */
                    if (config != null) {
                        netId = mWifiConfigStore.selectNetwork(config);
                    } else {
                        mWifiConfigStore.selectNetwork(netId);
                        NetworkUpdateResult result = mWifiConfigStore.saveNetwork(config);
                        netId = result.getNetworkId();
                    }

                    if (mWifiConfigStore.selectNetwork(netId) &&
                            mWifiNative.reconnect()) {
                        /* The state tracker handles enabling networks upon completion/failure */
                        mSupplicantStateTracker.sendMessage(WifiManager.CONNECT_NETWORK);

                    if (mWifiNative.reconnect()) {
                        replyToMessage(message, WifiManager.CONNECT_NETWORK_SUCCEEDED);
                        /* Expect a disconnection from the old connection */
                        transitionTo(mDisconnectingState);
                    } else {
                        loge("Failed to initiate connection");
                        loge("Failed to connect config: " + config + " netId: " + netId);
                        replyToMessage(message, WifiManager.CONNECT_NETWORK_FAILED,
                                WifiManager.ERROR);
                        break;
                    }

                    /* Expect a disconnection from the old connection */
                    transitionTo(mDisconnectingState);
                    break;
                case WifiManager.START_WPS:
                    WpsInfo wpsInfo = (WpsInfo) message.obj;