am 46b59ef0: Merge "Fix access point parsing: reset static link property after parsing static ip setting Fix removeConfiguredNetwork: add sleep between remove configured network and disable wifi" into honeycomb-mr1
* commit '46b59ef01be530a6bbe3f0e9a2bed27de9985f40': Fix access point parsing: reset static link property after parsing static ip setting Fix removeConfiguredNetwork: add sleep between remove configured network and disable wifi
This commit is contained in:
@@ -182,6 +182,7 @@ public class AccessPointParserHelper {
|
||||
}
|
||||
config.proxySettings = ProxySettings.NONE;
|
||||
networks.add(config);
|
||||
mLinkProperties = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -242,10 +242,10 @@ public class ConnectivityManagerTestActivity extends Activity {
|
||||
|
||||
initializeNetworkStates();
|
||||
|
||||
if (mWifiManager.isWifiEnabled()) {
|
||||
log("Clear Wifi before we start the test.");
|
||||
removeConfiguredNetworksAndDisableWifi();
|
||||
}
|
||||
mWifiManager.setWifiEnabled(true);
|
||||
log("Clear Wifi before we start the test.");
|
||||
sleep(SHORT_TIMEOUT);
|
||||
removeConfiguredNetworksAndDisableWifi();
|
||||
mWifiRegexs = mCM.getTetherableWifiRegexs();
|
||||
}
|
||||
|
||||
@@ -633,13 +633,13 @@ public class ConnectivityManagerTestActivity extends Activity {
|
||||
* Disconnect from the current AP and remove configured networks.
|
||||
*/
|
||||
public boolean disconnectAP() {
|
||||
if (mWifiManager.isWifiEnabled()) {
|
||||
// remove saved networks
|
||||
List<WifiConfiguration> wifiConfigList = mWifiManager.getConfiguredNetworks();
|
||||
for (WifiConfiguration wifiConfig: wifiConfigList) {
|
||||
log("remove wifi configuration: " + wifiConfig.toString());
|
||||
mWifiManager.forgetNetwork(wifiConfig.networkId);
|
||||
}
|
||||
// remove saved networks
|
||||
List<WifiConfiguration> wifiConfigList = mWifiManager.getConfiguredNetworks();
|
||||
log("size of wifiConfigList: " + wifiConfigList.size());
|
||||
for (WifiConfiguration wifiConfig: wifiConfigList) {
|
||||
log("remove wifi configuration: " + wifiConfig.networkId);
|
||||
int netId = wifiConfig.networkId;
|
||||
mWifiManager.forgetNetwork(netId);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -655,20 +655,23 @@ public class ConnectivityManagerTestActivity extends Activity {
|
||||
* Remove configured networks and disable wifi
|
||||
*/
|
||||
public boolean removeConfiguredNetworksAndDisableWifi() {
|
||||
if (!disconnectAP()) {
|
||||
return false;
|
||||
}
|
||||
// Disable Wifi
|
||||
if (!mWifiManager.setWifiEnabled(false)) {
|
||||
return false;
|
||||
}
|
||||
// Wait for the actions to be completed
|
||||
try {
|
||||
Thread.sleep(SHORT_TIMEOUT);
|
||||
} catch (InterruptedException e) {}
|
||||
if (!disconnectAP()) {
|
||||
return false;
|
||||
}
|
||||
sleep(SHORT_TIMEOUT);
|
||||
if (!mWifiManager.setWifiEnabled(false)) {
|
||||
return false;
|
||||
}
|
||||
sleep(SHORT_TIMEOUT);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void sleep(long sleeptime) {
|
||||
try {
|
||||
Thread.sleep(sleeptime);
|
||||
} catch (InterruptedException e) {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set airplane mode
|
||||
*/
|
||||
|
||||
@@ -72,10 +72,8 @@ public class WifiConnectionTest
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
log("before we launch the test activity, we preserve all the configured networks.");
|
||||
mRunner = ((ConnectivityManagerTestRunner)getInstrumentation());
|
||||
mWifiManager = (WifiManager) mRunner.getContext().getSystemService(Context.WIFI_SERVICE);
|
||||
enabledNetworks = getEnabledNetworks(mWifiManager.getConfiguredNetworks());
|
||||
|
||||
mAct = getActivity();
|
||||
mWifiManager.asyncConnect(mAct, new WifiServiceHandler());
|
||||
@@ -123,42 +121,9 @@ public class WifiConnectionTest
|
||||
public void tearDown() throws Exception {
|
||||
log("tearDown()");
|
||||
mAct.removeConfiguredNetworksAndDisableWifi();
|
||||
reEnableNetworks(enabledNetworks);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
private Set<WifiConfiguration> getEnabledNetworks(List<WifiConfiguration> configuredNetworks) {
|
||||
Set<WifiConfiguration> networks = new HashSet<WifiConfiguration>();
|
||||
for (WifiConfiguration wifiConfig : configuredNetworks) {
|
||||
if (wifiConfig.status == Status.ENABLED || wifiConfig.status == Status.CURRENT) {
|
||||
networks.add(wifiConfig);
|
||||
log("remembering enabled network " + wifiConfig.SSID +
|
||||
" status is " + wifiConfig.status);
|
||||
}
|
||||
}
|
||||
return networks;
|
||||
}
|
||||
|
||||
private void reEnableNetworks(Set<WifiConfiguration> enabledNetworks) {
|
||||
if (!mWifiManager.isWifiEnabled()) {
|
||||
log("reEnableNetworks: enable Wifi");
|
||||
mWifiManager.setWifiEnabled(true);
|
||||
sleep(ConnectivityManagerTestActivity.SHORT_TIMEOUT,
|
||||
"interruped while waiting for wifi to be enabled");
|
||||
}
|
||||
|
||||
for (WifiConfiguration config : enabledNetworks) {
|
||||
if (DEBUG) {
|
||||
log("recover wifi configuration: " + config.toString());
|
||||
}
|
||||
config.SSID = "\"" + config.SSID + "\"";
|
||||
config.networkId = -1;
|
||||
mWifiManager.connectNetwork(config);
|
||||
sleep(ConnectivityManagerTestActivity.SHORT_TIMEOUT,
|
||||
"interruped while connecting to " + config.SSID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to the provided Wi-Fi network
|
||||
* @param config is the network configuration
|
||||
|
||||
Reference in New Issue
Block a user