Search in sources :

Example 46 with WifiConfiguration

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

the class ConnectionUtil method connectToWifi.

/**
     * Associate the device to given SSID
     * If the device is already associated with a WiFi, disconnect and forget it,
     * We don't verify whether the connection is successful or not, leave this to the test
     */
public boolean connectToWifi(String knownSSID) {
    WifiConfiguration config = new WifiConfiguration();
    config.SSID = knownSSID;
    config.allowedKeyManagement.set(KeyMgmt.NONE);
    return connectToWifiWithConfiguration(config);
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration)

Example 47 with WifiConfiguration

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

the class WifiConnectionTest method testWifiConnections.

@LargeTest
public void testWifiConnections() {
    List<WifiConfiguration> wifiConfigs = loadConfigurations();
    printWifiConfigurations(wifiConfigs);
    assertFalse("No configurations to test against", wifiConfigs.isEmpty());
    boolean shouldPause = false;
    for (WifiConfiguration config : wifiConfigs) {
        if (shouldPause) {
            logv("Pausing for %d seconds", PAUSE_DURATION_MS / 1000);
            SystemClock.sleep(PAUSE_DURATION_MS);
        }
        logv("Start wifi connection test to: %s", config.SSID);
        connectToWifi(config);
        // verify that connection actually works
        assertTrue("No connectivity at end of test", checkNetworkConnectivity());
        // Disconnect and remove the network
        assertTrue("Unable to remove network", disconnectAP());
        logv("End wifi connection test to: %s", config.SSID);
        shouldPause = true;
    }
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 48 with WifiConfiguration

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

the class WifiApStress method testWifiHotSpot.

@LargeTest
public void testWifiHotSpot() {
    if (mWifiOnlyFlag) {
        logv(getName() + " is excluded for wi-fi only test");
        return;
    }
    WifiConfiguration config = new WifiConfiguration();
    config.SSID = NETWORK_ID;
    config.allowedKeyManagement.set(KeyMgmt.WPA_PSK);
    config.allowedAuthAlgorithms.set(AuthAlgorithm.OPEN);
    config.preSharedKey = PASSWD;
    // if wifiap enabled, disable it
    assertTrue("failed to disable wifi hotspot", mWifiManager.setWifiApEnabled(config, false));
    assertTrue("wifi hotspot not enabled", waitForWifiApState(WifiManager.WIFI_AP_STATE_DISABLED, 2 * LONG_TIMEOUT));
    // if Wifi is enabled, disable it
    if (mWifiManager.isWifiEnabled()) {
        assertTrue("failed to disable wifi", disableWifi());
        // wait for the wifi state to be DISABLED
        assertTrue("wifi state not disabled", waitForWifiState(WifiManager.WIFI_STATE_DISABLED, LONG_TIMEOUT));
    }
    int i;
    for (i = 0; i < mTotalIterations; i++) {
        logv("iteration: " + i);
        mLastIteration = i;
        // enable Wifi tethering
        assertTrue("failed to enable wifi hotspot", mWifiManager.setWifiApEnabled(config, true));
        // wait for wifi ap state to be ENABLED
        assertTrue("wifi hotspot not enabled", waitForWifiApState(WifiManager.WIFI_AP_STATE_ENABLED, 2 * LONG_TIMEOUT));
        // wait for wifi tethering result
        assertTrue("tether state not changed", waitForTetherStateChange(LONG_TIMEOUT));
        // allow the wifi tethering to be enabled for 10 seconds
        try {
            Thread.sleep(2 * SHORT_TIMEOUT);
        } catch (Exception e) {
        // ignore
        }
        assertTrue("no uplink data connection after Wi-Fi tethering", pingTest());
        // disable wifi hotspot
        assertTrue("failed to disable wifi hotspot", mWifiManager.setWifiApEnabled(config, false));
        assertTrue("wifi hotspot not enabled", waitForWifiApState(WifiManager.WIFI_AP_STATE_DISABLED, 2 * LONG_TIMEOUT));
        assertFalse("wifi hotspot still enabled", mWifiManager.isWifiApEnabled());
    }
}
Also used : WifiConfiguration(android.net.wifi.WifiConfiguration) LargeTest(android.test.suitebuilder.annotation.LargeTest)

Example 49 with WifiConfiguration

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

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 50 with WifiConfiguration

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

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)

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