summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/WifiApConfigStore.java144
-rw-r--r--service/java/com/android/server/wifi/WifiInjector.java16
-rw-r--r--service/wifi.rc1
-rw-r--r--service/wifi_inprocess.rc1
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java191
5 files changed, 221 insertions, 132 deletions
diff --git a/service/java/com/android/server/wifi/WifiApConfigStore.java b/service/java/com/android/server/wifi/WifiApConfigStore.java
index 7cb7a4cef..48ad9b1c0 100644
--- a/service/java/com/android/server/wifi/WifiApConfigStore.java
+++ b/service/java/com/android/server/wifi/WifiApConfigStore.java
@@ -39,11 +39,10 @@ import com.android.internal.messages.nano.SystemMessageProto.SystemMessage;
import com.android.wifi.R;
import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
import java.io.DataInputStream;
-import java.io.DataOutputStream;
+import java.io.File;
import java.io.FileInputStream;
-import java.io.FileOutputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.SecureRandom;
@@ -64,10 +63,13 @@ public class WifiApConfigStore {
private static final String TAG = "WifiApConfigStore";
- private static final String DEFAULT_AP_CONFIG_FILE =
+ // Note: This is the legacy Softap config file. This is only used for migrating data out
+ // of this file on first reboot.
+ private static final String LEGACY_AP_CONFIG_FILE =
Environment.getDataDirectory() + "/misc/wifi/softap.conf";
- private static final int AP_CONFIG_FILE_VERSION = 3;
+ @VisibleForTesting
+ public static final int AP_CONFIG_FILE_VERSION = 3;
private static final int RAND_SSID_INT_MIN = 1000;
private static final int RAND_SSID_INT_MAX = 9999;
@@ -84,24 +86,57 @@ public class WifiApConfigStore {
@VisibleForTesting
static final int AP_CHANNEL_DEFAULT = 0;
- private WifiConfiguration mWifiApConfig = null;
+ private WifiConfiguration mPersistentWifiApConfig = null;
private ArrayList<Integer> mAllowed2GChannel = null;
private final Context mContext;
private final WifiInjector mWifiInjector;
private final Handler mHandler;
- private final String mApConfigFile;
private final BackupManagerProxy mBackupManagerProxy;
private final FrameworkFacade mFrameworkFacade;
private final MacAddressUtil mMacAddressUtil;
private final Mac mMac;
+ private final WifiConfigStore mWifiConfigStore;
+ private final WifiConfigManager mWifiConfigManager;
private boolean mRequiresApBandConversion = false;
+ private boolean mHasNewDataToSerialize = false;
+
+ /**
+ * Module to interact with the wifi config store.
+ */
+ private class SoftApStoreDataSource implements SoftApStoreData.DataSource {
+
+ public WifiConfiguration toSerialize() {
+ mHasNewDataToSerialize = false;
+ return mPersistentWifiApConfig;
+ }
+
+ public void fromDeserialized(WifiConfiguration config) {
+ mPersistentWifiApConfig = new WifiConfiguration(config);
+ }
+
+ public void reset() {
+ if (mPersistentWifiApConfig != null) {
+ // Note: Reset is invoked when WifiConfigStore.read() is invoked on boot completed.
+ // If we had migrated data from the legacy store before that (which is most likely
+ // true because we read the legacy file in the constructor here, whereas
+ // WifiConfigStore.read() is only triggered on boot completed), trigger a write to
+ // persist the migrated data.
+ mHandler.post(() -> mWifiConfigManager.saveToStore(true));
+ }
+ }
+
+ public boolean hasNewDataToSerialize() {
+ return mHasNewDataToSerialize;
+ }
+ }
WifiApConfigStore(Context context, WifiInjector wifiInjector, Handler handler,
- BackupManagerProxy backupManagerProxy, FrameworkFacade frameworkFacade) {
- this(context, wifiInjector, handler, backupManagerProxy, frameworkFacade,
- DEFAULT_AP_CONFIG_FILE);
+ BackupManagerProxy backupManagerProxy, FrameworkFacade frameworkFacade,
+ WifiConfigStore wifiConfigStore, WifiConfigManager wifiConfigManager) {
+ this(context, wifiInjector, handler, backupManagerProxy, frameworkFacade, wifiConfigStore,
+ wifiConfigManager, LEGACY_AP_CONFIG_FILE);
}
WifiApConfigStore(Context context,
@@ -109,13 +144,16 @@ public class WifiApConfigStore {
Handler handler,
BackupManagerProxy backupManagerProxy,
FrameworkFacade frameworkFacade,
+ WifiConfigStore wifiConfigStore,
+ WifiConfigManager wifiConfigManager,
String apConfigFile) {
mContext = context;
mWifiInjector = wifiInjector;
mHandler = handler;
mBackupManagerProxy = backupManagerProxy;
mFrameworkFacade = frameworkFacade;
- mApConfigFile = apConfigFile;
+ mWifiConfigStore = wifiConfigStore;
+ mWifiConfigManager = wifiConfigManager;
String ap2GChannelListStr = mContext.getResources().getString(
R.string.config_wifi_framework_sap_2G_channel_list);
@@ -132,17 +170,27 @@ public class WifiApConfigStore {
mRequiresApBandConversion = mContext.getResources().getBoolean(
R.bool.config_wifi_convert_apband_5ghz_to_any);
- /* Load AP configuration from persistent storage. */
- mWifiApConfig = loadApConfiguration(mApConfigFile);
- if (mWifiApConfig == null) {
- /* Use default configuration. */
- Log.d(TAG, "Fallback to use default AP configuration");
- mWifiApConfig = getDefaultApConfiguration();
-
- /* Save the default configuration to persistent storage. */
- writeApConfiguration(mApConfigFile, mWifiApConfig);
+ // One time migration from legacy config store.
+ try {
+ File file = new File(apConfigFile);
+ FileInputStream fis = new FileInputStream(apConfigFile);
+ /* Load AP configuration from persistent storage. */
+ WifiConfiguration config = loadApConfigurationFromLegacyFile(fis);
+ if (config != null) {
+ // Persist in the new store.
+ persistConfigAndTriggerBackupManagerProxy(config);
+ Log.i(TAG, "Migrated data out of legacy store file " + apConfigFile);
+ // delete the legacy file.
+ file.delete();
+ }
+ } catch (FileNotFoundException e) {
+ // Expected on further reboots after the first reboot.
}
+ // Register store data listener
+ mWifiConfigStore.registerStoreData(
+ mWifiInjector.makeSoftApStoreData(new SoftApStoreDataSource()));
+
IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_HOTSPOT_CONFIG_USER_TAPPED_CONTENT);
mContext.registerReceiver(
@@ -176,13 +224,18 @@ public class WifiApConfigStore {
* Return the current soft access point configuration.
*/
public synchronized WifiConfiguration getApConfiguration() {
- WifiConfiguration config = sanitizePersistentApConfig(mWifiApConfig);
- if (mWifiApConfig != config) {
+ if (mPersistentWifiApConfig == null) {
+ /* Use default configuration. */
+ Log.d(TAG, "Fallback to use default AP configuration");
+ persistConfigAndTriggerBackupManagerProxy(getDefaultApConfiguration());
+ }
+ WifiConfiguration sanitizedPersistentconfig =
+ sanitizePersistentApConfig(mPersistentWifiApConfig);
+ if (mPersistentWifiApConfig != sanitizedPersistentconfig) {
Log.d(TAG, "persisted config was converted, need to resave it");
- mWifiApConfig = config;
- persistConfigAndTriggerBackupManagerProxy(mWifiApConfig);
+ persistConfigAndTriggerBackupManagerProxy(sanitizedPersistentconfig);
}
- return mWifiApConfig;
+ return mPersistentWifiApConfig;
}
/**
@@ -193,11 +246,11 @@ public class WifiApConfigStore {
*/
public synchronized void setApConfiguration(WifiConfiguration config) {
if (config == null) {
- mWifiApConfig = getDefaultApConfiguration();
+ config = getDefaultApConfiguration();
} else {
- mWifiApConfig = sanitizePersistentApConfig(config);
+ config = sanitizePersistentApConfig(config);
}
- persistConfigAndTriggerBackupManagerProxy(mWifiApConfig);
+ persistConfigAndTriggerBackupManagerProxy(config);
}
public ArrayList<Integer> getAllowed2GChannel() {
@@ -280,21 +333,22 @@ public class WifiApConfigStore {
}
private void persistConfigAndTriggerBackupManagerProxy(WifiConfiguration config) {
- writeApConfiguration(mApConfigFile, mWifiApConfig);
- // Stage the backup of the SettingsProvider package which backs this up
+ mPersistentWifiApConfig = config;
+ mHasNewDataToSerialize = true;
+ mWifiConfigManager.saveToStore(true);
mBackupManagerProxy.notifyDataChanged();
}
/**
- * Load AP configuration from persistent storage.
+ * Load AP configuration from legacy persistent storage.
+ * Note: This is deprecated and only used for migrating data once on reboot.
*/
- private static WifiConfiguration loadApConfiguration(final String filename) {
+ private static WifiConfiguration loadApConfigurationFromLegacyFile(FileInputStream fis) {
WifiConfiguration config = null;
DataInputStream in = null;
try {
config = new WifiConfiguration();
- in = new DataInputStream(
- new BufferedInputStream(new FileInputStream(filename)));
+ in = new DataInputStream(new BufferedInputStream(fis));
int version = in.readInt();
if (version < 1 || version > AP_CONFIG_FILE_VERSION) {
@@ -333,28 +387,6 @@ public class WifiApConfigStore {
}
/**
- * Write AP configuration to persistent storage.
- */
- private static void writeApConfiguration(final String filename,
- final WifiConfiguration config) {
- try (DataOutputStream out = new DataOutputStream(new BufferedOutputStream(
- new FileOutputStream(filename)))) {
- out.writeInt(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) {
- Log.e(TAG, "Error writing hotspot configuration" + e);
- }
- }
-
- /**
* Generate a default WPA2 based configuration with a random password.
* We are changing the Wifi Ap configuration storage from secure settings to a
* flat file accessible only by the system. A WPA2 based default configuration
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java
index f638c662c..683db73f6 100644
--- a/service/java/com/android/server/wifi/WifiInjector.java
+++ b/service/java/com/android/server/wifi/WifiInjector.java
@@ -241,9 +241,6 @@ public class WifiInjector {
SystemProperties.get(BOOT_DEFAULT_WIFI_COUNTRY_CODE),
mContext.getResources()
.getBoolean(R.bool.config_wifi_revert_country_code_on_cellular_loss));
- mWifiApConfigStore = new WifiApConfigStore(
- mContext,this, wifiHandler, mBackupManagerProxy, mFrameworkFacade);
-
// WifiConfigManager/Store objects and their dependencies.
KeyStore keyStore = null;
try {
@@ -267,6 +264,11 @@ public class WifiInjector {
new DeletedEphemeralSsidsStoreData(mClock), new RandomizedMacStoreData(),
mFrameworkFacade, wifiHandler, mDeviceConfigFacade);
mWifiMetrics.setWifiConfigManager(mWifiConfigManager);
+
+ mWifiApConfigStore = new WifiApConfigStore(
+ mContext, this, wifiHandler, mBackupManagerProxy, mFrameworkFacade,
+ mWifiConfigStore, mWifiConfigManager);
+
mWifiConnectivityHelper = new WifiConnectivityHelper(mWifiNative);
mConnectivityLocalLog = new LocalLog(
mContext.getSystemService(ActivityManager.class).isLowRamDevice() ? 256 : 512);
@@ -654,6 +656,14 @@ public class WifiInjector {
return new NetworkSuggestionStoreData(dataSource);
}
+ /**
+ * Construct an instance of {@link SoftApStoreData}.
+ */
+ public SoftApStoreData makeSoftApStoreData(
+ SoftApStoreData.DataSource dataSource) {
+ return new SoftApStoreData(dataSource);
+ }
+
public WifiPermissionsUtil getWifiPermissionsUtil() {
return mWifiPermissionsUtil;
}
diff --git a/service/wifi.rc b/service/wifi.rc
index 9a04252dc..5362ee69f 100644
--- a/service/wifi.rc
+++ b/service/wifi.rc
@@ -19,6 +19,7 @@
on post-fs-data
chown network_stack network_stack /data/misc/wifi
chown network_stack network_stack /data/misc/wifi/WifiConfigStore.xml
+ chown network_stack network_stack /data/misc/wifi/WifiConfigStoreSoftAp.xml
chown network_stack network_stack /data/misc/wifi/softap.conf
on property:sys.user.0.ce_available=true
diff --git a/service/wifi_inprocess.rc b/service/wifi_inprocess.rc
index 286d18063..43e4866b5 100644
--- a/service/wifi_inprocess.rc
+++ b/service/wifi_inprocess.rc
@@ -19,6 +19,7 @@
on post-fs-data
chown system system /data/misc/wifi
chown system system /data/misc/wifi/WifiConfigStore.xml
+ chown system system /data/misc/wifi/WifiConfigStoreSoftAp.xml
chown system system /data/misc/wifi/softap.conf
on property:sys.user.0.ce_available=true
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));
}