summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2016-08-22 10:35:03 -0700
committerRoshan Pius <rpius@google.com>2016-08-24 13:37:44 -0700
commit3a738a26918230b2469d917dbf14323234edd39b (patch)
tree0a1e905f149374765cd760b753f243e455d21004 /tests
parentee7bdc30d102e05df8d275ebc133afed21808e34 (diff)
WifiConfigManagerNew: Migration from legacy stores
Integrated the new |WifiConfigStoreLegacy| into the new WifiConfigManager. Every invocation of |loadFromStore| will check if there is any data to be migrated from legacy store files if the new store files are not present. If legacy store data is present, it will migrate all of the data from those stores and delete them permanently. The deletion of legacy stores is commented out in the first roll out of the new config store changes. This will be re-enabled once things are stable so that we can revert to this data if needed. BUG: 29337176 Change-Id: I35d626ed8bae70c676cb10b307cb116ed837a529 TEST: Existing unit tests.
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerNewTest.java59
1 files changed, 58 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerNewTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerNewTest.java
index 4b90b7660..832a0855c 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerNewTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerNewTest.java
@@ -38,6 +38,7 @@ import android.test.suitebuilder.annotation.SmallTest;
import android.text.TextUtils;
import com.android.internal.R;
+import com.android.server.wifi.WifiConfigStoreLegacy.WifiConfigStoreDataLegacy;
import org.junit.After;
import org.junit.Before;
@@ -78,6 +79,7 @@ public class WifiConfigManagerNewTest {
@Mock private UserManager mUserManager;
@Mock private WifiKeyStore mWifiKeyStore;
@Mock private WifiConfigStoreNew mWifiConfigStore;
+ @Mock private WifiConfigStoreLegacy mWifiConfigStoreLegacy;
@Mock private PackageManager mPackageManager;
private MockResources mResources;
@@ -146,6 +148,8 @@ public class WifiConfigManagerNewTest {
.updateNetworkKeys(any(WifiConfiguration.class), any(WifiConfiguration.class)))
.thenReturn(true);
+ when(mWifiConfigStore.areStoresPresent()).thenReturn(true);
+
createWifiConfigManager();
}
@@ -1791,11 +1795,64 @@ public class WifiConfigManagerNewTest {
assertTrue(result.isSuccess());
}
+ /**
+ * Verifies the loading of networks using {@link WifiConfigManagerNew#loadFromStore()} attempts
+ * to migrate data from legacy stores when the new store files are absent.
+ */
+ @Test
+ public void testMigrationFromLegacyStore() throws Exception {
+ // Create the store data to be returned from legacy stores.
+ List<WifiConfiguration> networks = new ArrayList<>();
+ networks.add(WifiConfigurationTestUtil.createPskNetwork());
+ networks.add(WifiConfigurationTestUtil.createEapNetwork());
+ networks.add(WifiConfigurationTestUtil.createWepNetwork());
+ WifiConfigStoreDataLegacy storeData =
+ new WifiConfigStoreDataLegacy(networks, new HashSet<String>());
+
+ // New store files not present, so migrate from the old store.
+ when(mWifiConfigStore.areStoresPresent()).thenReturn(false);
+ when(mWifiConfigStoreLegacy.areStoresPresent()).thenReturn(true);
+ when(mWifiConfigStoreLegacy.read()).thenReturn(storeData);
+
+ // Now trigger a load from store. This should populate the in memory list with all the
+ // networks above from the legacy store.
+ mWifiConfigManager.loadFromStore();
+
+ verify(mWifiConfigStore, never()).read();
+ verify(mWifiConfigStoreLegacy).read();
+
+ List<WifiConfiguration> retrievedNetworks =
+ mWifiConfigManager.getConfiguredNetworksWithPasswords();
+ WifiConfigurationTestUtil.assertConfigurationsEqualForConfigManagerAddOrUpdate(
+ networks, retrievedNetworks);
+ }
+
+ /**
+ * Verifies the loading of networks using {@link WifiConfigManagerNew#loadFromStore()} does
+ * not attempt to read from any of the stores (new or legacy) when the store files are
+ * not present.
+ */
+ @Test
+ public void testFreshInstallDoesNotLoadFromStore() throws Exception {
+ // New store files not present, so migrate from the old store.
+ when(mWifiConfigStore.areStoresPresent()).thenReturn(false);
+ when(mWifiConfigStoreLegacy.areStoresPresent()).thenReturn(false);
+
+ // Now trigger a load from store. This should populate the in memory list with all the
+ // networks above.
+ mWifiConfigManager.loadFromStore();
+
+ verify(mWifiConfigStore, never()).read();
+ verify(mWifiConfigStoreLegacy, never()).read();
+
+ assertTrue(mWifiConfigManager.getConfiguredNetworksWithPasswords().isEmpty());
+ }
+
private void createWifiConfigManager() {
mWifiConfigManager =
new WifiConfigManagerNew(
mContext, mFrameworkFacade, mClock, mUserManager, mWifiKeyStore,
- mWifiConfigStore);
+ mWifiConfigStore, mWifiConfigStoreLegacy);
mWifiConfigManager.enableVerboseLogging(1);
}