自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
WLAN 首选分流网络扫描
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Wi-Fi 首选分流网络 (PNO) 扫描是在设备与 Wi-Fi 断开连接且屏幕关闭后定期发生的低电耗 Wi-Fi 扫描。PNO 扫描用于查找并连接到已保存的网络。框架使用 NL80211_CMD_START_SCHED_SCAN
命令调度这些扫描。如需了解详情,请参阅 nl80211.h。
在搭载 Android 9 或更低版本的设备上,当设备与 Wi-Fi 断开连接且屏幕关闭后,PNO 扫描将以 20 秒为间隔执行前三次扫描,并以 60 秒为间隔执行所有后续扫描。找到已保存的网络或屏幕开启时,PNO 扫描会停止。
Android 10 在 WifiManager
中引入了一个名为 setDeviceMobilityState()
的可选 API 方法,该方法可根据设备的移动状态增加 PNO 扫描的间隔时长,从而减少耗电量。
可能的移动状态包括:
DEVICE_MOBILITY_STATE_UNKNOWN
:移动性未知
DEVICE_MOBILITY_STATE_HIGH_MVMT
:骑自行车或驾驶机动车
DEVICE_MOBILITY_STATE_LOW_MVMT
:步行或跑步
DEVICE_MOBILITY_STATE_STATIONARY
:没有移动
如果设备处于静止状态,Android 框架会将 PNO 扫描的间隔时长从 60 秒增加到 180 秒,以减少耗电量。这种优化基于以下假设:在设备没有移动时,设备不太可能通过 PNO 扫描找到任何新网络。
如果设备处于任何其他移动状态或者该方法未经调用,则设备将采用默认的 PNO 扫描行为。
实现
如需在搭载 Android 10 或更高版本的设备上实现此电耗优化功能,请推导出设备移动信息并从自定义系统应用中调用 setDeviceMobilityState()
方法。
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[null,null,["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# Wi-Fi preferred network offload scanning\n\nWi-Fi preferred network offload (PNO) scans are low-powered Wi-Fi scans that\noccur at regular intervals when a device is disconnected from Wi-Fi and the\nscreen is off. PNO scans are used to find and\nconnect to saved networks. These scans are scheduled by the framework using the\n`NL80211_CMD_START_SCHED_SCAN` command. For more information, see\n[nl80211.h](https://git.kernel.org/pub/scm/linux/kernel/git/linville/wireless.git/tree/include/uapi/linux/nl80211.h).\n\nOptimize power usage with device mobility information\n-----------------------------------------------------\n\nOn devices running Android 9 or lower, when the device\nis disconnected from Wi-Fi and the screen is off, PNO scans occur at 20 second\nintervals for the first three scans, then slow down to one scan every 60 seconds\nfor all subsequent scans. PNO scanning stops when a saved network is found or\nthe screen is turned on.\n\nAndroid 10 introduces an optional API method named\n[`setDeviceMobilityState()`](https://cs.android.com/android/platform/superproject/+/android-latest-release:packages/modules/Wifi/framework/java/android/net/wifi/WifiManager.java?q=func:setDeviceMobilityState)\nin `WifiManager` that increases the interval between\nPNO scans based on the device's mobility state to reduce power consumption.\n\nThe possible mobility states are:\n\n- `DEVICE_MOBILITY_STATE_UNKNOWN`: Unknown mobility\n- `DEVICE_MOBILITY_STATE_HIGH_MVMT`: On a bike or in a motor vehicle\n- `DEVICE_MOBILITY_STATE_LOW_MVMT`: Walking or running\n- `DEVICE_MOBILITY_STATE_STATIONARY`: Not moving\n\nIf the device is stationary, the Android framework increases the\ninterval between PNO scans from 60 seconds to 180 seconds to reduce power\nconsumption. This optimization is made on the assumption that the device is\nunlikely to find any new networks in PNO scans when the device is not moving.\n\nIf the device is in any other mobility state or if the method isn't called, the\ndevice uses the default PNO scan behavior.\n\n### Implementation\n\nTo implement this power-optimizing feature on a device running Android\n10 or higher, derive the device mobility information\nand call the `setDeviceMobilityState()` method from a custom system app."]]