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

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

Fix configured network status

For a connected network, keep status as CURRENT. For a network,
that is disconnected it should be ENABLED. A disabled network
will have the status as DISABLED

Also, add a unit test to ensure there is only one CURRENT network
that is connected

Change-Id: Iaa4a7124a0c372a8f6df3d846ae8c15d9b29cf13
parent c1761e7f
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -271,4 +271,46 @@ public class WifiClientTest extends AndroidTestCase {

    }

    // Test case 6: test configured network status
    @LargeTest
    public void testWifiConfiguredNetworkStatus() {

        /* Initialize */
        mWifiManager.setWifiEnabled(false);
        sleepAfterWifiEnable();

        /* Ensure no network is CURRENT */
        List<WifiConfiguration> configList = mWifiManager.getConfiguredNetworks();
        for (WifiConfiguration c : configList) {
            assertTrue(c.status != WifiConfiguration.Status.CURRENT);
        }

        /* Enable wifi */
        mWifiManager.setWifiEnabled(true);
        sleepAfterWifiEnable();

        /* Ensure connected network is CURRENT */
        String connectedSSID = mWifiManager.getConnectionInfo().getSSID();
        configList = mWifiManager.getConfiguredNetworks();
        for (WifiConfiguration c : configList) {
            if (c.SSID.contains(connectedSSID)) {
                assertTrue(c.status == WifiConfiguration.Status.CURRENT);
            } else {
                assertTrue(c.status != WifiConfiguration.Status.CURRENT);
            }
        }

        /* Disable wifi */
        mWifiManager.setWifiEnabled(false);
        sleepAfterWifiEnable();

        /* Ensure no network is CURRENT */
        configList = mWifiManager.getConfiguredNetworks();
        for (WifiConfiguration c : configList) {
            assertTrue(c.status != WifiConfiguration.Status.CURRENT);
        }
    }



}
+19 −0
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.net.DhcpInfoInternal;
import android.net.LinkAddress;
import android.net.LinkProperties;
import android.net.NetworkUtils;
import android.net.NetworkInfo.DetailedState;
import android.net.ProxyProperties;
import android.net.RouteInfo;
import android.net.wifi.WifiConfiguration.IpAssignment;
@@ -276,6 +277,24 @@ class WifiConfigStore {
        return result;
    }

    static void updateStatus(int netId, DetailedState state) {
        if (netId != INVALID_NETWORK_ID) {
            WifiConfiguration config = sConfiguredNetworks.get(netId);
            if (config == null) return;
            switch (state) {
                case CONNECTED:
                    config.status = Status.CURRENT;
                    break;
                case DISCONNECTED:
                    config.status = Status.ENABLED;
                    break;
                default:
                    //do nothing, retain the existing state
                    break;
            }
        }
    }

    /**
     * Forget the specified network and save config
     *
+4 −1
Original line number Diff line number Diff line
@@ -1642,8 +1642,10 @@ public class WifiStateMachine extends StateMachine {
        mWifiInfo.setRssi(MIN_RSSI);
        mWifiInfo.setLinkSpeed(-1);

        /* send event to CM & network change broadcast */
        setNetworkDetailedState(DetailedState.DISCONNECTED);
        WifiConfigStore.updateStatus(mLastNetworkId, DetailedState.DISCONNECTED);

        /* send event to CM & network change broadcast */
        sendNetworkStateChangeBroadcast(mLastBssid);

        /* Clear network properties */
@@ -1726,6 +1728,7 @@ public class WifiStateMachine extends StateMachine {
        } else {
            configureLinkProperties();
            setNetworkDetailedState(DetailedState.CONNECTED);
            WifiConfigStore.updateStatus(mLastNetworkId, DetailedState.CONNECTED);
            sendNetworkStateChangeBroadcast(mLastBssid);
        }
    }