From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Renlord Date: Sun, 8 Dec 2019 23:58:24 +0100 Subject: [PATCH] add option to always randomize MAC RANDOMIZATION_ALWAYS is set as the default option --- res/values/arrays.xml | 4 ++- .../WifiDetailPreferenceController.java | 3 +- .../WifiPrivacyPreferenceController.java | 31 ++++++++++++++----- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 0a9a9a31e8..6d95bcc58b 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -1239,7 +1239,8 @@ - Use randomized MAC (default) + Use fully randomized MAC (default) + Use per-network randomized MAC Use device MAC @@ -1255,6 +1256,7 @@ + 100 1 0 diff --git a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java index afcf883fb6..ce45108f22 100644 --- a/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java +++ b/src/com/android/settings/wifi/details/WifiDetailPreferenceController.java @@ -700,7 +700,8 @@ public class WifiDetailPreferenceController extends AbstractPreferenceController // return randomized MAC address if (mWifiConfig != null && - mWifiConfig.macRandomizationSetting == WifiConfiguration.RANDOMIZATION_PERSISTENT) { + (mWifiConfig.macRandomizationSetting == WifiConfiguration.RANDOMIZATION_PERSISTENT + || mWifiConfig.macRandomizationSetting == WifiConfiguration.RANDOMIZATION_ALWAYS)) { return mWifiConfig.getRandomizedMacAddress().toString(); } diff --git a/src/com/android/settings/wifi/details/WifiPrivacyPreferenceController.java b/src/com/android/settings/wifi/details/WifiPrivacyPreferenceController.java index 950cc131f4..1ed9646a7f 100644 --- a/src/com/android/settings/wifi/details/WifiPrivacyPreferenceController.java +++ b/src/com/android/settings/wifi/details/WifiPrivacyPreferenceController.java @@ -112,11 +112,12 @@ public class WifiPrivacyPreferenceController extends BasePreferenceController im if (mWifiConfiguration != null) { return mWifiConfiguration.macRandomizationSetting; } - return WifiConfiguration.RANDOMIZATION_PERSISTENT; + return WifiConfiguration.RANDOMIZATION_ALWAYS; } - private static final int PREF_RANDOMIZATION_PERSISTENT = 0; - private static final int PREF_RANDOMIZATION_NONE = 1; + private static final int PREF_RANDOMIZATION_ALWAYS = 0; + private static final int PREF_RANDOMIZATION_PERSISTENT = 1; + private static final int PREF_RANDOMIZATION_NONE = 2; /** * Returns preference index value. @@ -125,8 +126,16 @@ public class WifiPrivacyPreferenceController extends BasePreferenceController im * @return index value of preference */ public static int translateMacRandomizedValueToPrefValue(int macRandomized) { - return (macRandomized == WifiConfiguration.RANDOMIZATION_PERSISTENT) - ? PREF_RANDOMIZATION_PERSISTENT : PREF_RANDOMIZATION_NONE; + switch (macRandomized) { + case WifiConfiguration.RANDOMIZATION_ALWAYS: + return PREF_RANDOMIZATION_ALWAYS; + case WifiConfiguration.RANDOMIZATION_PERSISTENT: + return PREF_RANDOMIZATION_PERSISTENT; + case WifiConfiguration.RANDOMIZATION_NONE: + return PREF_RANDOMIZATION_NONE; + default: + return PREF_RANDOMIZATION_ALWAYS; + } } /** @@ -136,8 +145,16 @@ public class WifiPrivacyPreferenceController extends BasePreferenceController im * @return mac randomized value */ public static int translatePrefValueToMacRandomizedValue(int prefMacRandomized) { - return (prefMacRandomized == PREF_RANDOMIZATION_PERSISTENT) - ? WifiConfiguration.RANDOMIZATION_PERSISTENT : WifiConfiguration.RANDOMIZATION_NONE; + switch (prefMacRandomized) { + case PREF_RANDOMIZATION_ALWAYS: + return WifiConfiguration.RANDOMIZATION_ALWAYS; + case PREF_RANDOMIZATION_PERSISTENT: + return WifiConfiguration.RANDOMIZATION_PERSISTENT; + case PREF_RANDOMIZATION_NONE: + return WifiConfiguration.RANDOMIZATION_NONE; + default: + return WifiConfiguration.RANDOMIZATION_ALWAYS; + } } private void updateSummary(DropDownPreference preference, int macRandomized) {