Search in sources :

Example 71 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project android_frameworks_base by ParanoidAndroid.

the class WifiClientTest method testEnableDisableNetwork.

// 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);
        }
    }
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 72 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project android_frameworks_base by ParanoidAndroid.

the class WifiClientTest method testAddRemoveNetwork.

// 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);
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 73 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project android_frameworks_base by ParanoidAndroid.

the class WifiClientTest method testSaveConfig.

// Test case 4: save config
@LargeTest
public void testSaveConfig() {
    WifiConfiguration config = new WifiConfiguration();
    config.SSID = "\"TestSSID3\"";
    config.allowedKeyManagement.set(KeyMgmt.NONE);
    //add
    int netId = mWifiManager.addNetwork(config);
    assertTrue(netId != -1);
    mWifiManager.saveConfiguration();
    //restart wifi
    mWifiManager.setWifiEnabled(false);
    mWifiManager.setWifiEnabled(true);
    sleepAfterWifiEnable();
    //check config list
    List<WifiConfiguration> configList = mWifiManager.getConfiguredNetworks();
    boolean found = false;
    for (WifiConfiguration c : configList) {
        if (c.SSID.equals("TestSSID3")) {
            found = true;
        }
    }
    assertTrue(found);
    //restore config
    boolean ret = mWifiManager.removeNetwork(netId);
    assertTrue(ret);
    mWifiManager.saveConfiguration();
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 74 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project android_frameworks_base by ParanoidAndroid.

the class WifiSoftAPTest method testApSsidWithAlphabet.

// Test case 1: Test the soft AP SSID with letters
@LargeTest
public void testApSsidWithAlphabet() {
    WifiConfiguration config = new WifiConfiguration();
    config.SSID = "abcdefghijklmnopqrstuvwxyz";
    config.allowedKeyManagement.set(KeyMgmt.NONE);
    mWifiConfig = config;
    assertTrue(mWifiManager.setWifiApEnabled(mWifiConfig, true));
    try {
        Thread.sleep(DURATION);
    } catch (InterruptedException e) {
        Log.v(TAG, "exception " + e.getStackTrace());
        assertFalse(true);
    }
    assertNotNull(mWifiManager.getWifiApConfiguration());
    assertEquals("wifi AP state is not enabled", WifiManager.WIFI_AP_STATE_ENABLED, mWifiManager.getWifiApState());
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 75 with WifiConfiguration

use of android.net.wifi.WifiConfiguration in project android_frameworks_base by AOSPA.

the class WifiAssociationTest method getConfig.

/**
     * Get the {@link WifiConfiguration} based on ssid, security, and password.
     */
private WifiConfiguration getConfig(String ssid, SecurityType securityType, String password) {
    logv("Security type is %s", securityType.toString());
    WifiConfiguration config = null;
    switch(securityType) {
        case OPEN:
            config = WifiConfigurationHelper.createOpenConfig(ssid);
            break;
        case WEP64:
            assertNotNull("password is empty", password);
            // always use hex pair for WEP-40
            assertTrue(WifiConfigurationHelper.isHex(password, 10));
            config = WifiConfigurationHelper.createWepConfig(ssid, password);
            config.allowedGroupCiphers.set(GroupCipher.WEP40);
            break;
        case WEP128:
            assertNotNull("password is empty", password);
            // always use hex pair for WEP-104
            assertTrue(WifiConfigurationHelper.isHex(password, 26));
            config = WifiConfigurationHelper.createWepConfig(ssid, password);
            config.allowedGroupCiphers.set(GroupCipher.WEP104);
            break;
        case WPA_TKIP:
            assertNotNull("password is empty", password);
            config = WifiConfigurationHelper.createPskConfig(ssid, password);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
            config.allowedProtocols.set(Protocol.WPA);
            config.allowedPairwiseCiphers.set(PairwiseCipher.TKIP);
            config.allowedGroupCiphers.set(GroupCipher.TKIP);
            break;
        case WPA2_AES:
            assertNotNull("password is empty", password);
            config = WifiConfigurationHelper.createPskConfig(ssid, password);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
            config.allowedProtocols.set(Protocol.RSN);
            config.allowedPairwiseCiphers.set(PairwiseCipher.CCMP);
            config.allowedGroupCiphers.set(GroupCipher.CCMP);
            break;
        default:
            fail("Not a valid security type: " + securityType);
            break;
    }
    return config;
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration)

Aggregations

WifiConfiguration (android.net.wifi.WifiConfiguration)569 WifiManager (android.net.wifi.WifiManager)88 LargeTest (android.test.suitebuilder.annotation.LargeTest)53 IOException (java.io.IOException)48 ArrayList (java.util.ArrayList)47 AccessPoint (com.android.settingslib.wifi.AccessPoint)46 Test (org.junit.Test)45 WifiEnterpriseConfig (android.net.wifi.WifiEnterpriseConfig)40 WifiInfo (android.net.wifi.WifiInfo)36 ScanResult (android.net.wifi.ScanResult)27 NetworkInfo (android.net.NetworkInfo)22 StaticIpConfiguration (android.net.StaticIpConfiguration)20 Credential (com.android.hotspot2.pps.Credential)20 Scanner (com.android.settingslib.wifi.WifiTracker.Scanner)20 Intent (android.content.Intent)19 Bundle (android.os.Bundle)19 ValidatedEditTextPreference (com.android.settings.widget.ValidatedEditTextPreference)16 Before (org.junit.Before)13 VisibleForTesting (android.support.annotation.VisibleForTesting)12 Preference (android.support.v7.preference.Preference)12