diff options
author | Jong Wook Kim <jongwook@google.com> | 2018-03-13 12:55:16 -0700 |
---|---|---|
committer | Jong Wook Kim <jongwook@google.com> | 2018-03-21 11:47:08 -0700 |
commit | f927e3cdb59e8809991a5924c8ec82f15e0f52c9 (patch) | |
tree | 12df5f9cd5e24760a254c9d958acbcb42e7a8b2f /tests | |
parent | b7d6d452cc79e33208aef9b26b2aee31a99c85f7 (diff) |
Send "02:00:00:00:00:00" as device MAC when not connected
When Connected MAC Randomization is on and the device is disconnected,
we don't have a valid MAC address to show since we don't know what the
next MAC address is going to be. So instead of showing the MAC address
used during the previous connection, WifiInfo should return the default
MAC address "02:00:00:00:00:00".
In this change, the device resets MAC address stored in WifiInfo to the
default MAC address whenever it gets disconnected with Connected MAC
Randomization on.
Bug: 74436251
Test: Unittest
Change-Id: Ibc1027559a9d5abead2a764b5e94672498d4f7b4
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java index 884432a56..0d89338ca 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java @@ -139,6 +139,8 @@ public class WifiStateMachineTest { private static final int TEST_UID = Process.SYSTEM_UID + 1000; private static final MacAddress TEST_GLOBAL_MAC_ADDRESS = MacAddress.fromString("10:22:34:56:78:92"); + private static final MacAddress TEST_LOCAL_MAC_ADDRESS = + MacAddress.fromString("2a:53:43:c3:56:21"); // NetworkAgent creates threshold ranges with Integers private static final int RSSI_THRESHOLD_MAX = -30; @@ -2373,11 +2375,37 @@ public class WifiStateMachineTest { } /** + * Verifies that WifiInfo returns DEFAULT_MAC_ADDRESS as mac address when Connected MAC + * Randomization is on and the device is not connected to a wifi network. + */ + @Test + public void testWifiInfoReturnDefaultMacWhenDisconnectedWithRandomization() throws Exception { + when(mFrameworkFacade.getIntegerSetting(mContext, + Settings.Global.WIFI_CONNECTED_MAC_RANDOMIZATION_ENABLED, 0)).thenReturn(1); + mContentObserver.onChange(false); + when(mWifiNative.getMacAddress(WIFI_IFACE_NAME)) + .thenReturn(TEST_LOCAL_MAC_ADDRESS.toString()); + + connect(); + assertEquals(TEST_LOCAL_MAC_ADDRESS.toString(), mWsm.getWifiInfo().getMacAddress()); + + mWsm.sendMessage(WifiMonitor.NETWORK_DISCONNECTION_EVENT, -1, 3, sBSSID); + mLooper.dispatchAll(); + mWsm.sendMessage(WifiMonitor.SUPPLICANT_STATE_CHANGE_EVENT, 0, 0, + new StateChangeResult(0, sWifiSsid, sBSSID, SupplicantState.DISCONNECTED)); + mLooper.dispatchAll(); + + assertEquals("DisconnectedState", getCurrentState().getName()); + assertEquals(WifiInfo.DEFAULT_MAC_ADDRESS, mWsm.getWifiInfo().getMacAddress()); + assertFalse(mWsm.getWifiInfo().hasRealMacAddress()); + } + + /** * Verifies that connected MAC randomization methods are not called * when the feature is off. */ @Test - public void testConnectedMacRandomizationOff() throws Exception { + public void testConnectedMacRandomizationWhenFeatureOff() throws Exception { initializeAndAddNetworkAndVerifySuccess(); assertEquals(WifiStateMachine.CONNECT_MODE, mWsm.getOperationalModeForTest()); assertEquals(WifiManager.WIFI_STATE_ENABLED, mWsm.syncGetWifiState()); |