diff options
author | Ahmed ElArabawy <arabawy@google.com> | 2019-12-06 23:39:50 -0800 |
---|---|---|
committer | Ahmed ElArabawy <arabawy@google.com> | 2019-12-18 15:16:16 -0800 |
commit | 12e7eecdf27040164f39cea666392d8a43453210 (patch) | |
tree | e50a574dfd921a3bfb20edb62cbad987318884a0 /tests | |
parent | 1556231d78a09b299794d5f905fb989df3dcf792 (diff) |
Support 6GHz band for softAP
This commit adds support for 6GHz for softAP. This includes calling
the upgraded hidl API addAccessPoint_1_2().
Bug: 139354972
Test: atest com.android.wifi.server
Change-Id: I3320f66fd3f82bddeb058284e7ce9b901e53d840
Diffstat (limited to 'tests')
8 files changed, 461 insertions, 134 deletions
diff --git a/tests/wifitests/Android.bp b/tests/wifitests/Android.bp index 9c94f834d..2c16fe24f 100644 --- a/tests/wifitests/Android.bp +++ b/tests/wifitests/Android.bp @@ -44,6 +44,7 @@ android_test { "android.hardware.wifi-V1.4-java", "android.hardware.wifi.hostapd-V1.0-java", "android.hardware.wifi.hostapd-V1.1-java", + "android.hardware.wifi.hostapd-V1.2-java", "android.hardware.wifi.supplicant-V1.0-java", "android.hardware.wifi.supplicant-V1.1-java", "android.hardware.wifi.supplicant-V1.2-java", diff --git a/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java b/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java index a129de5b5..32e2c08f4 100644 --- a/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java +++ b/tests/wifitests/src/com/android/server/wifi/HostapdHalTest.java @@ -66,7 +66,8 @@ public class HostapdHalTest extends WifiBaseTest { private @Mock IHostapd mIHostapdMock; private @Mock WifiNative.HostapdDeathEventHandler mHostapdHalDeathHandler; private @Mock WifiCondManager.SoftApListener mSoftApListener; - private android.hardware.wifi.hostapd.V1_1.IHostapd mIHostapdMockV1_1; + private android.hardware.wifi.hostapd.V1_1.IHostapd mIHostapdMockV11; + private android.hardware.wifi.hostapd.V1_2.IHostapd mIHostapdMockV12; private IHostapdCallback mIHostapdCallback; private MockResources mResources; HostapdStatus mStatusSuccess; @@ -107,7 +108,13 @@ public class HostapdHalTest extends WifiBaseTest { @Override protected android.hardware.wifi.hostapd.V1_1.IHostapd getHostapdMockableV1_1() throws RemoteException { - return mIHostapdMockV1_1; + return mIHostapdMockV11; + } + + @Override + protected android.hardware.wifi.hostapd.V1_2.IHostapd getHostapdMockableV1_2() + throws RemoteException { + return mIHostapdMockV12; } } @@ -117,6 +124,8 @@ public class HostapdHalTest extends WifiBaseTest { mResources = new MockResources(); mResources.setBoolean(R.bool.config_wifi_softap_acs_supported, false); mResources.setBoolean(R.bool.config_wifi_softap_ieee80211ac_supported, false); + mResources.setBoolean(R.bool.config_wifiSoftapIeee80211axSupported, false); + mResources.setBoolean(R.bool.config_wifiSoftap6ghzSupported, false); mResources.setString(R.string.config_wifi_softap_acs_supported_channel_list, ""); mStatusSuccess = createHostapdStatus(HostapdStatusCode.SUCCESS); @@ -173,7 +182,7 @@ public class HostapdHalTest extends WifiBaseTest { public void testInitialize_successV1_1() throws Exception { when(mServiceManagerMock.getTransport(anyString(), anyString())) .thenReturn(IServiceManager.Transport.HWBINDER); - mIHostapdMockV1_1 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class); + mIHostapdMockV11 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class); executeAndValidateInitializationSequenceV1_1(false); } @@ -184,7 +193,7 @@ public class HostapdHalTest extends WifiBaseTest { public void testInitialize_registerCallbackFailureV1_1() throws Exception { when(mServiceManagerMock.getTransport(anyString(), anyString())) .thenReturn(IServiceManager.Transport.HWBINDER); - mIHostapdMockV1_1 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class); + mIHostapdMockV11 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class); executeAndValidateInitializationSequenceV1_1(true); } @@ -226,8 +235,7 @@ public class HostapdHalTest extends WifiBaseTest { configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(false); configurationBuilder.setWpa2Passphrase(NETWORK_PSK); - configurationBuilder.setChannel(apChannel); - configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ); + configurationBuilder.setChannel(apChannel, SoftApConfiguration.BAND_2GHZ); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), @@ -255,13 +263,12 @@ public class HostapdHalTest extends WifiBaseTest { @Test public void testAddAccessPointSuccess_Open_Band5G() throws Exception { executeAndValidateInitializationSequence(); - final int apChannel = 18; + final int apChannel = 149; Builder configurationBuilder = new SoftApConfiguration.Builder(); configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(true); - configurationBuilder.setChannel(apChannel); - configurationBuilder.setBand(SoftApConfiguration.BAND_5GHZ); + configurationBuilder.setChannel(apChannel, SoftApConfiguration.BAND_5GHZ); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), @@ -289,14 +296,13 @@ public class HostapdHalTest extends WifiBaseTest { @Test public void testAddAccessPointSuccess_Psk_Band5G_Hidden() throws Exception { executeAndValidateInitializationSequence(); - final int apChannel = 18; + final int apChannel = 149; Builder configurationBuilder = new SoftApConfiguration.Builder(); configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(true); configurationBuilder.setWpa2Passphrase(NETWORK_PSK); - configurationBuilder.setChannel(apChannel); - configurationBuilder.setBand(SoftApConfiguration.BAND_5GHZ); + configurationBuilder.setChannel(apChannel, SoftApConfiguration.BAND_5GHZ); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), @@ -334,8 +340,7 @@ public class HostapdHalTest extends WifiBaseTest { configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(false); configurationBuilder.setWpa2Passphrase(NETWORK_PSK); - configurationBuilder.setChannel(apChannel); - configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ); + configurationBuilder.setChannel(apChannel, SoftApConfiguration.BAND_2GHZ); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), @@ -373,8 +378,7 @@ public class HostapdHalTest extends WifiBaseTest { configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(false); configurationBuilder.setWpa2Passphrase(NETWORK_PSK); - configurationBuilder.setChannel(apChannel); - configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ); + configurationBuilder.setChannel(apChannel, SoftApConfiguration.BAND_2GHZ); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), @@ -405,13 +409,11 @@ public class HostapdHalTest extends WifiBaseTest { mHostapdHal = new HostapdHalSpy(); executeAndValidateInitializationSequence(); - final int apChannel = 6; Builder configurationBuilder = new SoftApConfiguration.Builder(); configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(false); configurationBuilder.setWpa2Passphrase(NETWORK_PSK); - configurationBuilder.setChannel(apChannel); configurationBuilder.setBand(SoftApConfiguration.BAND_ANY); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, @@ -435,22 +437,19 @@ public class HostapdHalTest extends WifiBaseTest { /** * Verifies the successful addition of access point. - * Verifies that BAND_ANY is downgraded to 2.4GHz if ACS is disabled. */ @Test - public void testAddAccessPointSuccess_Psk_BandAny_Downgraded_WithoutACS() throws Exception { + public void testAddAccessPointSuccess_Psk_WithoutACS() throws Exception { // Disable ACS in the config. mResources.setBoolean(R.bool.config_wifi_softap_acs_supported, false); mHostapdHal = new HostapdHalSpy(); executeAndValidateInitializationSequence(); - final int apChannel = 6; Builder configurationBuilder = new SoftApConfiguration.Builder(); configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(false); configurationBuilder.setWpa2Passphrase(NETWORK_PSK); - configurationBuilder.setChannel(apChannel); configurationBuilder.setBand(SoftApConfiguration.BAND_ANY); assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, @@ -461,9 +460,6 @@ public class HostapdHalTest extends WifiBaseTest { assertEquals(IFACE_NAME, mIfaceParamsCaptor.getValue().ifaceName); assertTrue(mIfaceParamsCaptor.getValue().hwModeParams.enable80211N); assertFalse(mIfaceParamsCaptor.getValue().hwModeParams.enable80211AC); - // Verify the band is downgraded to 2.4GHz. - assertEquals(IHostapd.Band.BAND_2_4_GHZ, - mIfaceParamsCaptor.getValue().channelParams.band); assertFalse(mIfaceParamsCaptor.getValue().channelParams.enableAcs); assertEquals(NativeUtil.stringToByteArrayList(NETWORK_SSID), @@ -481,7 +477,7 @@ public class HostapdHalTest extends WifiBaseTest { public void testAddAccessPointSuccess_Psk_BandAny_WithACS_AcsChannels() throws Exception { when(mServiceManagerMock.getTransport(anyString(), anyString())) .thenReturn(IServiceManager.Transport.HWBINDER); - mIHostapdMockV1_1 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class); + mIHostapdMockV11 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class); // Enable ACS and set available channels in the config. final String acsChannelStr = "1,6,11-13,40"; android.hardware.wifi.hostapd.V1_1.IHostapd.AcsChannelRange channelRange1 = @@ -507,7 +503,7 @@ public class HostapdHalTest extends WifiBaseTest { mResources.setString(R.string.config_wifi_softap_acs_supported_channel_list, acsChannelStr); mHostapdHal = new HostapdHalSpy(); - when(mIHostapdMockV1_1.addAccessPoint_1_1( + when(mIHostapdMockV11.addAccessPoint_1_1( mIfaceParamsCaptorV1_1.capture(), mNetworkParamsCaptor.capture())) .thenReturn(mStatusSuccess); @@ -522,7 +518,7 @@ public class HostapdHalTest extends WifiBaseTest { assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), () -> mSoftApListener.onFailure())); - verify(mIHostapdMockV1_1).addAccessPoint_1_1(any(), any()); + verify(mIHostapdMockV11).addAccessPoint_1_1(any(), any()); assertEquals(IFACE_NAME, mIfaceParamsCaptorV1_1.getValue().V1_0.ifaceName); assertTrue(mIfaceParamsCaptorV1_1.getValue().V1_0.hwModeParams.enable80211N); @@ -552,8 +548,7 @@ public class HostapdHalTest extends WifiBaseTest { Builder configurationBuilder = new SoftApConfiguration.Builder(); configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(true); - configurationBuilder.setChannel(6); - configurationBuilder.setBand(SoftApConfiguration.BAND_2GHZ); + configurationBuilder.setChannel(6, SoftApConfiguration.BAND_2GHZ); assertFalse(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), @@ -572,7 +567,7 @@ public class HostapdHalTest extends WifiBaseTest { Builder configurationBuilder = new SoftApConfiguration.Builder(); configurationBuilder.setSsid(NETWORK_SSID); configurationBuilder.setHiddenSsid(true); - configurationBuilder.setChannel(6); + configurationBuilder.setChannel(6, SoftApConfiguration.BAND_2GHZ); assertFalse(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), @@ -622,8 +617,8 @@ public class HostapdHalTest extends WifiBaseTest { public void testOnFailureCallbackHandling() throws Exception { when(mServiceManagerMock.getTransport(anyString(), anyString())) .thenReturn(IServiceManager.Transport.HWBINDER); - mIHostapdMockV1_1 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class); - when(mIHostapdMockV1_1.addAccessPoint_1_1( + mIHostapdMockV11 = mock(android.hardware.wifi.hostapd.V1_1.IHostapd.class); + when(mIHostapdMockV11.addAccessPoint_1_1( mIfaceParamsCaptorV1_1.capture(), mNetworkParamsCaptor.capture())) .thenReturn(mStatusSuccess); executeAndValidateInitializationSequenceV1_1(false); @@ -635,7 +630,7 @@ public class HostapdHalTest extends WifiBaseTest { assertTrue(mHostapdHal.addAccessPoint(IFACE_NAME, configurationBuilder.build(), () -> mSoftApListener.onFailure())); - verify(mIHostapdMockV1_1).addAccessPoint_1_1(any(), any()); + verify(mIHostapdMockV11).addAccessPoint_1_1(any(), any()); // Trigger on failure. mIHostapdCallback.onFailure(IFACE_NAME); @@ -702,7 +697,45 @@ public class HostapdHalTest extends WifiBaseTest { throws RemoteException { return mStatusFailure; } - }).when(mIHostapdMockV1_1).registerCallback(any(IHostapdCallback.class)); + }).when(mIHostapdMockV11).registerCallback(any(IHostapdCallback.class)); + } else { + doAnswer(new MockAnswerUtil.AnswerWithArguments() { + public HostapdStatus answer(IHostapdCallback cb) + throws RemoteException { + mIHostapdCallback = cb; + return mStatusSuccess; + } + }).when(mIHostapdMockV11).registerCallback(any(IHostapdCallback.class)); + } + // Initialize HostapdHal, should call serviceManager.registerForNotifications + assertTrue(mHostapdHal.initialize()); + // verify: service manager initialization sequence + mInOrder.verify(mServiceManagerMock).linkToDeath(mServiceManagerDeathCaptor.capture(), + anyLong()); + mInOrder.verify(mServiceManagerMock).registerForNotifications( + eq(IHostapd.kInterfaceName), eq(""), mServiceNotificationCaptor.capture()); + // act: cause the onRegistration(...) callback to execute + mServiceNotificationCaptor.getValue().onRegistration(IHostapd.kInterfaceName, "", true); + assertEquals(shouldSucceed, mHostapdHal.isInitializationComplete()); + mInOrder.verify(mIHostapdMock).linkToDeath(mHostapdDeathCaptor.capture(), anyLong()); + verify(mIHostapdMockV11).registerCallback(any(IHostapdCallback.class)); + } + + /** + * Calls.initialize(), mocking various callback answers and verifying flow, asserting for the + * expected result. Verifies if IHostapd manager is initialized or reset. + */ + private void executeAndValidateInitializationSequenceV1_2( + boolean causeCallbackFailure) throws Exception { + boolean shouldSucceed = !causeCallbackFailure; + mInOrder = inOrder(mServiceManagerMock, mIHostapdMock); + if (causeCallbackFailure) { + doAnswer(new MockAnswerUtil.AnswerWithArguments() { + public HostapdStatus answer(IHostapdCallback cb) + throws RemoteException { + return mStatusFailure; + } + }).when(mIHostapdMockV12).registerCallback(any(IHostapdCallback.class)); } else { doAnswer(new MockAnswerUtil.AnswerWithArguments() { public HostapdStatus answer(IHostapdCallback cb) @@ -710,7 +743,7 @@ public class HostapdHalTest extends WifiBaseTest { mIHostapdCallback = cb; return mStatusSuccess; } - }).when(mIHostapdMockV1_1).registerCallback(any(IHostapdCallback.class)); + }).when(mIHostapdMockV12).registerCallback(any(IHostapdCallback.class)); } // Initialize HostapdHal, should call serviceManager.registerForNotifications assertTrue(mHostapdHal.initialize()); @@ -723,7 +756,7 @@ public class HostapdHalTest extends WifiBaseTest { mServiceNotificationCaptor.getValue().onRegistration(IHostapd.kInterfaceName, "", true); assertEquals(shouldSucceed, mHostapdHal.isInitializationComplete()); mInOrder.verify(mIHostapdMock).linkToDeath(mHostapdDeathCaptor.capture(), anyLong()); - verify(mIHostapdMockV1_1).registerCallback(any(IHostapdCallback.class)); + verify(mIHostapdMockV12).registerCallback(any(IHostapdCallback.class)); } private HostapdStatus createHostapdStatus(int code) { diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java index 5826b7ae0..56d856081 100644 --- a/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SoftApBackupRestoreTest.java @@ -51,8 +51,7 @@ public class SoftApBackupRestoreTest extends WifiBaseTest { public void testSoftApConfigBackupAndRestoreWithWpa2Config() throws Exception { SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder(); configBuilder.setSsid("TestAP"); - configBuilder.setBand(SoftApConfiguration.BAND_5GHZ); - configBuilder.setChannel(40); + configBuilder.setChannel(40, SoftApConfiguration.BAND_5GHZ); configBuilder.setWpa2Passphrase("TestPsk"); configBuilder.setHiddenSsid(true); SoftApConfiguration config = configBuilder.build(); @@ -71,8 +70,7 @@ public class SoftApBackupRestoreTest extends WifiBaseTest { public void testSoftApConfigBackupAndRestoreWithOpenSecurityConfig() throws Exception { SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder(); configBuilder.setSsid("TestAP"); - configBuilder.setBand(SoftApConfiguration.BAND_2GHZ); - configBuilder.setChannel(12); + configBuilder.setChannel(12, SoftApConfiguration.BAND_2GHZ); configBuilder.setHiddenSsid(false); SoftApConfiguration config = configBuilder.build(); diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java index 93260ce4e..1b420fa90 100644 --- a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java @@ -536,7 +536,6 @@ public class SoftApManagerTest extends WifiBaseTest { public void startSoftApFailNoChannel() throws Exception { Builder configBuilder = new SoftApConfiguration.Builder(); configBuilder.setBand(SoftApConfiguration.BAND_5GHZ); - configBuilder.setChannel(0); configBuilder.setSsid(TEST_SSID); SoftApModeConfiguration softApConfig = new SoftApModeConfiguration( WifiManager.IFACE_IP_MODE_TETHERED, configBuilder.build()); @@ -1320,13 +1319,11 @@ public class SoftApManagerTest extends WifiBaseTest { if (config == null) { when(mWifiApConfigStore.getApConfiguration()).thenReturn(mDefaultApConfig); expectedConfig = new SoftApConfiguration.Builder(mDefaultApConfig) - .setBand(SoftApConfiguration.BAND_2GHZ) - .setChannel(DEFAULT_AP_CHANNEL) + .setChannel(DEFAULT_AP_CHANNEL, SoftApConfiguration.BAND_2GHZ) .build(); } else { expectedConfig = new SoftApConfiguration.Builder(config) - .setBand(SoftApConfiguration.BAND_2GHZ) - .setChannel(DEFAULT_AP_CHANNEL) + .setChannel(DEFAULT_AP_CHANNEL, SoftApConfiguration.BAND_2GHZ) .build(); } diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java index d368e9510..ee6821528 100644 --- a/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java +++ b/tests/wifitests/src/com/android/server/wifi/SoftApStoreDataTest.java @@ -139,7 +139,6 @@ public class SoftApStoreDataTest extends WifiBaseTest { softApConfigBuilder.setSsid(TEST_SSID); softApConfigBuilder.setWpa2Passphrase(TEST_WPA2_PASSPHRASE); softApConfigBuilder.setBand(TEST_BAND); - softApConfigBuilder.setChannel(TEST_CHANNEL); when(mDataSource.toSerialize()).thenReturn(softApConfigBuilder.build()); byte[] actualData = serializeData(); @@ -179,8 +178,6 @@ public class SoftApStoreDataTest extends WifiBaseTest { softApConfigBuilder.setSsid(TEST_SSID); softApConfigBuilder.setWpa2Passphrase(TEST_WPA2_PASSPHRASE); softApConfigBuilder.setBand(TEST_BAND); - softApConfigBuilder.setChannel(TEST_CHANNEL); - SoftApConfiguration softApConfig = softApConfigBuilder.build(); // Serialize first. diff --git a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java index d0670181d..b476589cc 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java @@ -161,8 +161,11 @@ public class WifiApConfigStoreTest extends WifiBaseTest { Builder configBuilder = new SoftApConfiguration.Builder(); configBuilder.setSsid(ssid); configBuilder.setWpa2Passphrase(preSharedKey); - configBuilder.setBand(band); - configBuilder.setChannel(channel); + if (channel == 0) { + configBuilder.setBand(band); + } else { + configBuilder.setChannel(channel, band); + } configBuilder.setHiddenSsid(hiddenSSID); return configBuilder.build(); } @@ -240,7 +243,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "ConfiguredAP", /* SSID */ "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ - 1, /* AP band (5GHz) */ + SoftApConfiguration.BAND_5GHZ, /* AP band (5GHz) */ 40, /* AP channel */ true /* Hidden SSID */); /* Create a temporary file for AP config file storage. */ @@ -276,7 +279,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "ConfiguredAP", /* SSID */ "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ - 1, /* AP band (5GHz) */ + SoftApConfiguration.BAND_5GHZ, /* AP band (5GHz) */ 40, /* AP channel */ true /* Hidden SSID */); WifiApConfigStore store = createWifiApConfigStore(); @@ -307,7 +310,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ SoftApConfiguration.BAND_2GHZ, /* AP band */ - 40, /* AP channel */ + 0, /* AP channel */ true /* Hidden SSID */); store.setApConfiguration(expectedConfig); verifyApConfig(expectedConfig, store.getApConfiguration()); @@ -334,7 +337,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ SoftApConfiguration.BAND_ANY, /* AP band (ANY) */ - 40, /* AP channel */ + 0, /* AP channel */ false /* Hidden SSID */); SoftApConfiguration expectedConfig = setupApConfig( @@ -342,7 +345,42 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ SoftApConfiguration.BAND_5GHZ, /* AP band (5GHz) */ - WifiApConfigStore.AP_CHANNEL_DEFAULT, /* AP channel */ + 0, /* AP channel */ + false /* Hidden SSID */); + store.setApConfiguration(providedConfig); + verifyApConfig(expectedConfig, store.getApConfiguration()); + verifyApConfig(expectedConfig, mDataStoreSource.toSerialize()); + verify(mWifiConfigManager, times(2)).saveToStore(true); + verify(mBackupManagerProxy, times(2)).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 + * is a multiband not including 5GHz converted into 2GHz. + */ + @Test + public void convertSingleModeDeviceMultibandTo2Ghz() throws Exception { + /* Initialize WifiApConfigStore with default configuration. */ + WifiApConfigStore store = createWifiApConfigStore(); + verifyDefaultApConfig(store.getApConfiguration(), TEST_DEFAULT_AP_SSID); + verify(mWifiConfigManager).saveToStore(true); + + /* Update with a valid configuration. */ + SoftApConfiguration providedConfig = setupApConfig( + "ConfiguredAP", /* SSID */ + "randomKey", /* preshared key */ + SECURITY_TYPE_WPA2_PSK, /* security type */ + SoftApConfiguration.BAND_2GHZ | SoftApConfiguration.BAND_6GHZ, /* AP band */ + 0, /* AP channel */ + false /* Hidden SSID */); + + SoftApConfiguration expectedConfig = setupApConfig( + "ConfiguredAP", /* SSID */ + "randomKey", /* preshared key */ + SECURITY_TYPE_WPA2_PSK, /* security type */ + SoftApConfiguration.BAND_2GHZ, /* AP band (5GHz) */ + 0, /* AP channel */ false /* Hidden SSID */); store.setApConfiguration(providedConfig); verifyApConfig(expectedConfig, store.getApConfiguration()); @@ -381,7 +419,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { /** * 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. + * 5GHz converted to include 2.4GHz. */ @Test public void convertDualModeDevice5GhzToAny() throws Exception { @@ -405,8 +443,9 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "ConfiguredAP", /* SSID */ "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ - SoftApConfiguration.BAND_ANY, /* AP band */ - WifiApConfigStore.AP_CHANNEL_DEFAULT, /* AP channel */ + SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_5GHZ, /* AP band */ + 0, /* AP channel */ false /* Hidden SSID */); store.setApConfiguration(providedConfig); verifyApConfig(expectedConfig, store.getApConfiguration()); @@ -435,7 +474,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ SoftApConfiguration.BAND_ANY, /* AP band */ - 40, /* AP channel */ + 0, /* AP channel */ false /* Hidden SSID */); store.setApConfiguration(expectedConfig); verifyApConfig(expectedConfig, store.getApConfiguration()); @@ -457,14 +496,14 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ SoftApConfiguration.BAND_ANY, /* AP band */ - 40, /* AP channel */ + 0, /* AP channel */ false /* Hidden SSID */); SoftApConfiguration expectedConfig = setupApConfig( "ConfiguredAP", /* SSID */ "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ SoftApConfiguration.BAND_5GHZ, /* AP band */ - WifiApConfigStore.AP_CHANNEL_DEFAULT, /* AP channel */ + 0, /* AP channel */ false /* Hidden SSID */); WifiApConfigStore store = createWifiApConfigStore(); mDataStoreSource.fromDeserialized(persistedConfig); @@ -499,7 +538,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { /** * 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. + * config with 5GHz only set for the apBand to include 2.4GHz. */ @Test public void dualModeDevice5GhzConvertedToAnyAtRetrieval() throws Exception { @@ -516,8 +555,9 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "ConfiguredAP", /* SSID */ "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ - SoftApConfiguration.BAND_ANY, /* AP band */ - WifiApConfigStore.AP_CHANNEL_DEFAULT, /* AP channel */ + SoftApConfiguration.BAND_5GHZ + | SoftApConfiguration.BAND_2GHZ, /* AP band */ + 0, /* AP channel */ false /* Hidden SSID */); WifiApConfigStore store = createWifiApConfigStore(); @@ -542,7 +582,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest { "randomKey", /* preshared key */ SECURITY_TYPE_WPA2_PSK, /* security type */ SoftApConfiguration.BAND_ANY, /* AP band */ - 40, /* AP channel */ + 0, /* AP channel */ false /* Hidden SSID */); WifiApConfigStore store = createWifiApConfigStore(); diff --git a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java index f3cf19fd6..4381a4a73 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiServiceImplTest.java @@ -1289,6 +1289,112 @@ public class WifiServiceImplTest extends WifiBaseTest { } /** + * Verify attempt to start softAp with a supported 5GHz band succeeds. + */ + @Test + public void testStartTetheredHotspotWithSupported5gBand() { + when(mResources.getBoolean( + eq(R.bool.config_wifi5ghzSupport))) + .thenReturn(true); + SoftApConfiguration config = new SoftApConfiguration.Builder() + .setSsid("TestAp") + .setWpa2Passphrase("thisIsABadPassword") + .setBand(SoftApConfiguration.BAND_5GHZ) + .build(); + + boolean result = mWifiServiceImpl.startTetheredHotspot(config); + assertTrue(result); + verify(mActiveModeWarden).startSoftAp(mSoftApModeConfigCaptor.capture()); + assertThat(config).isEqualTo(mSoftApModeConfigCaptor.getValue().getSoftApConfiguration()); + } + + /** + * Verify attempt to start softAp with a non-supported 5GHz band fails. + */ + @Test + public void testStartTetheredHotspotWithUnSupported5gBand() { + when(mResources.getBoolean( + eq(R.bool.config_wifi5ghzSupport))) + .thenReturn(false); + SoftApConfiguration config = new SoftApConfiguration.Builder() + .setSsid("TestAp") + .setWpa2Passphrase("thisIsABadPassword") + .setBand(SoftApConfiguration.BAND_5GHZ) + .build(); + + boolean result = mWifiServiceImpl.startTetheredHotspot(config); + assertFalse(result); + verifyZeroInteractions(mActiveModeWarden); + } + + /** + * Verify attempt to start softAp with a supported 6GHz band succeeds. + */ + @Test + public void testStartTetheredHotspotWithSupported6gBand() { + when(mResources.getBoolean( + eq(R.bool.config_wifi6ghzSupport))) + .thenReturn(true); + when(mResources.getBoolean( + eq(R.bool.config_wifiSoftap6ghzSupported))) + .thenReturn(true); + + SoftApConfiguration config = new SoftApConfiguration.Builder() + .setSsid("TestAp") + .setWpa2Passphrase("thisIsABadPassword") + .setBand(SoftApConfiguration.BAND_6GHZ) + .build(); + + boolean result = mWifiServiceImpl.startTetheredHotspot(config); + assertTrue(result); + verify(mActiveModeWarden).startSoftAp(mSoftApModeConfigCaptor.capture()); + assertThat(config).isEqualTo(mSoftApModeConfigCaptor.getValue().getSoftApConfiguration()); + } + + /** + * Verify attempt to start softAp with a non-supported 6GHz band fails. + */ + @Test + public void testStartTetheredHotspotWithUnSupported6gBand() { + when(mResources.getBoolean( + eq(R.bool.config_wifi6ghzSupport))) + .thenReturn(true); + when(mResources.getBoolean( + eq(R.bool.config_wifiSoftap6ghzSupported))) + .thenReturn(false); + + SoftApConfiguration config = new SoftApConfiguration.Builder() + .setSsid("TestAp") + .setWpa2Passphrase("thisIsABadPassword") + .setBand(SoftApConfiguration.BAND_6GHZ) + .build(); + + boolean result = mWifiServiceImpl.startTetheredHotspot(config); + assertFalse(result); + verifyZeroInteractions(mActiveModeWarden); + } + + /** + * Verify attempt to start softAp with a supported band succeeds. + */ + @Test + public void testStartTetheredHotspotWithSupportedBand() { + when(mResources.getBoolean( + eq(R.bool.config_wifi5ghzSupport))) + .thenReturn(true); + SoftApConfiguration config = new SoftApConfiguration.Builder() + .setSsid("TestAp") + .setWpa2Passphrase("thisIsABadPassword") + .setBand(SoftApConfiguration.BAND_5GHZ) + .build(); + + boolean result = mWifiServiceImpl.startTetheredHotspot(config); + assertTrue(result); + verify(mActiveModeWarden).startSoftAp(mSoftApModeConfigCaptor.capture()); + assertThat(config).isEqualTo(mSoftApModeConfigCaptor.getValue().getSoftApConfiguration()); + } + + /** * Verify a SecurityException is thrown when a caller without the correct permission attempts to * start softap. */ diff --git a/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java b/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java index db48f833d..6da587d5e 100644 --- a/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java +++ b/tests/wifitests/src/com/android/server/wifi/util/ApConfigUtilTest.java @@ -17,11 +17,14 @@ package com.android.server.wifi.util; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; import android.net.wifi.SoftApConfiguration; import android.net.wifi.SoftApConfiguration.Builder; +import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiScanner; import androidx.test.filters.SmallTest; @@ -51,61 +54,68 @@ public class ApConfigUtilTest extends WifiBaseTest { * even indices are frequencies and odd indices are channels. */ private static final int[] FREQUENCY_TO_CHANNEL_MAP = { - 2412, 1, - 2417, 2, - 2422, 3, - 2427, 4, - 2432, 5, - 2437, 6, - 2442, 7, - 2447, 8, - 2452, 9, - 2457, 10, - 2462, 11, + 2412, SoftApConfiguration.BAND_2GHZ, 1, + 2417, SoftApConfiguration.BAND_2GHZ, 2, + 2422, SoftApConfiguration.BAND_2GHZ, 3, + 2427, SoftApConfiguration.BAND_2GHZ, 4, + 2432, SoftApConfiguration.BAND_2GHZ, 5, + 2437, SoftApConfiguration.BAND_2GHZ, 6, + 2442, SoftApConfiguration.BAND_2GHZ, 7, + 2447, SoftApConfiguration.BAND_2GHZ, 8, + 2452, SoftApConfiguration.BAND_2GHZ, 9, + 2457, SoftApConfiguration.BAND_2GHZ, 10, + 2462, SoftApConfiguration.BAND_2GHZ, 11, /* 12, 13 are only legitimate outside the US. */ - 2467, 12, - 2472, 13, + 2467, SoftApConfiguration.BAND_2GHZ, 12, + 2472, SoftApConfiguration.BAND_2GHZ, 13, /* 14 is for Japan, DSSS and CCK only. */ - 2484, 14, + 2484, SoftApConfiguration.BAND_2GHZ, 14, /* 34 valid in Japan. */ - 5170, 34, - 5180, 36, - 5190, 38, - 5200, 40, - 5210, 42, - 5220, 44, - 5230, 46, - 5240, 48, - 5260, 52, - 5280, 56, - 5300, 60, - 5320, 64, - 5500, 100, - 5520, 104, - 5540, 108, - 5560, 112, - 5580, 116, + 5170, SoftApConfiguration.BAND_5GHZ, 34, + 5180, SoftApConfiguration.BAND_5GHZ, 36, + 5190, SoftApConfiguration.BAND_5GHZ, 38, + 5200, SoftApConfiguration.BAND_5GHZ, 40, + 5210, SoftApConfiguration.BAND_5GHZ, 42, + 5220, SoftApConfiguration.BAND_5GHZ, 44, + 5230, SoftApConfiguration.BAND_5GHZ, 46, + 5240, SoftApConfiguration.BAND_5GHZ, 48, + 5260, SoftApConfiguration.BAND_5GHZ, 52, + 5280, SoftApConfiguration.BAND_5GHZ, 56, + 5300, SoftApConfiguration.BAND_5GHZ, 60, + 5320, SoftApConfiguration.BAND_5GHZ, 64, + 5500, SoftApConfiguration.BAND_5GHZ, 100, + 5520, SoftApConfiguration.BAND_5GHZ, 104, + 5540, SoftApConfiguration.BAND_5GHZ, 108, + 5560, SoftApConfiguration.BAND_5GHZ, 112, + 5580, SoftApConfiguration.BAND_5GHZ, 116, /* 120, 124, 128 valid in Europe/Japan. */ - 5600, 120, - 5620, 124, - 5640, 128, + 5600, SoftApConfiguration.BAND_5GHZ, 120, + 5620, SoftApConfiguration.BAND_5GHZ, 124, + 5640, SoftApConfiguration.BAND_5GHZ, 128, /* 132+ valid in US. */ - 5660, 132, - 5680, 136, - 5700, 140, + 5660, SoftApConfiguration.BAND_5GHZ, 132, + 5680, SoftApConfiguration.BAND_5GHZ, 136, + 5700, SoftApConfiguration.BAND_5GHZ, 140, /* 144 is supported by a subset of WiFi chips. */ - 5720, 144, - 5745, 149, - 5765, 153, - 5785, 157, - 5805, 161, - 5825, 165, - 5845, 169, - 5865, 173 + 5720, SoftApConfiguration.BAND_5GHZ, 144, + 5745, SoftApConfiguration.BAND_5GHZ, 149, + 5765, SoftApConfiguration.BAND_5GHZ, 153, + 5785, SoftApConfiguration.BAND_5GHZ, 157, + 5805, SoftApConfiguration.BAND_5GHZ, 161, + 5825, SoftApConfiguration.BAND_5GHZ, 165, + 5845, SoftApConfiguration.BAND_5GHZ, 169, + 5865, SoftApConfiguration.BAND_5GHZ, 173, + /* Now some 6GHz channels */ + 5945, SoftApConfiguration.BAND_6GHZ, 1, + 5960, SoftApConfiguration.BAND_6GHZ, 4, + 6100, SoftApConfiguration.BAND_6GHZ, 32 }; + + private static final Integer[] ALLOWED_2G_CHANNELS = {1, 2, 3, 4}; private static final int[] ALLOWED_5G_FREQS = {5180, 5190, 5200}; + private static final int[] ALLOWED_6G_FREQS = {5945, 5965}; private static final int[] ALLOWED_5G_CHANNELS = {36, 38, 40}; @Mock WifiNative mWifiNative; @@ -121,14 +131,100 @@ public class ApConfigUtilTest extends WifiBaseTest { } /** - * Verify frequency to channel conversion for all possible frequencies. + * verify convert WifiConfiguration Band to SoftApConfigurationBand. + */ + @Test + public void convertWifiConfigBandToSoftapConfigBandTest() throws Exception { + assertEquals(SoftApConfiguration.BAND_2GHZ, ApConfigUtil + .convertWifiConfigBandToSoftApConfigBand(WifiConfiguration.AP_BAND_2GHZ)); + assertEquals(SoftApConfiguration.BAND_5GHZ, ApConfigUtil + .convertWifiConfigBandToSoftApConfigBand(WifiConfiguration.AP_BAND_5GHZ)); + assertEquals(SoftApConfiguration.BAND_2GHZ | SoftApConfiguration.BAND_5GHZ, ApConfigUtil + .convertWifiConfigBandToSoftApConfigBand(WifiConfiguration.AP_BAND_ANY)); + } + + + + /** + * Verify isMultiband success + */ + @Test + public void isMultibandSuccess() throws Exception { + assertTrue(ApConfigUtil.isMultiband(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_6GHZ)); + assertTrue(ApConfigUtil.isMultiband(SoftApConfiguration.BAND_5GHZ + | SoftApConfiguration.BAND_6GHZ)); + assertTrue(ApConfigUtil.isMultiband(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_6GHZ)); + assertTrue(ApConfigUtil.isMultiband(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_5GHZ | SoftApConfiguration.BAND_6GHZ)); + } + + /** + * Verify isMultiband failure + */ + @Test + public void isMultibandFailure() throws Exception { + assertFalse(ApConfigUtil.isMultiband(SoftApConfiguration.BAND_2GHZ)); + assertFalse(ApConfigUtil.isMultiband(SoftApConfiguration.BAND_5GHZ)); + assertFalse(ApConfigUtil.isMultiband(SoftApConfiguration.BAND_6GHZ)); + } + + /** + * Verify containsBand success + */ + @Test + public void containsBandSuccess() throws Exception { + assertTrue(ApConfigUtil.containsBand(SoftApConfiguration.BAND_2GHZ, + SoftApConfiguration.BAND_2GHZ)); + assertTrue(ApConfigUtil.containsBand(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_6GHZ, SoftApConfiguration.BAND_2GHZ)); + assertTrue(ApConfigUtil.containsBand(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_5GHZ | SoftApConfiguration.BAND_6GHZ, + SoftApConfiguration.BAND_6GHZ)); + } + + /** + * Verify containsBand failure + */ + @Test + public void containsBandFailure() throws Exception { + assertFalse(ApConfigUtil.containsBand(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_5GHZ, SoftApConfiguration.BAND_6GHZ)); + assertFalse(ApConfigUtil.containsBand(SoftApConfiguration.BAND_5GHZ, + SoftApConfiguration.BAND_6GHZ)); + } + + /** + * Verify isBandValidSuccess + */ + @Test + public void isBandValidSuccess() throws Exception { + assertTrue(ApConfigUtil.isBandValid(SoftApConfiguration.BAND_2GHZ)); + assertTrue(ApConfigUtil.isBandValid(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_6GHZ)); + assertTrue(ApConfigUtil.isBandValid(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_5GHZ | SoftApConfiguration.BAND_6GHZ)); + } + + /** + * Verify isBandValidFailure + */ + @Test + public void isBandValidFailure() throws Exception { + assertFalse(ApConfigUtil.isBandValid(0)); + assertFalse(ApConfigUtil.isBandValid(SoftApConfiguration.BAND_2GHZ + | SoftApConfiguration.BAND_6GHZ | 0x0F)); + } + + /** + * verify frequency to channel conversion for all possible frequencies. */ @Test public void convertFrequencyToChannel() throws Exception { - for (int i = 0; i < FREQUENCY_TO_CHANNEL_MAP.length; i += 2) { - assertEquals(FREQUENCY_TO_CHANNEL_MAP[i + 1], - ApConfigUtil.convertFrequencyToChannel( - FREQUENCY_TO_CHANNEL_MAP[i])); + for (int i = 0; i < FREQUENCY_TO_CHANNEL_MAP.length; i += 3) { + assertEquals(FREQUENCY_TO_CHANNEL_MAP[i + 2], + ApConfigUtil.convertFrequencyToChannel(FREQUENCY_TO_CHANNEL_MAP[i])); } } @@ -137,7 +233,31 @@ public class ApConfigUtilTest extends WifiBaseTest { */ @Test public void convertFrequencyToChannelWithInvalidFreq() throws Exception { - assertEquals(-1, ApConfigUtil.convertFrequencyToChannel(6200)); + assertEquals(-1, ApConfigUtil.convertFrequencyToChannel(8000)); + } + + /** + * verify frequency to band conversion for all possible frequencies. + */ + @Test + public void convertFrequencytoBand() throws Exception { + for (int i = 0; i < FREQUENCY_TO_CHANNEL_MAP.length; i += 3) { + assertEquals(FREQUENCY_TO_CHANNEL_MAP[i + 1], + ApConfigUtil.convertFrequencyToBand( + FREQUENCY_TO_CHANNEL_MAP[i])); + } + } + + /** + * verify channel/band to frequency conversion for all possible channels. + */ + @Test + public void convertChannelToFrequency() throws Exception { + for (int i = 0; i < FREQUENCY_TO_CHANNEL_MAP.length; i += 3) { + assertEquals(FREQUENCY_TO_CHANNEL_MAP[i], + ApConfigUtil.convertChannelToFrequency( + FREQUENCY_TO_CHANNEL_MAP[i + 2], FREQUENCY_TO_CHANNEL_MAP[i + 1])); + } } /** @@ -146,8 +266,9 @@ public class ApConfigUtilTest extends WifiBaseTest { */ @Test public void chooseApChannel2GBandWithNoAllowedChannel() throws Exception { - assertEquals(ApConfigUtil.DEFAULT_AP_CHANNEL, ApConfigUtil.chooseApChannel( - SoftApConfiguration.BAND_2GHZ, null, ALLOWED_5G_FREQS)); + int freq = ApConfigUtil.chooseApChannel(SoftApConfiguration.BAND_2GHZ, + null, ALLOWED_5G_FREQS, ALLOWED_6G_FREQS); + assertEquals(ApConfigUtil.DEFAULT_AP_CHANNEL, ApConfigUtil.convertFrequencyToChannel(freq)); } /** @@ -155,9 +276,10 @@ public class ApConfigUtilTest extends WifiBaseTest { */ @Test public void chooseApChannel2GBandWithAllowedChannels() throws Exception { - int channel = ApConfigUtil.chooseApChannel( - SoftApConfiguration.BAND_2GHZ, mAllowed2GChannels, ALLOWED_5G_FREQS); - assertTrue(mAllowed2GChannels.contains(channel)); + int freq = ApConfigUtil.chooseApChannel( + SoftApConfiguration.BAND_2GHZ, mAllowed2GChannels, ALLOWED_5G_FREQS, + ALLOWED_6G_FREQS); + assertTrue(mAllowed2GChannels.contains(ApConfigUtil.convertFrequencyToChannel(freq))); } /** @@ -165,9 +287,11 @@ public class ApConfigUtilTest extends WifiBaseTest { */ @Test public void chooseApChannel5GBandWithAllowedChannels() throws Exception { - int channel = ApConfigUtil.chooseApChannel( - SoftApConfiguration.BAND_5GHZ, mAllowed2GChannels, ALLOWED_5G_FREQS); - assertTrue(ArrayUtils.contains(ALLOWED_5G_CHANNELS, channel)); + int freq = ApConfigUtil.chooseApChannel( + SoftApConfiguration.BAND_5GHZ, mAllowed2GChannels, ALLOWED_5G_FREQS, + ALLOWED_6G_FREQS); + assertTrue(ArrayUtils.contains(ALLOWED_5G_CHANNELS, + ApConfigUtil.convertFrequencyToChannel(freq))); } /** @@ -177,7 +301,7 @@ public class ApConfigUtilTest extends WifiBaseTest { @Test public void chooseApChannel5GBandWithNoAllowedChannels() throws Exception { assertEquals(-1, ApConfigUtil.chooseApChannel( - SoftApConfiguration.BAND_5GHZ, mAllowed2GChannels, null)); + SoftApConfiguration.BAND_5GHZ, mAllowed2GChannels, null, null)); } /** @@ -187,13 +311,12 @@ public class ApConfigUtilTest extends WifiBaseTest { @Test public void updateApChannelConfigWithoutHal() throws Exception { Builder configBuilder = new SoftApConfiguration.Builder(); - configBuilder.setChannel(36); - configBuilder.setBand(SoftApConfiguration.BAND_5GHZ); + configBuilder.setChannel(36, SoftApConfiguration.BAND_5GHZ); when(mWifiNative.isHalStarted()).thenReturn(false); assertEquals(ApConfigUtil.SUCCESS, ApConfigUtil.updateApChannelConfig(mWifiNative, TEST_COUNTRY_CODE, - mAllowed2GChannels, configBuilder, configBuilder.build())); + mAllowed2GChannels, configBuilder, configBuilder.build(), false)); /* Verify default band and channel is used. */ assertEquals(ApConfigUtil.DEFAULT_AP_BAND, configBuilder.build().getBand()); assertEquals(ApConfigUtil.DEFAULT_AP_CHANNEL, configBuilder.build().getChannel()); @@ -210,7 +333,7 @@ public class ApConfigUtilTest extends WifiBaseTest { when(mWifiNative.isHalStarted()).thenReturn(true); assertEquals(ApConfigUtil.ERROR_GENERIC, ApConfigUtil.updateApChannelConfig(mWifiNative, null, mAllowed2GChannels, - configBuilder, configBuilder.build())); + configBuilder, configBuilder.build(), false)); } /** @@ -219,12 +342,11 @@ public class ApConfigUtilTest extends WifiBaseTest { @Test public void updateApChannelConfigWithChannelSpecified() throws Exception { Builder configBuilder = new SoftApConfiguration.Builder(); - configBuilder.setBand(SoftApConfiguration.BAND_5GHZ); - configBuilder.setChannel(36); + configBuilder.setChannel(36, SoftApConfiguration.BAND_5GHZ); when(mWifiNative.isHalStarted()).thenReturn(true); assertEquals(ApConfigUtil.SUCCESS, ApConfigUtil.updateApChannelConfig(mWifiNative, TEST_COUNTRY_CODE, - mAllowed2GChannels, configBuilder, configBuilder.build())); + mAllowed2GChannels, configBuilder, configBuilder.build(), false)); assertEquals(SoftApConfiguration.BAND_5GHZ, configBuilder.build().getBand()); assertEquals(36, configBuilder.build().getChannel()); } @@ -242,6 +364,39 @@ public class ApConfigUtilTest extends WifiBaseTest { .thenReturn(null); assertEquals(ApConfigUtil.ERROR_NO_CHANNEL, ApConfigUtil.updateApChannelConfig(mWifiNative, TEST_COUNTRY_CODE, - mAllowed2GChannels, configBuilder, configBuilder.build())); + mAllowed2GChannels, configBuilder, configBuilder.build(), false)); + } + + /** + * Verify updateApChannelConfig will select a channel number and band when acs is + * disabled. + */ + @Test + public void updateApChannelConfigWithAcsDisabled() throws Exception { + Builder configBuilder = new SoftApConfiguration.Builder(); + configBuilder.setBand(SoftApConfiguration.BAND_5GHZ | SoftApConfiguration.BAND_2GHZ); + when(mWifiNative.isHalStarted()).thenReturn(true); + assertEquals(ApConfigUtil.SUCCESS, + ApConfigUtil.updateApChannelConfig(mWifiNative, TEST_COUNTRY_CODE, + mAllowed2GChannels, configBuilder, configBuilder.build(), false)); + assertFalse(ApConfigUtil.isMultiband(configBuilder.build().getBand())); + assertNotEquals(0, configBuilder.build().getChannel()); + } + + /** + * Verify updateApChannelConfig will not select a channel number and band when acs is + * enabled. + */ + @Test + public void updateApChannelConfigWithAcsEnabled() throws Exception { + Builder configBuilder = new SoftApConfiguration.Builder(); + configBuilder.setBand(SoftApConfiguration.BAND_5GHZ | SoftApConfiguration.BAND_2GHZ); + when(mWifiNative.isHalStarted()).thenReturn(true); + assertEquals(ApConfigUtil.SUCCESS, + ApConfigUtil.updateApChannelConfig(mWifiNative, TEST_COUNTRY_CODE, + mAllowed2GChannels, configBuilder, configBuilder.build(), true)); + assertEquals(SoftApConfiguration.BAND_5GHZ | SoftApConfiguration.BAND_2GHZ, + configBuilder.build().getBand()); + assertEquals(0, configBuilder.build().getChannel()); } } |