Android DOZE mode GCM Priority

允我心安 提交于 2019-12-08 05:34:12

问题


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)

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

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

  1. Run the GCM based app
  2. Induce the DOZE mode by issuing commands from adb shell (link) $ adb shell dumpsys battery unplug $ adb shell dumpsys deviceidle step
  3. Send a message from Server (phpfiddle)

Expected behavior : There is no immediate delivery for normal priority GCM Observed 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?


回答1:


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:

  1. If you are not building with Play Services 8.3.0, update to that version.
  2. Use curl and the instructions linked above for sending test messages to see if that produces different behavior than your server code.


来源:https://stackoverflow.com/questions/33999016/android-doze-mode-gcm-priority

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!