3588 记忆热点开关状态功能
- 需求:原系统在开启热点后重启,热点不会保持开启状态,需要增加热点开关状态的记忆功能。
运行环境
Android13 RK3588
思路
添加一个安卓属性标记热点的开关状态,找到热点的开启和关闭函数,在其中对属性赋值,开机时根据该属性设置热点开关。 比如点击开启热点时,赋值属性为热点开状态,开机时检测到属性为热点开状态,则设置热点开启。
logcat定位
- 日志标记(TAG) → 定位Java类
- Tethering(网络共享)
- SoftAp(热点)
- hostapd(热点后台守护进程)
- wlan0(无线接口)
- WifiService(Wi-Fi系统服务)
- 日志消息(Message) → 定位具体函数
- 进程/线程ID → 定位执行上下文
在logcat状态下,点击关闭热点,抓到相关日志如下:
05-28 15:32:21.856 55 55 I rk_hdmirx fdee0000.hdmirx-controller: hdmirx_audio_interrupts_setup: 1
05-28 15:32:21.929 886 886 I TetheringManager: stopTethering caller:com.android.settings
05-28 15:32:21.929 539 810 I WifiService: stopSoftAp uid=1000
05-28 15:32:21.930 539 692 D WifiActiveModeWarden: Shutting down all softap mode managers in mode 1
05-28 15:32:21.930 539 692 D SoftApManager[wlan0]: currentstate: StartedState
05-28 15:32:21.930 539 810 I Tethering: [EntitlementManager] removeDownstreamMapping: 0
05-28 15:32:21.931 539 692 D WifiDiags: stopLogging() iface list is {} after removing wlan0
05-28 15:32:21.931 379 379 I WifiHAL : Successfully removed event handler 0xb400006eeeb56710:0x6dca866674 for vendor 0x1a11, subcmd 0xb from 1
05-28 15:32:21.931 379 379 D WifiHAL : Success to clear alerthandler
05-28 15:32:21.932 539 692 E WifiVendorHal: resetLogHandler(l.2252) failed {.code = ERROR_NOT_AVAILABLE, .description = }
05-28 15:32:21.932 539 692 W WifiDiags: Fail to reset log handler
05-28 15:32:21.933 379 379 I WifiHAL : wifi_virtual_interface_delete: wlan0 is static iface, skip delete
05-28 15:32:21.933 379 379 I [email protected]: Adding interface handle for wlan0
05-28 15:32:21.933 379 379 W [email protected]: No active wlan interfaces in use! Using default
05-28 15:32:21.933 360 2107 D modules.primary.audio_hal: start_output_stream:1268 out = 0xf25c4a50,device = 0x2,outputs[OUTPUT_HDMI_MULTI] = 0x0
05-28 15:32:21.933 360 2107 D modules.primary.audio_hal: card0 id:rockchiphdmiin
05-28 15:32:21.934 360 2107 D modules.primary.audio_hal: card1 id:rockchipes8316c
05-28 15:32:21.934 360 2107 D modules.primary.audio_hal: card2 id:rockchiphdmi0
05-28 15:32:21.934 360 2107 D modules.primary.audio_hal: dump out device info
05-28 15:32:21.934 360 2107 D modules.primary.audio_hal: dev_info SPEAKER card=1, device:0
05-28 15:32:21.934 360 2107 D modules.primary.audio_hal: dev_info HDMI card=2, device:0
05-28 15:32:21.934 2291 2291 I hostapd : Remove interface 'wlan0'
05-28 15:32:21.934 360 2107 D modules.primary.audio_hal: start_output_stream: i = 0, device = 0x2
05-28 15:32:21.934 360 2107 E modules.primary.audio_hal: ben mode test!
05-28 15:32:21.934 2291 2291 I hostapd : wlan0: interface state ENABLED->DISABLED
05-28 15:32:21.934 360 2107 D alsa_route: route_info->sound_card 0, route_info->devices 0
05-28 15:32:21.934 360 2107 E alsa_mixer: mixer_open() get tlv for control Headphone Playback Volume fail
05-28 15:32:21.934 360 2107 D alsa_route: route_set_controls() set route 0
05-28 15:32:21.936 360 2107 E modules.primary.audio_hal: ben... card num. 8000, 1
05-28 15:32:21.936 360 2107 E modules.primary.audio_hal: ben1... invalid card num. 0,5
05-28 15:32:21.936 360 2107 E modules.primary.audio_hal: ben2... card num.
05-28 15:32:21.936 360 2107 E modules.primary.audio_hal: ben4... card num.
05-28 15:32:21.936 360 2107 D modules.primary.audio_hal: out->SampleRate : 48000
05-28 15:32:21.936 360 2107 D modules.primary.audio_hal: out->Channels : 2
05-28 15:32:21.936 360 2107 D modules.primary.audio_hal: out->Format : 0
05-28 15:32:21.936 360 2107 D modules.primary.audio_hal: out->PreiodSize : 1024
05-28 15:32:21.937 360 2107 D modules.primary.audio_hal: out->Device[0] : 0x2
05-28 15:32:21.937 360 2107 D modules.primary.audio_hal: out->SampleRate : 48000
05-28 15:32:21.937 360 2107 D modules.primary.audio_hal: out->Channels : 2
05-28 15:32:21.937 360 2107 D modules.primary.audio_hal: out->Format : 0
05-28 15:32:21.937 360 2107 D modules.primary.audio_hal: out->PreiodSize : 1024
05-28 15:32:21.937 360 2107 D modules.primary.audio_hal: start_output_stream:1397, out = 0xf25c4a50
05-28 15:32:25.247 2291 2291 W WLC_IOCTL: cmd: 159, val: 0, len: 388, set: 0
05-28 15:32:25.247 2291 2291 W WLC_IOCTL: cmd: 201, val: 3, len: 12, set: 1
05-28 15:32:25.248 2291 2291 I CFG80211-INFO) wl_cfg80211_del_station: Disconnect STA : 66:66:3a:66:66:3a scb_val.val 3
05-28 15:32:21.939 2291 2291 I hostapd : wlan0: AP-DISABLED
05-28 15:32:21.940 2291 2291 I hostapd : wlan0: CTRL-EVENT-TERMINATING
05-28 15:32:21.940 539 747 W HostapdHalAidlImp: Failure on iface wlan0, instance: wlan0
05-28 15:32:21.940 2291 2291 I hostapd : nl80211: deinit ifname=wlan0 disabled_11b_rates=0
05-28 15:32:25.248 2107 2107 W : es8316_mute...
05-28 15:32:25.248 2107 2107 W : es8316_mute...false
05-28 15:32:21.950 886 886 D WifiTetherSettings: updating display config due to receiving broadcast action android.net.wifi.WIFI_AP_STATE_CHANGED
05-28 15:32:25.274 2291 2291 I CFG80211-INFO) wl_cfg80211_get_bus_state: dhd->hang_was_sent = 0 and busstate = 2
05-28 15:32:25.275 2291 2291 W WLC_IOCTL: cmd: 86, val: 2, len: 4, set: 1
05-28 15:32:25.276 2291 2291 W WLC_SET_VAR: cmd: 263, msg: tdls_enable val: 0x1, len: 16, set: 1, txn-id: 65535
05-28 15:32:25.276 2291 2291 I CFG80211-INFO) wl_cfg80211_bss_up: wl bss -C 0 down
05-28 15:32:21.972 539 1185 I EthernetTracker: interfaceLinkStateChanged, iface: wlan0, up: true
05-28 15:32:25.279 2291 2291 W WLC_SET_VAR: cmd: 263, msg: bss val: 0x0, len: 12, set: 1, txn-id: 65535
05-28 15:32:25.279 130 130 W MACEVENT: WLC_E_LINK DOWN flags:0x0 status:0
05-28 15:32:25.279 1564 1564 I CFG80211-INFO) wl_print_event_data: event_type (16), ifidx: 0 bssidx: 0 status:0 reason:4
05-28 15:32:25.279 1564 1564 I CFG80211-INFO) wl_notify_connect_status_ap: [wlan0] Mode AP/GO. Event:16 status:0 reason:4
05-28 15:32:25.281 2291 2291 W WLC_SET_VAR: cmd: 263, msg: arp_ol val: 0x19, len: 11, set: 1, txn-id: 65535
05-28 15:32:25.284 2291 2291 W WLC_IOCTL: cmd: 2, val: 0, len: 4, set: 1
05-28 15:32:21.976 449 449 I wificond: Regulatory domain changed to country: 00 on wiphy_index: 0
05-28 15:32:21.976 539 791 D WifiNl80211Manager: OnRegDomainChanged 00
05-28 15:32:21.976 539 791 D WifiNative: onCountryCodeChanged: 00
05-28 15:32:21.976 539 791 I WifiCountryCode: Receive onDriverCountryCodeChanged 00
05-28 15:32:21.978 449 449 I wificond: 2.4Ghz frequencies: 2412 2417 2422 2427 2432 2437 2442 2447 2452 2457 2462
05-28 15:32:21.978 449 449 I wificond: 5Ghz non-DFS frequencies:
05-28 15:32:21.978 449 449 I wificond: 5Ghz DFS frequencies:
05-28 15:32:21.978 449 449 I wificond: 6Ghz frequencies:
05-28 15:32:21.978 449 449 I wificond: 60Ghz frequencies:
05-28 15:32:25.314 2291 2291 I CFG80211-INFO) wl_cfg80211_change_virtual_iface: [wlan0] Enter. current cfg_iftype:3 new cfg_iftype:2
05-28 15:32:25.314 2291 2291 I CFG80211-INFO) wl_cfg80211_add_del_bss: wl bss 2 bssidx:0 iface:wlan0
05-28 15:32:25.315 2291 2291 W WLC_SET_VAR: cmd: 263, msg: bss val: 0x0, len: 20, set: 1, txn-id: 65535
05-28 15:32:25.316 2291 2291 W WLC_IOCTL: cmd: 20, val: 1, len: 4, set: 1
05-28 15:32:25.316 2291 2291 W WLC_SET_VAR: cmd: 263, msg: buf_key_b4_m4 val: 0x1, len: 18, set: 1, txn-id: 65535
05-28 15:32:25.316 2291 2291 I CFG80211-INFO) wl_cfg80211_change_virtual_iface: [wlan0] cfg_iftype changed to 2
05-28 15:32:25.317 2291 2291 W WLC_GET_VAR: cmd: 262, msg: qtxpower val: 0x7f, len: 256, set: 0, txn-id: 65535
05-28 15:32:25.318 449 449 W : [wlan0] tx queue stopped
05-28 15:32:25.318 449 449 W dhd_stop: ######### dhd_stop called for ifidx=0 #########
05-28 15:32:25.318 449 449 W dhd_stop: making dhdpub up FALSE
05-28 15:32:25.318 449 449 I CFG80211-INFO) __wl_cfg80211_down: cfg80211 down
05-28 15:32:25.319 60 60 W WLC_SET_VAR: cmd: 263, msg: mcast_list val: 0x5, len: 45, set: 1, txn-id: 65535
05-28 15:32:25.320 449 449 W WLC_GET_VAR: cmd: 262, msg: event_msgs val: 0x9c8b1fff, len: 28, set: 0, txn-id: 65535
05-28 15:32:25.320 60 60 W WLC_SET_VAR: cmd: 263, msg: allmulti val: 0x1, len: 13, set: 1, txn-id: 65535
05-28 15:32:25.321 449 449 W WLC_SET_VAR: cmd: 263, msg: event_msgs val: 0x9c8b1fff, len: 27, set: 1, txn-id: 65535
05-28 15:32:25.321 449 449 I CFG80211-INFO) wl_cfg80211_cancel_scan: No scan in progress
05-28 15:32:25.321 449 449 I CFG80211-INFO) __wl_cfg80211_down: wl_cfg80211_down. connection state bit status: [0:0:0:0] for wlan0
05-28 15:32:25.321 60 60 W WLC_IOCTL: cmd: 10, val: 0, len: 4, set: 1
05-28 15:32:25.322 449 449 W WLC_IOCTL: cmd: 86, val: 2, len: 4, set: 1
05-28 15:32:25.323 449 449 W WLC_SET_VAR: cmd: 263, msg: tdls_enable val: 0x1, len: 16, set: 1, txn-id: 65535
05-28 15:32:25.324 449 449 W WLC_IOCTL: cmd: 219, val: 1, len: 4, set: 1
05-28 15:32:25.324 449 449 I CFG80211-INFO) wl_cfg80211_set_frameburst: frameburst is enabled
05-28 15:32:25.324 449 449 I CFGP2P-ERROR) wl_cfgp2p_disable_discovery:
05-28 15:32:25.324 449 449 W : do nothing, not initialized
05-28 15:32:25.324 449 449 I CFGP2P-INFO) wl_cfgp2p_deinit_priv:
05-28 15:32:25.324 449 449 W : In
05-28 15:32:25.324 449 449 I CFG80211-INFO) dhd_cfg80211_down: Dongle is already down
05-28 15:32:25.324 449 449 W dhd_tcpack_suppress_set 387: already set to 0
05-28 15:32:22.017 539 791 I EthernetTracker: interfaceLinkStateChanged, iface: wlan0, up: false
05-28 15:32:22.018 449 449 I wificond: tearDownApInterface: erasing wiphy_index for iface_name wlan0
05-28 15:32:22.018 449 449 I wificond: remove channel type 0 support at wiphy index 0
05-28 15:32:22.020 539 692 I HostapdHalAidlImp: Terminate HostApd Service.
05-28 15:32:22.020 2291 2291 I hostapd : Terminating...
05-28 15:32:22.020 2291 2291 I BpBinder: onLastStrongRef automatically unlinking death recipients: android.hardware.wifi.hostapd.IHostapdCallback
05-28 15:32:22.021 2291 2291 I hostapd : Deiniting aidl control
05-28 15:32:22.021 2291 2291 I hostapd : Terminating...
05-28 15:32:25.332 1 1 I init : Service 'hostapd' (pid 2291) exited with status 0 oneshot service took 12.159000 seconds in background
05-28 15:32:25.332 1 1 I init : Sending signal 9 to service 'hostapd' (pid 2291) process group...
05-28 15:32:25.333 1 1 I libprocessgroup: Successfully killed process cgroup uid 1010 pid 2291 in 0ms
05-28 15:32:22.050 539 1033 W HostapdHalAidlImp: IHostapd/IHostapd died. who android.os.BinderProxy@cb7c1d8 service android.os.BinderProxy@cb7c1d8
05-28 15:32:22.050 539 692 D HostapdHalAidlImp: Got service death confirmation
05-28 15:32:22.050 539 692 D WifiNl80211Manager: tearing down interfaces in wificond
05-28 15:32:22.051 379 379 I WifiHAL : found interface wlan0
05-28 15:32:22.051 379 379 E WifiHAL : Calling hal cleanup
05-28 15:32:22.051 379 379 I WifiHAL : wifi_cleanup_dynamic_ifaces: virtual iface size 0
05-28 15:32:22.051 379 379 I WifiHAL : Cleaned dynamic virtual ifaces
05-28 15:32:22.051 379 379 E WifiHAL : Cancel: Stop Hal
05-28 15:32:22.051 379 379 I WifiHAL : wifi_stop_hal success
05-28 15:32:22.051 379 379 I WifiHAL : wifi nan internal clean up done
05-28 15:32:22.051 379 379 I WifiHAL : wifi twt internal clean up done
05-28 15:32:22.051 379 379 I WifiHAL : event_cb callbacks left: 1
05-28 15:32:22.051 379 379 I WifiHAL : event_cb cleanup. index:0
05-28 15:32:22.051 379 379 I WifiHAL : event_cb cleanup. vendor cmd:4120 sub_cmd:33
05-28 15:32:22.051 379 379 I WifiHAL : Command left in event_cb 0xb400006edeb548d0
05-28 15:32:22.051 379 379 I WifiHAL : Check bad commands: num_cmd:2 bad_commands:0
05-28 15:32:22.051 379 379 I WifiHAL : Cancelling command 0xb400006eceb50900:HalInit
05-28 15:32:22.051 379 379 E WifiHAL : Cancel: Stop Hal
05-28 15:32:22.051 379 379 I WifiHAL : Cancelling command 0xb400006edeb548d0:SetRestartHandler
05-28 15:32:22.051 379 379 I WifiHAL : Clear Restart Handler
05-28 15:32:22.051 379 379 I WifiHAL : Successfully removed event handler 0xb400006edeb548d0:0x6dca866674 for vendor 0x1018, subcmd 0x21 from 0
05-28 15:32:22.051 379 379 I WifiHAL : Success to clear restarthandler
05-28 15:32:22.051 379 379 E WifiHAL : wifi_clean_up done
05-28 15:32:22.051 379 2292 I WifiHAL : Got a signal to exit!!!
05-28 15:32:22.051 379 2292 I WifiHAL : internal clean up
05-28 15:32:22.051 379 2292 I WifiHAL : cmd_sock non null. clean up
05-28 15:32:22.051 379 2292 I WifiHAL : cleanup_handler cb
05-28 15:32:22.051 379 2292 I [email protected]: Legacy HAL stop complete callback received
05-28 15:32:22.051 379 2292 I WifiHAL : Internal cleanup completed
05-28 15:32:22.051 379 2292 E WifiHAL : Exit wifi_event_loop
05-28 15:32:22.052 379 379 I [email protected]: Wifi HAL stopped
05-28 15:32:22.052 539 692 I WifiVendorHal: Vendor Hal stopped
05-28 15:32:22.052 539 692 I WifiNative: Successfully torn down Iface:{Name=wlan0,Id=1,Type=AP}
05-28 15:32:22.052 539 692 D HalDevMgr: updateRttController: no one is interested in RTT controllers
05-28 15:32:22.052 539 692 I WifiNative: Successfully initiated teardown for iface=wlan0
05-28 15:32:22.052 539 692 D SoftApManager: ---- mSoftApWakeLock.release ----
05-28 15:32:25.358 56 56 I binder : undelivered death notification, b400006e71c0b010
05-28 15:32:25.359 379 379 I CFG80211-INFO) wl_cfgvendor_stop_hal: wl_cfgvendor_stop_hal,[DUMP] HAL STOPPED
05-28 15:32:25.359 379 379 I CFG80211-INFO) wl_cfgvendor_stop_hal: wl_cfgvendor_stop_hal,[DUMP] HAL STOPPED
05-28 15:32:22.053 539 692 D SoftApManager[wlan0]: Soft AP is stopped
05-28 15:32:22.053 539 692 D SoftApManager[wlan0]: Timeout message canceled on wlan0
05-28 15:32:22.054 539 692 D SoftApManager[unknown]: SoftApInfo update null, isRemoved: false
05-28 15:32:22.054 539 692 V WifiManager: SoftApCallbackProxy on mode 1, send InfoChanged, newInfo: SoftApInfo{bandwidth= 0, frequency= 0, wifiStandard= 0, mApInstanceIdentif
ier= null, mIdleShutdownTimeoutMillis= 0}
05-28 15:32:22.054 539 692 V WifiManager: SoftApCallbackProxy on mode 1, send InfoChanged, changedInfoList: []
05-28 15:32:22.055 539 692 I WifiCountryCode: No active mode, call onDriverCountryCodeChanged with Null
05-28 15:32:22.055 755 1323 V WifiManager: SoftApCallbackProxy on mode 1, send InfoChanged, newInfo: SoftApInfo{bandwidth= 0, frequency= 0, wifiStandard= 0, mApInstanceIdentif
ier= null, mIdleShutdownTimeoutMillis= 0}
05-28 15:32:22.055 755 1323 V WifiManager: SoftApCallbackProxy on mode 1, send InfoChanged, changedInfoList: []
05-28 15:32:22.055 539 692 W HostapdHalAidlImp: Handle IHostapd/IHostapd died.
05-28 15:32:22.055 539 692 D WifiController: SoftAp mode disabled, return to DisabledState
05-28 15:32:22.055 539 692 D WifiController: EnabledState.exit()
05-28 15:32:22.056 539 692 D WifiController: DisabledState.enter()
05-28 15:32:22.057 539 747 D WifiCountryCode: Reading country code from telephony
05-28 15:32:22.058 539 747 D WifiCountryCode: Set telephony country code to:
05-28 15:32:22.059 2296 2296 I dnsmasq : Closing listener [fe80::def5:5ff:fe16:a855%wlan0]:53
05-28 15:32:22.059 2296 2296 I dnsmasq : using nameserver 192.168.0.1#53
05-28 15:32:25.372 353 353 W WLC_SET_VAR: cmd: 263, msg: arp_hostip_clear val: 0x0, len: 17, set: 1, txn-id: 65535
05-28 15:32:25.372 353 353 W WLC_SET_VAR: cmd: 263, msg: arp_table_clear val: 0x0, len: 16, set: 1, txn-id: 65535
05-28 15:32:25.373 353 353 W WLC_GET_VAR: cmd: 262, msg: arp_hostip val: 0x0, len: 32, set: 0, txn-id: 65535
05-28 15:32:25.373 353 353 W WLC_SET_VAR: cmd: 263, msg: arp_hostip_clear val: 0x0, len: 17, set: 1, txn-id: 65535
05-28 15:32:25.374 353 353 W WLC_SET_VAR: cmd: 263, msg: arp_hostip val: 0xa25fa8c0, len: 15, set: 1, txn-id: 65535
05-28 15:32:22.068 539 810 I WifiService: updateInterfaceIpState uid=1000
05-28 15:32:22.068 539 692 D WifiService: updateInterfaceIpState: ifaceName=wlan0 mode=-1 previous LOHS mode= -1
05-28 15:32:22.069 2296 2296 I dnsmasq : exiting on receipt of SIGTERM
05-28 15:32:25.375 353 353 W WLC_SET_VAR: cmd: 263, msg: arp_hostip_clear val: 0x0, len: 17, set: 1, txn-id: 65535
05-28 15:32:25.376 353 353 W WLC_SET_VAR: cmd: 263, msg: arp_table_clear val: 0x0, len: 16, set: 1, txn-id: 65535
05-28 15:32:22.076 886 886 D WifiTetherSettings: updating display config due to receiving broadcast action android.net.wifi.WIFI_AP_STATE_CHANGED
05-28 15:32:22.076 360 2107 W StreamHAL: Error from HAL stream in function get_presentation_position: Operation not permitted
05-28 15:32:22.078 539 1185 D WifiCountryCode: Reading country code from telephony
05-28 15:32:22.079 539 1185 D WifiCountryCode: Set telephony country code to:
05-28 15:32:25.384 2107 2107 W : es8316_enable_spk..0
05-28 15:32:22.172 539 700 D ConnectivityService: releasing NetworkRequest [ LISTEN id=44, [ RequestorUid: 1000 RequestorPkg: com.android.networkstack.tethering.inprocess Und
erlyingNetworks: Null] ] (release request)
05-28 15:32:26.593 55 55 E fdee0000.hdmirx-controller: hdmirx_wait_lock_and_get_timing signal not lock, tmds_clk_ratio:0
05-28 15:32:26.593 55 55 E fdee0000.hdmirx-controller: hdmirx_wait_lock_and_get_timing mu_st:0x0, scdc_st:0x0, dma_st10:0x10
05-28 15:32:24.310 390 953 D V4L2DeviceEvent: 9: unknown event
05-28 15:32:24.310 390 953 D tv_input: hinDevEventCallback event type: 134217729
05-28 15:32:24.310 390 953 D tv_input_HinDevImpl: deal_priv_message hdmiinout
05-28 15:32:24.310 390 953 E tv_input: hinDevEventCallback width:640,height:480,format:0x1d,0
05-28 15:32:24.310 539 539 W TvInputHal: handleMessage in, mEvent.type = 6
05-28 15:32:24.310 539 539 I TvInputHardwareManager: EnableHDMIInAudio false
05-28 15:32:24.310 539 539 D AudioStream: stop
05-28 15:32:24.311 1270 1320 D SampleTvInputService: onPrivCmdToApp hdmiinout
05-28 15:32:24.311 1270 1320 W ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.sendBroadcast:1189 android.content.ContextW
rapper.sendBroadcast:500 com.example.partnersupportsampletvinput.SampleTvInputService.sendPrivCmdBroadcast:140 com.example.partnersupportsampletvinput.SampleTvInputService.-$$Nes
t$msendPrivCmdBroadcast:0 com.example.partnersupportsampletvinput.SampleTvInputService$2.onPrivCmdToApp:131
^C
- 关键日志如下
05-28 15:32:21.929 886 886 I TetheringManager: stopTethering caller:com.android.settings 05-28 15:32:21.929 539 810 I WifiService: stopSoftAp uid=1000 05-28 15:32:21.930 539 692 D WifiActiveModeWarden: Shutting down all softap mode managers in mode 1 05-28 15:32:21.930 539 692 D SoftApManager[wlan0]: currentstate: StartedState 05-28 15:32:21.934 2291 2291 I hostapd : Remove interface 'wlan0' 05-28 15:32:22.053 539 692 D SoftApManager[wlan0]: Soft AP is stopped - 日志中可以看出来的是,代码肯定是与这几个TAG有关
- TetheringManager
- WifiService
- WifiActiveModeWarden
- SoftApManager
- hostapd
-
需要知道java层,wifi相关代码的位置,如果不知道,直接在package里面搜也慢不了多少
packages/modules/Wifi/service/java/com/android/server/wifi - 直接寻找日志内容
grep -irn "stopSoftAp uid=" packages/modules/Wifi/service/java/com/android/server/wifi/ - 可以找到下面的内容
packages/modules/Wifi/service/java/com/android/server/wifi/WifiServiceImpl.java:1695: mLog.info("stopSoftAp uid=%").c(Binder.getCallingUid()).flush();这个语句位于
stopSoftAP函数内,相应的,可以找到startSoftAp - 同样的,搜索另一段日志
grep -irn "Soft AP is stopped" packages/modules/Wifi/service/java/com/android/server/wifi/ packages/modules/Wifi/service/java/com/android/server/wifi/SoftApManager.java:808: Log.d(getTag(), "Soft AP is stopped");也可以找到对应的
startSoftAp和stopSoftAp
也就是说,开关热点肯定是用到了这些函数。
属性设置
下一步,设置一个记录热点开关的属性,并且在调用的这些开关函数中,对属性进行设置。
自定义属性
diff --git a/device/rockchip/rk3588/rk3588_QY/rk3588_QY.mk b/device/rockchip/rk3588/rk3588_QY/rk3588_QY.mk
index 442bdd81ab..5f13b9179b 100644
--- a/device/rockchip/rk3588/rk3588_QY/rk3588_QY.mk
+++ b/device/rockchip/rk3588/rk3588_QY/rk3588_QY.mk
@@ -44,3 +44,4 @@ PRODUCT_PROPERTY_OVERRIDES += persist.wifi.sleep.delay.ms=0
PRODUCT_PROPERTY_OVERRIDES += persist.bt.power.down=true
PRODUCT_PROPERTY_OVERRIDES += vendor.hwc.device.extend=HDMI-A-1,DP-1
PRODUCT_PROPERTY_OVERRIDES += vendor.hwc.device.primary=eDP-1
+PRODUCT_PROPERTY_OVERRIDES += persist.hotspot.enable=true
在开关函数中调用
-
这里我选择了上面找到的
packages/modules/Wifi/service/java/com/android/server/wifi/SoftApManager.java中的startSoftAp和stopSoftAp,在startSoftAp时设置persist.hotspot.enable=true,在stopSoftAp中设置为false - 一般来说,属性这么设置就可以
import android.os.SystemProperties; SystemProperties.set("persist.hotspot.enable", "true"); - 但是我这么设置后编译报错 ```sh packages/modules/Wifi/service/java/com/android/server/wifi/SoftApManager.java:772: error: cannot find symbol SystemProperties.set(“persist.hotspot.enable”, “true”); ^ symbol: method set(String,String) location: class SystemProperties packages/modules/Wifi/service/java/com/android/server/wifi/SoftApManager.java:802: error: cannot find symbol SystemProperties.set(“persist.hotspot.enable”, “false”); ^ symbol: method set(String,String) location: class SystemProperties 2 errors 1 warning 17:13:08 ninja failed with: exit status 1
failed to build some targets (08:48 (mm:ss))
Build android failed!
- 原因是这个API是隐藏的(被标记为@hide),在当前编译环境中不可见。
- 两种方式解决,一种是配置Android.bp和Android.mk,启用平台API访问,但是我在这一步遇到了其他问题;方式二是使用反射。
反射是 Java 语言的一种高级特性,它允许程序在运行时(而非编译时)动态获取类的信息并操作类的方法、字段等元素,绕过编译时的访问控制。如下:
```java
try {
// 1. 动态加载类
Class<?> clazz = Class.forName("android.os.SystemProperties");
// 2. 查找特定方法
Method setMethod = clazz.getMethod("set", String.class, String.class);
// 3. 执行方法调用(因为是静态方法,实例参数传null)
setMethod.invoke(null, "persist.hotspot.enable", "true");
} catch (Exception e) {
// 错误处理
Log.e(TAG, "设置属性失败", e);
}
具体修改如下
diff --git a/packages/modules/Wifi/service/java/com/android/server/wifi/SoftApManager.java b/packages/modules/Wifi/service/java/com/android/server/wifi/SoftApManager.java
index 8ce9f06240..cd3efe538e 100644
--- a/packages/modules/Wifi/service/java/com/android/server/wifi/SoftApManager.java
+++ b/packages/modules/Wifi/service/java/com/android/server/wifi/SoftApManager.java
@@ -80,6 +80,9 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
+import android.os.SystemProperties;
+import java.lang.reflect.Method;
+
/**
* Manage WiFi in AP mode.
* The internal state machine runs under the ClientModeImpl handler thread context.
@@ -767,6 +770,16 @@ public class SoftApManager implements ActiveModeManager {
}
Log.d(getTag(), "Soft AP is started ");
+ // SystemProperties.set("persist.hotspot.enable", "true");
+ try {
+ Class<?> clazz = Class.forName("android.os.SystemProperties");
+ Method setMethod = clazz.getMethod("set", String.class, String.class);
+ setMethod.invoke(null, "persist.hotspot.enable", "true");
+ } catch (Exception e) {
+ Log.e(TAG, "wsh: set prop error", e);
+ }
+ Log.d(TAG, "wsh: persist.hotspot.enable set to true. Hotspot already set to normally on state");
+
return SUCCESS;
}
@@ -793,6 +806,16 @@ public class SoftApManager implements ActiveModeManager {
mSoftApWakeLock.release();
}
Log.d(getTag(), "Soft AP is stopped");
+
+ // SystemProperties.set("persist.hotspot.enable", "false");
+ try {
+ Class<?> clazz = Class.forName("android.os.SystemProperties");
+ Method setMethod = clazz.getMethod("set", String.class, String.class);
+ setMethod.invoke(null, "persist.hotspot.enable", "false");
+ } catch (Exception e) {
+ Log.e(TAG, "wsh: set prop error", e);
+ }
+ Log.d(TAG, "wsh: persist.hotspot.enable set to false. Hotspot already set to normally off state");
}
private void addClientToPendingDisconnectionList(WifiClient client, int reason) {
开机时读取属性开启热点
参考https://blog.csdn.net/wenzhi20102321/article/details/135139745
热点操作其实同样在 WifiServiceImpl 判断处理即可,因为热点的api实现很多也是封装在WifiServiceImpl 里面的。
packages\modules\Wifi\service\java\com\android\server\wifi\WifiServiceImpl.java```java diff –git a/packages/modules/Wifi/service/java/com/android/server/wifi/WifiServiceImpl.java b/packages/modules/Wifi/service/java/com/android/server/wifi/WifiServiceImpl.java index 3c742d9636..85dd9c16d0 100644 — a/packages/modules/Wifi/service/java/com/android/server/wifi/WifiServiceImpl.java +++ b/packages/modules/Wifi/service/java/com/android/server/wifi/WifiServiceImpl.java @@ -206,6 +206,9 @@ import java.util.concurrent.Executor; import java.util.concurrent.TimeUnit; import java.util.function.BiConsumer;
+ +import android.os.SystemProperties; + /**
- WifiService handles remote WiFi operation requests by implementing
- the IWifiManager interface. @@ -660,6 +663,16 @@ public class WifiServiceImpl extends BaseWifiService { mWifiInjector.getAdaptiveConnectivityEnabledSettingObserver().initialize(); mIsWifiServiceStarted = true; }); +
- //根据热点属性判断是否启动热点
- mWifiThreadRunner.postDelayed(() -> {
- boolean isHotspotEnable = SystemProperties.getBoolean(“persist.hotspot.enable”, false);
- Log.d(TAG, “wsh: checkAndStartWifi start ap isHotspotEnable = “ + isHotspotEnable);
- if (isHotspotEnable) {
- startTetheredHotspot(getSoftApConfiguration(), mContext.getPackageName());
- }
- },
- 100);//延时,避免wifi启动未处理完成 }
private void updateLocationMode() { ```
留下评论