Methods Summary |
---|
protected void | setUp()
super.setUp();
// register a connectivity receiver for CONNECTIVITY_ACTION;
mWifiStateListener = new WifiStateListener();
IntentFilter mIntentFilter = new IntentFilter();
mIntentFilter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
mIntentFilter.addAction(WifiManager.SUPPLICANT_STATE_CHANGED_ACTION);
mIntentFilter.addAction(WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION);
mIntentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
getContext().registerReceiver(mWifiStateListener, mIntentFilter);
mWifiManager = (WifiManager) getContext().getSystemService(Context.WIFI_SERVICE);
mWifiManager.setWifiEnabled(true);
assertNotNull(mWifiManager);
|
private void | sleepAfterWifiEnable()
try {
Thread.sleep(DELAY);
} catch (Exception e) {
fail("Sleep timeout " + e);
}
|
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);
|
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);
}
}
|
public void | testPingSupplicant()
assertTrue(mWifiManager.pingSupplicant());
mWifiManager.setWifiEnabled(false);
sleepAfterWifiEnable();
assertFalse(mWifiManager.pingSupplicant());
mWifiManager.setWifiEnabled(true);
sleepAfterWifiEnable();
|
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();
|
public void | testWifiBroadcasts()
/* Initialize */
mWifiManager.setWifiEnabled(false);
sleepAfterWifiEnable();
mDisableBroadcastCounter = 0;
mEnableBroadcastCounter = 0;
mSupplicantConnection = false;
mNetworkInfo = null;
mSupplicantState = null;
/* Enable wifi */
mWifiManager.setWifiEnabled(true);
sleepAfterWifiEnable();
assertTrue(mEnableBroadcastCounter == 2);
assertTrue(mSupplicantConnection == true);
assertTrue(mNetworkInfo.isConnected());
assertTrue(mSupplicantState == SupplicantState.COMPLETED);
/* Disable wifi */
mWifiManager.setWifiEnabled(false);
sleepAfterWifiEnable();
assertTrue(mDisableBroadcastCounter == 2);
assertTrue(mSupplicantConnection == false);
assertTrue(!mNetworkInfo.isConnected());
assertTrue(mSupplicantState != SupplicantState.COMPLETED);
|
public void | testWifiConfiguredNetworkStatus()
/* Initialize */
mWifiManager.setWifiEnabled(false);
sleepAfterWifiEnable();
/* Ensure no network is CURRENT */
List<WifiConfiguration> configList = mWifiManager.getConfiguredNetworks();
for (WifiConfiguration c : configList) {
assertTrue(c.status != WifiConfiguration.Status.CURRENT);
}
/* Enable wifi */
mWifiManager.setWifiEnabled(true);
sleepAfterWifiEnable();
/* Ensure connected network is CURRENT */
String connectedSSID = mWifiManager.getConnectionInfo().getSSID();
configList = mWifiManager.getConfiguredNetworks();
for (WifiConfiguration c : configList) {
if (c.SSID.contains(connectedSSID)) {
assertTrue(c.status == WifiConfiguration.Status.CURRENT);
} else {
assertTrue(c.status != WifiConfiguration.Status.CURRENT);
}
}
/* Disable wifi */
mWifiManager.setWifiEnabled(false);
sleepAfterWifiEnable();
/* Ensure no network is CURRENT */
configList = mWifiManager.getConfiguredNetworks();
for (WifiConfiguration c : configList) {
assertTrue(c.status != WifiConfiguration.Status.CURRENT);
}
|