Code example for WifiManager

Methods: pingSupplicantsetWifiEnabled, sleep

0
        assertNotNull(mWifiManager);
    } 
 
    private void sleepAfterWifiEnable() { 
        try { 
            Thread.sleep(DELAY);
        } catch (Exception e) {
            fail("Sleep timeout " + e);
        } 
    } 
 
    // Test case 1: add/remove a open network 
    @LargeTest 
    public void testAddRemoveNetwork() { 
        WifiConfiguration config = new WifiConfiguration();
        config.SSID = "\"TestSSID1\"";
        config.allowedKeyManagement.set(KeyMgmt.NONE);
 
        //add 
        int netId = mWifiManager.addNetwork(config);
        assertTrue(netId != -1);
 
        //check config list 
        List<WifiConfiguration> configList = mWifiManager.getConfiguredNetworks();
        boolean found = false;
        for (WifiConfiguration c : configList) {
            if (c.networkId == netId && c.SSID.equals(config.SSID)) {
                found = true;
            } 
        } 
        assertTrue(found);
 
        //remove 
        boolean ret = mWifiManager.removeNetwork(netId);
        assertTrue(ret);
 
        //check config list 
        configList = mWifiManager.getConfiguredNetworks();
        found = false;
        for (WifiConfiguration c : configList) {
            if (c.networkId == netId) {
                found = true;
            } 
        } 
 
        assertFalse(found);
    } 
 
    // Test case 2: enable/disable a open network 
    @LargeTest 
    public void testEnableDisableNetwork() { 
        WifiConfiguration config = new WifiConfiguration();
        config.SSID = "\"TestSSID2\"";
        config.allowedKeyManagement.set(KeyMgmt.NONE);
 
        //add 
        int netId = mWifiManager.addNetwork(config);
        assertTrue(netId != -1);
 
        //enable network and disable others 
        boolean ret = mWifiManager.enableNetwork(netId, true);
        assertTrue(ret);
 
        //check config list 
        List<WifiConfiguration> configList = mWifiManager.getConfiguredNetworks();
        for (WifiConfiguration c : configList) {
            if (c.networkId == netId) {
                assertTrue(c.status == Status.ENABLED);
            } else { 
                assertFalse(c.status == Status.ENABLED);
            } 
        } 
 
        //disable network 
        ret = mWifiManager.disableNetwork(netId);
        assertTrue(ret);
 
        //check config list 
        configList = mWifiManager.getConfiguredNetworks();
        for (WifiConfiguration c : configList) {
            if (c.networkId == netId) {
                assertTrue(c.status == Status.DISABLED);
            } 
        } 
    } 
 
    // Test case 3: ping supplicant 
    @LargeTest 
    public void testPingSupplicant() { 
        assertTrue(mWifiManager.pingSupplicant());
        mWifiManager.setWifiEnabled(false);
        sleepAfterWifiEnable(); 
 
        assertFalse(mWifiManager.pingSupplicant());
        mWifiManager.setWifiEnabled(true);
        sleepAfterWifiEnable(); 
    } 
 
    // Test case 4: save config 
    @LargeTest