From d3f7fa6aef24b39afd8dc332528f9c40bc68cd3d Mon Sep 17 00:00:00 2001 From: Etan Cohen Date: Sun, 19 Mar 2023 16:20:48 +0000 Subject: [PATCH] Force MAC randomization to enabled on ACTION_WIFI_ADD_NETWORKS The ACTION_WIFI_ADD_NETWORKS allows an app to request the user to confirm addition of WiFi networks. The intent attaches WifiNetworkSuggestions (used to specify the networks). However, the calling app may configure MAC randomization to be disabled - using reflection. Fix to always override the MAC randomization setting to enabled. This will override any user configuration to disable randomization - however, considering this is (now) a new configuration it should safely start from the default Setting. Verified using using a test app to force non-randomized (using reflection) value and confirm that without change randomization is disabled and that with change it is reset correctly. Bug: 236825742 Test: manual - use a test app Change-Id: I3fba958c461d88005fdb5d2c3d1f2fd4ce725b8c --- .../wifi/addappnetworks/AddAppNetworksFragment.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java b/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java index 63ab173d190..60031b02930 100644 --- a/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java +++ b/src/com/android/settings/wifi/addappnetworks/AddAppNetworksFragment.java @@ -655,6 +655,10 @@ public class AddAppNetworksFragment extends InstrumentedFragment implements try { mWifiManager.addOrUpdatePasspointConfiguration(passpointConfig); mAnyNetworkSavedSuccess = true; + + // (force) enable MAC randomization on new credentials + mWifiManager.setMacRandomizationSettingPasspointEnabled( + passpointConfig.getHomeSp().getFqdn(), true); } catch (IllegalArgumentException e) { mResultCodeArrayList.set(mUiToRequestedList.get(index).mIndex, RESULT_NETWORK_ADD_ERROR); @@ -669,6 +673,10 @@ public class AddAppNetworksFragment extends InstrumentedFragment implements final WifiConfiguration wifiConfiguration = mUiToRequestedList.get(index).mWifiNetworkSuggestion.getWifiConfiguration(); wifiConfiguration.SSID = addQuotationIfNeeded(wifiConfiguration.SSID); + + // (force) enable MAC randomization on new credentials + wifiConfiguration.setMacRandomizationSetting( + WifiConfiguration.RANDOMIZATION_PERSISTENT); mWifiManager.save(wifiConfiguration, mSaveListener); } }