diff options
author | Roshan Pius <rpius@google.com> | 2018-04-03 11:01:29 -0700 |
---|---|---|
committer | Sat K <satk@google.com> | 2018-04-06 19:22:31 +0000 |
commit | f210755c2ac34dc466bcab188b9716b2482bbfe1 (patch) | |
tree | 5c75c9902c0eb6a636c878cec4f1ba28f17b07fd /tests | |
parent | dafc81f174519aa709e2ba4127360408d1644905 (diff) |
WifiConfigStorLegacy: Add null check during restore
One of our OEM's is running into a crash in the config store migration
logic added in O. See the below bug for more details. This issue is not
seen on Pixel devices, because the |configKey| can never be null there.
Also, added a wrapper for IpConfigStore to help in mocking static
method in IpConfigstore.
Note: This code is pretty much unused on Pixel devices & other OEM's
who have upgraded from N to O. Only will help OEM's who upgrade from N
to P directly.
Bug: 73877225
Test: Unit tests
Change-Id: I1b24c05bbb2bc488d77f3f93ec550517c1d1e5c3
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiConfigStoreLegacyTest.java | 42 |
1 files changed, 39 insertions, 3 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreLegacyTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreLegacyTest.java index 0404a244b..ae4a396f6 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreLegacyTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreLegacyTest.java @@ -26,7 +26,7 @@ import android.support.test.filters.SmallTest; import android.text.TextUtils; import android.util.SparseArray; -import com.android.server.net.IpConfigStore; +import com.android.server.wifi.WifiConfigStoreLegacy.IpConfigStoreWrapper; import com.android.server.wifi.hotspot2.LegacyPasspointConfig; import com.android.server.wifi.hotspot2.LegacyPasspointConfigParser; @@ -51,7 +51,7 @@ public class WifiConfigStoreLegacyTest { // Test mocks @Mock private WifiNative mWifiNative; @Mock private WifiNetworkHistory mWifiNetworkHistory; - @Mock private IpConfigStore mIpconfigStore; + @Mock private IpConfigStoreWrapper mIpconfigStoreWrapper; @Mock private LegacyPasspointConfigParser mPasspointConfigParser; /** @@ -68,7 +68,7 @@ public class WifiConfigStoreLegacyTest { MockitoAnnotations.initMocks(this); mWifiConfigStore = new WifiConfigStoreLegacy(mWifiNetworkHistory, mWifiNative, - mIpconfigStore, mPasspointConfigParser); + mIpconfigStoreWrapper, mPasspointConfigParser); } /** @@ -140,6 +140,8 @@ public class WifiConfigStoreLegacyTest { any(), any(Map.class), any(SparseArray.class)); when(mPasspointConfigParser.parseConfig(anyString())).thenReturn(passpointConfigs); + when(mIpconfigStoreWrapper.readIpAndProxyConfigurations(anyString())) + .thenReturn(createIpConfigStoreLoadData(networks)); WifiConfigStoreLegacy.WifiConfigStoreDataLegacy storeData = mWifiConfigStore.read(); // Update the expected configuration for Passpoint network. @@ -154,6 +156,40 @@ public class WifiConfigStoreLegacyTest { networks, storeData.getConfigurations()); } + /** + * Verify loading of network configurations from legacy stores with a null configKey. + * This happens if the 'ID_STR' field in wpa_supplicant.conf is not populated for some reason. + */ + @Test + public void testLoadFromStoresWithNullConfigKey() throws Exception { + WifiConfiguration pskNetwork = WifiConfigurationTestUtil.createPskNetwork(); + WifiConfiguration wepNetwork = WifiConfigurationTestUtil.createWepNetwork(); + WifiConfiguration eapNetwork = WifiConfigurationTestUtil.createEapNetwork(); + eapNetwork.enterpriseConfig.setPassword("EapPassword"); + + final List<WifiConfiguration> networks = new ArrayList<>(); + networks.add(pskNetwork); + networks.add(wepNetwork); + networks.add(eapNetwork); + + // Return the config data with null configKey. + doAnswer(new AnswerWithArguments() { + public boolean answer(String ifaceName, Map<String, WifiConfiguration> configs, + SparseArray<Map<String, String>> networkExtras) { + for (Map.Entry<String, WifiConfiguration> entry: + createWpaSupplicantLoadData(networks).entrySet()) { + configs.put(null, entry.getValue()); + } + return true; + } + }).when(mWifiNative).migrateNetworksFromSupplicant( + any(), any(Map.class), any(SparseArray.class)); + + when(mIpconfigStoreWrapper.readIpAndProxyConfigurations(anyString())) + .thenReturn(createIpConfigStoreLoadData(networks)); + assertNotNull(mWifiConfigStore.read()); + } + private SparseArray<IpConfiguration> createIpConfigStoreLoadData( List<WifiConfiguration> configurations) { SparseArray<IpConfiguration> newIpConfigurations = new SparseArray<>(); |