当前位置:   article > 正文

Android13 热点默认5G频道配置修改_android 系统 wifi ap热点功能配置方式_android13 hotspot band

android13 hotspot band

最后

跳槽季整理面试题已经成了我多年的习惯!在这里我和身边一些朋友特意整理了一份快速进阶为Android高级工程师的系统且全面的学习资料。涵盖了Android初级——Android高级架构师进阶必备的一些学习技能。

附上:我们之前因为秋招收集的二十套一二线互联网公司Android面试真题(含BAT、小米、华为、美团、滴滴)和我自己整理Android复习笔记(包含Android基础知识点、Android扩展知识点、Android源码解析、设计模式汇总、Gradle知识点、常见算法题汇总。)

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化学习资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

Android13 热点默认5G频道配置修改

文章目录

一、前言

Android开发中经常要设置默认热点,名称,热点密码,是否是5G频段。

之前也有对默认名称和密码进行分析的文章,但是热点频道没怎么看,热点频段对传输性能还是比较重要的,有的平台默认就要5G,查看代码发现默认是2.4G热点。

本文对 Android 默认热点5G频段配置 进行分析。

配置热点信息后,会生成热点配置文件:

wifi信息保存位置:
/data/misc/apexdata/com.android.wifi/WifiConfigStore.xml

热点信息保存位置:
/data/misc/apexdata/com.android.wifi/WifiConfigStoreSoftAp.xml

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

热点的信息文件包含了:热点名称,热点密码,热点频段和信道值等基本信息;

wifi 的信息文件包含了:连接过的wifi名称,密码,MAC地址等信息。

二、修改默认配置

1、代码中修改默认配置

系统中热点默认配置信息对象 WifiApConfigStore.java

实现思路:

在默认配置方法getDefaultApConfiguration() 中设置默认信息即可。

packages\modules\Wifi\service\java\com\android\server\wifi\WifiApConfigStore.java

import android.os.SystemProperties; //添加prop属性

public class WifiApConfigStore {

 
    private static final String TAG = "WifiApConfigStore";
	
	//(1)获取默认配置信息方法,该方法在系统无法检测到默认配置文件时会生成
	//系统第一次运行时会执行到,还有就是把系统热点配置文件删除后再重启也是会执行到
	private SoftApConfiguration getDefaultApConfiguration() {
        SoftApConfiguration.Builder configBuilder = new SoftApConfiguration.Builder();
        //configBuilder.setBand(generateDefaultBand(mContext)); //(2)原来的逻辑。2.4G热点
        //(3)加个打印,查看默认的频段值
        Log.d(TAG, "getDefaultApConfiguration generateDefaultBand = " + generateDefaultBand(mContext));
        
        //(4)设置默认5G的一段逻辑,添加prop属性进行判断
        boolean isDefault5G = SystemProperties.getBoolean("persist.sys.mydebug.hotspot_default_5G", true);
        Log.d(TAG, "getDefaultApConfiguration isDefault5G = " + isDefault5G);
        if (isDefault5G) {
        	// (5)判断是否支持5G,设置5G band 和 36 信道值。
            if (ApConfigUtil.isBandSupported(SoftApConfiguration.BAND_5GHZ, mContext)) {
                Log.d(TAG, "getDefaultApConfiguration set band = 5G");
                configBuilder.setChannel(36, SoftApConfiguration.BAND_5GHZ);
            } else {
                Log.d(TAG, "getDefaultApConfiguration set band = 2G");
                configBuilder.setChannel(3, SoftApConfiguration.BAND_2GHZ);
            }
        } else { // (6)如果设置prop属性为 false,还是原来的逻辑
            configBuilder.setBand(generateDefaultBand(mContext));
        }

		//(7)默认名称,AndroidAP_四位随机数
        configBuilder.setSsid(mContext.getResources().getString(
                R.string.wifi_tether_configure_ssid_default) + "_" + getRandomIntForDefaultSsid());
        
        //(8)热点加密形式,默认不支持wpa3,加密类型:WPA2_PSK
        if (ApConfigUtil.isWpa3SaeSupported(mContext)) {
            configBuilder.setPassphrase(generatePassword(),
                    SECURITY_TYPE_WPA3_SAE_TRANSITION);
        } else {
            configBuilder.setPassphrase(generatePassword(),
                    SECURITY_TYPE_WPA2_PSK);
        }

        //(9)桥接模式,默认不支持
        if (ApConfigUtil.isBridgedModeSupported(mContext)) {
            if (SdkLevel.isAtLeastS()) {
                int[] dual_bands = new int[] {
                        SoftApConfiguration.BAND_2GHZ,
                        SoftApConfiguration.BAND_2GHZ | SoftApConfiguration.BAND_5GHZ};
                configBuilder.setBands(dual_bands);
            }
        }

        // Update default MAC randomization setting to NONE when feature doesn't support it.	//(10)MAC地址随机,默认为true,但这里方法没进
        if (!ApConfigUtil.isApMacRandomizationSupported(mContext)) {
            if (SdkLevel.isAtLeastS()) {
                configBuilder.setMacRandomizationSetting(SoftApConfiguration.RANDOMIZATION_NONE);
            }
        }

        configBuilder.setUserConfiguration(false);
        //(11)根据信息构建 WifiApConfigStore 对象
        return configBuilder.build();
    }
    
    
    //(12)获取默认频段,BAND_TYPES:2G,5G,6G
    public static @BandType int generateDefaultBand(Context context) {
        for (int band : SoftApConfiguration.BAND_TYPES) {
            //(13)这里判断首先是否支持2.4G,支持直接返回了,并未进行后续判断。所以默认是2.4G热点!
            if (ApConfigUtil.isBandSupported(band, context)) {
                return band;
            }
        }
        Log.e(TAG, "Invalid overlay configuration! No any band supported on SoftAp");
        return SoftApConfiguration.BAND_2GHZ;
    }
    
}

  • 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
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81

