RK:android5.1、android7.1便携式WLAN热点 记住State
Platform: RK3288
OS: Android 5.1
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 | diff --git a/frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiServiceImpl.java b/frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiServiceImpl.java old mode 100644 new mode 100755 index cc5824e..49d371a --- a/frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiServiceImpl.java @@ - 353 , 6 + 353 , 13 @@ public final class WifiServiceImpl extends IWifiManager.Stub { mWifiController.start(); + int wifiap_on = SystemProperties.getInt( "persist.sys.wifiapenable" , 0 ); + if (wifiap_on == 1 ) { + setWifiApEnabled(getWifiApConfiguration(), true ); + } else if (wifiEnabled){ + setWifiEnabled(wifiEnabled); + } + // If we are already disabled (could be due to airplane mode), avoid changing persist // state here if (wifiEnabled) setWifiEnabled(wifiEnabled); @@ - 725 , 6 + 732 , 12 @@ public final class WifiServiceImpl extends IWifiManager.Stub { } // null wifiConfig is a meaningful input for CMD_SET_AP if (wifiConfig == null || wifiConfig.isValid()) { + if (enabled){ + SystemProperties.set( "persist.sys.wifiapenable" , "1" ); + } else { + SystemProperties.set( "persist.sys.wifiapenable" , "0" ); + } + mWifiController.obtainMessage(CMD_SET_AP, enabled ? 1 : 0 , 0 , wifiConfig).sendToTarget(); } else { Slog.e(TAG, "Invalid WifiConfiguration" ); diff --git a/packages/apps/Settings/src/com/android/settings/TetherSettings.java b/packages/apps/Settings/src/com/android/settings/TetherSettings.java old mode 100644 new mode 100755 index e33ddb0..5a34a4a --- a/packages/apps/Settings/src/com/android/settings/TetherSettings.java +++ b/packages/apps/Settings/src/com/android/settings/TetherSettings.java @@ - 40 , 6 + 40 , 7 @@ import android.preference.Preference; import android.preference.PreferenceScreen; import android.preference.SwitchPreference; import android.widget.TextView; + import android.util.Log; import com.android.settings.wifi.WifiApDialog; import com.android.settings.wifi.WifiApEnabler; @@ - 308 , 6 + 309 , 15 @@ public class TetherSettings extends SettingsPreferenceFragment activity.registerReceiver(mTetherChangeReceiver, filter); if (intent != null ) mTetherChangeReceiver.onReceive(activity, intent); + if (mEnableWifiAp != null ) + { + if (SystemProperties.getInt( "persist.sys.wifiapenable" , 0 ) == 1 ) + { + mEnableWifiAp.setChecked( true ); + } else { + mEnableWifiAp.setChecked( false ); + } + } if (mWifiApEnabler != null ) { mEnableWifiAp.setOnPreferenceChangeListener( this ); mWifiApEnabler.resume(); @@ - 454 , 8 + 464 , 10 @@ public class TetherSettings extends SettingsPreferenceFragment boolean enable = (Boolean) value; if (enable) { + SystemProperties.set( "persist.sys.wifiapenable" , "1" ); startProvisioningIfNecessary(WIFI_TETHERING); } else { + SystemProperties.set( "persist.sys.wifiapenable" , "0" ); if (isProvisioningNeeded(mProvisionApp)) { TetherService.cancelRecheckAlarmIfNecessary(getActivity(), WIFI_TETHERING); } |
https://blog.csdn.net/weixin_39966398/article/details/103661656
Platform: RK3399
OS: Android 7.1.1
需求:开机默认打开wifi热点
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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | diff --git a/frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiServiceImpl.java b/frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiServiceImpl.java index 0f3e901..060563c 100644 --- a/frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/frameworks/opt/net/wifi/service/java/com/android/server/wifi/WifiServiceImpl.java @@ - 408 , 14 + 408 , 21 @@ public class WifiServiceImpl extends IWifiManager.Stub { public void checkAndStartWifi() { /* Check if wi-fi needs to be enabled */ ..... ..... ..... // Adding optimizations of only receiving broadcasts when wifi is enabled // can result in race conditions when apps toggle wifi in the background // without active user involvement. Always receive broadcasts. registerForBroadcasts(); registerForPackageOrUserRemoval(); mInIdleMode = mPowerManager.isDeviceIdleMode(); mWifiController.start(); + int wifiap_on = Settings.Global.getInt(mContext.getContentResolver(), Settings.Global.WIFIAP_ON, 0 ); + if (wifiap_on == 1 ) { + setWifiApEnabled(getWifiApConfiguration(), true ); + } else if (wifiEnabled){ + setWifiEnabled(wifiEnabled); + } } public void setWifiApEnabled(WifiConfiguration wifiConfig, boolean enabled) { enforceChangePermission(); ConnectivityManager.enforceTetherChangePermission(mContext); if (mUserManager.hasUserRestriction(UserManager.DISALLOW_CONFIG_TETHERING)) { throw new SecurityException( "DISALLOW_CONFIG_TETHERING is enabled for this user." ); } // null wifiConfig is a meaningful input for CMD_SET_AP if (wifiConfig == null || isValid(wifiConfig)) { + Settings.Global.putInt(mContext.getContentResolver(), Settings.Global.WIFIAP_ON, enabled ? 1 : 0 ); mWifiController.obtainMessage(CMD_SET_AP, enabled ? 1 : 0 , 0 , wifiConfig).sendToTarget(); } else { Slog.e(TAG, "Invalid WifiConfiguration" ); } } diff --git a/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java b/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java index 20b95b9..545af52 100644 --- a/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java +++ b/frameworks/base/packages/SettingsProvider/src/com/android/providers/settings/DatabaseHelper.java @@ - 2581 , 6 + 2581 , 9 @@ class DatabaseHelper extends SQLiteOpenHelper { private void loadGlobalSettings(SQLiteDatabase db) { ...... ...... loadBooleanSetting(stmt, Settings.Global.AIRPLANE_MODE_ON, R.bool.def_airplane_mode_on); + loadBooleanSetting(stmt, Settings.Global.WIFIAP_ON, + R.bool.def_wifiap_on); + loadBooleanSetting(stmt, Settings.Global.THEATER_MODE_ON, R.bool.def_theater_mode_on); diff --git a/frameworks/base/packages/SettingsProvider/res/values/defaults.xml b/frameworks/base/packages/SettingsProvider/res/values/defaults.xml index a2e0012..3cc42eb 100644 --- a/frameworks/base/packages/SettingsProvider/res/values/defaults.xml +++ b/frameworks/base/packages/SettingsProvider/res/values/defaults.xml @@ - 7 , 4 + 7 , 7 @@ + <!-- if true while boot_completed will start wifiap on --> + <bool name= "def_wifiap_on" > true </bool> diff --git a/frameworks/base/core/java/android/provider/Settings.java b/frameworks/base/core/java/android/provider/Settings.java index d8e8e45..82a50f3 100755 --- a/frameworks/base/core/java/android/provider/Settings.java +++ b/frameworks/base/core/java/android/provider/Settings.java @@ - 4249 , 7 + 4249 , 7 @@ public final class Settings { MOVED_TO_GLOBAL.add(Settings.Global.WIFI_ON); MOVED_TO_GLOBAL.add(Settings.Global.WIFI_P2P_DEVICE_NAME); MOVED_TO_GLOBAL.add(Settings.Global.WIFI_SAVED_STATE); + MOVED_TO_GLOBAL.add(Settings.Global.WIFIAP_ON); MOVED_TO_GLOBAL.add(Settings.Global.WIFI_SUPPLICANT_SCAN_INTERVAL_MS); MOVED_TO_GLOBAL.add(Settings.Global.WIFI_SUSPEND_OPTIMIZATIONS_ENABLED); MOVED_TO_GLOBAL.add(Settings.Global.WIFI_VERBOSE_LOGGING_ENABLED); @@ - 7764 , 7 + 7764 , 7 @@ public final class Settings { /** * Settings to allow BLE scans to be enabled even when Bluetooth is turned off for * connectivity. * @hide */ public static final String BLE_SCAN_ALWAYS_AVAILABLE = "ble_scan_always_enabled" ; + /** + * Used to save the WifiAP_ON State + * @hide + */ + public static final String WIFIAP_ON = "wifiap_on" ; |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 地球OL攻略 —— 某应届生求职总结
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 提示词工程——AI应用必不可少的技术
· .NET周刊【3月第1期 2025-03-02】