Android 13.0 Wi-Fi如何使用固定mac地址,禁用随机mac地址,以及framework 实现原理的分析

一、概述

最近在看android wifi mac地址相关的一些内容,发现网上对android 13的 wifi framework 层代码分析较少,因此写下了这篇关于wifi mac地址分析的文章。
文章主要包括以下几部分:

  • 如何禁用wifi的随机mac地址,使用wifi自带的固定mac地址。
  • 讲解wifi mac地址相关的代码,弄明白函数之间的调用关系。
  • 简单画了关于wifi mac地址的函数调用关系。

二、禁用随机mac地址的方法

关于mac地址,android 13有三种模式:

  • 使用出厂自带的mac地址。
  • 使用持久的随机mac地址。
  • 使用随机的mac地址,也是android 13默认的方式。

下面将以AP功能进行讲解。

1、 禁用随机mac地址,使用出厂自带的mac地址方法

这个比较简单,直接修改xml配置就可以了。
配置文件所在位置:packages/modules/Wifi/service/ServiceWifiResources/res/values/config.xml

	<!-- Indicates that AP mode MAC randomization is supported on this device -->            
<bool translatable="false" name="config_wifi_ap_mac_randomization_supported">true</bool>

直接将上面的true改为false,wifi 就会使用wifi自带的固定地址了。如下:

	<!-- Indicates that AP mode MAC randomization is supported on this device -->            
<bool translatable="false" name="config_wifi_ap_mac_randomization_supported">false</bool>

具体原理,后面会讲到。

2、使用持久化的随机mac地址方法

在WifiApConfigStore.java类中修改代码,修改的函数和内容如下:

/**                                                                                                 
¦* Return the current soft access point configuration.                                              
¦*/                                                                                                 
public synchronized SoftApConfiguration getApConfiguration() {
                                         
¦   if (mPersistentWifiApConfig == null) {
                                                             
¦   ¦   /* Use default configuration. */                                                            
¦   ¦   Log.d(TAG, "Fallback to use default AP configuration");                                     
¦   ¦   persistConfigAndTriggerBackupManagerProxy(                                                  
¦   ¦   ¦   ¦   updatePersistentRandomizedMacAddress(getDefaultApConfiguration()));                 
¦   }                                                                                               
¦   SoftApConfiguration sanitizedPersistentconfig =                                                 
¦   ¦   ¦   sanitizePersistentApConfig(mPersistentWifiApConfig);                                    
    //追加的代码 开始                                                                               
¦   SoftApConfiguration.Builder convertedConfigBuilder =                                            
¦   ¦   ¦   new SoftApConfiguration.Builder(sanitizedPersistentconfig);                             
    convertedConfigBuilder.setMacRandomizationSetting(SoftApConfiguration.RANDOMIZATION_PERSISTENT);
    sanitizedPersistentconfig = sanitizedPersistentconfig.build();                                  
    //追加的代码 结束                                                                               
¦   if (!Objects.equals(mPersistentWifiApConfig, sanitizedPersistentconfig)) {
                         
¦   ¦   Log.d(TAG, "persisted config was converted, need to resave it");                            
¦   ¦   persistConfigAndTriggerBackupManagerProxy(sanitizedPersistentconfig);                       
¦   }                                                                                               
                                                                                                    
¦   if (mForceApChannel) {
                                                                             
¦   ¦   Log.d(TAG, "getApConfiguration: Band force to " + mForcedApBand                             
¦   ¦   ¦   ¦   + ", and channel force to " + mForcedApChannel);                                    
¦   ¦   return mForcedApChannel == 0                                                                
¦   ¦   ¦   ¦   ? new SoftApConfiguration.Builder(mPersistentWifiApConfig)                          
¦   ¦   ¦   ¦   ¦   ¦   .setBand(mForcedApBand).build()                                             
¦   ¦   ¦   ¦   : new SoftApConfiguration.Builder(mPersistentWifiApConfig)                          
¦   ¦   ¦   ¦   ¦   ¦   .setChannel(mForcedApChannel, mForcedApBand).build();                       
¦   }                                                                       
  • 53
    点赞
  • 49
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值