上面的 getDefaultApConfiguration() 方法只是系统第一次运行会执行到,并且把获取的默认信息保存到本地配置文件,后续打开过后已经存在信息配置文件就不会再调用获取默认配置的方法了,而是从本地保存的配置文件信息里面获取数据,每次手动保存的数据也是会保存到本地配置文件中的。

更多热点信息可以查看 WifiApConfigStore.java具体代码 。

2、保存默认配置文件设置默认5G频段配置

在系统源码某个mk文件添加文件复制代码:

#set default ap config
PRODUCT_COPY_FILES += \
xxx/WifiConfigStoreSoftAp.xml:data/misc/apexdata/com.android.wifi/WifiConfigStoreSoftAp.xml

  • 1
  • 2
  • 3
  • 4

在源码xxx路径文件 WifiConfigStoreSoftAp.xml,编译到运行系统的对应目录。

热点配置文件完整信息示例:
console:/ # cat data/misc/apexdata/com.android.wifi/WifiConfigStoreSoftAp.xml
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<WifiConfigStoreData>
<int name="Version" value="3" />
<SoftAp>
<string name="WifiSsid">&quot;AndroidAP_5409&quot;</string>
<boolean name="HiddenSSID" value="false" />
<int name="SecurityType" value="1" />
<string name="Passphrase">844qwtdw</string>
<int name="MaxNumberOfClients" value="0" />
<boolean name="ClientControlByUser" value="false" />
<boolean name="AutoShutdownEnabled" value="true" />
<long name="ShutdownTimeoutMillis" value="-1" />
<BlockedClientList />
<AllowedClientList />
<boolean name="BridgedModeOpportunisticShutdownEnabled" value="true" />
<int name="MacRandomizationSetting" value="2" />
<BandChannelMap>
<BandChannel>
<int name="Band" value="2" />
<int name="Channel" value="36" />
</BandChannel>
</BandChannelMap>
<boolean name="80211axEnabled" value="true" />
<boolean name="UserConfiguration" value="true" />
<long name="BridgedModeOpportunisticShutdownTimeoutMillis" value="-1" />
<VendorElements />
<boolean name="80211beEnabled" value="true" />
<string name="PersistentRandomizedMacAddress">82:d0:fe:82:e1:d0</string>
</SoftAp>
</WifiConfigStoreData>
console:/ # 

  • 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

可以根据自己需求对部分信息进行修改。

编译系统后,直接打开热点就是按照上面的配置信息传给底层的;

应用调用了设置热点配置方法,配置信息也是会保存到 WifiConfigStoreSoftAp.xml 文件的,

后续热点打开都是 WifiConfigStoreSoftAp.xml 的配置信息。

下面的是特殊场景,设置特定热点配置信息,

不管本地配置文件和应用怎么设置,最终热点都是以特定的配置打开。

3、代码中强制设置配置信息

不管应用怎么设置,系统实际生效都是特定的配置,

虽然现实中可能这样的场景比较少,但是万一有呢?

所以还是给大家介绍一下。

(1)在关键流程设置
热点开启和关闭代码:
ConnectivityManager mConnectivityManager = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);

//开启
mConnectivityManager.startTethering(ConnectivityManager.TETHERING_WIFI, true,
mOnStartTetheringCallback, new Handler(Looper.getMainLooper()));

//关闭
mConnectivityManager.stopTethering(ConnectivityManager.TETHERING_WIFI);


  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

如果需要实现这个就要对Android 热点设置的流程 比较熟悉了,具体在哪个类进行适配可以呢?

热点启动流程
(1)ConnectivityManager.startTethering
(2)TetheringManager.startTethering(request, executor, tetheringCallback)
(3)TetheringService.TetheringConnector.startTethering
(4)Tethering.startTethering(request, listener);
//方法名变化,使用null 对象开启热点
(5)WifiManager.startTetheredHotspot(null /* use existing softap config */)
(6)WifiServiceImpl.startTetheredHotspot(@Nullable SoftApConfiguration softApConfig) 


最后看一下学习需要的所有知识点的思维导图。在刚刚那份学习笔记里包含了下面知识点所有内容!文章里已经展示了部分!如果你正愁这块不知道如何学习或者想提升学习这块知识的学习效率,那么这份学习笔记绝对是你的秘密武器!

![](https://img-blog.csdnimg.cn/img_convert/9f63233f34cc8af66386c63c3850bb1a.webp?x-oss-process=image/format,png)




**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**[需要这份系统化学习资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618156601)**

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

何学习或者想提升学习这块知识的学习效率,那么这份学习笔记绝对是你的秘密武器!

[外链图片转存中...(img-yfKiuhaY-1715164379234)]




**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**

**[需要这份系统化学习资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618156601)**

**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**

  • 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
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/运维做开发/article/detail/962251
推荐阅读
相关标签
  

闽ICP备14008679号