summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJong Wook Kim <jongwook@google.com>2018-05-17 20:06:12 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-05-17 20:06:12 +0000
commitfaa9f916fa34a5ec0af6aa0f80b0d88dfdbb6ca8 (patch)
tree2f87fac786ddb2c0bbefe340c362592cf42c2d3b
parent514a1fbaca27f86221279b841a0617b43db18a7e (diff)
parentee780140e31af01e3e6ed380459f097633c87355 (diff)
Merge "Update WifiInfo MAC address more frequently" into pi-dev
-rw-r--r--service/java/com/android/server/wifi/WifiStateMachine.java2
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java38
2 files changed, 40 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/WifiStateMachine.java b/service/java/com/android/server/wifi/WifiStateMachine.java
index 1d40360f9..74a4dc7f0 100644
--- a/service/java/com/android/server/wifi/WifiStateMachine.java
+++ b/service/java/com/android/server/wifi/WifiStateMachine.java
@@ -4297,6 +4297,7 @@ public class WifiStateMachine extends StateMachine {
if (config != null) {
mWifiInfo.setBSSID(mLastBssid);
mWifiInfo.setNetworkId(mLastNetworkId);
+ mWifiInfo.setMacAddress(mWifiNative.getMacAddress(mInterfaceName));
ScanDetailCache scanDetailCache =
mWifiConfigManager.getScanDetailCacheForNetwork(config.networkId);
@@ -4848,6 +4849,7 @@ public class WifiStateMachine extends StateMachine {
mWifiInfo.setBSSID((String) message.obj);
mLastNetworkId = message.arg1;
mWifiInfo.setNetworkId(mLastNetworkId);
+ mWifiInfo.setMacAddress(mWifiNative.getMacAddress(mInterfaceName));
if(!mLastBssid.equals(message.obj)) {
mLastBssid = (String) message.obj;
sendNetworkStateChangeBroadcast(mLastBssid);
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
index 2712a42e3..b067d9dfa 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiStateMachineTest.java
@@ -2395,4 +2395,42 @@ public class WifiStateMachineTest {
verify(mIpClient).shutdown();
verify(mIpClient).awaitShutdown();
}
+
+ /**
+ * Verify that WifiInfo's MAC address is updated when the state machine receives
+ * NETWORK_CONNECTION_EVENT while in ConnectedState.
+ */
+ @Test
+ public void verifyWifiInfoMacUpdatedWithNetworkConnectionWhileConnected() throws Exception {
+ when(mWifiNative.getMacAddress(WIFI_IFACE_NAME))
+ .thenReturn(TEST_LOCAL_MAC_ADDRESS.toString());
+ connect();
+ assertEquals("ConnectedState", getCurrentState().getName());
+ assertEquals(TEST_LOCAL_MAC_ADDRESS.toString(), mWsm.getWifiInfo().getMacAddress());
+
+ when(mWifiNative.getMacAddress(WIFI_IFACE_NAME))
+ .thenReturn(TEST_GLOBAL_MAC_ADDRESS.toString());
+ mWsm.sendMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, sBSSID);
+ mLooper.dispatchAll();
+ assertEquals(TEST_GLOBAL_MAC_ADDRESS.toString(), mWsm.getWifiInfo().getMacAddress());
+ }
+
+ /**
+ * Verify that WifiInfo's MAC address is updated when the state machine receives
+ * NETWORK_CONNECTION_EVENT while in DisconnectedState.
+ */
+ @Test
+ public void verifyWifiInfoMacUpdatedWithNetworkConnectionWhileDisconnected() throws Exception {
+ when(mWifiNative.getMacAddress(WIFI_IFACE_NAME))
+ .thenReturn(TEST_LOCAL_MAC_ADDRESS.toString());
+ disconnect();
+ assertEquals("DisconnectedState", getCurrentState().getName());
+ assertEquals(TEST_LOCAL_MAC_ADDRESS.toString(), mWsm.getWifiInfo().getMacAddress());
+
+ when(mWifiNative.getMacAddress(WIFI_IFACE_NAME))
+ .thenReturn(TEST_GLOBAL_MAC_ADDRESS.toString());
+ mWsm.sendMessage(WifiMonitor.NETWORK_CONNECTION_EVENT, 0, 0, sBSSID);
+ mLooper.dispatchAll();
+ assertEquals(TEST_GLOBAL_MAC_ADDRESS.toString(), mWsm.getWifiInfo().getMacAddress());
+ }
}