diff options
3 files changed, 57 insertions, 4 deletions
diff --git a/service/java/com/android/server/wifi/WifiInjector.java b/service/java/com/android/server/wifi/WifiInjector.java index b18dd6a29..993debba5 100644 --- a/service/java/com/android/server/wifi/WifiInjector.java +++ b/service/java/com/android/server/wifi/WifiInjector.java @@ -304,7 +304,8 @@ public class WifiInjector { mWifiCarrierInfoManager, mWifiKeyStore, mLruConnectionTracker); mPasspointManager = new PasspointManager(mContext, this, wifiHandler, mWifiNative, mWifiKeyStore, mClock, new PasspointObjectFactory(), - mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mWifiCarrierInfoManager); + mWifiConfigManager, mWifiConfigStore, mWifiMetrics, mWifiCarrierInfoManager, + mMacAddressUtil); PasspointNetworkNominateHelper nominateHelper = new PasspointNetworkNominateHelper(mPasspointManager, mWifiConfigManager, mConnectivityLocalLog); diff --git a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java index 25553b8fe..9cb4254c0 100644 --- a/service/java/com/android/server/wifi/hotspot2/PasspointManager.java +++ b/service/java/com/android/server/wifi/hotspot2/PasspointManager.java @@ -18,12 +18,14 @@ package com.android.server.wifi.hotspot2; import static android.app.AppOpsManager.OPSTR_CHANGE_WIFI_STATE; import static android.net.wifi.WifiConfiguration.MeteredOverride; +import static android.net.wifi.WifiInfo.DEFAULT_MAC_ADDRESS; import static java.security.cert.PKIXReason.NO_TRUST_ANCHOR; import android.annotation.NonNull; import android.app.AppOpsManager; import android.content.Context; +import android.net.MacAddress; import android.net.wifi.ScanResult; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiEnterpriseConfig; @@ -40,6 +42,7 @@ import android.util.Log; import android.util.Pair; import com.android.server.wifi.Clock; +import com.android.server.wifi.MacAddressUtil; import com.android.server.wifi.NetworkUpdateResult; import com.android.server.wifi.WifiCarrierInfoManager; import com.android.server.wifi.WifiConfigManager; @@ -118,6 +121,7 @@ public class PasspointManager { private final PasspointProvisioner mPasspointProvisioner; private final AppOpsManager mAppOps; private final WifiCarrierInfoManager mWifiCarrierInfoManager; + private final MacAddressUtil mMacAddressUtil; /** * Map of package name of an app to the app ops changed listener for the app. @@ -304,7 +308,8 @@ public class PasspointManager { PasspointObjectFactory objectFactory, WifiConfigManager wifiConfigManager, WifiConfigStore wifiConfigStore, WifiMetrics wifiMetrics, - WifiCarrierInfoManager wifiCarrierInfoManager) { + WifiCarrierInfoManager wifiCarrierInfoManager, + MacAddressUtil macAddressUtil) { mPasspointEventHandler = objectFactory.makePasspointEventHandler(wifiNative, new CallbackHandler(context)); mWifiInjector = wifiInjector; @@ -326,6 +331,7 @@ public class PasspointManager { this, wifiMetrics); mAppOps = (AppOpsManager) context.getSystemService(Context.APP_OPS_SERVICE); sPasspointManager = this; + mMacAddressUtil = macAddressUtil; } /** @@ -1096,6 +1102,15 @@ public class PasspointManager { continue; } WifiConfiguration config = provider.getWifiConfig(); + if (mWifiConfigManager.shouldUseAggressiveRandomization(config)) { + config.setRandomizedMacAddress(MacAddress.fromString(DEFAULT_MAC_ADDRESS)); + } else { + MacAddress result = mMacAddressUtil.calculatePersistentMac(config.getKey(), + mMacAddressUtil.obtainMacRandHashFunction(Process.WIFI_UID)); + if (result != null) { + config.setRandomizedMacAddress(result); + } + } // If the Passpoint configuration is from a suggestion, check if the app shares this // suggestion with the user. if (provider.isFromSuggestion() diff --git a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java index dbc38d493..9caf85f4e 100644 --- a/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java @@ -20,6 +20,7 @@ import static android.app.AppOpsManager.MODE_IGNORED; import static android.app.AppOpsManager.OPSTR_CHANGE_WIFI_STATE; import static android.net.wifi.WifiConfiguration.METERED_OVERRIDE_METERED; import static android.net.wifi.WifiConfiguration.METERED_OVERRIDE_NOT_METERED; +import static android.net.wifi.WifiInfo.DEFAULT_MAC_ADDRESS; import static com.android.server.wifi.WifiConfigurationTestUtil.SECURITY_EAP; @@ -50,6 +51,7 @@ import static org.mockito.MockitoAnnotations.initMocks; import android.app.AppOpsManager; import android.content.Context; import android.content.Intent; +import android.net.MacAddress; import android.net.Uri; import android.net.wifi.EAPConstants; import android.net.wifi.ScanResult; @@ -78,6 +80,7 @@ import com.android.server.wifi.ClientModeImpl; import com.android.server.wifi.Clock; import com.android.server.wifi.FakeKeys; import com.android.server.wifi.FrameworkFacade; +import com.android.server.wifi.MacAddressUtil; import com.android.server.wifi.NetworkUpdateResult; import com.android.server.wifi.WifiBaseTest; import com.android.server.wifi.WifiCarrierInfoManager; @@ -188,6 +191,7 @@ public class PasspointManagerTest extends WifiBaseTest { @Mock TelephonyManager mTelephonyManager; @Mock SubscriptionManager mSubscriptionManager; @Mock WifiNetworkSuggestionsManager mWifiNetworkSuggestionsManager; + @Mock MacAddressUtil mMacAddressUtil; Handler mHandler; TestLooper mLooper; @@ -223,7 +227,7 @@ public class PasspointManagerTest extends WifiBaseTest { mHandler = new Handler(mLooper.getLooper()); mManager = new PasspointManager(mContext, mWifiInjector, mHandler, mWifiNative, mWifiKeyStore, mClock, mObjectFactory, mWifiConfigManager, - mWifiConfigStore, mWifiMetrics, mWifiCarrierInfoManager); + mWifiConfigStore, mWifiMetrics, mWifiCarrierInfoManager, mMacAddressUtil); ArgumentCaptor<PasspointEventHandler.Callbacks> callbacks = ArgumentCaptor.forClass(PasspointEventHandler.Callbacks.class); verify(mObjectFactory).makePasspointEventHandler(any(WifiNative.class), @@ -749,7 +753,7 @@ public class PasspointManagerTest extends WifiBaseTest { .thenReturn(true); PasspointManager ut = new PasspointManager(mContext, mWifiInjector, mHandler, mWifiNative, mWifiKeyStore, mClock, spyFactory, mWifiConfigManager, - mWifiConfigStore, mWifiMetrics, mWifiCarrierInfoManager); + mWifiConfigStore, mWifiMetrics, mWifiCarrierInfoManager, mMacAddressUtil); assertTrue(ut.addOrUpdateProvider(config, TEST_CREATOR_UID, TEST_PACKAGE, true, true)); @@ -1230,6 +1234,39 @@ public class PasspointManagerTest extends WifiBaseTest { } /** + * Verify that a {@link WifiConfiguration} will be returned with the correct value for the + * randomized MAC address. + */ + @Test + public void getWifiConfigsForPasspointProfilesWithoutEnhancedMacRandomization() { + MacAddress randomizedMacAddress = MacAddress.fromString("01:23:45:67:89:ab"); + when(mMacAddressUtil.calculatePersistentMac(any(), any())).thenReturn(randomizedMacAddress); + when(mWifiConfigManager.shouldUseAggressiveRandomization(any())).thenReturn(false); + PasspointProvider provider = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, + TEST_PACKAGE, false, null); + WifiConfiguration config = mManager.getWifiConfigsForPasspointProfiles( + Collections.singletonList(provider.getConfig().getUniqueId())).get(0); + assertEquals(config.getRandomizedMacAddress(), randomizedMacAddress); + } + + /** + * Verify that a {@link WifiConfiguration} will be returned with DEFAULT_MAC_ADDRESS for the + * randomized MAC address if enhanced mac randomization is enabled. This value will display in + * the wifi picker's network details page as "Not available" if the network is disconnected. + */ + @Test + public void getWifiConfigsForPasspointProfilesWithEnhancedMacRandomization() { + MacAddress randomizedMacAddress = MacAddress.fromString("01:23:45:67:89:ab"); + when(mMacAddressUtil.calculatePersistentMac(any(), any())).thenReturn(randomizedMacAddress); + when(mWifiConfigManager.shouldUseAggressiveRandomization(any())).thenReturn(true); + PasspointProvider provider = addTestProvider(TEST_FQDN, TEST_FRIENDLY_NAME, + TEST_PACKAGE, false, null); + WifiConfiguration config = mManager.getWifiConfigsForPasspointProfiles( + Collections.singletonList(provider.getConfig().getUniqueId())).get(0); + assertEquals(config.getRandomizedMacAddress(), MacAddress.fromString(DEFAULT_MAC_ADDRESS)); + } + + /** * Verify that an empty map will be returned when trying to get all matching FQDN for a {@code * null} {@link ScanResult}. */ |