summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorOscar Shu <xshu@google.com>2020-04-24 04:43:25 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2020-04-24 04:43:25 +0000
commit65d9ad5fd183f58dd2a962913148fef1bb612d08 (patch)
treec2082fd59ae94f1282bb9131cd5fe012fa63c2da /tests
parent67fbe2bf5663042fe4f74074679c9b34990adb4a (diff)
parent761fec1b48fa7329dc40713ccfe0637dd9dd20a9 (diff)
Merge "Randomize sta MAC address upon start" into rvc-dev
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java32
1 files changed, 20 insertions, 12 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
index 2923315d6..0c48521e1 100644
--- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
@@ -2646,7 +2646,7 @@ public class ClientModeImplTest extends WifiBaseTest {
* 3. macRandomizationSetting of the WifiConfiguration is RANDOMIZATION_PERSISTENT and
* 4. randomized MAC for the network to connect to is different from the current MAC.
*
- * Then the current MAC does not change when CMD_START_CONNECT executes.
+ * The factory MAC address is used for the connection.
*/
@Test
public void testConnectedMacRandomizationNotSupported() throws Exception {
@@ -2657,11 +2657,7 @@ public class ClientModeImplTest extends WifiBaseTest {
assertEquals(WifiManager.WIFI_STATE_ENABLED, mCmi.syncGetWifiState());
connect();
- verify(mWifiNative, never()).setMacAddress(WIFI_IFACE_NAME, TEST_LOCAL_MAC_ADDRESS);
- verify(mWifiMetrics, never())
- .logStaEvent(eq(StaEvent.TYPE_MAC_CHANGE), any(WifiConfiguration.class));
assertEquals(TEST_GLOBAL_MAC_ADDRESS.toString(), mCmi.getWifiInfo().getMacAddress());
-
}
/**
@@ -2746,9 +2742,8 @@ public class ClientModeImplTest extends WifiBaseTest {
* Verifies that when
* 1. connected MAC randomization is on and
* 2. macRandomizationSetting of the WifiConfiguration is RANDOMIZATION_NONE and
- * 3. current MAC is the factory MAC.
*
- * Then MAC change should not occur when CMD_START_CONNECT executes.
+ * Then the factory MAC should be used to connect to the network.
* @throws Exception
*/
@Test
@@ -2765,9 +2760,6 @@ public class ClientModeImplTest extends WifiBaseTest {
mCmi.sendMessage(ClientModeImpl.CMD_START_CONNECT, 0, 0, sBSSID);
mLooper.dispatchAll();
- verify(mWifiNative, never()).setMacAddress(WIFI_IFACE_NAME, TEST_GLOBAL_MAC_ADDRESS);
- verify(mWifiMetrics, never())
- .logStaEvent(eq(StaEvent.TYPE_MAC_CHANGE), any(WifiConfiguration.class));
assertEquals(TEST_GLOBAL_MAC_ADDRESS.toString(), mCmi.getWifiInfo().getMacAddress());
}
@@ -2812,7 +2804,8 @@ public class ClientModeImplTest extends WifiBaseTest {
mCmi.sendMessage(ClientModeImpl.CMD_START_CONNECT, 0, 0, sBSSID);
mLooper.dispatchAll();
- verify(mWifiNative, never()).setMacAddress(eq(WIFI_IFACE_NAME), any(MacAddress.class));
+ // setMacAddress is invoked once when ClientModeImpl starts to prevent leak of factory MAC.
+ verify(mWifiNative).setMacAddress(eq(WIFI_IFACE_NAME), any(MacAddress.class));
}
/**
@@ -3828,7 +3821,7 @@ public class ClientModeImplTest extends WifiBaseTest {
initializeCmi();
initializeAndAddNetworkAndVerifySuccess();
when(mWifiNative.getFactoryMacAddress(WIFI_IFACE_NAME)).thenReturn(null);
- assertEquals(TEST_GLOBAL_MAC_ADDRESS.toString(), mCmi.getFactoryMacAddress());
+ mCmi.getFactoryMacAddress();
verify(mWifiNative).getFactoryMacAddress(anyString());
verify(mWifiNative, times(2)).getMacAddress(WIFI_IFACE_NAME);
}
@@ -3845,6 +3838,21 @@ public class ClientModeImplTest extends WifiBaseTest {
}
/**
+ * Verify the MAC address is being randomized at start to prevent leaking the factory MAC.
+ */
+ @Test
+ public void testRandomizeMacAddressOnStart() throws Exception {
+ ArgumentCaptor<MacAddress> macAddressCaptor = ArgumentCaptor.forClass(MacAddress.class);
+ loadComponentsInStaMode();
+ verify(mWifiNative).setMacAddress(anyString(), macAddressCaptor.capture());
+ MacAddress currentMac = macAddressCaptor.getValue();
+
+ assertNotEquals("The currently programmed MAC address should be different from the factory "
+ + "MAC address after ClientModeImpl starts",
+ mCmi.getFactoryMacAddress(), currentMac.toString());
+ }
+
+ /**
* Verify bugreport will be taken when get IP_REACHABILITY_LOST
*/
@Test