文章目录
- 开发平台基本信息
- 问题描述
- 解决方法
 
开发平台基本信息
芯片: MT8766
 版本: Android 12
 kernel: msm-4.19
问题描述
之前有个需求要设备默认开启WIFI热点,默认开启usb共享网络;而热点在原生的设定里面有个超时机制,如果在限定时间内,没有任何设备连接共享出来的网络,则会自动关闭热点。但是,客户的需求是一直保持共享网络开启。
解决方法
热点超时时间是读取config文件中config_wifiFrameworkSoftApShutDownTimeoutMilliseconds的值;这个在低版本是写在framework目录下;而在Android12中,则是放在了packages/modules/Wifi/service/ServiceWifiResources/res/values/config.xml;默认值是
 600000;也就是10分钟;所以,改大这个默认值也可以实现默认不关闭,但是,最大也就是int类型的最大值2147483647;大概是10天左右。
- 还有一种做法,就是在触发超时关闭共享网络的地方,跳过关闭的步骤,具体实现如下:
--- a/packages/modules/Wifi/service/java/com/android/server/wifi/SoftApManager.java
+++ b/packages/modules/Wifi/service/java/com/android/server/wifi/SoftApManager.java
@@ -1424,21 +1424,21 @@ public class SoftApManager implements ActiveModeManager {// Already started, ignore this command.break;case CMD_NO_ASSOCIATED_STATIONS_TIMEOUT:
-                        if (!mTimeoutEnabled) {
-                            Log.wtf(getTag(), "Timeout message received while timeout is disabled."
-                                    + " Dropping.");
-                            break;
-                        }
-                        if (getConnectedClientList().size() != 0) {
-                            Log.wtf(getTag(), "Timeout message received but has clients. "
-                                    + "Dropping.");
-                            break;
-                        }
-                        mSoftApNotifier.showSoftApShutdownTimeoutExpiredNotification();
-                        Log.i(getTag(), "Timeout message received. Stopping soft AP.");
-                        updateApState(WifiManager.WIFI_AP_STATE_DISABLING,
-                                WifiManager.WIFI_AP_STATE_ENABLED, 0);
-                        quitNow();
+                        // if (!mTimeoutEnabled) {
+                        //     Log.wtf(getTag(), "Timeout message received while timeout is disabled."
+                        //             + " Dropping.");
+                        //     break;
+                        // }
+                        // if (getConnectedClientList().size() != 0) {
+                        //     Log.wtf(getTag(), "Timeout message received but has clients. "
+                        //             + "Dropping.");
+                        //     break;
+                        // }
+                        // mSoftApNotifier.showSoftApShutdownTimeoutExpiredNotification();
+                        // Log.i(getTag(), "Timeout message received. Stopping soft AP.");
+                        // updateApState(WifiManager.WIFI_AP_STATE_DISABLING,
+                        //         WifiManager.WIFI_AP_STATE_ENABLED, 0);
+                        // quitNow();break;case CMD_NO_ASSOCIATED_STATIONS_TIMEOUT_ON_ONE_INSTANCE:if (!isBridgedMode() || mCurrentSoftApInfoMap.size() != 2) {