summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2017-07-17 16:47:13 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-07-17 16:47:13 +0000
commit0b23b1445f2f45a4e1c2c466dfb9ec0788634715 (patch)
tree75edb830a867a10dcaf12673eb4ae0817e2e555d
parent654ba3541b834d8e4d0516842dd0dc591b8344a7 (diff)
parentacf2243b213c160eeeed47e88a688f40f394417f (diff)
Merge "WifiConfigManager: Method to remove all transient networks" into oc-dr1-dev am: c9f254bcdf
am: acf2243b21 Change-Id: I69249e9f7f04c3664ef06be81a100e3cb50d4934
-rw-r--r--service/java/com/android/server/wifi/WifiConfigManager.java27
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java12
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java34
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigurationTestUtil.java6
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java11
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 0a3a17d08..b54603d51 100644
--- a/service/java/com/android/server/wifi/WifiConfigManager.java
+++ b/service/java/com/android/server/wifi/WifiConfigManager.java
@@ -1225,6 +1225,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 05fdfd06f..2f3f11e0f 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -4814,16 +4814,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();
+ }
}