简体   繁体   English

Android DOZE模式GCM优先级

[英]Android DOZE mode GCM Priority

For DOZE mode test, I am developing a sample GCM App on Android 6.0. 对于DOZE模式测试,我正在Android 6.0上开发示例GCM应用。

As it's said, In DOZE mode the device would not wakeup for normal priority GCM. 就像说的那样,在DOZE模式下,设备不会为正常优先级GCM唤醒。 I wanted to check this. 我想检查一下。

As per the documentation ( https://developers.google.com/cloud-messaging/concept-options#setting-the-priority-of-a-message ) 根据文档( https://developers.google.com/cloud-messaging/concept-options#setting-the-priority-of-a-message

Normal priority. 正常优先级。 This is the default priority for message delivery. 这是邮件传递的默认优先级。 Normal priority messages won't open network connections on a sleeping device, and their delivery may be delayed to conserve battery. 普通优先级消息不会在睡眠设备上打开网络连接,并且可能会延迟传递消息以节省电池。 For less time-sensitive messages, such as notifications of new email or other data to sync, choose normal delivery priority. 对于时间不太敏感的消息,例如新电子邮件通知或要同步的其他数据,请选择“正常传递优先级”。

I tested my app with some server code from this link. 我使用此链接中的一些服务器代码测试了我的应用。 https://stackoverflow.com/a/22169411/4242382 https://stackoverflow.com/a/22169411/4242382

The message I send from server is like this: 我从服务器发送的消息是这样的:

$msg = array
(
    'message'       => 'here is a message. message',
    'title'         => 'This is a title. title',
    'subtitle'      => 'This is a subtitle. subtitle',
    'tickerText'    => 'Ticker text here...Ticker text here...Ticker text here',
    'vibrate'   => 1,
    'sound'     => 1
);

As you see there is no priority set, so while in DOZE mode I should not get this immediately. 如您所见,没有设置优先级,因此在DOZE模式下,我不应该立即获得此优先级。 But still the device receives the GCM message immediately. 但是设备仍然会立即收到GCM消息。

Method of test 测试方法

  1. Run the GCM based app 运行基于GCM的应用
  2. Induce the DOZE mode by issuing commands from adb shell ( link ) $ adb shell dumpsys battery unplug $ adb shell dumpsys deviceidle step 通过从adb shell( 链接 )发出命令来$ adb shell dumpsys battery unplug $ adb shell dumpsys deviceidle step DOZE模式$ adb shell dumpsys battery unplug $ adb shell dumpsys deviceidle step
  3. Send a message from Server (phpfiddle) 从服务器发送消息(phpfiddle)

Expected behavior : There is no immediate delivery for normal priority GCM Observed behavior : There is an immediate delivery of message 预期的行为:正常优先级GCM不会立即交付观察到的行为:消息会立即交付

Does the DOZE mode work as per documentation ? DOZE模式是否按照文档工作? I don't see it happening, anybody facing the same? 我没有看到这种情况的发生,有人面对同样的事情吗?

I tested non-priority GCM message delivery using an emulator running API 23 and observed the documented behavior: When the emulated device was in Doze mode, the message was not delivered. 我使用运行API 23的仿真器测试了非优先级GCM消息传递,并观察了记录的行为:当仿真设备处于打mode模式时,该消息未传递。 A few seconds after exiting Doze mode, the message was received. 退出打ze模式几秒钟后,收到消息。

My test app was built using Goggle Play Services 8.3.0. 我的测试应用是使用Goggle Play服务8.3.0构建的。 The emulator image for API 23 includes an older version of Play Services, which resulted in a warning when the app initialized to update to 8.3.0. API 23的仿真器映像包含旧版本的Play服务,当应用初始化为更新至8.3.0时,会产生警告。 I don't know how to do that on an emulator. 我不知道如何在模拟器上执行此操作。 The app successfully registered for and received messages, so I continued with the test. 该应用程序成功注册并接收了消息,因此我继续进行测试。

I put the emulated device into Doze mode with: 我使用以下命令将仿真设备置于打ze模式:

$ adb shell dumpsys deviceidle enable

and repeated: 并重复:

$ adb shell dumpsys deviceidle step

I sent messages using curl , following the instructions provided here . 我按照此处提供的说明使用curl发送邮件。 Message receipt was confirmed by observing logcat output. 通过观察logcat输出确认了消息接收。

The deviceidle step command produced states: IDLE_PENDING, SENSING, IDLE_MAINTENANCE, and IDLE. deviceidle step命令生成的状态为:IDLE_PENDING,SENSING,IDLE_MAINTENANCE和IDLE。 For all but IDLE, messages were received immediately. 对于除IDLE以外的所有人,都立即收到了消息。 The message sent while in IDLE was not received. 未收到在IDLE中发送的消息。 After waiting about a minute, deviceidle step was used to enter IDLE_MAINTENACE state. 等待约一分钟后,使用deviceidle step进入IDLE_MAINTENACE状态。 Within a few seconds, the held message was delivered. 几秒钟之内,保留的邮件已传递。

Two suggestions: 两个建议:

  1. If you are not building with Play Services 8.3.0, update to that version. 如果您不是使用Play Services 8.3.0构建的,请更新到该版本。
  2. Use curl and the instructions linked above for sending test messages to see if that produces different behavior than your server code. 使用curl和上面链接的说明发送测试消息,以查看是否产生与服务器代码不同的行为。

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

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