diff options
author | TreeHugger Robot <treehugger-gerrit@google.com> | 2019-07-11 21:51:20 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2019-07-11 21:51:20 +0000 |
commit | 227fefbd539e3e0b8f183e3b6fac1b3aea4409a2 (patch) | |
tree | 1a6594f6cb81a814691da10753a232571592a229 | |
parent | a8153646b0c113f2cb5bcc1c565e9998c4f125f2 (diff) | |
parent | 608b03f29d70b6d9055f349dcf194fae0248c9bb (diff) |
Merge "Mask out macRandomizationSetting when feature is unsupported" into qt-r1-dev
-rw-r--r-- | service/java/com/android/server/wifi/WifiConfigManager.java | 6 | ||||
-rw-r--r-- | tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java | 39 |
2 files changed, 45 insertions, 0 deletions
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java index 1d287f02d..bda1eb7d2 100644 --- a/service/java/com/android/server/wifi/WifiConfigManager.java +++ b/service/java/com/android/server/wifi/WifiConfigManager.java @@ -271,6 +271,7 @@ public class WifiConfigManager { private final WifiPermissionsUtil mWifiPermissionsUtil; private final WifiPermissionsWrapper mWifiPermissionsWrapper; private final WifiInjector mWifiInjector; + private boolean mConnectedMacRandomzationSupported; /** * Local log used for debugging any WifiConfigManager issues. @@ -437,6 +438,8 @@ public class WifiConfigManager { } }); updatePnoRecencySortingSetting(); + mConnectedMacRandomzationSupported = mContext.getResources() + .getBoolean(R.bool.config_wifi_connected_mac_randomization_supported); try { mSystemUiUid = mContext.getPackageManager().getPackageUidAsUser(SYSUI_PACKAGE_NAME, PackageManager.MATCH_SYSTEM_ONLY, UserHandle.USER_SYSTEM); @@ -541,6 +544,9 @@ public class WifiConfigManager { && targetUid != configuration.creatorUid) { maskRandomizedMacAddressInWifiConfiguration(network); } + if (!mConnectedMacRandomzationSupported) { + network.macRandomizationSetting = WifiConfiguration.RANDOMIZATION_NONE; + } return network; } diff --git a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java index 3b86be887..686b2098d 100644 --- a/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java +++ b/tests/wifitests/src/com/android/server/wifi/WifiConfigManagerTest.java @@ -164,6 +164,7 @@ public class WifiConfigManagerTest { mResources.setInteger( R.integer.config_wifi_framework_associated_partial_scan_max_num_active_channels, TEST_MAX_NUM_ACTIVE_CHANNELS_FOR_PARTIAL_SCAN); + mResources.setBoolean(R.bool.config_wifi_connected_mac_randomization_supported, true); when(mContext.getResources()).thenReturn(mResources); // Setup UserManager profiles for the default user. @@ -1940,6 +1941,44 @@ public class WifiConfigManagerTest { } /** + * Verifies that macRandomizationSetting is not masked out when MAC randomization is supported. + */ + @Test + public void testGetConfiguredNetworksNotMaskMacRandomizationSetting() { + WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork(); + NetworkUpdateResult result = verifyAddNetworkToWifiConfigManager(config); + + MacAddress testMac = MacAddress.createRandomUnicastAddress(); + mWifiConfigManager.setNetworkRandomizedMacAddress(result.getNetworkId(), testMac); + + // Verify macRandomizationSetting is not masked out when feature is supported. + List<WifiConfiguration> configs = mWifiConfigManager.getSavedNetworks(Process.WIFI_UID); + assertEquals(1, configs.size()); + assertEquals(WifiConfiguration.RANDOMIZATION_PERSISTENT, + configs.get(0).macRandomizationSetting); + } + + /** + * Verifies that macRandomizationSetting is masked out to WifiConfiguration.RANDOMIZATION_NONE + * when MAC randomization is not supported on the device. + */ + @Test + public void testGetConfiguredNetworksMasksMacRandomizationSetting() { + mResources.setBoolean(R.bool.config_wifi_connected_mac_randomization_supported, false); + createWifiConfigManager(); + WifiConfiguration config = WifiConfigurationTestUtil.createOpenNetwork(); + NetworkUpdateResult result = verifyAddNetworkToWifiConfigManager(config); + + MacAddress testMac = MacAddress.createRandomUnicastAddress(); + mWifiConfigManager.setNetworkRandomizedMacAddress(result.getNetworkId(), testMac); + + // Verify macRandomizationSetting is masked out when feature is unsupported. + List<WifiConfiguration> configs = mWifiConfigManager.getSavedNetworks(Process.WIFI_UID); + assertEquals(1, configs.size()); + assertEquals(WifiConfiguration.RANDOMIZATION_NONE, configs.get(0).macRandomizationSetting); + } + + /** * Verifies that passwords are masked out when we return external configs except when * explicitly asked for them. */ |