从android M (6.0)开始, Google加入了doze mode支持.
1. doze模式几个状态
ACTIVE
- Device is in use, or connected to a charge source.INACTIVE
- Device has recently come out of the active state (user turned off the display or unplugged it, for example)IDLE_PENDING
- Hold on to your hats, we are about to enter idle mode.IDLE
- Device is idle.IDLE_MAINTENANCE
- Window is open for applications to do processing.
2. 实现
frameworks/base/services/core/java/com/android/server/DeviceIdleController.java
frameworks/base/services/core/java/com/android/server/SystemConfig.java
log:
D/DeviceIdleController( 941): Moved from STATE_ACTIVE to STATE_INACTIVE
D/DeviceIdleController( 941): Moved from STATE_ACTIVE to STATE_INACTIVE
D/DeviceIdleController( 941): Moved from STATE_INACTIVE to STATE_IDLE_PENDING.
D/DeviceIdleController( 941): Moved from STATE_IDLE_PENDING to STATE_SENSING.
D/DeviceIdleController( 941): Moved from STATE_SENSING to STATE_LOCATING.
D/DeviceIdleController( 941): Moved to STATE_IDLE. Next alarm in 3600000 ms.
D/DeviceIdleController( 941): updateDisplayLocked: screenOn=true
I/DeviceIdleController( 941): becomeActiveLocked, reason = screen
(I/DeviceIdleController( 941): becomeActiveLocked, reason = disabled)
3. 进入退出doze mode命令
3.1 进入doze mode
adb shell dumpsys battery unplug
adb shell dumpsys deviceidle step
3.2 退出doze mode
adb shell dumpsys deviceidle disable
3.3 enable doze mode
adb shell dumpsys deviceidle enable
4. 白名单
4.1 查看白名单
adb shell dumpsys deviceidle
adb shell dumpsys deviceidle whitelist
4.2 加入白名单
adb shell dumpsys deviceidle whitelist +packageName
4.3 删除白名单
adb shell dumpsys deviceidle whitelist -packageName
vendor/google/etc/sysconfig/google.xml (etc/sysconfig/google.xml)
frameworks/base/data/etc/platform.xml (etc/permissions/platform.xml)
4.4 配置白名单
<!-- These are the standard packages that are white-listed to always have internet
access while in power save mode, even if they aren't in the foreground. -->
<allow-in-power-save-except-idle package="com.android.providers.downloads" />
5. deviceilde影响的service
NetworkPolicyManagerService
JobSchedulerService
SyncManager
PowerManagerService
AlarmManagerService
参考文档
https://developer.android.com/training/monitoring-device-state/doze-standby.html
https://newcircle.com/s/post/1739/2015/06/12/diving-into-android-m-doze
http://blog.sina.com.cn/s/blog_b9ead2b70102w07r.html