diff options
3 files changed, 26 insertions, 57 deletions
diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java index 3667c7b..d22356d 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/AccessPointParserHelper.java @@ -182,6 +182,7 @@ public class AccessPointParserHelper { } config.proxySettings = ProxySettings.NONE; networks.add(config); + mLinkProperties = null; } } diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java index e138200..adf1883 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/ConnectivityManagerTestActivity.java @@ -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 */ diff --git a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiConnectionTest.java b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiConnectionTest.java index fe79e6c..22b1759 100644 --- a/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiConnectionTest.java +++ b/core/tests/ConnectivityManagerTest/src/com/android/connectivitymanagertest/functional/WifiConnectionTest.java @@ -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 |