summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2016-11-12 00:26:28 +0000
committerGerrit Code Review <noreply-gerritcodereview@google.com>2016-11-12 00:26:28 +0000
commitda0d52dd85b54d6ced2a2083423c883ec3e20449 (patch)
treec15024232e35b7074c8688e8ef200fec1a01fe3c
parent45ff377d3332f5a77d5290ca6392e4de0533db6a (diff)
parentb2c8d28046e96c4506482e030c6320cda6db8f30 (diff)
Merge changes I5fbdd533,I547ae5aa
* changes: WifiConfigManager: Remove legacy store files WifiConfigManager: Don't trigger store writes for ephemeral networks
-rw-r--r--service/java/com/android/server/wifi/WifiConfigManager.java15
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java81
2 files changed, 80 insertions, 16 deletions
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java
index d267fdad1..812a3031d 100644
--- a/service/java/com/android/server/wifi/WifiConfigManager.java
+++ b/service/java/com/android/server/wifi/WifiConfigManager.java
@@ -976,8 +976,10 @@ public class WifiConfigManager {
result.isNewNetwork()
? WifiManager.CHANGE_REASON_ADDED
: WifiManager.CHANGE_REASON_CONFIG_CHANGE);
- // External modification, persist it immediately.
- saveToStore(true);
+ // Unless the added network is ephemeral, persist the network update/addition.
+ if (!config.ephemeral) {
+ saveToStore(true);
+ }
return result;
}
@@ -1038,8 +1040,10 @@ public class WifiConfigManager {
clearLastSelectedNetwork();
}
sendConfiguredNetworkChangedBroadcast(config, WifiManager.CHANGE_REASON_REMOVED);
- // External modification, persist it immediately.
- saveToStore(true);
+ // Unless the removed network is ephemeral, persist the network removal.
+ if (!config.ephemeral) {
+ saveToStore(true);
+ }
return true;
}
@@ -2415,8 +2419,7 @@ public class WifiConfigManager {
if (!saveToStore(true)) {
return false;
}
- // TODO: Remove the legacy store files
- // mWifiConfigStoreLegacy.removeStores();
+ mWifiConfigStoreLegacy.removeStores();
Log.d(TAG, "Migration from legacy store completed");
}
return true;
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index 401c4f013..b96d4e954 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -217,13 +217,13 @@ public class WifiConfigManagerTest {
* the {@link WifiConfigManager#getSavedNetworks()} does not return this network.
*/
@Test
- public void testAddSingleEphemeralNetwork() {
- WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork();
- openNetwork.ephemeral = true;
+ public void testAddSingleEphemeralNetwork() throws Exception {
+ WifiConfiguration ephemeralNetwork = WifiConfigurationTestUtil.createOpenNetwork();
+ ephemeralNetwork.ephemeral = true;
List<WifiConfiguration> networks = new ArrayList<>();
- networks.add(openNetwork);
+ networks.add(ephemeralNetwork);
- verifyAddEphemeralNetworkToWifiConfigManager(openNetwork);
+ verifyAddEphemeralNetworkToWifiConfigManager(ephemeralNetwork);
List<WifiConfiguration> retrievedNetworks =
mWifiConfigManager.getConfiguredNetworksWithPasswords();
@@ -235,6 +235,26 @@ public class WifiConfigManagerTest {
}
/**
+ * Verifies the addition of 2 networks (1 normal and 1 ephemeral) using
+ * {@link WifiConfigManager#addOrUpdateNetwork(WifiConfiguration, int)} and ensures that
+ * the ephemeral network configuration is not persisted in config store.
+ */
+ @Test
+ public void testAddMultipleNetworksAndEnsureEphemeralNetworkNotPersisted() {
+ WifiConfiguration ephemeralNetwork = WifiConfigurationTestUtil.createOpenNetwork();
+ ephemeralNetwork.ephemeral = true;
+ WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork();
+
+ assertTrue(addNetworkToWifiConfigManager(ephemeralNetwork).isSuccess());
+ assertTrue(addNetworkToWifiConfigManager(openNetwork).isSuccess());
+
+ // The open network addition should trigger a store write.
+ WifiConfigStoreData storeData = captureWriteStoreData();
+ assertFalse(isNetworkInConfigStoreData(ephemeralNetwork, storeData));
+ assertTrue(isNetworkInConfigStoreData(openNetwork, storeData));
+ }
+
+ /**
* Verifies that the modification of a single open network using
* {@link WifiConfigManager#addOrUpdateNetwork(WifiConfiguration, int)} with a UID which
* has no permission to modify the network fails.
@@ -387,13 +407,30 @@ public class WifiConfigManagerTest {
@Test
public void testRemoveSingleOpenNetwork() {
WifiConfiguration openNetwork = WifiConfigurationTestUtil.createOpenNetwork();
- List<WifiConfiguration> networks = new ArrayList<>();
- networks.add(openNetwork);
verifyAddNetworkToWifiConfigManager(openNetwork);
+ // Ensure that configured network list is not empty.
+ assertFalse(mWifiConfigManager.getConfiguredNetworks().isEmpty());
verifyRemoveNetworkFromWifiConfigManager(openNetwork);
+ // Ensure that configured network list is empty now.
+ assertTrue(mWifiConfigManager.getConfiguredNetworks().isEmpty());
+ }
+
+ /**
+ * Verifies the removal of an ephemeral network using
+ * {@link WifiConfigManager#removeNetwork(int)}
+ */
+ @Test
+ public void testRemoveSingleEphemeralNetwork() throws Exception {
+ WifiConfiguration ephemeralNetwork = WifiConfigurationTestUtil.createOpenNetwork();
+ ephemeralNetwork.ephemeral = true;
+
+ verifyAddEphemeralNetworkToWifiConfigManager(ephemeralNetwork);
+ // Ensure that configured network list is not empty.
+ assertFalse(mWifiConfigManager.getConfiguredNetworks().isEmpty());
+ verifyRemoveEphemeralNetworkFromWifiConfigManager(ephemeralNetwork);
// Ensure that configured network list is empty now.
assertTrue(mWifiConfigManager.getConfiguredNetworks().isEmpty());
}
@@ -1874,6 +1911,7 @@ public class WifiConfigManagerTest {
verify(mWifiConfigStore, never()).read();
verify(mWifiConfigStoreLegacy).read();
+ verify(mWifiConfigStoreLegacy).removeStores();
List<WifiConfiguration> retrievedNetworks =
mWifiConfigManager.getConfiguredNetworksWithPasswords();
@@ -2361,10 +2399,19 @@ public class WifiConfigManagerTest {
if (storeData == null) {
return false;
}
+ return isNetworkInConfigStoreData(configuration, storeData);
+ }
+
+ /**
+ * Returns whether the provided network was in the store data or not.
+ */
+ private boolean isNetworkInConfigStoreData(
+ WifiConfiguration configuration, WifiConfigStoreData storeData) {
boolean foundNetworkInStoreData = false;
for (WifiConfiguration retrievedConfig : storeData.getConfigurations()) {
if (retrievedConfig.configKey().equals(configuration.configKey())) {
foundNetworkInStoreData = true;
+ break;
}
}
return foundNetworkInStoreData;
@@ -2491,7 +2538,7 @@ public class WifiConfigManagerTest {
* Add ephemeral network to WifiConfigManager and ensure that it was successful.
*/
private NetworkUpdateResult verifyAddEphemeralNetworkToWifiConfigManager(
- WifiConfiguration configuration) {
+ WifiConfiguration configuration) throws Exception {
NetworkUpdateResult result = addNetworkToWifiConfigManager(configuration);
assertTrue(result.getNetworkId() != WifiConfiguration.INVALID_NETWORK_ID);
assertTrue(result.isNewNetwork());
@@ -2499,8 +2546,9 @@ public class WifiConfigManagerTest {
assertTrue(result.hasProxyChanged());
verifyNetworkAddBroadcast(configuration);
- // Ephemeral networks should not be persisted.
- verifyNetworkNotInConfigStoreData(configuration);
+ // Ensure that the write was not invoked for ephemeral network addition.
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore, never())
+ .write(anyBoolean(), any(WifiConfigStoreData.class));
return result;
}
@@ -2570,6 +2618,19 @@ public class WifiConfigManagerTest {
}
/**
+ * Removes ephemeral network from WifiConfigManager and ensure that it was successful.
+ */
+ private void verifyRemoveEphemeralNetworkFromWifiConfigManager(
+ WifiConfiguration configuration) throws Exception {
+ assertTrue(mWifiConfigManager.removeNetwork(configuration.networkId, TEST_CREATOR_UID));
+
+ verifyNetworkRemoveBroadcast(configuration);
+ // Ensure that the write was not invoked for ephemeral network remove.
+ mContextConfigStoreMockOrder.verify(mWifiConfigStore, never())
+ .write(anyBoolean(), any(WifiConfigStoreData.class));
+ }
+
+ /**
* Verifies the provided network's public status and ensures that the network change broadcast
* has been sent out.
*/