Search in sources :

Example 6 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 7 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 8 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 9 with WifiConfiguration

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

the class ConnectionUtil method disconnectAP.

/*
     * Disconnect from the current AP and remove configured networks.
     */
public boolean disconnectAP() {
    // remove saved networks
    List<WifiConfiguration> wifiConfigList = mWifiManager.getConfiguredNetworks();
    Log.v(LOG_TAG, "size of wifiConfigList: " + wifiConfigList.size());
    for (WifiConfiguration wifiConfig : wifiConfigList) {
        Log.v(LOG_TAG, "Remove wifi configuration: " + wifiConfig.networkId);
        int netId = wifiConfig.networkId;
        mWifiManager.forget(netId, new WifiManager.ActionListener() {

            public void onSuccess() {
            }

            public void onFailure(int reason) {
                Log.e(LOG_TAG, "forget failed " + reason);
            }
        });
    }
    return true;
}
Also used : WifiManager(android.net.wifi.WifiManager) WifiConfiguration(android.net.wifi.WifiConfiguration)

Example 10 with WifiConfiguration

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

the class WifiAssociationTest method testWifiAssociation.

@LargeTest
public void testWifiAssociation() {
    assertNotNull("no test ssid", mSsid);
    WifiConfiguration config = new WifiConfiguration();
    config.SSID = mSsid;
    SECURITY_TYPE security = SECURITY_TYPE.valueOf(mSecurityType);
    log("Security type is " + security.toString());
    switch(security) {
        // set network configurations
        case OPEN:
            config.allowedKeyManagement.set(KeyMgmt.NONE);
            break;
        case WEP64:
            // always use hex pair for WEP-40
            assertTrue("not a WEP64 security type?", mPassword.length() == 10);
            config.allowedKeyManagement.set(KeyMgmt.NONE);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
            config.allowedGroupCiphers.set(GroupCipher.WEP40);
            if (mPassword != null) {
                int length = mPassword.length();
                // WEP-40
                if (mPassword.matches("[0-9A-Fa-f]*")) {
                    config.wepKeys[0] = mPassword;
                } else {
                    fail("Please type hex pair for the password");
                }
            }
            break;
        case WEP128:
            assertNotNull("password is empty", mPassword);
            // always use hex pair for WEP-104
            assertTrue("not a WEP128 security type?", mPassword.length() == 26);
            config.allowedKeyManagement.set(KeyMgmt.NONE);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.SHARED);
            config.allowedGroupCiphers.set(GroupCipher.WEP104);
            if (mPassword != null) {
                int length = mPassword.length();
                // WEP-40
                if (mPassword.matches("[0-9A-Fa-f]*")) {
                    config.wepKeys[0] = mPassword;
                } else {
                    fail("Please type hex pair for the password");
                }
            }
            break;
        case WPA_TKIP:
            assertNotNull("missing password", mPassword);
            config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
            config.allowedProtocols.set(Protocol.WPA);
            config.allowedPairwiseCiphers.set(PairwiseCipher.TKIP);
            config.allowedGroupCiphers.set(GroupCipher.TKIP);
            if (mPassword.matches("[0-9A-Fa-f]{64}")) {
                config.preSharedKey = mPassword;
            } else {
                config.preSharedKey = '"' + mPassword + '"';
            }
            break;
        case WPA2_AES:
            assertNotNull("missing password", mPassword);
            config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
            config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
            config.allowedProtocols.set(Protocol.RSN);
            config.allowedPairwiseCiphers.set(PairwiseCipher.CCMP);
            config.allowedGroupCiphers.set(GroupCipher.CCMP);
            config.allowedProtocols.set(Protocol.RSN);
            if (mPassword.matches("[0-9A-Fa-f]{64}")) {
                config.preSharedKey = mPassword;
            } else {
                config.preSharedKey = '"' + mPassword + '"';
            }
            break;
        default:
            fail("Not a valid security type: " + mSecurityType);
            break;
    }
    Log.v(TAG, "network config: " + config.toString());
    connectToWifi(config);
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Aggregations

WifiConfiguration (android.net.wifi.WifiConfiguration)316 WifiManager (android.net.wifi.WifiManager)54 LargeTest (android.test.suitebuilder.annotation.LargeTest)53 IOException (java.io.IOException)44 ArrayList (java.util.ArrayList)38 WifiEnterpriseConfig (android.net.wifi.WifiEnterpriseConfig)32 ScanResult (android.net.wifi.ScanResult)27 Credential (com.android.hotspot2.pps.Credential)20 Scanner (com.android.settingslib.wifi.WifiTracker.Scanner)20 WifiInfo (android.net.wifi.WifiInfo)16 Bundle (android.os.Bundle)12 NetworkPolicy (android.net.NetworkPolicy)10 SpannableString (android.text.SpannableString)10 EAP (com.android.anqp.eap.EAP)10 X509Certificate (java.security.cert.X509Certificate)10 StaticIpConfiguration (android.net.StaticIpConfiguration)7 PackageManager (android.content.pm.PackageManager)6 NetworkInfo (android.net.NetworkInfo)6 PowerManager (android.os.PowerManager)6 RemoteException (android.os.RemoteException)6