问题描述
对于DOZE模式测试,我正在开发一个Android 6.0示例GCM应用程序。正如所说,在DOZE模式下,设备不会唤醒正常优先级GCM 。我想检查一下。
根据文档(
我从服务器发送的消息如下所示:
$ msg = array
(
'message'=>'here is a message。'message',
'title'=>'This is a title。title',
'subtitle'=>'This is subtitle。subtitle',
'tickerText'=>'此处的代码文本...此处的代码文本...此处的代码文本',
'vibrate'=> 1,
'sound'=> 1
);
正如你所看到的,没有优先级设置,所以在DOZE模式下,我不应该马上得到它。但是设备仍然会立即收到GCM消息。
运行基于GCM的应用程序
$ adb shell dumpsys battery unplug
$ adb shell dumpsys deviceidle步骤
预期行为:对于普通优先级GCM没有立即交付GCM
观察到的行为:立即发送消息
DOZE模式是否工作根据文件?我没有看到它发生,任何人都面临同样的情况吗?
我使用模拟器运行测试非优先GCM消息传递API 23,并观察记录的行为:当仿真设备处于打盹模式时,消息未传送。退出睡眠模式几秒钟后,收到消息。
我的测试应用程序是使用Goggle Play Services 8.3.0构建的。 API 23的模拟器映像包含较旧版本的Play Services,当应用程序初始化为更新至8.3.0时会产生警告。我不知道如何在模拟器上做到这一点。该应用程序已成功注册并收到消息,因此我继续进行测试。
我将仿真设备置于打盹模式:
$ adb shell dumpsys deviceidle enable
并重复:
$ adb shell dumpsys deviceidle step
我使用 curl 发送邮件,按照。消息接收通过观察 logcat 输出来确认。
步骤命令生成状态:IDLE_PENDING,SENSING,IDLE_MAINTENANCE和IDLE。对于除IDLE以外的所有消息,立即收到消息。没有收到在IDLE中发送的消息。等待大约一分钟后,使用 deviceidle step 来进入IDLE_MAINTENACE状态。在几秒钟内,交付的消息。
两个建议:
- 如果您不打算使用Play Services 8.3.0,请更新至该版本。 使用 curl 以及上面链接的说明发送测试消息以查看是否产生与您的服务器代码不同的行为。
For DOZE mode test, I am developing a sample GCM App on Android 6.0.
As it's said, In DOZE mode the device would not wakeup for normal priority GCM. I wanted to check this.
As per the documentation (https://developers.google.com/cloud-messaging/concept-options#setting-the-priority-of-a-message)
I tested my app with some server code from this link.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. But still the device receives the GCM message immediately.
Method of test
- Run the GCM based app
- Induce the DOZE mode by issuing commands from adb shell (link)$ adb shell dumpsys battery unplug$ adb shell dumpsys deviceidle step
- Send a message from Server (phpfiddle)
Expected behavior : There is no immediate delivery for normal priority GCMObserved behavior : There is an immediate delivery of message
Does the DOZE mode work as per documentation ? 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. A few seconds after exiting Doze mode, the message was received.
My test app was built using Goggle Play Services 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. 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:
$ adb shell dumpsys deviceidle enable
and repeated:
$ adb shell dumpsys deviceidle step
I sent messages using curl, following the instructions provided here. Message receipt was confirmed by observing logcat output.
The deviceidle step command produced states: IDLE_PENDING, SENSING, IDLE_MAINTENANCE, and IDLE. For all but IDLE, messages were received immediately. The message sent while in IDLE was not received. After waiting about a minute, deviceidle step was used to enter IDLE_MAINTENACE state. Within a few seconds, the held message was delivered.
Two suggestions:
- If you are not building with Play Services 8.3.0, update to that version.
- Use curl and the instructions linked above for sending test messages to see if that produces different behavior than your server code.
这篇关于Android DOZE模式GCM优先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!