• 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
    
    • 1
    • 2
    core/res/res/values/config.xml:751:    <bool translatable="false" name="config_wifi_connected_mac_randomization_supported">true</bool>
    
    • 1

    默认为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>
    
    • 1
    • 2
    • 3

    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*/;
         }
     
         /**
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
  • 相关阅读:
    计算机毕业设计Java医疗机构药房管理系统软件开发(源码+系统+mysql数据库+lw文档)
    01、Docker入门
    学懂C++ (十九):高级教程——深入详解C++信号处理
    SOME/IP 支持两种序列化方式:TLV 和 TV
    【数据库】E-R图相关知识、绘制方法及工具推荐
    keras-gpu安装
    如何将vscode和Linux远程链接:
    微信小程序的开发---tabBar的介绍
    双向链表遍历以及增删改查操作(思路分析) [数据结构][Java]
    SDL2 播放音频数据(PCM)
  • 原文地址:https://blog.csdn.net/nq1737274479/article/details/136630584