简体   繁体   English

打ze模式如何影响注册的侦听器(尤其是传感器侦听器)

[英]How does Doze mode affect registered listeners (especially sensor listeners)

How does Doze mode affect registered listeners? 打ze模式如何影响注册的侦听器?

Also I would like to know how it does affect sensor listeners if possible. 我也想知道,如果可能的话,它如何影响传感器监听器。

My problem is that I have a WatchFaceService with a wake lock permission in the manifest. 我的问题是我有一个WatchFaceService中的唤醒锁权限的WatchFaceService The watchFace runs the onTimeTick every minute. onTimeTick每分钟运行一次onTimeTick A lot of times this happens when the device is Dozed. 当设备被Dozed时,通常会发生这种情况。 At that moment it registers a listener for HR to collect 10 values. 那时,它为HR注册了一个侦听器以收集10个值。 Doze mode kicks in after the listener is registered, according to my observations, but the sensor remains active. 根据我的观察,在收听者注册之后,打ze模式便会启动,但传感器仍处于活动状态。 For example the HR Sensor stays lit. 例如,心率传感器保持点亮。

Is this normal and why? 这正常吗?为什么? Here are my observations 这是我的观察


Listener with a sampling period of 0 microseconds: 侦听器的采样周期为0微秒:

sensorManager.registerListener(averagingSensorEventListener, sensor, averageSamplingPeriodUs, averageMaxReportLatencyUs);

Logs: 日志:

06-12 17:35:00.308 724-724/? D/android.sensor.heart_rate: Starting average calculation
06-12 17:36:01.065 724-724/? D/android.sensor.heart_rate: Event value 75.0 accepted
06-12 17:36:01.166 724-724/? D/android.sensor.heart_rate: Event value 75.0 accepted
06-12 17:36:20.471 724-724/? D/android.sensor.heart_rate: Event value 71.0 accepted
06-12 17:37:01.066 724-724/? D/android.sensor.heart_rate: Event value 72.0 accepted
06-12 17:38:01.067 724-724/? D/android.sensor.heart_rate: Event value 73.0 accepted
06-12 17:39:00.072 724-724/? D/android.sensor.heart_rate: Event value 81.0 accepted
06-12 17:39:28.135 724-724/? D/android.sensor.heart_rate: Event value 81.0 accepted
06-12 17:39:28.276 724-724/? D/android.sensor.heart_rate: Event value 80.0 accepted
06-12 17:39:29.244 724-724/? D/android.sensor.heart_rate: Event value 77.0 accepted
06-12 17:39:30.110 724-724/? D/android.sensor.heart_rate: Event value 75.0 accepted
06-12 17:39:31.172 724-724/? D/android.sensor.heart_rate: Event value 73.0 accepted
06-12 17:39:31.173 724-724/? D/android.sensor.heart_rate: Stopped listening
06-12 17:39:31.180 724-724/? D/android.sensor.heart_rate: Average calculated: 76.0
06-12 17:39:31.180 724-724/? D/android.sensor.heart_rate: Event value 76.0 accepted

It takes more than 4 minutes to complete and in these minutes the HR sensor is active (green light) without firing the onSensorChanged Callback or reporting a value with the listener registered. 这需要4分钟以上的时间才能完成,并且在这几分钟内,HR传感器处于活动状态(绿灯),而不会触发onSensorChanged回调或向已注册的侦听器报告值。


UPDATE: 更新:

For my problems and after the excellent answer from Morales, I solved it via every time I need to register a listener I acquire a wake lock and I release it after the sampling is done. 对于我的问题,在得到莫拉莱斯的出色回答之后,我每次需要注册侦听器时都解决了此问题,我获得了唤醒锁,并在采样完成后释放了它。 This way the events are consistent to the times I ask and do not keep the sensor active. 这样,事件与我询问的时间保持一致,并且不会保持传感器处于活动状态。

Sensors 感测器

Documentation says that there are several sensor types , every sensor has a reporting-mode ( continuous , on-change , one-shot and special ) and every sensor is classified by type sensor returned: 文档说有几种传感器类型 ,每个传感器都有一个报告模式连续on-change单发特殊 ),每个传感器都按返回的传感器类型进行分类:

  • Wake-up sensor : ensure that their data is delivered independently of the state of the SoC. 唤醒传感器 :确保独立于SoC状态传送其数据。
  • Non-wake-up sensor : do not prevent the SoC from going into suspend mode and do not wake the SoC up to report data. 非唤醒传感器 :不要阻止SoC进入挂起模式,也不要唤醒SoC来报告数据。

Doze documentation not points any information about particular sensors, except for significant motion sensor that is required to configure doze mode. 打ze文档没有指出有关特定传感器的任何信息,但配置打ze模式所需的重要运动传感器除外。

To see the individual sensor type descriptions for details on when the events are generated you can check documentation . 要查看有关事件生成时间的详细信息,请查看各个传感器的类型说明 ,您可以查看文档

Restrictions 限制条件

There are some restrictions that apply to your app while in Doze mode: 在打ze模式下,有一些限制适用于您的应用程序:

  • Network access is suspended. 网络访问已暂停。
  • The system ignores wake locks . 系统将忽略唤醒锁
  • Standard AlarmManager alarms (including setExact() and setWindow() ) are deferred to the next maintenance window. 标准AlarmManager警报(包括setExact()setWindow() )被推迟到下一个维护窗口。
  • The system does not perform Wi-Fi scans. 系统不执行Wi-Fi扫描。
  • The system does not allow sync adapters to run. 系统不允许运行同步适配器
  • The system does not allow JobScheduler to run. 系统不允许JobScheduler运行。

Doze can affect apps differently, depending on the capabilities they offer and the services they use. ze睡可能会对应用程序产生不同的影响,具体取决于它们提供的功能和使用的服务。 Many apps function normally across Doze cycles without modification. 许多应用程序在不打cycles的整个周期内都可以正常运行。 In some cases, you must optimize the way that your app manages network , alarms , jobs , and syncs . 在某些情况下,您必须优化应用程序管理网络警报作业同步的方式 Apps should be able to efficiently manage activities during each maintenance window . 应用程序应该能够在每个维护时段有效地管理活动。

From Optimizing for Doze and App Standby . 优化Doze和App Standby开始

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM