summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorQuang Luong <qal@google.com>2020-08-03 20:59:01 -0700
committerQuang Luong <qal@google.com>2020-08-11 17:15:29 +0000
commit356f4a66d6e2d7cb974ba917083846d702b39f7b (patch)
tree10e1abf50cb361ac4122580b2bb0b698b1498376 /tests
parent058fc1de39ed8c11473bf9d60aac92dbf21106c0 (diff)
Populate randomized mac address for passpoint wifi configs
Calculate the randomized mac address for passpoint wifi configs before returning them in getWifiConfigsForPasspointProfiles. If enhanced mac randomization is enabled for a config, then populate it with DEFAULT_MAC_ADDRESS, which displays in Settings as "Not available". Bug: 160028657 Test: atest PasspointManagerTest, visual verification that randomized mac address appears in Network Details page for Passpoint networks, and appears as "Not available" if enhanced mac randomization is enabled. Change-Id: Icf90940b3c7212f302964db68fc126a012ef36d3 (cherry picked from commit d7ecbaef528e7e3677a400334b9e9a6e5bfb65fd) Merged-In: Icf90940b3c7212f302964db68fc126a012ef36d3
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/hotspot2/PasspointManagerTest.java41
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}.
*/