summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2019-11-19 00:30:32 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-11-19 00:30:32 +0000
commitbd5e98762e50b8aef4c62d2a3c69cca9c817fdd2 (patch)
treee7c0b66392ea624634daae1cecdcad7e7f7249d4 /tests
parent92b207156beffb163671c5e3bd9e9f4c4cba0b27 (diff)
parent27c6ad5908d8c302a4ec8c4af2d90c9fdb2ba93c (diff)
Merge changes I5c05a897,Ic250919b,I42836a06
* changes: WifiApConfigStore: Switch to new config store mechanism SoftApStoreData: Class for serializing/deserializing softap config WifiConfigStore: Support more than 1 shared store file
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/Android.bp1
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java205
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java191
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java6
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java5
5 files changed, 326 insertions, 82 deletions
diff --git a/tests/wifitests/Android.bp b/tests/wifitests/Android.bp
index 3bbbc46c2..341ab0982 100644
--- a/tests/wifitests/Android.bp
+++ b/tests/wifitests/Android.bp
@@ -250,6 +250,7 @@ android_test {
"com.android.server.wifi.SoftApManager",
"com.android.server.wifi.SoftApManager.*",
"com.android.server.wifi.SoftApModeConfiguration",
+ "com.android.server.wifi.SoftApStoreData",
"com.android.server.wifi.SsidSetStoreData",
"com.android.server.wifi.SsidSetStoreData.*",
"com.android.server.wifi.StateChangeResult",
diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java
new file mode 100644
index 000000000..577767c16
--- /dev/null
+++ b/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.server.wifi;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import android.net.wifi.WifiConfiguration;
+import android.util.Xml;
+
+import androidx.test.filters.SmallTest;
+
+import com.android.internal.util.FastXmlSerializer;
+import com.android.server.wifi.util.WifiConfigStoreEncryptionUtil;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlSerializer;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.nio.charset.StandardCharsets;
+
+/**
+ * Unit tests for {@link com.android.server.wifi.SoftApStoreData}.
+ */
+@SmallTest
+public class SoftApStoreDataTest extends WifiBaseTest {
+ private static final String TEST_SSID = "SSID";
+ private static final String TEST_PRESHARED_KEY = "Test";
+ private static final boolean TEST_HIDDEN = false;
+ private static final int TEST_BAND = WifiConfiguration.AP_BAND_ANY;
+ private static final int TEST_CHANNEL = 0;
+
+ private static final String TEST_SOFTAP_CONFIG_XML_STRING =
+ "<string name=\"SSID\">" + TEST_SSID + "</string>\n"
+ + "<int name=\"Band\" value=\"" + TEST_BAND + "\" />\n"
+ + "<int name=\"Channel\" value=\"" + TEST_CHANNEL + "\" />\n"
+ + "<boolean name=\"HiddenSSID\" value=\"" + TEST_HIDDEN + "\" />\n"
+ + "<byte-array name=\"AllowedKeyMgmt\" num=\"1\">02</byte-array>\n"
+ + "<string name=\"PreSharedKey\">" + TEST_PRESHARED_KEY + "</string>\n";
+
+ @Mock SoftApStoreData.DataSource mDataSource;
+ SoftApStoreData mSoftApStoreData;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ mSoftApStoreData = new SoftApStoreData(mDataSource);
+ }
+
+ /**
+ * Helper function for serializing configuration data to a XML block.
+ *
+ * @return byte[] of the XML data
+ * @throws Exception
+ */
+ private byte[] serializeData() throws Exception {
+ final XmlSerializer out = new FastXmlSerializer();
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ out.setOutput(outputStream, StandardCharsets.UTF_8.name());
+ mSoftApStoreData.serializeData(out, mock(WifiConfigStoreEncryptionUtil.class));
+ out.flush();
+ return outputStream.toByteArray();
+ }
+
+ /**
+ * Helper function for parsing configuration data from a XML block.
+ *
+ * @param data XML data to parse from
+ * @throws Exception
+ */
+ private void deserializeData(byte[] data) throws Exception {
+ final XmlPullParser in = Xml.newPullParser();
+ final ByteArrayInputStream inputStream = new ByteArrayInputStream(data);
+ in.setInput(inputStream, StandardCharsets.UTF_8.name());
+ mSoftApStoreData.deserializeData(in, in.getDepth(),
+ WifiConfigStore.ENCRYPT_CREDENTIALS_CONFIG_STORE_DATA_VERSION,
+ mock(WifiConfigStoreEncryptionUtil.class));
+ }
+
+ /**
+ * Verify that parsing an empty data doesn't cause any crash and no configuration should
+ * be deserialized.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void deserializeEmptyStoreData() throws Exception {
+ deserializeData(new byte[0]);
+ verify(mDataSource, never()).fromDeserialized(any());
+ }
+
+ /**
+ * Verify that SoftApStoreData is written to
+ * {@link WifiConfigStore#STORE_FILE_SHARED_SOFTAP}.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void getUserStoreFileId() throws Exception {
+ assertEquals(WifiConfigStore.STORE_FILE_SHARED_SOFTAP,
+ mSoftApStoreData.getStoreFileId());
+ }
+
+ /**
+ * Verify that the store data is serialized correctly, matches the predefined test XML data.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void serializeSoftAp() throws Exception {
+ WifiConfiguration softApConfig = new WifiConfiguration();
+ softApConfig.SSID = TEST_SSID;
+ softApConfig.preSharedKey = TEST_PRESHARED_KEY;
+ softApConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
+ softApConfig.apBand = TEST_BAND;
+ softApConfig.apChannel = TEST_CHANNEL;
+
+ when(mDataSource.toSerialize()).thenReturn(softApConfig);
+ byte[] actualData = serializeData();
+ assertEquals(TEST_SOFTAP_CONFIG_XML_STRING, new String(actualData));
+ }
+
+ /**
+ * Verify that the store data is deserialized correctly using the predefined test XML data.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void deserializeSoftAp() throws Exception {
+ deserializeData(TEST_SOFTAP_CONFIG_XML_STRING.getBytes());
+
+ ArgumentCaptor<WifiConfiguration> softapConfigCaptor =
+ ArgumentCaptor.forClass(WifiConfiguration.class);
+ verify(mDataSource).fromDeserialized(softapConfigCaptor.capture());
+ WifiConfiguration softApConfig = softapConfigCaptor.getValue();
+ assertNotNull(softApConfig);
+ assertEquals(softApConfig.SSID, TEST_SSID);
+ assertEquals(softApConfig.preSharedKey, TEST_PRESHARED_KEY);
+ assertTrue(softApConfig.allowedKeyManagement.get(WifiConfiguration.KeyMgmt.WPA_PSK));
+ assertEquals(softApConfig.hiddenSSID, TEST_HIDDEN);
+ assertEquals(softApConfig.apBand, TEST_BAND);
+ assertEquals(softApConfig.apChannel, TEST_CHANNEL);
+ }
+
+ /**
+ * Verify that the store data is serialized/deserialized correctly.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void serializeDeserializeSoftAp() throws Exception {
+ WifiConfiguration softApConfig = new WifiConfiguration();
+ softApConfig.SSID = TEST_SSID;
+ softApConfig.preSharedKey = TEST_PRESHARED_KEY;
+ softApConfig.allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK);
+ softApConfig.apBand = TEST_BAND;
+ softApConfig.apChannel = TEST_CHANNEL;
+
+ // Serialize first.
+ when(mDataSource.toSerialize()).thenReturn(softApConfig);
+ byte[] serializedData = serializeData();
+
+ // Now deserialize first.
+ deserializeData(serializedData);
+ ArgumentCaptor<WifiConfiguration> softapConfigCaptor =
+ ArgumentCaptor.forClass(WifiConfiguration.class);
+ verify(mDataSource).fromDeserialized(softapConfigCaptor.capture());
+ WifiConfiguration softApConfigDeserialized = softapConfigCaptor.getValue();
+ assertNotNull(softApConfigDeserialized);
+
+ assertEquals(softApConfig.SSID, softApConfigDeserialized.SSID);
+ assertEquals(softApConfig.preSharedKey, softApConfigDeserialized.preSharedKey);
+ assertEquals(softApConfig.allowedKeyManagement,
+ softApConfigDeserialized.allowedKeyManagement);
+ assertEquals(softApConfig.hiddenSSID, softApConfigDeserialized.hiddenSSID);
+ assertEquals(softApConfig.apBand, softApConfigDeserialized.apBand);
+ assertEquals(softApConfig.apChannel, softApConfigDeserialized.apChannel);
+ }
+}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
index f150bf797..71b034a2e 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
@@ -21,9 +21,11 @@ import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.eq;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -46,15 +48,17 @@ import androidx.test.filters.SmallTest;
import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.wifi.R;
-import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
+import java.io.BufferedOutputStream;
+import java.io.DataOutputStream;
import java.io.File;
-import java.lang.reflect.Method;
+import java.io.FileOutputStream;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
@@ -89,30 +93,32 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
@Mock private Context mContext;
@Mock private WifiInjector mWifiInjector;
+ private TestLooper mLooper;
private Handler mHandler;
@Mock private BackupManagerProxy mBackupManagerProxy;
@Mock private FrameworkFacade mFrameworkFacade;
- private File mApConfigFile;
+ @Mock private WifiConfigStore mWifiConfigStore;
+ @Mock private WifiConfigManager mWifiConfigManager;
+ private File mLegacyApConfigFile;
private Random mRandom;
private MockResources mResources;
@Mock private ApplicationInfo mMockApplInfo;
private BroadcastReceiver mBroadcastReceiver;
@Mock private NotificationManager mNotificationManager;
@Mock private MacAddressUtil mMacAddressUtil;
+ private SoftApStoreData.DataSource mDataStoreSource;
private ArrayList<Integer> mKnownGood2GChannelList;
@Before
public void setUp() throws Exception {
- mHandler = new Handler(new TestLooper().getLooper());
+ mLooper = new TestLooper();
+ mHandler = new Handler(mLooper.getLooper());
MockitoAnnotations.initMocks(this);
when(mContext.getSystemService(Context.NOTIFICATION_SERVICE))
.thenReturn(mNotificationManager);
mMockApplInfo.targetSdkVersion = Build.VERSION_CODES.P;
when(mContext.getApplicationInfo()).thenReturn(mMockApplInfo);
- /* Create a temporary file for AP config file storage. */
- mApConfigFile = File.createTempFile(TEST_AP_CONFIG_FILE_PREFIX, "");
-
/* Setup expectations for Resources to return some default settings. */
mResources = new MockResources();
mResources.setString(R.string.config_wifi_framework_sap_2G_channel_list,
@@ -139,28 +145,39 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
when(mMacAddressUtil.calculatePersistentMac(any(), any())).thenReturn(TEST_RANDOMIZED_MAC);
}
- @After
- public void cleanUp() {
- /* Remove the temporary AP config file. */
- mApConfigFile.delete();
- }
-
/**
* Helper method to create and verify actions for the ApConfigStore used in the following tests.
*/
- private WifiApConfigStore createWifiApConfigStore() {
- WifiApConfigStore store = new WifiApConfigStore(
- mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
- mApConfigFile.getPath());
+ private WifiApConfigStore createWifiApConfigStore(String legacyFilePath) {
+ WifiApConfigStore store;
+ if (legacyFilePath == null) {
+ store = new WifiApConfigStore(
+ mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
+ mWifiConfigStore, mWifiConfigManager);
+ } else {
+ store = new WifiApConfigStore(
+ mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
+ mWifiConfigStore, mWifiConfigManager, legacyFilePath);
+ }
ArgumentCaptor<BroadcastReceiver> broadcastReceiverCaptor =
ArgumentCaptor.forClass(BroadcastReceiver.class);
verify(mContext).registerReceiver(broadcastReceiverCaptor.capture(), any(), any(), any());
mBroadcastReceiver = broadcastReceiverCaptor.getValue();
+ verify(mWifiConfigStore).registerStoreData(any());
+ ArgumentCaptor<SoftApStoreData.DataSource> dataStoreSourceArgumentCaptor =
+ ArgumentCaptor.forClass(SoftApStoreData.DataSource.class);
+ verify(mWifiInjector).makeSoftApStoreData(dataStoreSourceArgumentCaptor.capture());
+ mDataStoreSource = dataStoreSourceArgumentCaptor.getValue();
+
return store;
}
+ private WifiApConfigStore createWifiApConfigStore() {
+ return createWifiApConfigStore(null);
+ }
+
/**
* Generate a WifiConfiguration based on the specified parameters.
*/
@@ -177,16 +194,28 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
return config;
}
- private void writeApConfigFile(WifiConfiguration config) throws Exception {
- Method m = WifiApConfigStore.class.getDeclaredMethod(
- "writeApConfiguration", String.class, WifiConfiguration.class);
- m.setAccessible(true);
- m.invoke(null, mApConfigFile.getPath(), config);
+ private void writeLegacyApConfigFile(WifiConfiguration config) throws Exception {
+ try (DataOutputStream out = new DataOutputStream(new BufferedOutputStream(
+ new FileOutputStream(mLegacyApConfigFile)))) {
+ out.writeInt(WifiApConfigStore.AP_CONFIG_FILE_VERSION);
+ out.writeUTF(config.SSID);
+ out.writeInt(config.apBand);
+ out.writeInt(config.apChannel);
+ out.writeBoolean(config.hiddenSSID);
+ int authType = config.getAuthType();
+ out.writeInt(authType);
+ if (authType != KeyMgmt.NONE) {
+ out.writeUTF(config.preSharedKey);
+ }
+ } catch (IOException e) {
+ fail("Error writing hotspot configuration" + e);
+ }
}
private void verifyApConfig(WifiConfiguration config1, WifiConfiguration config2) {
assertEquals(config1.SSID, config2.SSID);
assertEquals(config1.preSharedKey, config2.preSharedKey);
+ assertEquals(config1.allowedKeyManagement, config2.allowedKeyManagement);
assertEquals(config1.getAuthType(), config2.getAuthType());
assertEquals(config1.apBand, config2.apBand);
assertEquals(config1.apChannel, config2.apChannel);
@@ -224,18 +253,17 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
*/
@Test
public void initWithDefaultConfiguration() throws Exception {
- WifiApConfigStore store = new WifiApConfigStore(
- mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
- mApConfigFile.getPath());
+ WifiApConfigStore store = createWifiApConfigStore();
verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID);
+ verify(mWifiConfigManager).saveToStore(true);
}
/**
* Verify WifiApConfigStore can correctly load the existing configuration
- * from the config file.
+ * from the legacy config file and migrate it to the new config store.
*/
@Test
- public void initWithExistingConfiguration() throws Exception {
+ public void initWithExistingConfigurationInLegacyFile() throws Exception {
WifiConfiguration expectedConfig = setupApConfig(
"ConfiguredAP", /* SSID */
"randomKey", /* preshared key */
@@ -243,11 +271,25 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
1, /* AP band (5GHz) */
40, /* AP channel */
true /* Hidden SSID */);
- writeApConfigFile(expectedConfig);
- WifiApConfigStore store = new WifiApConfigStore(
- mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
- mApConfigFile.getPath());
+ /* Create a temporary file for AP config file storage. */
+ mLegacyApConfigFile = File.createTempFile(TEST_AP_CONFIG_FILE_PREFIX, "");
+
+ writeLegacyApConfigFile(expectedConfig);
+ WifiApConfigStore store = createWifiApConfigStore(mLegacyApConfigFile.getPath());
+ verify(mWifiConfigManager).saveToStore(true);
+ verify(mBackupManagerProxy).notifyDataChanged();
verifyApConfig(expectedConfig, store.getApConfiguration());
+ verifyApConfig(expectedConfig, mDataStoreSource.toSerialize());
+ // Simulate the config store read to trigger the write to new config store.
+ mDataStoreSource.reset();
+ mLooper.dispatchAll();
+ // Triggers write twice:
+ // a) On reading the legacy file (new config store not ready yet)
+ // b) When the new config store is ready.
+ verify(mWifiConfigManager, times(2)).saveToStore(true);
+
+ // The temporary legacy AP config file should be removed after migration.
+ assertFalse(mLegacyApConfigFile.exists());
}
/**
@@ -265,14 +307,14 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
1, /* AP band (5GHz) */
40, /* AP channel */
true /* Hidden SSID */);
- writeApConfigFile(expectedConfig);
- WifiApConfigStore store = new WifiApConfigStore(
- mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
- mApConfigFile.getPath());
+ WifiApConfigStore store = createWifiApConfigStore();
+ mDataStoreSource.fromDeserialized(expectedConfig);
verifyApConfig(expectedConfig, store.getApConfiguration());
store.setApConfiguration(null);
verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID);
+ verifyDefaultApConfig(mDataStoreSource.toSerialize(), TEST_DEFAULT_AP_SSID);
+ verify(mWifiConfigManager).saveToStore(true);
verify(mBackupManagerProxy).notifyDataChanged();
}
@@ -282,10 +324,10 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
@Test
public void updateApConfiguration() throws Exception {
/* Initialize WifiApConfigStore with default configuration. */
- WifiApConfigStore store = new WifiApConfigStore(
- mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
- mApConfigFile.getPath());
+ WifiApConfigStore store = createWifiApConfigStore();
+
verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID);
+ verify(mWifiConfigManager).saveToStore(true);
/* Update with a valid configuration. */
WifiConfiguration expectedConfig = setupApConfig(
@@ -297,7 +339,9 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
true /* Hidden SSID */);
store.setApConfiguration(expectedConfig);
verifyApConfig(expectedConfig, store.getApConfiguration());
- verify(mBackupManagerProxy).notifyDataChanged();
+ verifyApConfig(expectedConfig, mDataStoreSource.toSerialize());
+ verify(mWifiConfigManager, times(2)).saveToStore(true);
+ verify(mBackupManagerProxy, times(2)).notifyDataChanged();
}
/**
@@ -308,10 +352,9 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
@Test
public void convertSingleModeDeviceAnyTo5Ghz() throws Exception {
/* Initialize WifiApConfigStore with default configuration. */
- WifiApConfigStore store = new WifiApConfigStore(
- mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
- mApConfigFile.getPath());
+ WifiApConfigStore store = createWifiApConfigStore();
verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID);
+ verify(mWifiConfigManager).saveToStore(true);
/* Update with a valid configuration. */
WifiConfiguration providedConfig = setupApConfig(
@@ -331,7 +374,9 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
false /* Hidden SSID */);
store.setApConfiguration(providedConfig);
verifyApConfig(expectedConfig, store.getApConfiguration());
- verify(mBackupManagerProxy).notifyDataChanged();
+ verifyApConfig(expectedConfig, mDataStoreSource.toSerialize());
+ verify(mWifiConfigManager, times(2)).saveToStore(true);
+ verify(mBackupManagerProxy, times(2)).notifyDataChanged();
}
/**
@@ -342,10 +387,9 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
@Test
public void singleModeDevice5GhzNotConverted() throws Exception {
/* Initialize WifiApConfigStore with default configuration. */
- WifiApConfigStore store = new WifiApConfigStore(
- mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
- mApConfigFile.getPath());
+ WifiApConfigStore store = createWifiApConfigStore();
verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID);
+ verify(mWifiConfigManager).saveToStore(true);
/* Update with a valid configuration. */
WifiConfiguration expectedConfig = setupApConfig(
@@ -357,6 +401,9 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
false /* Hidden SSID */);
store.setApConfiguration(expectedConfig);
verifyApConfig(expectedConfig, store.getApConfiguration());
+ verifyApConfig(expectedConfig, mDataStoreSource.toSerialize());
+ verify(mWifiConfigManager, times(2)).saveToStore(true);
+ verify(mBackupManagerProxy, times(2)).notifyDataChanged();
}
/**
@@ -369,10 +416,9 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
mResources.setBoolean(R.bool.config_wifi_convert_apband_5ghz_to_any, true);
/* Initialize WifiApConfigStore with default configuration. */
- WifiApConfigStore store = new WifiApConfigStore(
- mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
- mApConfigFile.getPath());
+ WifiApConfigStore store = createWifiApConfigStore();
verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID);
+ verify(mWifiConfigManager).saveToStore(true);
/* Update with a valid configuration. */
WifiConfiguration providedConfig = setupApConfig(
@@ -392,7 +438,9 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
false /* Hidden SSID */);
store.setApConfiguration(providedConfig);
verifyApConfig(expectedConfig, store.getApConfiguration());
- verify(mBackupManagerProxy).notifyDataChanged();
+ verifyApConfig(expectedConfig, mDataStoreSource.toSerialize());
+ verify(mWifiConfigManager, times(2)).saveToStore(true);
+ verify(mBackupManagerProxy, times(2)).notifyDataChanged();
}
/**
@@ -405,10 +453,9 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
mResources.setBoolean(R.bool.config_wifi_convert_apband_5ghz_to_any, true);
/* Initialize WifiApConfigStore with default configuration. */
- WifiApConfigStore store = new WifiApConfigStore(
- mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
- mApConfigFile.getPath());
+ WifiApConfigStore store = createWifiApConfigStore();
verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID);
+ verify(mWifiConfigManager).saveToStore(true);
/* Update with a valid configuration. */
WifiConfiguration expectedConfig = setupApConfig(
@@ -419,8 +466,10 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
40, /* AP channel */
false /* Hidden SSID */);
store.setApConfiguration(expectedConfig);
- verify(mBackupManagerProxy).notifyDataChanged();
verifyApConfig(expectedConfig, store.getApConfiguration());
+ verifyApConfig(expectedConfig, mDataStoreSource.toSerialize());
+ verify(mWifiConfigManager, times(2)).saveToStore(true);
+ verify(mBackupManagerProxy, times(2)).notifyDataChanged();
}
/**
@@ -445,11 +494,11 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
WifiConfiguration.AP_BAND_5GHZ, /* AP band */
WifiApConfigStore.AP_CHANNEL_DEFAULT, /* AP channel */
false /* Hidden SSID */);
- writeApConfigFile(persistedConfig);
- WifiApConfigStore store = new WifiApConfigStore(
- mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
- mApConfigFile.getPath());
+ WifiApConfigStore store = createWifiApConfigStore();
+ mDataStoreSource.fromDeserialized(persistedConfig);
verifyApConfig(expectedConfig, store.getApConfiguration());
+ verifyApConfig(expectedConfig, mDataStoreSource.toSerialize());
+ verify(mWifiConfigManager).saveToStore(true);
verify(mBackupManagerProxy).notifyDataChanged();
}
@@ -468,11 +517,10 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
40, /* AP channel */
false /* Hidden SSID */);
- writeApConfigFile(persistedConfig);
- WifiApConfigStore store = new WifiApConfigStore(
- mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
- mApConfigFile.getPath());
+ WifiApConfigStore store = createWifiApConfigStore();
+ mDataStoreSource.fromDeserialized(persistedConfig);
verifyApConfig(persistedConfig, store.getApConfiguration());
+ verify(mWifiConfigManager, never()).saveToStore(true);
verify(mBackupManagerProxy, never()).notifyDataChanged();
}
@@ -500,11 +548,11 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
WifiApConfigStore.AP_CHANNEL_DEFAULT, /* AP channel */
false /* Hidden SSID */);
- writeApConfigFile(persistedConfig);
- WifiApConfigStore store = new WifiApConfigStore(
- mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
- mApConfigFile.getPath());
+ WifiApConfigStore store = createWifiApConfigStore();
+ mDataStoreSource.fromDeserialized(persistedConfig);
verifyApConfig(expectedConfig, store.getApConfiguration());
+ verifyApConfig(expectedConfig, mDataStoreSource.toSerialize());
+ verify(mWifiConfigManager).saveToStore(true);
verify(mBackupManagerProxy).notifyDataChanged();
}
@@ -525,11 +573,10 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
40, /* AP channel */
false /* Hidden SSID */);
- writeApConfigFile(persistedConfig);
- WifiApConfigStore store = new WifiApConfigStore(
- mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
- mApConfigFile.getPath());
+ WifiApConfigStore store = createWifiApConfigStore();
+ mDataStoreSource.fromDeserialized(persistedConfig);
verifyApConfig(persistedConfig, store.getApConfiguration());
+ verify(mWifiConfigManager, never()).saveToStore(true);
verify(mBackupManagerProxy, never()).notifyDataChanged();
}
@@ -538,9 +585,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
*/
@Test
public void getDefaultApConfigurationIsValid() {
- WifiApConfigStore store = new WifiApConfigStore(
- mContext, mWifiInjector, mHandler, mBackupManagerProxy, mFrameworkFacade,
- mApConfigFile.getPath());
+ WifiApConfigStore store = createWifiApConfigStore();
WifiConfiguration config = store.getApConfiguration();
assertTrue(WifiApConfigStore.validateApWifiConfiguration(config));
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index d48966143..edbd5cb7e 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -213,7 +213,6 @@ public class WifiConfigManagerTest extends WifiBaseTest {
.updateNetworkKeys(any(WifiConfiguration.class), any()))
.thenReturn(true);
- when(mWifiConfigStore.areStoresPresent()).thenReturn(true);
setupStoreDataForRead(new ArrayList<>(), new ArrayList<>(), new HashMap<>());
when(mWifiPermissionsUtil.checkNetworkSettingsPermission(anyInt())).thenReturn(true);
@@ -3758,8 +3757,6 @@ public class WifiConfigManagerTest extends WifiBaseTest {
*/
@Test
public void testFreshInstallLoadFromStore() throws Exception {
- when(mWifiConfigStore.areStoresPresent()).thenReturn(false);
-
assertTrue(mWifiConfigManager.loadFromStore());
verify(mWifiConfigStore).read();
@@ -3774,8 +3771,6 @@ public class WifiConfigManagerTest extends WifiBaseTest {
*/
@Test
public void testFreshInstallLoadFromStoreAfterUserUnlock() throws Exception {
- when(mWifiConfigStore.areStoresPresent()).thenReturn(false);
-
int user1 = TEST_DEFAULT_USER;
// Unlock the user1 (default user) for the first time and ensure that we don't read the
@@ -3797,7 +3792,6 @@ public class WifiConfigManagerTest extends WifiBaseTest {
@Test
public void testHandleUserSwitchAfterFreshInstall() throws Exception {
int user2 = TEST_DEFAULT_USER + 1;
- when(mWifiConfigStore.areStoresPresent()).thenReturn(false);
assertTrue(mWifiConfigManager.loadFromStore());
verify(mWifiConfigStore).read();
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java
index 06a246593..814dc6134 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigStoreTest.java
@@ -51,6 +51,7 @@ import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -212,7 +213,7 @@ public class WifiConfigStoreTest extends WifiBaseTest {
setupMocks();
mWifiConfigStore = new WifiConfigStore(mContext, new Handler(mLooper.getLooper()), mClock,
- mWifiMetrics, mSharedStore);
+ mWifiMetrics, Arrays.asList(mSharedStore));
// Enable verbose logging before tests.
mWifiConfigStore.enableVerboseLogging(true);
}
@@ -420,7 +421,6 @@ public class WifiConfigStoreTest extends WifiBaseTest {
// |readRawData| would return null.
mWifiConfigStore.registerStoreData(sharedStoreData);
mWifiConfigStore.registerStoreData(userStoreData);
- assertFalse(mWifiConfigStore.areStoresPresent());
mWifiConfigStore.read();
// Ensure that we got the call to deserialize empty shared data, but no user data.
@@ -450,7 +450,6 @@ public class WifiConfigStoreTest extends WifiBaseTest {
mWifiConfigStore.registerStoreData(userStoreData);
// Read both share and user config store.
mWifiConfigStore.setUserStores(mUserStores);
- assertFalse(mWifiConfigStore.areStoresPresent());
mWifiConfigStore.read();
// Ensure that we got the call to deserialize empty shared & user data.