diff options
author | Oscar Shu <xshu@google.com> | 2019-12-02 18:34:58 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-12-02 18:34:58 +0000 |
commit | 1369ef2a467dd13aa67ff3a0a85e21f0a52b73fe (patch) | |
tree | f42b4885af2b75f52c8e9a4858e13e79d5f26a90 /tests | |
parent | f6795e881345d61b51bc3c9c40d476c886ffdff8 (diff) | |
parent | 1c806a782ad338eacae26edbc3be30b9ee0a845e (diff) |
Merge "aggrssive randomization - Enforce min wait time after disconnect"
Diffstat (limited to 'tests')
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index 3cd9e622f..8992cd961 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -2086,12 +2086,12 @@ public class WifiConfigManagerTest extends WifiBaseTest { final MacAddress aggressiveMac = config.getRandomizedMacAddress(); assertNotEquals(WifiInfo.DEFAULT_MAC_ADDRESS, aggressiveMac.toString()); assertEquals(TEST_WALLCLOCK_CREATION_TIME_MILLIS - + WifiConfigManager.AGGRESSIVE_MAC_REFRESH_MS_DEFAULT, + + WifiConfigManager.AGGRESSIVE_MAC_WAIT_AFTER_DISCONNECT_MS, config.randomizedMacExpirationTimeMs); // verify the new randomized mac should be different from the original mac. when(mClock.getWallClockMillis()).thenReturn(TEST_WALLCLOCK_CREATION_TIME_MILLIS - + WifiConfigManager.AGGRESSIVE_MAC_REFRESH_MS_DEFAULT + 1); + + WifiConfigManager.AGGRESSIVE_MAC_WAIT_AFTER_DISCONNECT_MS + 1); MacAddress aggressiveMac2 = mWifiConfigManager.getRandomizedMacAndUpdateIfNeeded(config); // verify internal WifiConfiguration has MacAddress updated correctly by comparing the @@ -2099,9 +2099,6 @@ public class WifiConfigManagerTest extends WifiBaseTest { config = getFirstInternalWifiConfiguration(); assertEquals(aggressiveMac2, config.getRandomizedMacAddress()); assertNotEquals(aggressiveMac, aggressiveMac2); - assertEquals(TEST_WALLCLOCK_CREATION_TIME_MILLIS - + (WifiConfigManager.AGGRESSIVE_MAC_REFRESH_MS_DEFAULT * 2) + 1, - config.randomizedMacExpirationTimeMs); // Now disable aggressive randomization and verify the randomized MAC is changed back to // the persistent MAC. @@ -2116,9 +2113,6 @@ public class WifiConfigManagerTest extends WifiBaseTest { assertEquals(persistentMac, config.getRandomizedMacAddress()); assertNotEquals(persistentMac, aggressiveMac); assertNotEquals(persistentMac, aggressiveMac2); - assertEquals(TEST_WALLCLOCK_CREATION_TIME_MILLIS - + (WifiConfigManager.AGGRESSIVE_MAC_REFRESH_MS_DEFAULT * 2) + 1, - config.randomizedMacExpirationTimeMs); } /** @@ -2154,6 +2148,40 @@ public class WifiConfigManagerTest extends WifiBaseTest { } /** + * Verifies that the expiration time of the currently used aggressive MAC is set to the + * maximum of some predefined time and the remaining DHCP lease duration at disconnect. + */ + @Test + public void testRandomizedMacExpirationTimeUpdatedAtDisconnect() { + setUpWifiConfigurationForAggressiveRandomization(); + WifiConfiguration config = getFirstInternalWifiConfiguration(); + when(mClock.getWallClockMillis()).thenReturn(0L); + + // First set the DHCP expiration time to be longer than the predefined time. + long dhcpLeaseTimeInSeconds = (WifiConfigManager.AGGRESSIVE_MAC_WAIT_AFTER_DISCONNECT_MS + / 1000) + 1; + mWifiConfigManager.updateRandomizedMacExpireTime(config, dhcpLeaseTimeInSeconds); + config = getFirstInternalWifiConfiguration(); + long expirationTime = config.randomizedMacExpirationTimeMs; + assertEquals(WifiConfigManager.AGGRESSIVE_MAC_WAIT_AFTER_DISCONNECT_MS + 1000, + expirationTime); + + // Verify that network disconnect does not update the expiration time since the remaining + // lease duration is greater. + mWifiConfigManager.updateNetworkAfterDisconnect(config.networkId); + config = getFirstInternalWifiConfiguration(); + assertEquals(expirationTime, config.randomizedMacExpirationTimeMs); + + // Simulate time moving forward, then verify that a network disconnection updates the + // MAC address expiration time correctly. + when(mClock.getWallClockMillis()).thenReturn(5000L); + mWifiConfigManager.updateNetworkAfterDisconnect(config.networkId); + config = getFirstInternalWifiConfiguration(); + assertEquals(WifiConfigManager.AGGRESSIVE_MAC_WAIT_AFTER_DISCONNECT_MS + 5000, + config.randomizedMacExpirationTimeMs); + } + + /** * Verifies that the randomized MAC address is not updated when insufficient time have past * since the previous update. */ @@ -2165,12 +2193,12 @@ public class WifiConfigManagerTest extends WifiBaseTest { final MacAddress aggressiveMac = config.getRandomizedMacAddress(); assertNotEquals(WifiInfo.DEFAULT_MAC_ADDRESS, aggressiveMac.toString()); assertEquals(TEST_WALLCLOCK_CREATION_TIME_MILLIS - + WifiConfigManager.AGGRESSIVE_MAC_REFRESH_MS_DEFAULT, + + WifiConfigManager.AGGRESSIVE_MAC_WAIT_AFTER_DISCONNECT_MS, config.randomizedMacExpirationTimeMs); // verify that the randomized MAC is unchanged. when(mClock.getWallClockMillis()).thenReturn(TEST_WALLCLOCK_CREATION_TIME_MILLIS - + WifiConfigManager.AGGRESSIVE_MAC_REFRESH_MS_DEFAULT); + + WifiConfigManager.AGGRESSIVE_MAC_WAIT_AFTER_DISCONNECT_MS); MacAddress newMac = mWifiConfigManager.getRandomizedMacAndUpdateIfNeeded(config); assertEquals(aggressiveMac, newMac); } @@ -2191,6 +2219,7 @@ public class WifiConfigManagerTest extends WifiBaseTest { ssidList.add(c.SSID); mWifiConfigManager.setAggressiveMacRandomizationWhitelist(ssidList); NetworkUpdateResult result = verifyAddNetworkToWifiConfigManager(c); + mWifiConfigManager.updateNetworkAfterDisconnect(result.getNetworkId()); } /** |