Android10禁用wifi随机mac地址,固定mac地址

1、写在前面,为什么固定?因为在Android设备未连接网络时,会使用随机mac地址,如果想ota升级,不固定mac地址会导致风险。

2、控制wifi是否为随机mac地址功能的核心代码

frameworks/base/core/res/res/values/config.xml
packages/apps/Settings/src/com/android/settings/wifi/WifiConfigController.java
core/res/res/values/config.xml:751:    <bool translatable="false" name="config_wifi_connected_mac_randomization_supported">true</bool>

默认为ture 修改为false

grep一下如果有这几个文件,也需要改为false:

device/google/wahoo/overlay/frameworks/base/core/res/res/values/config.xml:370:    <bool name="config_wifi_connected_mac_randomization_supported">true</bool>
device/google/crosshatch/overlay/frameworks/base/core/res/res/values/config.xml:449:    <bool name="config_wifi_connected_mac_randomization_supported">true</bool>
device/google/bonito/overlay/frameworks/base/core/res/res/values/config.xml:412:    <bool name="config_wifi_connected_mac_randomization_supported">true</bool>

3、在初始化的时候进行修改

diff --git a/packages/apps/Settings/src/com/android/settings/wifi/WifiConfigController.java b/packages/apps/Settings/src/com/android/settings/wifi/WifiConfigController.java
old mode 100644 (file)
new mode 100755 (executable)
index 88f6c3e..9baa158
--- a/packages/apps/Settings/src/com/android/settings/wifi/WifiConfigController.java
+++ b/packages/apps/Settings/src/com/android/settings/wifi/WifiConfigController.java
@@ -449,8 +449,8 @@ public class WifiConfigController implements TextWatcher,
         if (!isSplitSystemUser()) {
             mSharedCheckBox.setVisibility(View.GONE);
         }
-
+        mPrivacySettingsSpinner.setSelection(1);
         mConfigUi.setCancelButton(res.getString(R.string.wifi_cancel));
         if (mConfigUi.getSubmitButton() != null) {
             enableSubmitIfAppropriate();

--- a/packages/apps/Settings/src/com/android/settings/wifi/details/WifiPrivacyPreferenceController.java
+++ b/packages/apps/Settings/src/com/android/settings/wifi/details/WifiPrivacyPreferenceController.java
@@ -93,8 +93,9 @@ public class WifiPrivacyPreferenceController extends BasePreferenceController im
 
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
+               android.util.Log.e("privacy","newValue:"+(String) newValue);
         if (mWifiConfiguration != null) {
-            mWifiConfiguration.macRandomizationSetting = Integer.parseInt((String) newValue);
+            mWifiConfiguration.macRandomizationSetting = 1/*Integer.parseInt((String) newValue)*/;
             mWifiManager.updateNetwork(mWifiConfiguration);
 
             // To activate changing, we need to reconnect network. WiFi will auto connect to
@@ -103,7 +104,7 @@ public class WifiPrivacyPreferenceController extends BasePreferenceController im
                 mWifiManager.disconnect();
             }
         }
-        updateSummary((DropDownPreference) preference, Integer.parseInt((String) newValue));
+        updateSummary((DropDownPreference) preference, 1/*Integer.parseInt((String) newValue)*/);
         return true;
     }
 
@@ -125,9 +126,9 @@ 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;
+        return 1/*(macRandomized == WifiConfiguration.RANDOMIZATION_PERSISTENT)
+            ? PREF_RANDOMIZATION_PERSISTENT : PREF_RANDOMIZATION_NONE*/;
     }
 
     /**

你可能感兴趣的:(Android,ROM,定制,Java,安卓应用学习,android,rom定制,framework)