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);
}
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;
}
}
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());
}
}
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);
}
}
}
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();
}
Aggregations