diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2020-08-11 23:50:19 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2020-08-11 23:50:19 +0000 |
commit | c6cf48cd848c87e9331662f3a24103340f459b94 (patch) | |
tree | e048088e0acec0473e20cffa1e87828afb55b6ad /tests | |
parent | 6ee5e95fdd68f75a38f0df8953b547035aff0fc0 (diff) | |
parent | 356f4a66d6e2d7cb974ba917083846d702b39f7b (diff) |
Merge "Populate randomized mac address for passpoint wifi configs" into rvc-qpr-dev
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java | 41 |
1 files changed, 39 insertions, 2 deletions
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}. */ |