diff options
author | Roshan Pius <rpius@google.com> | 2020-02-10 12:39:43 -0800 |
---|---|---|
committer | Roshan Pius <rpius@google.com> | 2020-02-18 07:27:31 -0800 |
commit | df01391f63407ea6611a02befd600efe4dd80c0f (patch) | |
tree | 06027bd26b6ef81374e008413e8eec1dae5d60df /tests | |
parent | 40369495ec8f3fc06f655d3dd2ab07ae4844c130 (diff) |
WifiApConfigStore: Store the shutdown enabled flag in config store
Changes:
a) Don't use the Settings.Global value to store the feature toggle.
Store the info in config store file along with other softap
configuration.
b) Use the new WifiOemMigrationHook class to migrate the data out of the
existing Settings value (for both backup/restore & config store).
Also, fixed a bug in the
ApConfigUtil.checkConfigurationChangeNeedToRestart() (was checking for
object instance equality)
Bug: 147779354
Bug: 148514485
Test: atest com.android.server.wifi
Test: Manually verified the toggle from Settings.
Change-Id: I84dd00ae112223b271e5fdbe4b25ea4ba8b1c9be
Diffstat (limited to 'tests')
3 files changed, 213 insertions, 46 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java index 331ba92e4..c7565c6ca 100644 --- a/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java @@ -21,22 +21,32 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.*; import static org.mockito.Mockito.*; +import android.content.Context; import android.net.MacAddress; import android.net.wifi.SoftApConfiguration; import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiOemMigrationHook; import android.util.BackupUtils; import androidx.test.filters.SmallTest; +import com.android.dx.mockito.inline.extended.ExtendedMockito; import com.android.server.wifi.util.ApConfigUtil; +import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.MockitoSession; +import org.mockito.quality.Strictness; import java.io.ByteArrayOutputStream; import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; /** * Unit tests for {@link com.android.server.wifi.SoftApBackupRestore}. @@ -44,15 +54,25 @@ import java.util.ArrayList; @SmallTest public class SoftApBackupRestoreTest extends WifiBaseTest { + @Mock private Context mContext; + @Mock private WifiOemMigrationHook.SettingsMigrationData mOemMigrationData; private SoftApBackupRestore mSoftApBackupRestore; + private final ArrayList<MacAddress> mTestBlockedList = new ArrayList<>(); + private final ArrayList<MacAddress> mTestAllowedList = new ArrayList<>(); private static final int LAST_WIFICOFIGURATION_BACKUP_VERSION = 3; private static final boolean TEST_CLIENTCONTROLENABLE = false; private static final int TEST_MAXNUMBEROFCLIENTS = 10; private static final int TEST_SHUTDOWNTIMEOUTMILLIS = 600_000; - private static final ArrayList<MacAddress> TEST_BLOCKEDLIST = new ArrayList<>(); private static final String TEST_BLOCKED_CLIENT = "11:22:33:44:55:66"; - private static final ArrayList<MacAddress> TEST_ALLOWEDLIST = new ArrayList<>(); private static final String TEST_ALLOWED_CLIENT = "aa:bb:cc:dd:ee:ff"; + private static final String TEST_SSID = "TestAP"; + private static final String TEST_PASSPHRASE = "TestPskPassphrase"; + private static final int TEST_SECURITY = SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION; + private static final int TEST_BAND = SoftApConfiguration.BAND_5GHZ; + private static final int TEST_CHANNEL = 40; + private static final boolean TEST_HIDDEN = false; + + MockitoSession mSession; /** * Asserts that the WifiConfigurations equal to SoftApConfiguration. @@ -76,10 +96,24 @@ public class SoftApBackupRestoreTest extends WifiBaseTest { assertEquals(backup.hiddenSSID, restore.isHiddenSsid()); } - @Before public void setUp() throws Exception { - mSoftApBackupRestore = new SoftApBackupRestore(); + MockitoAnnotations.initMocks(this); + + mSession = ExtendedMockito.mockitoSession() + .mockStatic(WifiOemMigrationHook.class, withSettings().lenient()) + .strictness(Strictness.LENIENT) + .startMocking(); + when(WifiOemMigrationHook.loadFromSettings(any(Context.class))) + .thenReturn(mOemMigrationData); + when(mOemMigrationData.isSoftApTimeoutEnabled()).thenReturn(true); + + mSoftApBackupRestore = new SoftApBackupRestore(mContext); + } + + @After + public void tearDown() throws Exception { + mSession.finishMocking(); } /** @@ -169,6 +203,7 @@ public class SoftApBackupRestoreTest extends WifiBaseTest { configBuilder.setPassphrase("TestPskPassphrase", SoftApConfiguration.SECURITY_TYPE_WPA3_SAE); configBuilder.setHiddenSsid(true); + configBuilder.setAutoShutdownEnabled(true); SoftApConfiguration config = configBuilder.build(); byte[] data = mSoftApBackupRestore.retrieveBackupDataFromSoftApConfiguration(config); @@ -190,6 +225,7 @@ public class SoftApBackupRestoreTest extends WifiBaseTest { configBuilder.setPassphrase("TestPskPassphrase", SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION); configBuilder.setHiddenSsid(true); + configBuilder.setAutoShutdownEnabled(false); SoftApConfiguration config = configBuilder.build(); byte[] data = mSoftApBackupRestore.retrieveBackupDataFromSoftApConfiguration(config); @@ -203,20 +239,19 @@ public class SoftApBackupRestoreTest extends WifiBaseTest { * Verifies that the serialization/de-serialization for wpa3-sae-transition softap config. */ @Test - public void testSoftApConfigBackupAndRestoreWithMaxShutDonwClientList() throws Exception { - TEST_BLOCKEDLIST.add(MacAddress.fromString(TEST_BLOCKED_CLIENT)); - TEST_ALLOWEDLIST.add(MacAddress.fromString(TEST_ALLOWED_CLIENT)); + public void testSoftApConfigBackupAndRestoreWithMaxShutDownClientList() throws Exception { + mTestBlockedList.add(MacAddress.fromString(TEST_BLOCKED_CLIENT)); + mTestAllowedList.add(MacAddress.fromString(TEST_ALLOWED_CLIENT)); SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder(); - configBuilder.setSsid("TestAP"); + configBuilder.setSsid(TEST_SSID); configBuilder.setBand(SoftApConfiguration.BAND_5GHZ); configBuilder.setChannel(40, SoftApConfiguration.BAND_5GHZ); - configBuilder.setPassphrase("TestPskPassphrase", - SoftApConfiguration.SECURITY_TYPE_WPA3_SAE_TRANSITION); - configBuilder.setHiddenSsid(true); + configBuilder.setPassphrase(TEST_PASSPHRASE, TEST_SECURITY); + configBuilder.setHiddenSsid(TEST_HIDDEN); configBuilder.setMaxNumberOfClients(TEST_MAXNUMBEROFCLIENTS); configBuilder.setShutdownTimeoutMillis(TEST_SHUTDOWNTIMEOUTMILLIS); configBuilder.enableClientControlByUser(TEST_CLIENTCONTROLENABLE); - configBuilder.setClientList(TEST_BLOCKEDLIST, TEST_ALLOWEDLIST); + configBuilder.setClientList(mTestBlockedList, mTestAllowedList); SoftApConfiguration config = configBuilder.build(); byte[] data = mSoftApBackupRestore.retrieveBackupDataFromSoftApConfiguration(config); @@ -225,4 +260,74 @@ public class SoftApBackupRestoreTest extends WifiBaseTest { assertThat(config).isEqualTo(restoredConfig); } + + /** + * Verifies that the restore of version 5 backup data will read the auto shutdown enable/disable + * tag from {@link WifiOemMigrationHook#loadFromSettings(Context)} + */ + @Test + public void testSoftApConfigRestoreFromVersion5() throws Exception { + mTestBlockedList.add(MacAddress.fromString(TEST_BLOCKED_CLIENT)); + mTestAllowedList.add(MacAddress.fromString(TEST_ALLOWED_CLIENT)); + SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder(); + configBuilder.setSsid(TEST_SSID); + configBuilder.setBand(TEST_BAND); + configBuilder.setChannel(TEST_CHANNEL, TEST_BAND); + configBuilder.setPassphrase(TEST_PASSPHRASE, TEST_SECURITY); + configBuilder.setHiddenSsid(TEST_HIDDEN); + configBuilder.setMaxNumberOfClients(TEST_MAXNUMBEROFCLIENTS); + configBuilder.setShutdownTimeoutMillis(TEST_SHUTDOWNTIMEOUTMILLIS); + configBuilder.enableClientControlByUser(TEST_CLIENTCONTROLENABLE); + configBuilder.setClientList(mTestBlockedList, mTestAllowedList); + + // Toggle on when migrating. + when(mOemMigrationData.isSoftApTimeoutEnabled()).thenReturn(true); + SoftApConfiguration expectedConfig = configBuilder.setAutoShutdownEnabled(true).build(); + SoftApConfiguration restoredConfig = + mSoftApBackupRestore.retrieveSoftApConfigurationFromBackupData( + retrieveVersion5BackupDataFromSoftApConfiguration(expectedConfig)); + assertEquals(expectedConfig, restoredConfig); + + // Toggle off when migrating. + when(mOemMigrationData.isSoftApTimeoutEnabled()).thenReturn(false); + expectedConfig = configBuilder.setAutoShutdownEnabled(false).build(); + restoredConfig = mSoftApBackupRestore.retrieveSoftApConfigurationFromBackupData( + retrieveVersion5BackupDataFromSoftApConfiguration(expectedConfig)); + assertEquals(expectedConfig, restoredConfig); + } + + /** + * This is a copy of the old serialization code (version 5) + * + * Changes: Version = 5, AutoShutdown tag is missing. + */ + private byte[] retrieveVersion5BackupDataFromSoftApConfiguration(SoftApConfiguration config) + throws Exception { + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(baos); + + out.writeInt(5); + BackupUtils.writeString(out, config.getSsid()); + out.writeInt(config.getBand()); + out.writeInt(config.getChannel()); + BackupUtils.writeString(out, config.getPassphrase()); + out.writeInt(config.getSecurityType()); + out.writeBoolean(config.isHiddenSsid()); + out.writeInt(config.getMaxNumberOfClients()); + out.writeInt(config.getShutdownTimeoutMillis()); + out.writeBoolean(config.isClientControlByUserEnabled()); + writeMacAddressList(out, config.getBlockedClientList()); + writeMacAddressList(out, config.getAllowedClientList()); + return baos.toByteArray(); + } + + private void writeMacAddressList(DataOutputStream out, List<MacAddress> macList) + throws IOException { + out.writeInt(macList.size()); + Iterator<MacAddress> iterator = macList.iterator(); + while (iterator.hasNext()) { + byte[] mac = iterator.next().toByteArray(); + out.write(mac, 0, 6); + } + } } diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java index a66480978..c5e90c5e6 100644 --- a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java @@ -54,9 +54,7 @@ import android.app.test.TestAlarmManager; import android.content.Context; import android.content.Intent; import android.content.res.Resources; -import android.database.ContentObserver; import android.net.MacAddress; -import android.net.Uri; import android.net.wifi.SoftApCapability; import android.net.wifi.SoftApConfiguration; import android.net.wifi.SoftApConfiguration.Builder; @@ -111,9 +109,8 @@ public class SoftApManagerTest extends WifiBaseTest { SoftApInfo.CHANNEL_WIDTH_20MHZ_NOHT; private static final int TEST_AP_BANDWIDTH_IN_SOFTAPINFO = SoftApInfo.CHANNEL_WIDTH_20MHZ_NOHT; private static final int[] EMPTY_CHANNEL_ARRAY = {}; - private final SoftApConfiguration mDefaultApConfig = createDefaultApConfig(); + private SoftApConfiguration mDefaultApConfig = createDefaultApConfig(); - private ContentObserver mContentObserver; private TestLooper mLooper; private TestAlarmManager mAlarmManager; private SoftApInfo mTestSoftApInfo; @@ -1473,9 +1470,10 @@ public class SoftApManagerTest extends WifiBaseTest { mTestSoftApCapability); startSoftApAndVerifyEnabled(apConfig); - when(mFrameworkFacade.getIntegerSetting( - mContext, Settings.Global.SOFT_AP_TIMEOUT_ENABLED, 1)).thenReturn(0); - mContentObserver.onChange(false); + SoftApConfiguration newConfig = new SoftApConfiguration.Builder(mDefaultApConfig) + .setAutoShutdownEnabled(false) + .build(); + mSoftApManager.updateConfiguration(newConfig); mLooper.dispatchAll(); // Verify timer is canceled @@ -1485,16 +1483,18 @@ public class SoftApManagerTest extends WifiBaseTest { @Test public void schedulesTimeoutTimerOnTimeoutToggleChangeWhenNoClients() throws Exception { // start with timeout toggle disabled - when(mFrameworkFacade.getIntegerSetting( - mContext, Settings.Global.SOFT_AP_TIMEOUT_ENABLED, 1)).thenReturn(0); + mDefaultApConfig = new SoftApConfiguration.Builder(mDefaultApConfig) + .setAutoShutdownEnabled(false) + .build(); SoftApModeConfiguration apConfig = new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null, mTestSoftApCapability); startSoftApAndVerifyEnabled(apConfig); - when(mFrameworkFacade.getIntegerSetting( - mContext, Settings.Global.SOFT_AP_TIMEOUT_ENABLED, 1)).thenReturn(1); - mContentObserver.onChange(false); + SoftApConfiguration newConfig = new SoftApConfiguration.Builder(mDefaultApConfig) + .setAutoShutdownEnabled(true) + .build(); + mSoftApManager.updateConfiguration(newConfig); mLooper.dispatchAll(); // Verify timer is scheduled @@ -1505,8 +1505,9 @@ public class SoftApManagerTest extends WifiBaseTest { @Test public void doesNotScheduleTimeoutTimerOnStartWhenTimeoutIsDisabled() throws Exception { // start with timeout toggle disabled - when(mFrameworkFacade.getIntegerSetting( - mContext, Settings.Global.SOFT_AP_TIMEOUT_ENABLED, 1)).thenReturn(0); + mDefaultApConfig = new SoftApConfiguration.Builder(mDefaultApConfig) + .setAutoShutdownEnabled(false) + .build(); SoftApModeConfiguration apConfig = new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null, mTestSoftApCapability); @@ -1521,8 +1522,9 @@ public class SoftApManagerTest extends WifiBaseTest { public void doesNotScheduleTimeoutTimerWhenAllClientsDisconnectButTimeoutIsDisabled() throws Exception { // start with timeout toggle disabled - when(mFrameworkFacade.getIntegerSetting( - mContext, Settings.Global.SOFT_AP_TIMEOUT_ENABLED, 1)).thenReturn(0); + mDefaultApConfig = new SoftApConfiguration.Builder(mDefaultApConfig) + .setAutoShutdownEnabled(false) + .build(); SoftApModeConfiguration apConfig = new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null, mTestSoftApCapability); @@ -1541,18 +1543,6 @@ public class SoftApManagerTest extends WifiBaseTest { } @Test - public void unregistersSettingsObserverOnStop() throws Exception { - SoftApModeConfiguration apConfig = - new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null, - mTestSoftApCapability); - startSoftApAndVerifyEnabled(apConfig); - mSoftApManager.stop(); - mLooper.dispatchAll(); - - verify(mFrameworkFacade).unregisterContentObserver(eq(mContext), eq(mContentObserver)); - } - - @Test public void resetsFactoryMacWhenRandomizationOff() throws Exception { Builder configBuilder = new SoftApConfiguration.Builder(); configBuilder.setBand(SoftApConfiguration.BAND_2GHZ); @@ -1751,8 +1741,6 @@ public class SoftApManagerTest extends WifiBaseTest { .build(); } - ArgumentCaptor<ContentObserver> observerCaptor = ArgumentCaptor.forClass( - ContentObserver.class); ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class); when(mWifiNative.setupInterfaceForSoftApMode(any())) @@ -1787,9 +1775,6 @@ public class SoftApManagerTest extends WifiBaseTest { softApConfig.getTargetMode()); verify(mListener).onStarted(); verify(mWifiMetrics).addSoftApUpChangedEvent(true, softApConfig.getTargetMode()); - verify(mFrameworkFacade).registerContentObserver(eq(mContext), any(Uri.class), eq(true), - observerCaptor.capture()); - mContentObserver = observerCaptor.getValue(); } private void checkApStateChangedBroadcast(Intent intent, int expectedCurrentState, diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java index 62e20cc18..4275518a9 100644 --- a/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java @@ -17,20 +17,26 @@ package com.android.server.wifi; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; 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 static org.mockito.Mockito.withSettings; +import android.content.Context; import android.net.MacAddress; import android.net.wifi.SoftApConfiguration; import android.net.wifi.WifiConfiguration; +import android.net.wifi.WifiOemMigrationHook; import android.util.Xml; import androidx.test.filters.SmallTest; +import com.android.dx.mockito.inline.extended.ExtendedMockito; import com.android.internal.util.FastXmlSerializer; import com.android.server.wifi.util.WifiConfigStoreEncryptionUtil; @@ -40,6 +46,8 @@ import org.junit.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.mockito.MockitoSession; +import org.mockito.quality.Strictness; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlSerializer; @@ -63,6 +71,7 @@ public class SoftApStoreDataTest extends WifiBaseTest { private static final int TEST_OLD_BAND = WifiConfiguration.AP_BAND_ANY; private static final int TEST_SECURITY = SoftApConfiguration.SECURITY_TYPE_WPA2_PSK; private static final boolean TEST_CLIENT_CONTROL_BY_USER = false; + private static final boolean TEST_AUTO_SHUTDOWN_ENABLED = true; private static final int TEST_MAX_NUMBER_OF_CLIENTS = 10; private static final int TEST_SHUTDOWN_TIMEOUT_MILLIS = 600_000; private static final ArrayList<MacAddress> TEST_BLOCKEDLIST = new ArrayList<>(); @@ -97,6 +106,8 @@ public class SoftApStoreDataTest extends WifiBaseTest { + TEST_MAX_NUMBER_OF_CLIENTS + "\" />\n" + "<boolean name=\"ClientControlByUser\" value=\"" + TEST_CLIENT_CONTROL_BY_USER + "\" />\n" + + "<boolean name=\"AutoShutdownEnabled\" value=\"" + + TEST_AUTO_SHUTDOWN_ENABLED + "\" />\n" + "<int name=\"ShutdownTimeoutMillis\" value=\"" + TEST_SHUTDOWN_TIMEOUT_MILLIS + "\" />\n" + "<BlockedClientList>\n" @@ -106,6 +117,27 @@ public class SoftApStoreDataTest extends WifiBaseTest { + "<string name=\"ClientMacAddress\">" + TEST_ALLOWED_CLIENT + "</string>\n" + "</AllowedClientList>\n"; + private static final String TEST_SOFTAP_CONFIG_XML_STRING_WITH_ALL_CONFIG_EXCEPT_AUTO_SHUTDOWN = + "<string name=\"SSID\">" + TEST_SSID + "</string>\n" + + "<int name=\"ApBand\" value=\"" + TEST_BAND + "\" />\n" + + "<int name=\"Channel\" value=\"" + TEST_CHANNEL + "\" />\n" + + "<boolean name=\"HiddenSSID\" value=\"" + TEST_HIDDEN + "\" />\n" + + "<int name=\"SecurityType\" value=\"" + TEST_SECURITY + "\" />\n" + + "<string name=\"Passphrase\">" + TEST_PASSPHRASE + "</string>\n" + + "<int name=\"MaxNumberOfClients\" value=\"" + + TEST_MAX_NUMBER_OF_CLIENTS + "\" />\n" + + "<boolean name=\"ClientControlByUser\" value=\"" + + TEST_CLIENT_CONTROL_BY_USER + "\" />\n" + + "<int name=\"ShutdownTimeoutMillis\" value=\"" + + TEST_SHUTDOWN_TIMEOUT_MILLIS + "\" />\n" + + "<BlockedClientList>\n" + + "<string name=\"ClientMacAddress\">" + TEST_BLOCKED_CLIENT + "</string>\n" + + "</BlockedClientList>\n" + + "<AllowedClientList>\n" + + "<string name=\"ClientMacAddress\">" + TEST_ALLOWED_CLIENT + "</string>\n" + + "</AllowedClientList>\n"; + + @Mock private Context mContext; @Mock SoftApStoreData.DataSource mDataSource; @Mock WifiOemConfigStoreMigrationDataHolder mWifiOemConfigStoreMigrationDataHolder; SoftApStoreData mSoftApStoreData; @@ -113,7 +145,8 @@ public class SoftApStoreDataTest extends WifiBaseTest { @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); - mSoftApStoreData = new SoftApStoreData(mDataSource, mWifiOemConfigStoreMigrationDataHolder); + mSoftApStoreData = + new SoftApStoreData(mContext, mDataSource, mWifiOemConfigStoreMigrationDataHolder); TEST_BLOCKEDLIST.add(MacAddress.fromString(TEST_BLOCKED_CLIENT)); TEST_ALLOWEDLIST.add(MacAddress.fromString(TEST_ALLOWED_CLIENT)); } @@ -150,6 +183,7 @@ public class SoftApStoreDataTest extends WifiBaseTest { softApConfigBuilder.setBand(TEST_BAND); softApConfigBuilder.enableClientControlByUser(TEST_CLIENT_CONTROL_BY_USER); softApConfigBuilder.setMaxNumberOfClients(TEST_MAX_NUMBER_OF_CLIENTS); + softApConfigBuilder.setAutoShutdownEnabled(true); softApConfigBuilder.setShutdownTimeoutMillis(TEST_SHUTDOWN_TIMEOUT_MILLIS); softApConfigBuilder.setClientList(TEST_BLOCKEDLIST, TEST_ALLOWEDLIST); return softApConfigBuilder.build(); @@ -229,6 +263,7 @@ public class SoftApStoreDataTest extends WifiBaseTest { assertEquals(softApConfig.getBand(), TEST_BAND); assertEquals(softApConfig.isClientControlByUserEnabled(), TEST_CLIENT_CONTROL_BY_USER); assertEquals(softApConfig.getMaxNumberOfClients(), TEST_MAX_NUMBER_OF_CLIENTS); + assertTrue(softApConfig.isAutoShutdownEnabled()); assertEquals(softApConfig.getShutdownTimeoutMillis(), TEST_SHUTDOWN_TIMEOUT_MILLIS); assertEquals(softApConfig.getBlockedClientList(), TEST_BLOCKEDLIST); assertEquals(softApConfig.getAllowedClientList(), TEST_ALLOWEDLIST); @@ -419,4 +454,46 @@ public class SoftApStoreDataTest extends WifiBaseTest { assertEquals(softApConfig.getAllowedClientList(), TEST_ALLOWEDLIST); } + /** + * Verify that the store data is deserialized correctly using the predefined test XML data + * when the auto shutdown tag is retrieved from + * {@link WifiOemMigrationHook.loadFromSettings(Context)}. + * + * @throws Exception + */ + @Test + public void deserializeSoftApWithNoAutoShutdownTag() throws Exception { + MockitoSession session = ExtendedMockito.mockitoSession() + .mockStatic(WifiConfigStore.class, withSettings().lenient()) + .strictness(Strictness.LENIENT) + .startMocking(); + WifiOemMigrationHook.SettingsMigrationData migrationData = mock( + WifiOemMigrationHook.SettingsMigrationData.class); + when(WifiOemMigrationHook.loadFromSettings(any())).thenReturn(migrationData); + + // Toggle on when migrating. + when(migrationData.isSoftApTimeoutEnabled()).thenReturn(true); + deserializeData( + TEST_SOFTAP_CONFIG_XML_STRING_WITH_ALL_CONFIG_EXCEPT_AUTO_SHUTDOWN.getBytes()); + ArgumentCaptor<SoftApConfiguration> softapConfigCaptor = + ArgumentCaptor.forClass(SoftApConfiguration.class); + verify(mDataSource).fromDeserialized(softapConfigCaptor.capture()); + SoftApConfiguration softApConfig = softapConfigCaptor.getValue(); + assertNotNull(softApConfig); + assertEquals(softApConfig.getSsid(), TEST_SSID); + assertTrue(softApConfig.isAutoShutdownEnabled()); + + // Toggle off when migrating. + when(migrationData.isSoftApTimeoutEnabled()).thenReturn(false); + deserializeData( + TEST_SOFTAP_CONFIG_XML_STRING_WITH_ALL_CONFIG_EXCEPT_AUTO_SHUTDOWN.getBytes()); + verify(mDataSource).fromDeserialized(softapConfigCaptor.capture()); + softApConfig = softapConfigCaptor.getValue(); + assertNotNull(softApConfig); + assertEquals(softApConfig.getSsid(), TEST_SSID); + assertFalse(softApConfig.isAutoShutdownEnabled()); + + session.finishMocking(); + } + } |