summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorRoshan Pius <rpius@google.com>2018-07-20 21:41:47 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-07-20 21:41:47 +0000
commit5f8a8498536179c6d7060f712c73f5346036936f (patch)
treea9a82c7ea6c200f0f1be0d56abf8639598f79fa9 /tests
parent31b106d6610b9a61787a71dc51dba24b5f33e278 (diff)
parent3c57f9c394c6158b3407fd5c5b67857874433168 (diff)
Merge "SoftApManager: Set country code before channel selection"
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java148
1 files changed, 136 insertions, 12 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
index 6a2c21242..21c3797b3 100644
--- a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
@@ -114,6 +114,9 @@ public class SoftApManagerTest {
when(mContext.getResources()).thenReturn(mResources);
when(mResources.getInteger(R.integer.config_wifi_framework_soft_ap_timeout_delay))
.thenReturn(600000);
+ when(mWifiNative.setCountryCodeHal(
+ TEST_INTERFACE_NAME, TEST_COUNTRY_CODE.toUpperCase(Locale.ROOT)))
+ .thenReturn(true);
}
private WifiConfiguration createDefaultApConfig() {
@@ -122,7 +125,7 @@ public class SoftApManagerTest {
return defaultConfig;
}
- private SoftApManager createSoftApManager(SoftApModeConfiguration config) throws Exception {
+ private SoftApManager createSoftApManager(SoftApModeConfiguration config, String countryCode) {
if (config.getWifiConfiguration() == null) {
when(mWifiApConfigStore.getApConfiguration()).thenReturn(mDefaultApConfig);
}
@@ -130,7 +133,7 @@ public class SoftApManagerTest {
mLooper.getLooper(),
mFrameworkFacade,
mWifiNative,
- TEST_COUNTRY_CODE,
+ countryCode,
mCallback,
mWifiApConfigStore,
config,
@@ -312,11 +315,54 @@ public class SoftApManagerTest {
}
/**
+ * Tests that the generic error is propagated and properly reported when starting softap and no
+ * country code is provided.
+ */
+ @Test
+ public void startSoftApOn5GhzFailGeneralErrorForNoCountryCode() throws Exception {
+ WifiConfiguration config = new WifiConfiguration();
+ config.apBand = WifiConfiguration.AP_BAND_5GHZ;
+ config.SSID = TEST_SSID;
+ SoftApModeConfiguration softApConfig =
+ new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+
+ when(mWifiNative.setupInterfaceForSoftApMode(any())).thenReturn(TEST_INTERFACE_NAME);
+
+ SoftApManager newSoftApManager = new SoftApManager(mContext,
+ mLooper.getLooper(),
+ mFrameworkFacade,
+ mWifiNative,
+ null,
+ mCallback,
+ mWifiApConfigStore,
+ softApConfig,
+ mWifiMetrics,
+ mSarManager);
+ mLooper.dispatchAll();
+ newSoftApManager.start();
+ mLooper.dispatchAll();
+
+ verify(mWifiNative, never()).setCountryCodeHal(eq(TEST_INTERFACE_NAME), any());
+
+ ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
+ verify(mContext, times(2)).sendStickyBroadcastAsUser(intentCaptor.capture(),
+ eq(UserHandle.ALL));
+
+ List<Intent> capturedIntents = intentCaptor.getAllValues();
+ checkApStateChangedBroadcast(capturedIntents.get(0), WIFI_AP_STATE_ENABLING,
+ WIFI_AP_STATE_DISABLED, HOTSPOT_NO_ERROR, TEST_INTERFACE_NAME,
+ softApConfig.getTargetMode());
+ checkApStateChangedBroadcast(capturedIntents.get(1), WIFI_AP_STATE_FAILED,
+ WIFI_AP_STATE_ENABLING, WifiManager.SAP_START_FAILURE_GENERAL, TEST_INTERFACE_NAME,
+ softApConfig.getTargetMode());
+ }
+
+ /**
* Tests that the generic error is propagated and properly reported when starting softap and the
- * specified channel cannot be used.
+ * country code cannot be set.
*/
@Test
- public void startSoftApFailGeneralErrorForConfigChannel() throws Exception {
+ public void startSoftApOn5GhzFailGeneralErrorForCountryCodeSetFailure() throws Exception {
WifiConfiguration config = new WifiConfiguration();
config.apBand = WifiConfiguration.AP_BAND_5GHZ;
config.SSID = TEST_SSID;
@@ -324,13 +370,15 @@ public class SoftApManagerTest {
new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
when(mWifiNative.setupInterfaceForSoftApMode(any())).thenReturn(TEST_INTERFACE_NAME);
- when(mWifiNative.setCountryCodeHal(eq(TEST_INTERFACE_NAME), any())).thenReturn(false);
+ when(mWifiNative.setCountryCodeHal(
+ TEST_INTERFACE_NAME, TEST_COUNTRY_CODE.toUpperCase(Locale.ROOT)))
+ .thenReturn(false);
SoftApManager newSoftApManager = new SoftApManager(mContext,
mLooper.getLooper(),
mFrameworkFacade,
mWifiNative,
- "US",
+ TEST_COUNTRY_CODE,
mCallback,
mWifiApConfigStore,
softApConfig,
@@ -340,6 +388,9 @@ public class SoftApManagerTest {
newSoftApManager.start();
mLooper.dispatchAll();
+ verify(mWifiNative).setCountryCodeHal(
+ TEST_INTERFACE_NAME, TEST_COUNTRY_CODE.toUpperCase(Locale.ROOT));
+
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
verify(mContext, times(2)).sendStickyBroadcastAsUser(intentCaptor.capture(),
eq(UserHandle.ALL));
@@ -354,6 +405,76 @@ public class SoftApManagerTest {
}
/**
+ * Tests that there is no failure in starting softap in 2Ghz band when no country code is
+ * provided.
+ */
+ @Test
+ public void startSoftApOn24GhzNoFailForNoCountryCode() throws Exception {
+ WifiConfiguration config = new WifiConfiguration();
+ config.apBand = WifiConfiguration.AP_BAND_2GHZ;
+ config.SSID = TEST_SSID;
+ SoftApModeConfiguration softApConfig =
+ new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+
+ startSoftApAndVerifyEnabled(softApConfig, null);
+ verify(mWifiNative, never()).setCountryCodeHal(eq(TEST_INTERFACE_NAME), any());
+ }
+
+ /**
+ * Tests that there is no failure in starting softap in ANY band when no country code is
+ * provided.
+ */
+ @Test
+ public void startSoftApOnAnyGhzNoFailForNoCountryCode() throws Exception {
+ WifiConfiguration config = new WifiConfiguration();
+ config.apBand = WifiConfiguration.AP_BAND_ANY;
+ config.SSID = TEST_SSID;
+ SoftApModeConfiguration softApConfig =
+ new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+
+ startSoftApAndVerifyEnabled(softApConfig, null);
+ verify(mWifiNative, never()).setCountryCodeHal(eq(TEST_INTERFACE_NAME), any());
+ }
+
+ /**
+ * Tests that there is no failure in starting softap in 2Ghz band when country code cannot be
+ * set.
+ */
+ @Test
+ public void startSoftApOn2GhzNoFailForCountryCodeSetFailure() throws Exception {
+ WifiConfiguration config = new WifiConfiguration();
+ config.apBand = WifiConfiguration.AP_BAND_2GHZ;
+ config.SSID = TEST_SSID;
+ SoftApModeConfiguration softApConfig =
+ new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+
+ when(mWifiNative.setCountryCodeHal(eq(TEST_INTERFACE_NAME), any())).thenReturn(false);
+
+ startSoftApAndVerifyEnabled(softApConfig, TEST_COUNTRY_CODE);
+ verify(mWifiNative).setCountryCodeHal(
+ TEST_INTERFACE_NAME, TEST_COUNTRY_CODE.toUpperCase(Locale.ROOT));
+ }
+
+ /**
+ * Tests that there is no failure in starting softap in ANY band when country code cannot be
+ * set.
+ */
+ @Test
+ public void startSoftApOnAnyNoFailForCountryCodeSetFailure() throws Exception {
+ WifiConfiguration config = new WifiConfiguration();
+ config.apBand = WifiConfiguration.AP_BAND_ANY;
+ config.SSID = TEST_SSID;
+ SoftApModeConfiguration softApConfig =
+ new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, config);
+
+ when(mWifiNative.setCountryCodeHal(eq(TEST_INTERFACE_NAME), any())).thenReturn(false);
+
+ startSoftApAndVerifyEnabled(softApConfig, TEST_COUNTRY_CODE);
+ verify(mWifiNative).setCountryCodeHal(
+ TEST_INTERFACE_NAME, TEST_COUNTRY_CODE.toUpperCase(Locale.ROOT));
+ }
+
+ /**
* Tests that the NO_CHANNEL error is propagated and properly reported when starting softap and
* a valid channel cannot be determined.
*/
@@ -432,7 +553,8 @@ public class SoftApManagerTest {
@Test
public void stopWhenNotStarted() throws Exception {
mSoftApManager = createSoftApManager(
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null));
+ new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null),
+ TEST_COUNTRY_CODE);
mSoftApManager.stop();
mLooper.dispatchAll();
/* Verify no state changes. */
@@ -911,14 +1033,16 @@ public class SoftApManagerTest {
/** Starts soft AP and verifies that it is enabled successfully. */
protected void startSoftApAndVerifyEnabled(
SoftApModeConfiguration softApConfig) throws Exception {
+ startSoftApAndVerifyEnabled(softApConfig, TEST_COUNTRY_CODE);
+ }
+
+ /** Starts soft AP and verifies that it is enabled successfully. */
+ protected void startSoftApAndVerifyEnabled(
+ SoftApModeConfiguration softApConfig, String countryCode) throws Exception {
WifiConfiguration expectedConfig;
InOrder order = inOrder(mCallback, mWifiNative);
- when(mWifiNative.setCountryCodeHal(
- TEST_INTERFACE_NAME, TEST_COUNTRY_CODE.toUpperCase(Locale.ROOT)))
- .thenReturn(true);
-
- mSoftApManager = createSoftApManager(softApConfig);
+ mSoftApManager = createSoftApManager(softApConfig, countryCode);
WifiConfiguration config = softApConfig.getWifiConfiguration();
if (config == null) {
when(mWifiApConfigStore.getApConfiguration()).thenReturn(mDefaultApConfig);