summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/java/com/android/server/wifi/ClientModeImpl.java8
-rw-r--r--tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java15
2 files changed, 20 insertions, 3 deletions
diff --git a/service/java/com/android/server/wifi/ClientModeImpl.java b/service/java/com/android/server/wifi/ClientModeImpl.java
index b80371285..fa2f4a980 100644
--- a/service/java/com/android/server/wifi/ClientModeImpl.java
+++ b/service/java/com/android/server/wifi/ClientModeImpl.java
@@ -3380,12 +3380,14 @@ public class ClientModeImpl extends StateMachine {
Log.e(TAG, "No config to change MAC address to");
return;
}
- MacAddress currentMac = MacAddress.fromString(mWifiNative.getMacAddress(mInterfaceName));
+ String currentMacString = mWifiNative.getMacAddress(mInterfaceName);
+ MacAddress currentMac = currentMacString == null ? null :
+ MacAddress.fromString(currentMacString);
MacAddress newMac = config.getOrCreateRandomizedMacAddress();
mWifiConfigManager.setNetworkRandomizedMacAddress(config.networkId, newMac);
if (!WifiConfiguration.isValidMacAddressForRandomization(newMac)) {
Log.wtf(TAG, "Config generated an invalid MAC address");
- } else if (currentMac.equals(newMac)) {
+ } else if (newMac.equals(currentMac)) {
Log.d(TAG, "No changes in MAC address");
} else {
mWifiMetrics.logStaEvent(StaEvent.TYPE_MAC_CHANGE, config);
@@ -3393,7 +3395,7 @@ public class ClientModeImpl extends StateMachine {
mWifiNative.setMacAddress(mInterfaceName, newMac);
Log.d(TAG, "ConnectedMacRandomization SSID(" + config.getPrintableSsid()
+ "). setMacAddress(" + newMac.toString() + ") from "
- + currentMac.toString() + " = " + setMacSuccess);
+ + currentMacString + " = " + setMacSuccess);
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
index 7896a8f0b..f0e9d2c10 100644
--- a/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/ClientModeImplTest.java
@@ -2748,6 +2748,21 @@ public class ClientModeImplTest {
}
/**
+ * Verify that we don't crash when WifiNative returns null as the current MAC address.
+ * @throws Exception
+ */
+ @Test
+ public void testMacRandomizationWifiNativeReturningNull() throws Exception {
+ when(mWifiNative.getMacAddress(anyString())).thenReturn(null);
+ initializeAndAddNetworkAndVerifySuccess();
+ assertEquals(ClientModeImpl.CONNECT_MODE, mCmi.getOperationalModeForTest());
+ assertEquals(WifiManager.WIFI_STATE_ENABLED, mCmi.syncGetWifiState());
+
+ connect();
+ verify(mWifiNative).setMacAddress(WIFI_IFACE_NAME, TEST_LOCAL_MAC_ADDRESS);
+ }
+
+ /**
* Verifies that CMD_START_CONNECT make WifiDiagnostics report
* CONNECTION_EVENT_STARTED
* @throws Exception