summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorxshu <xshu@google.com>2019-11-14 13:38:13 -0800
committerxshu <xshu@google.com>2019-11-14 15:49:05 -0800
commita0877687846696eaa0539b166bdb6acd9e9d3bd6 (patch)
treeb2ce999c6d6ce1b6eabb2cd1ef9e71122fc873eb /tests
parent418df18cc1ed9a43158822f3c25c30cd7c45afda (diff)
per-SSID SAP randomization
Making the SoftAp MAC address be persistently randomized per-SSID. Bug: 144525535 Test: atest FrameworksWifiTests Test: Verified on device that we are always using the same MAC address for the same SSID. Change-Id: I884f5adcd4dec87cf1b5b81c6b785f6cd5eca9f2
Diffstat (limited to 'tests')
-rw-r--r--tests/wifitests/src/com/android/server/wifi/MacAddressUtilTest.java12
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java16
-rw-r--r--tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java3
3 files changed, 14 insertions, 17 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/MacAddressUtilTest.java b/tests/wifitests/src/com/android/server/wifi/MacAddressUtilTest.java
index 331725c14..1e04c8643 100644
--- a/tests/wifitests/src/com/android/server/wifi/MacAddressUtilTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/MacAddressUtilTest.java
@@ -49,23 +49,21 @@ public class MacAddressUtilTest extends WifiBaseTest {
}
/**
- * Verifies that calculatePersistentMacForConfiguration valid randomized MACs.
+ * Verifies that calculatePersistentMac generate valid randomized MACs.
*/
@Test
- public void testCalculatePersistentMacForConfiguration() {
+ public void testCalculatePersistentMac() {
// verify null inputs
- assertNull(mMacAddressUtil.calculatePersistentMacForConfiguration(null, null));
+ assertNull(mMacAddressUtil.calculatePersistentMac(null, null));
Random rand = new Random();
// Verify that a the MAC address calculated is valid
for (int i = 0; i < 10; i++) {
- WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork();
-
byte[] bytes = new byte[32];
rand.nextBytes(bytes);
when(mMac.doFinal(any())).thenReturn(bytes);
- MacAddress macAddress = mMacAddressUtil.calculatePersistentMacForConfiguration(
- config, mMac);
+ MacAddress macAddress = mMacAddressUtil.calculatePersistentMac(
+ "TEST_SSID_AND_SECURITY_TYPE_" + i, mMac);
assertTrue(WifiConfiguration.isValidMacAddressForRandomization(macAddress));
}
}
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
index 3d78e1e46..f150bf797 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiApConfigStoreTest.java
@@ -84,6 +84,8 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
private static final String TEST_STRING_UTF8_WITH_32_BYTES = "ΣωκράτηςΣωκράτης";
private static final String TEST_STRING_UTF8_WITH_33_BYTES = "一片汪洋大海中的一條魚";
private static final String TEST_STRING_UTF8_WITH_34_BYTES = "Ευπροσηγοροςγινου";
+ private static final MacAddress TEST_RANDOMIZED_MAC =
+ MacAddress.fromString("d2:11:19:34:a5:20");
@Mock private Context mContext;
@Mock private WifiInjector mWifiInjector;
@@ -96,6 +98,7 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
@Mock private ApplicationInfo mMockApplInfo;
private BroadcastReceiver mBroadcastReceiver;
@Mock private NotificationManager mNotificationManager;
+ @Mock private MacAddressUtil mMacAddressUtil;
private ArrayList<Integer> mKnownGood2GChannelList;
@Before
@@ -132,6 +135,8 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
mKnownGood2GChannelList = new ArrayList(Arrays.asList(1, 2, 3, 4, 5, 6));
mRandom = new Random();
+ when(mWifiInjector.getMacAddressUtil()).thenReturn(mMacAddressUtil);
+ when(mMacAddressUtil.calculatePersistentMac(any(), any())).thenReturn(TEST_RANDOMIZED_MAC);
}
@After
@@ -591,14 +596,9 @@ public class WifiApConfigStoreTest extends WifiBaseTest {
WifiConfiguration baseConfig = new WifiConfiguration();
WifiApConfigStore store = createWifiApConfigStore();
- WifiConfiguration config1 = store.randomizeBssidIfUnset(mContext, baseConfig);
- WifiConfiguration config2 = store.randomizeBssidIfUnset(mContext, baseConfig);
-
- assertThat(config1.BSSID).isNotNull();
- assertThat(config2.BSSID).isNotNull();
- MacAddress mac1 = MacAddress.fromString(config1.BSSID);
- MacAddress mac2 = MacAddress.fromString(config2.BSSID);
- assertThat(mac1).isNotEqualTo(mac2);
+ WifiConfiguration config = store.randomizeBssidIfUnset(mContext, baseConfig);
+
+ assertEquals(TEST_RANDOMIZED_MAC.toString(), config.BSSID);
}
@Test
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
index e99224512..895a169a1 100644
--- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
+++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java
@@ -222,8 +222,7 @@ public class WifiConfigManagerTest extends WifiBaseTest {
.thenReturn(false);
when(mWifiInjector.getCarrierNetworkConfig()).thenReturn(mCarrierNetworkConfig);
when(mWifiInjector.getMacAddressUtil()).thenReturn(mMacAddressUtil);
- when(mMacAddressUtil.calculatePersistentMacForConfiguration(any(), any()))
- .thenReturn(TEST_RANDOMIZED_MAC);
+ when(mMacAddressUtil.calculatePersistentMac(any(), any())).thenReturn(TEST_RANDOMIZED_MAC);
mTelephonyUtil = new TelephonyUtil(mTelephonyManager, mSubscriptionManager);
createWifiConfigManager();