打瞌睡模式、电池优化白名单、AlarmManager 频率超过 9 分钟

Doze Mode, Battery Optimization whitelist, AlarmManager more frequent than 9 mins

我正在创建一个应用程序来连接 BT 设备以收集健康数据(即:体温)。

传感器周期性休眠,仅在有限的 window 连接时间内唤醒。

我尝试创建 AlarmManager,它使用 setExactAndAllowWhileIdle() 触发前台服务,并且它在超过 9 分钟的时间内按预期工作,

但不到 9 分钟它会进入打瞌睡模式并且不会触发 AlarmManager BroadcastReceiver。

根据文档,我不明白将应用程序添加到电池优化白名单是否会允许 AlarmManager 更频繁地触发 https://developer.android.com/training/monitoring-device-state/doze-standby#support_for_other_use_cases

For example, the whitelisted app’s jobs and syncs are deferred (on API level 23 and below), and its regular AlarmManager alarms do not fire

有哪些常规闹钟? setExactAndAllowWhileIdle() 正常吗?

任何澄清将不胜感激

编辑:

我知道 setExactAndAllowWhileIdle() 会在休眠模式下触发事件超过 9 分钟,问题是将应用程序添加到白名单是否会允许它更频繁地触发

What are the regular alarms ? is setExactAndAllowWhileIdle() regular ?

没有。 setExactAndAllowWhileIdle() 不规则。常规警报可以是通过 setExact() 和 setWindow() 设置的 AlarmManager 警报。

but below 9 minutes it goes to doze mode and do not fire AlarmManager BroadcastReceiver

它对设置闹钟的频率有限制。

基于documentation

To reduce abuse, there are restrictions on how frequently these alarms will go off for a particular application. Under normal system operation, it will not dispatch these alarms more than about every minute (at which point every such pending alarm is dispatched); when in low-power idle modes this duration may be significantly longer, such as 15 minutes.

你可以参考Doze restrictions里面说:

Standard AlarmManager alarms (including setExact() and setWindow()) are deferred to the next maintenance window.

  • If you need to set alarms that fire while in Doze, use setAndAllowWhileIdle() or setExactAndAllowWhileIdle().
  • Alarms set with setAlarmClock() continue to fire normally — the system exits Doze shortly before those alarms fire

对于白名单:

白名单中可用的应用部分免于打瞌睡和应用待机优化。这并不意味着他们可以完全访问并可以在打瞌睡模式下执行任务。列入白名单的应用程序可以使用网络并在打盹和应用程序待机期间保持部分唤醒锁定。然而,其他限制,如工作不同,标准警报触发仍然强加

注意:您应该check acceptable usecases将应用列入白名单。

Google Play policies prohibit apps from requesting direct exemption from Power Management features in Android 6.0+ (Doze and App Standby) unless the core function of the app is adversely affected.