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