From ee38c65d579f5363f2ffd63e850582350233d0e4 Mon Sep 17 00:00:00 2001 From: Rebecca Silberstein Date: Fri, 25 May 2018 09:23:51 -0700 Subject: WifiApConfigStore: convert 5GHZ to ANY for dual mode devices When setting or getting an ap config, check for necessary apband conversions. For some devices, apBand options are limited to 2.4(only) and ANY. A second class of devices are limited to 2.4(only) and 5(only). Single band devices are still limited to 2.4(only). Bug: 80251951 Test: frameworks/opt/net/wifi/tests/wifitests/runtests.sh Test: manually confirmed configs are converted for different device types Change-Id: I14150f0e890696e12ef04f402c0d8afad09e984e --- .../android/server/wifi/WifiApConfigStoreTest.java | 238 ++++++++++++++++++++- 1 file changed, 228 insertions(+), 10 deletions(-) (limited to 'tests') diff --git a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java index 7e7edd4d4..1672dca58 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java @@ -19,6 +19,7 @@ package com.android.server.wifi; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -61,6 +62,7 @@ public class WifiApConfigStoreTest { @Mock BackupManagerProxy mBackupManagerProxy; File mApConfigFile; Random mRandom; + MockResources mResources; @Before public void setUp() throws Exception { @@ -70,14 +72,16 @@ public class WifiApConfigStoreTest { mApConfigFile = File.createTempFile(TEST_AP_CONFIG_FILE_PREFIX, ""); /* Setup expectations for Resources to return some default settings. */ - MockResources resources = new MockResources(); - resources.setString(R.string.config_wifi_framework_sap_2G_channel_list, + mResources = new MockResources(); + mResources.setString(R.string.config_wifi_framework_sap_2G_channel_list, TEST_DEFAULT_2G_CHANNEL_LIST); - resources.setString(R.string.wifi_tether_configure_ssid_default, + mResources.setString(R.string.wifi_tether_configure_ssid_default, TEST_DEFAULT_AP_SSID); - resources.setString(R.string.wifi_localhotspot_configure_ssid_default, + mResources.setString(R.string.wifi_localhotspot_configure_ssid_default, TEST_DEFAULT_HOTSPOT_SSID); - when(mContext.getResources()).thenReturn(resources); + /* Default to device that does not require ap band conversion */ + mResources.setBoolean(R.bool.config_wifi_convert_apband_5ghz_to_any, false); + when(mContext.getResources()).thenReturn(mResources); mRandom = new Random(); } @@ -203,16 +207,230 @@ public class WifiApConfigStoreTest { /* Update with a valid configuration. */ WifiConfiguration expectedConfig = setupApConfig( - "ConfiguredAP", /* SSID */ - "randomKey", /* preshared key */ - KeyMgmt.WPA_EAP, /* key management */ - 1, /* AP band (5GHz) */ - 40 /* AP channel */); + "ConfiguredAP", /* SSID */ + "randomKey", /* preshared key */ + KeyMgmt.WPA_EAP, /* key management */ + WifiConfiguration.AP_BAND_2GHZ, /* AP band */ + 40 /* AP channel */); + store.setApConfiguration(expectedConfig); + verifyApConfig(expectedConfig, store.getApConfiguration()); + verify(mBackupManagerProxy).notifyDataChanged(); + } + + /** + * Due to different device hw capabilities, some bands are not available if a device is + * dual/single mode capable. This test verifies that a single mode device will have apBand = + * ANY converted to 5GHZ. + */ + @Test + public void convertSingleModeDeviceAnyTo5Ghz() throws Exception { + /* Initialize WifiApConfigStore with default configuration. */ + WifiApConfigStore store = new WifiApConfigStore( + mContext, mBackupManagerProxy, mApConfigFile.getPath()); + verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID); + + /* Update with a valid configuration. */ + WifiConfiguration providedConfig = setupApConfig( + "ConfiguredAP", /* SSID */ + "randomKey", /* preshared key */ + KeyMgmt.WPA_EAP, /* key management */ + WifiConfiguration.AP_BAND_ANY, /* AP band (ANY) */ + 40 /* AP channel */); + + WifiConfiguration expectedConfig = setupApConfig( + "ConfiguredAP", /* SSID */ + "randomKey", /* preshared key */ + KeyMgmt.WPA_EAP, /* key management */ + WifiConfiguration.AP_BAND_5GHZ, /* AP band (5GHz) */ + WifiApConfigStore.AP_CHANNEL_DEFAULT /* AP channel */); + store.setApConfiguration(providedConfig); + verifyApConfig(expectedConfig, store.getApConfiguration()); + verify(mBackupManagerProxy).notifyDataChanged(); + } + + /** + * Due to different device hw capabilities, some bands are not available if a device is + * dual/single mode capable. This test verifies that a single mode device does not convert + * apBand to ANY. + */ + @Test + public void singleModeDevice5GhzNotConverted() throws Exception { + /* Initialize WifiApConfigStore with default configuration. */ + WifiApConfigStore store = new WifiApConfigStore( + mContext, mBackupManagerProxy, mApConfigFile.getPath()); + verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID); + + /* Update with a valid configuration. */ + WifiConfiguration expectedConfig = setupApConfig( + "ConfiguredAP", /* SSID */ + "randomKey", /* preshared key */ + KeyMgmt.WPA_EAP, /* key management */ + WifiConfiguration.AP_BAND_5GHZ, /* AP band */ + 40 /* AP channel */); + store.setApConfiguration(expectedConfig); + verifyApConfig(expectedConfig, store.getApConfiguration()); + } + + /** + * Due to different device hw capabilities, some bands are not available if a device is + * dual/single mode capable. This test verifies that a dual mode device will have apBand = + * 5GHz converted to ANY. + */ + @Test + public void convertDualModeDevice5GhzToAny() throws Exception { + mResources.setBoolean(R.bool.config_wifi_convert_apband_5ghz_to_any, true); + + /* Initialize WifiApConfigStore with default configuration. */ + WifiApConfigStore store = new WifiApConfigStore( + mContext, mBackupManagerProxy, mApConfigFile.getPath()); + verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID); + + /* Update with a valid configuration. */ + WifiConfiguration providedConfig = setupApConfig( + "ConfiguredAP", /* SSID */ + "randomKey", /* preshared key */ + KeyMgmt.WPA_EAP, /* key management */ + WifiConfiguration.AP_BAND_5GHZ, /* AP band */ + 40 /* AP channel */); + + WifiConfiguration expectedConfig = setupApConfig( + "ConfiguredAP", /* SSID */ + "randomKey", /* preshared key */ + KeyMgmt.WPA_EAP, /* key management */ + WifiConfiguration.AP_BAND_ANY, /* AP band */ + WifiApConfigStore.AP_CHANNEL_DEFAULT /* AP channel */); + store.setApConfiguration(providedConfig); + verifyApConfig(expectedConfig, store.getApConfiguration()); + verify(mBackupManagerProxy).notifyDataChanged(); + } + + /** + * Due to different device hw capabilities, some bands are not available if a device is + * dual/single mode capable. This test verifies that a dual mode device does not convert + * apBand to 5Ghz. + */ + @Test + public void dualModeDeviceAnyNotConverted() throws Exception { + mResources.setBoolean(R.bool.config_wifi_convert_apband_5ghz_to_any, true); + + /* Initialize WifiApConfigStore with default configuration. */ + WifiApConfigStore store = new WifiApConfigStore( + mContext, mBackupManagerProxy, mApConfigFile.getPath()); + verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID); + + /* Update with a valid configuration. */ + WifiConfiguration expectedConfig = setupApConfig( + "ConfiguredAP", /* SSID */ + "randomKey", /* preshared key */ + KeyMgmt.WPA_EAP, /* key management */ + WifiConfiguration.AP_BAND_ANY, /* AP band */ + 40 /* AP channel */); store.setApConfiguration(expectedConfig); + verify(mBackupManagerProxy).notifyDataChanged(); + verifyApConfig(expectedConfig, store.getApConfiguration()); + } + + /** + * Due to different device hw capabilities, some bands are not available if a device is + * dual/single mode capable. This test verifies that a single mode device converts a persisted + * ap config with ANY set for the apBand to 5GHz. + */ + @Test + public void singleModeDeviceAnyConvertedTo5GhzAtRetrieval() throws Exception { + + WifiConfiguration persistedConfig = setupApConfig( + "ConfiguredAP", /* SSID */ + "randomKey", /* preshared key */ + KeyMgmt.WPA_EAP, /* key management */ + WifiConfiguration.AP_BAND_ANY, /* AP band */ + 40 /* AP channel */); + WifiConfiguration expectedConfig = setupApConfig( + "ConfiguredAP", /* SSID */ + "randomKey", /* preshared key */ + KeyMgmt.WPA_EAP, /* key management */ + WifiConfiguration.AP_BAND_5GHZ, /* AP band */ + WifiApConfigStore.AP_CHANNEL_DEFAULT /* AP channel */); + + writeApConfigFile(persistedConfig); + WifiApConfigStore store = new WifiApConfigStore( + mContext, mBackupManagerProxy, mApConfigFile.getPath()); + verifyApConfig(expectedConfig, store.getApConfiguration()); + verify(mBackupManagerProxy).notifyDataChanged(); + } + + /** + * Due to different device hw capabilities, some bands are not available if a device is + * dual/single mode capable. This test verifies that a single mode device does not convert + * a persisted ap config with 5GHz set for the apBand. + */ + @Test + public void singleModeDeviceNotConvertedAtRetrieval() throws Exception { + WifiConfiguration persistedConfig = setupApConfig( + "ConfiguredAP", /* SSID */ + "randomKey", /* preshared key */ + KeyMgmt.WPA_EAP, /* key management */ + WifiConfiguration.AP_BAND_5GHZ, /* AP band */ + 40 /* AP channel */); + + writeApConfigFile(persistedConfig); + WifiApConfigStore store = new WifiApConfigStore( + mContext, mBackupManagerProxy, mApConfigFile.getPath()); + verifyApConfig(persistedConfig, store.getApConfiguration()); + verify(mBackupManagerProxy, never()).notifyDataChanged(); + } + + /** + * Due to different device hw capabilities, some bands are not available if a device is + * dual/single mode capable. This test verifies that a dual mode device converts a persisted ap + * config with 5GHz only set for the apBand to ANY. + */ + @Test + public void dualModeDevice5GhzConvertedToAnyAtRetrieval() throws Exception { + mResources.setBoolean(R.bool.config_wifi_convert_apband_5ghz_to_any, true); + + WifiConfiguration persistedConfig = setupApConfig( + "ConfiguredAP", /* SSID */ + "randomKey", /* preshared key */ + KeyMgmt.WPA_EAP, /* key management */ + WifiConfiguration.AP_BAND_5GHZ, /* AP band */ + 40 /* AP channel */); + WifiConfiguration expectedConfig = setupApConfig( + "ConfiguredAP", /* SSID */ + "randomKey", /* preshared key */ + KeyMgmt.WPA_EAP, /* key management */ + WifiConfiguration.AP_BAND_ANY, /* AP band */ + WifiApConfigStore.AP_CHANNEL_DEFAULT /* AP channel */); + + writeApConfigFile(persistedConfig); + WifiApConfigStore store = new WifiApConfigStore( + mContext, mBackupManagerProxy, mApConfigFile.getPath()); verifyApConfig(expectedConfig, store.getApConfiguration()); verify(mBackupManagerProxy).notifyDataChanged(); } + /** + * Due to different device hw capabilities, some bands are not available if a device is + * dual/single mode capable. This test verifies that a dual mode device does not convert + * a persisted ap config with ANY set for the apBand. + */ + @Test + public void dualModeDeviceNotConvertedAtRetrieval() throws Exception { + mResources.setBoolean(R.bool.config_wifi_convert_apband_5ghz_to_any, true); + + WifiConfiguration persistedConfig = setupApConfig( + "ConfiguredAP", /* SSID */ + "randomKey", /* preshared key */ + KeyMgmt.WPA_EAP, /* key management */ + WifiConfiguration.AP_BAND_ANY, /* AP band */ + 40 /* AP channel */); + + writeApConfigFile(persistedConfig); + WifiApConfigStore store = new WifiApConfigStore( + mContext, mBackupManagerProxy, mApConfigFile.getPath()); + verifyApConfig(persistedConfig, store.getApConfiguration()); + verify(mBackupManagerProxy, never()).notifyDataChanged(); + } + /** * Verify a proper WifiConfiguration is generate by getDefaultApConfiguration(). */ -- cgit v1.2.3