From 347faef7fe3f5df209da431eb844bc026a1ba007 Mon Sep 17 00:00:00 2001 From: Roshan Pius Date: Tue, 15 Aug 2017 09:03:03 -0700 Subject: WifiConfigManager: Skip data migration if new store is present If the new config store files are present, skip data migration from the older store file. The old store files may still be present in the device if WifiConfigStoreLegacy.removeStores() failed for some reason during the earlier migration. Also, ensure that we attempt to delete all the store files in WifiConfigStoreLegacy.removeStores(). Returning early on failure in that method may leave the device in an incoherent state (some old store files are deleted, while others are not). Bug: 63376504 Test: Unit tests Change-Id: If2e65a7e03677040dfccf88298887e21201aff92 --- .../android/server/wifi/WifiConfigManagerTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index 7509c18b3..a85e5740b 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -2555,6 +2555,7 @@ public class WifiConfigManagerTest { new WifiConfigStoreDataLegacy(networks, deletedEphermalSSIDs); when(mWifiConfigStoreLegacy.areStoresPresent()).thenReturn(true); + when(mWifiConfigStore.areStoresPresent()).thenReturn(false); when(mWifiConfigStoreLegacy.read()).thenReturn(storeData); // Now trigger the migration from legacy store. This should populate the in memory list with @@ -2587,6 +2588,24 @@ public class WifiConfigManagerTest { verify(mWifiConfigStoreLegacy, never()).removeStores(); } + /** + * Verifies the loading of networks using {@link WifiConfigManager#migrateFromLegacyStore()} ()} + * does not attempt to migrate data from legacy stores when the new store files are present + * (i.e migration was already done once). + */ + @Test + public void testNewStoreFilesPresentNoMigrationFromLegacyStore() throws Exception { + when(mWifiConfigStore.areStoresPresent()).thenReturn(true); + when(mWifiConfigStoreLegacy.areStoresPresent()).thenReturn(true); + + // Now trigger a migration from legacy store. + assertTrue(mWifiConfigManager.migrateFromLegacyStore()); + + verify(mWifiConfigStoreLegacy, never()).read(); + // Verify that we went ahead and deleted the old store files. + verify(mWifiConfigStoreLegacy).removeStores(); + } + /** * Verifies the loading of networks using {@link WifiConfigManager#loadFromStore()} does * not attempt to read from any of the stores (new or legacy) when the store files are -- cgit v1.2.3