105 lines
5.1 KiB
Diff
105 lines
5.1 KiB
Diff
From b859c277fbdfaec867f671c0a81fe973a66f954d Mon Sep 17 00:00:00 2001
|
|
From: harvey186 <harvey186@hotmail.com>
|
|
Date: Tue, 19 Dec 2023 11:49:18 +0100
|
|
Subject: [PATCH] Random_MAC
|
|
|
|
Change-Id: I4d36c2614db995153a4079a27e22d2351f6d47e0
|
|
---
|
|
framework/api/current.txt | 1 +
|
|
.../java/android/net/wifi/WifiConfiguration.java | 12 +++++++++---
|
|
.../com/android/server/wifi/WifiConfigManager.java | 6 +++++-
|
|
.../android/server/wifi/WifiConfigurationUtil.java | 2 +-
|
|
4 files changed, 16 insertions(+), 5 deletions(-)
|
|
|
|
diff --git a/framework/api/current.txt b/framework/api/current.txt
|
|
index abed5b1a93..e6a839a2f4 100644
|
|
--- a/framework/api/current.txt
|
|
+++ b/framework/api/current.txt
|
|
@@ -172,6 +172,7 @@ package android.net.wifi {
|
|
method public void writeToParcel(android.os.Parcel, int);
|
|
field @Deprecated public String BSSID;
|
|
field @Deprecated public String FQDN;
|
|
+ field @Deprecated public static final int RANDOMIZATION_ALWAYS = 100; // 0x64
|
|
field @Deprecated public static final int RANDOMIZATION_AUTO = 3; // 0x3
|
|
field @Deprecated public static final int RANDOMIZATION_NONE = 0; // 0x0
|
|
field @Deprecated public static final int RANDOMIZATION_NON_PERSISTENT = 2; // 0x2
|
|
diff --git a/framework/java/android/net/wifi/WifiConfiguration.java b/framework/java/android/net/wifi/WifiConfiguration.java
|
|
index 0bea151452..90e5bbba64 100644
|
|
--- a/framework/java/android/net/wifi/WifiConfiguration.java
|
|
+++ b/framework/java/android/net/wifi/WifiConfiguration.java
|
|
@@ -1793,7 +1793,8 @@ public class WifiConfiguration implements Parcelable {
|
|
RANDOMIZATION_NONE,
|
|
RANDOMIZATION_PERSISTENT,
|
|
RANDOMIZATION_NON_PERSISTENT,
|
|
- RANDOMIZATION_AUTO})
|
|
+ RANDOMIZATION_AUTO,
|
|
+ RANDOMIZATION_ALWAYS})
|
|
public @interface MacRandomizationSetting {}
|
|
|
|
/**
|
|
@@ -1816,17 +1817,22 @@ public class WifiConfiguration implements Parcelable {
|
|
* Let the wifi framework automatically decide the MAC randomization strategy.
|
|
*/
|
|
public static final int RANDOMIZATION_AUTO = 3;
|
|
+
|
|
+ /**
|
|
+ * Generate a randomize MAC always
|
|
+ */
|
|
+ public static final int RANDOMIZATION_ALWAYS = 100;
|
|
|
|
/**
|
|
* Level of MAC randomization for this network.
|
|
* One of {@link #RANDOMIZATION_NONE}, {@link #RANDOMIZATION_AUTO},
|
|
* {@link #RANDOMIZATION_PERSISTENT} or {@link #RANDOMIZATION_NON_PERSISTENT}.
|
|
- * By default this field is set to {@link #RANDOMIZATION_AUTO}.
|
|
+ * {@link #RANDOMIZATION_PERSISTENT} or {@link #RANDOMIZATION_NON_PERSISTENT} or RANDOMIZATION_ALWAYS.
|
|
* @hide
|
|
*/
|
|
@SystemApi
|
|
@MacRandomizationSetting
|
|
- public int macRandomizationSetting = RANDOMIZATION_AUTO;
|
|
+ public int macRandomizationSetting = RANDOMIZATION_ALWAYS;
|
|
|
|
/**
|
|
* Set the MAC randomization setting for this network.
|
|
diff --git a/service/java/com/android/server/wifi/WifiConfigManager.java b/service/java/com/android/server/wifi/WifiConfigManager.java
|
|
index 373efbe724..370ac3402b 100644
|
|
--- a/service/java/com/android/server/wifi/WifiConfigManager.java
|
|
+++ b/service/java/com/android/server/wifi/WifiConfigManager.java
|
|
@@ -466,6 +466,9 @@ public class WifiConfigManager {
|
|
* @return
|
|
*/
|
|
public boolean shouldUseNonPersistentRandomization(WifiConfiguration config) {
|
|
+ if (config.macRandomizationSetting == WifiConfiguration.RANDOMIZATION_ALWAYS) {
|
|
+ return true;
|
|
+ }
|
|
if (!isMacRandomizationSupported()
|
|
|| config.macRandomizationSetting == WifiConfiguration.RANDOMIZATION_NONE) {
|
|
return false;
|
|
@@ -615,7 +618,8 @@ public class WifiConfigManager {
|
|
private MacAddress updateRandomizedMacIfNeeded(WifiConfiguration config) {
|
|
boolean shouldUpdateMac = config.randomizedMacExpirationTimeMs
|
|
< mClock.getWallClockMillis() || mClock.getWallClockMillis()
|
|
- - config.randomizedMacLastModifiedTimeMs >= NON_PERSISTENT_MAC_REFRESH_MS_MAX;
|
|
+ - config.randomizedMacLastModifiedTimeMs >= NON_PERSISTENT_MAC_REFRESH_MS_MAX ||
|
|
+ config.macRandomizationSetting == WifiConfiguration.RANDOMIZATION_ALWAYS;
|
|
if (!shouldUpdateMac) {
|
|
return config.getRandomizedMacAddress();
|
|
}
|
|
diff --git a/service/java/com/android/server/wifi/WifiConfigurationUtil.java b/service/java/com/android/server/wifi/WifiConfigurationUtil.java
|
|
index d5de4191b0..95d1b377fb 100644
|
|
--- a/service/java/com/android/server/wifi/WifiConfigurationUtil.java
|
|
+++ b/service/java/com/android/server/wifi/WifiConfigurationUtil.java
|
|
@@ -258,7 +258,7 @@ public class WifiConfigurationUtil {
|
|
public static boolean hasMacRandomizationSettingsChanged(WifiConfiguration existingConfig,
|
|
WifiConfiguration newConfig) {
|
|
if (existingConfig == null) {
|
|
- return newConfig.macRandomizationSetting != WifiConfiguration.RANDOMIZATION_AUTO;
|
|
+ return newConfig.macRandomizationSetting != WifiConfiguration.RANDOMIZATION_ALWAYS;
|
|
}
|
|
return newConfig.macRandomizationSetting != existingConfig.macRandomizationSetting;
|
|
}
|
|
--
|
|
2.34.1
|
|
|