diff options
author | Roshan Pius <rpius@google.com> | 2017-07-17 16:29:47 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-07-17 16:29:47 +0000 |
commit | c9f254bcdf9a1f2b535626a85b416de56a615610 (patch) | |
tree | 6d7c779120c6f9639138914231bc7d7d68ea0c55 | |
parent | 77315558f37f2ddc71ed029e262deffe0de52b70 (diff) | |
parent | e9d6e6722d8e4724b42f4c1dffa02bed05ee8b0a (diff) |
Merge "WifiConfigManager: Method to remove all transient networks" into oc-dr1-dev
5 files changed, 80 insertions, 10 deletions
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java index 8a6ef4647..8aaebb2df 100644 --- a/service/java/com/android/server/wifi/WifiConfigManager.java +++ b/service/java/com/android/server/wifi/WifiConfigManager.java @@ -1207,6 +1207,33 @@ public class WifiConfigManager { } /** + * Iterates through the internal list of configured networks and removes any ephemeral or + * passpoint network configurations which are transient in nature. + * + * @return true if a network was removed, false otherwise. + */ + public boolean removeAllEphemeralOrPasspointConfiguredNetworks() { + if (mVerboseLoggingEnabled) { + Log.v(TAG, "Removing all passpoint or ephemeral configured networks"); + } + boolean didRemove = false; + WifiConfiguration[] copiedConfigs = + mConfiguredNetworks.valuesForAllUsers().toArray(new WifiConfiguration[0]); + for (WifiConfiguration config : copiedConfigs) { + if (config.isPasspoint()) { + Log.d(TAG, "Removing passpoint network config " + config.configKey()); + removeNetwork(config.networkId, mSystemUiUid); + didRemove = true; + } else if (config.ephemeral) { + Log.d(TAG, "Removing ephemeral network config " + config.configKey()); + removeNetwork(config.networkId, mSystemUiUid); + didRemove = true; + } + } + return didRemove; + } + + /** * Helper method to mark a network enabled for network selection. */ private void setNetworkSelectionEnabled(WifiConfiguration config) { diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java index 183f32ff0..b347ea322 100644 --- a/service/java/com/android/server/wifi/WifiStateMachine.java +++ b/service/java/com/android/server/wifi/WifiStateMachine.java @@ -4810,16 +4810,8 @@ public class WifiStateMachine extends StateMachine implements WifiNative.WifiRss void registerDisconnected() { if (mLastNetworkId != WifiConfiguration.INVALID_NETWORK_ID) { mWifiConfigManager.updateNetworkAfterDisconnect(mLastNetworkId); - // We are switching away from this configuration, - // hence record the time we were connected last - WifiConfiguration config = mWifiConfigManager.getConfiguredNetwork(mLastNetworkId); - if (config != null) { - // Remove WifiConfiguration for ephemeral or Passpoint networks, since they're - // temporary networks. - if (config.ephemeral || config.isPasspoint()) { - mWifiConfigManager.removeNetwork(mLastNetworkId, Process.WIFI_UID); - } - } + // Let's remove any ephemeral or passpoint networks on every disconnect. + mWifiConfigManager.removeAllEphemeralOrPasspointConfiguredNetworks(); } } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index 961d9d676..aa858c822 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -2744,6 +2744,40 @@ public class WifiConfigManagerTest { } /** + * Verifies that all the ephemeral and passpoint networks are removed when + * {@link WifiConfigManager#removeAllEphemeralOrPasspointConfiguredNetworks()} is invoked. + */ + @Test + public void testRemoveAllEphemeralOrPasspointConfiguredNetworks() throws Exception { + WifiConfiguration savedOpenNetwork = WifiConfigurationTestUtil.createOpenNetwork(); + WifiConfiguration ephemeralNetwork = WifiConfigurationTestUtil.createEphemeralNetwork(); + WifiConfiguration passpointNetwork = WifiConfigurationTestUtil.createPasspointNetwork(); + + verifyAddNetworkToWifiConfigManager(savedOpenNetwork); + verifyAddEphemeralNetworkToWifiConfigManager(ephemeralNetwork); + verifyAddPasspointNetworkToWifiConfigManager(passpointNetwork); + + List<WifiConfiguration> expectedConfigsBeforeRemove = new ArrayList<WifiConfiguration>() {{ + add(savedOpenNetwork); + add(ephemeralNetwork); + add(passpointNetwork); + }}; + WifiConfigurationTestUtil.assertConfigurationsEqualForConfigManagerAddOrUpdate( + expectedConfigsBeforeRemove, mWifiConfigManager.getConfiguredNetworks()); + + assertTrue(mWifiConfigManager.removeAllEphemeralOrPasspointConfiguredNetworks()); + + List<WifiConfiguration> expectedConfigsAfterRemove = new ArrayList<WifiConfiguration>() {{ + add(savedOpenNetwork); + }}; + WifiConfigurationTestUtil.assertConfigurationsEqualForConfigManagerAddOrUpdate( + expectedConfigsAfterRemove, mWifiConfigManager.getConfiguredNetworks()); + + // No more ephemeral or passpoint networks to remove now. + assertFalse(mWifiConfigManager.removeAllEphemeralOrPasspointConfiguredNetworks()); + } + + /** * Verifies that the modification of a single network using * {@link WifiConfigManager#addOrUpdateNetwork(WifiConfiguration, int)} and ensures that any * updates to the network config in diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java index b9afce47f..62a68d47b 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java @@ -229,6 +229,12 @@ public class WifiConfigurationTestUtil { null, SECURITY_NONE); } + public static WifiConfiguration createEphemeralNetwork() { + WifiConfiguration configuration = createOpenNetwork(); + configuration.ephemeral = true; + return configuration; + } + public static WifiConfiguration createOpenHiddenNetwork() { WifiConfiguration configuration = createOpenNetwork(); configuration.hiddenSSID = true; diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index 52b4d3687..c91f937fe 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -2020,4 +2020,15 @@ public class WifiStateMachineTest { mLooper.dispatchAll(); verify(mWifiNative, never()).resetTxPowerLimit(); } + + /* + * Verifies that a network disconnection event will result in WifiStateMachine invoking + * {@link WifiConfigManager#removeAllEphemeralOrPasspointConfiguredNetworks()} to remove + * any ephemeral or passpoint networks from it's internal database. + */ + @Test + public void testDisconnectionRemovesEphemeralAndPasspointNetworks() throws Exception { + disconnect(); + verify(mWifiConfigManager).removeAllEphemeralOrPasspointConfiguredNetworks(); + } } |