summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorLes Lee <lesl@google.com>2020-07-14 14:51:29 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-07-14 14:51:29 +0000
commitb276cac78ff7ab76c25c5c761c0cc41c6eb04f88 (patch)
tree5c2137b6112134c9ee51c5fc6a80dbf09e1bcda9 /tests
parent3a524f8d1a4fcd7164652bab45a4d1935a40253e (diff)
parenta9d21f0ec9fe8d88fb0f0e770ad09219934bf04f (diff)
Merge "wifi: bypass randomized Mac set failure when hal not support" into rvc-dev am: c794cd4c5f am: a9d21f0ec9
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/opt/net/wifi/+/12108426 Change-Id: I714f0e1f94c2a9f979334956e30eafec5565778e
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java96
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java9
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java30
3 files changed, 121 insertions, 14 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
index ddd8fe515..c4c00939a 100644
--- a/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/SoftApManagerTest.java
@@ -146,6 +146,8 @@ public class SoftApManagerTest extends WifiBaseTest {
MockitoAnnotations.initMocks(this);
mLooper = new TestLooper();
+ when(mWifiNative.isSetMacAddressSupported(any())).thenReturn(true);
+ when(mWifiNative.setMacAddress(any(), any())).thenReturn(true);
when(mWifiNative.startSoftAp(eq(TEST_INTERFACE_NAME), any(), any())).thenReturn(true);
when(mFrameworkFacade.getIntegerSetting(
@@ -1699,17 +1701,75 @@ public class SoftApManagerTest extends WifiBaseTest {
}
@Test
- public void setMacFailureAllowedWhenRandomizationOff() throws Exception {
- when(mResources.getBoolean(R.bool.config_wifi_ap_mac_randomization_supported))
- .thenReturn(false);
- SoftApModeConfiguration apConfig =
- new SoftApModeConfiguration(WifiManager.IFACE_IP_MODE_TETHERED, null,
- mTestSoftApCapability);
+ public void setsCustomMacWhenSetMacNotSupport() throws Exception {
+ when(mWifiNative.setupInterfaceForSoftApMode(any())).thenReturn(TEST_INTERFACE_NAME);
+ when(mWifiNative.isSetMacAddressSupported(any())).thenReturn(false);
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setBand(SoftApConfiguration.BAND_2GHZ);
+ configBuilder.setSsid(TEST_SSID);
+ configBuilder.setBssid(MacAddress.fromString("23:34:45:56:67:78"));
+ SoftApModeConfiguration apConfig = new SoftApModeConfiguration(
+ IFACE_IP_MODE_LOCAL_ONLY, configBuilder.build(), mTestSoftApCapability);
+ ArgumentCaptor<MacAddress> mac = ArgumentCaptor.forClass(MacAddress.class);
+
+ mSoftApManager = createSoftApManager(apConfig, TEST_COUNTRY_CODE);
+ mSoftApManager.start();
+ mLooper.dispatchAll();
+ verify(mCallback).onStateChanged(WifiManager.WIFI_AP_STATE_ENABLING, 0);
+ verify(mCallback).onStateChanged(WifiManager.WIFI_AP_STATE_FAILED,
+ WifiManager.SAP_START_FAILURE_UNSUPPORTED_CONFIGURATION);
+ verify(mWifiNative, never()).setMacAddress(any(), any());
+ }
+
+ @Test
+ public void setMacFailureWhenCustomMac() throws Exception {
+ when(mWifiNative.setupInterfaceForSoftApMode(any())).thenReturn(TEST_INTERFACE_NAME);
+ Builder configBuilder = new SoftApConfiguration.Builder();
+ configBuilder.setBand(SoftApConfiguration.BAND_2GHZ);
+ configBuilder.setSsid(TEST_SSID);
+ configBuilder.setBssid(MacAddress.fromString("23:34:45:56:67:78"));
+ SoftApModeConfiguration apConfig = new SoftApModeConfiguration(
+ IFACE_IP_MODE_LOCAL_ONLY, configBuilder.build(), mTestSoftApCapability);
ArgumentCaptor<MacAddress> mac = ArgumentCaptor.forClass(MacAddress.class);
+ when(mWifiNative.setMacAddress(eq(TEST_INTERFACE_NAME), mac.capture())).thenReturn(false);
- when(mWifiNative.setMacAddress(any(), any())).thenReturn(false);
+ mSoftApManager = createSoftApManager(apConfig, TEST_COUNTRY_CODE);
+ mSoftApManager.start();
+ mLooper.dispatchAll();
+ verify(mCallback).onStateChanged(WifiManager.WIFI_AP_STATE_ENABLING, 0);
+ verify(mCallback).onStateChanged(WifiManager.WIFI_AP_STATE_FAILED,
+ WifiManager.SAP_START_FAILURE_GENERAL);
+ assertThat(mac.getValue()).isEqualTo(MacAddress.fromString("23:34:45:56:67:78"));
+ }
+ @Test
+ public void setMacFailureWhenRandomMac() throws Exception {
+ when(mWifiNative.setupInterfaceForSoftApMode(any())).thenReturn(TEST_INTERFACE_NAME);
+ when(mWifiApConfigStore.getApConfiguration()).thenReturn(mDefaultApConfig);
+ SoftApConfiguration randomizedBssidConfig =
+ new SoftApConfiguration.Builder(mDefaultApConfig)
+ .setBssid(TEST_MAC_ADDRESS).build();
+ when(mWifiApConfigStore.randomizeBssidIfUnset(any(), any())).thenReturn(
+ randomizedBssidConfig);
+ SoftApModeConfiguration apConfig = new SoftApModeConfiguration(
+ IFACE_IP_MODE_LOCAL_ONLY, null, mTestSoftApCapability);
+ ArgumentCaptor<MacAddress> mac = ArgumentCaptor.forClass(MacAddress.class);
+ when(mWifiNative.setMacAddress(eq(TEST_INTERFACE_NAME), mac.capture())).thenReturn(false);
+ mSoftApManager = createSoftApManager(apConfig, TEST_COUNTRY_CODE);
+ mSoftApManager.start();
+ mLooper.dispatchAll();
+ verify(mCallback).onStateChanged(WifiManager.WIFI_AP_STATE_ENABLING, 0);
+ verify(mCallback).onStateChanged(WifiManager.WIFI_AP_STATE_FAILED,
+ WifiManager.SAP_START_FAILURE_GENERAL);
+ }
+
+ @Test
+ public void setRandomMacWhenSetMacNotsupport() throws Exception {
+ when(mWifiNative.isSetMacAddressSupported(any())).thenReturn(false);
+ SoftApModeConfiguration apConfig = new SoftApModeConfiguration(
+ IFACE_IP_MODE_LOCAL_ONLY, null, mTestSoftApCapability);
startSoftApAndVerifyEnabled(apConfig);
+ verify(mWifiNative, never()).setMacAddress(any(), any());
}
@Test
@@ -1852,15 +1912,22 @@ public class SoftApManagerTest extends WifiBaseTest {
/** Starts soft AP and verifies that it is enabled successfully. */
protected void startSoftApAndVerifyEnabled(
SoftApModeConfiguration softApConfig, String countryCode) throws Exception {
- SoftApConfiguration expectedConfig;
+ // The expected config to pass to Native
+ SoftApConfiguration expectedConfig = null;
+ // The config which base on mDefaultApConfig and generate ramdonized mac address
+ SoftApConfiguration randomizedBssidConfig = null;
InOrder order = inOrder(mCallback, mWifiNative);
- mSoftApManager = createSoftApManager(softApConfig, countryCode);
- mSoftApManager.mSoftApNotifier = mFakeSoftApNotifier;
SoftApConfiguration config = softApConfig.getSoftApConfiguration();
if (config == null) {
+ // Only generate randomized mac for default config since test case doesn't care it.
when(mWifiApConfigStore.getApConfiguration()).thenReturn(mDefaultApConfig);
- expectedConfig = new SoftApConfiguration.Builder(mDefaultApConfig)
+ randomizedBssidConfig =
+ new SoftApConfiguration.Builder(mDefaultApConfig)
+ .setBssid(TEST_MAC_ADDRESS).build();
+ when(mWifiApConfigStore.randomizeBssidIfUnset(any(), any())).thenReturn(
+ randomizedBssidConfig);
+ expectedConfig = new SoftApConfiguration.Builder(randomizedBssidConfig)
.setChannel(DEFAULT_AP_CHANNEL, SoftApConfiguration.BAND_2GHZ)
.build();
} else {
@@ -1868,7 +1935,8 @@ public class SoftApManagerTest extends WifiBaseTest {
.setChannel(DEFAULT_AP_CHANNEL, SoftApConfiguration.BAND_2GHZ)
.build();
}
-
+ mSoftApManager = createSoftApManager(softApConfig, countryCode);
+ mSoftApManager.mSoftApNotifier = mFakeSoftApNotifier;
ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
when(mWifiNative.setupInterfaceForSoftApMode(any()))
@@ -1905,8 +1973,8 @@ public class SoftApManagerTest extends WifiBaseTest {
verify(mListener).onStarted();
verify(mWifiMetrics).addSoftApUpChangedEvent(true, softApConfig.getTargetMode(),
TEST_DEFAULT_SHUTDOWN_TIMEOUT_MILLS);
- verify(mWifiMetrics).updateSoftApConfiguration(config == null ? mDefaultApConfig : config,
- softApConfig.getTargetMode());
+ verify(mWifiMetrics).updateSoftApConfiguration(config == null
+ ? randomizedBssidConfig : config, softApConfig.getTargetMode());
verify(mWifiMetrics).updateSoftApCapability(softApConfig.getCapability(),
softApConfig.getTargetMode());
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java
index ea4ebe5d0..46a3de86a 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiNativeTest.java
@@ -866,6 +866,15 @@ public class WifiNativeTest extends WifiBaseTest {
}
/**
+ * Verifies that isSetMacAddressSupported() calls underlying WifiVendorHal.
+ */
+ @Test
+ public void testIsSetMacAddressSupported() throws Exception {
+ mWifiNative.isSetMacAddressSupported(WIFI_IFACE_NAME);
+ verify(mWifiVendorHal).isSetMacAddressSupported(WIFI_IFACE_NAME);
+ }
+
+ /**
* Test that selectTxPowerScenario() calls into WifiVendorHal (success case)
*/
@Test
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java
index 363ae6923..9cf9ed4b1 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiVendorHalTest.java
@@ -2965,6 +2965,36 @@ public class WifiVendorHalTest extends WifiBaseTest {
}
/**
+ * Verifies isSetMacAddressSupported().
+ */
+ @Test
+ public void testIsSetMacAddressSupportedWhenV1_4Support() throws Exception {
+ mWifiVendorHal = spy(mWifiVendorHal);
+ when(mWifiVendorHal.getWifiApIfaceForV1_4Mockable(TEST_IFACE_NAME_1))
+ .thenReturn(mIWifiApIfaceV14);
+
+ assertTrue(mWifiVendorHal.isSetMacAddressSupported(TEST_IFACE_NAME_1));
+ }
+
+ /**
+ * Verifies isSetMacAddressSupported().
+ */
+ @Test
+ public void testIsSetMacAddressSupportedWhenV1_2Support() throws Exception {
+ // Expose the 1.2 IWifiStaIface.
+ mWifiVendorHal = new WifiVendorHalSpyV1_2(mHalDeviceManager, mHandler);
+ assertTrue(mWifiVendorHal.isSetMacAddressSupported(TEST_IFACE_NAME));
+ }
+
+ /**
+ * Verifies isSetMacAddressSupported() does not crash with older HALs.
+ */
+ @Test
+ public void testIsSetMacAddressSupportedOnOlderHal() throws Exception {
+ assertFalse(mWifiVendorHal.isSetMacAddressSupported(TEST_IFACE_NAME));
+ }
+
+ /**
* Verifies radio mode change callback to indicate DBS mode.
*/
@Test