Android DOZE模式GCM优先 [英] Android DOZE mode GCM Priority

查看:334
本文介绍了Android DOZE模式GCM优先的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于DOZE模式测试,我正在开发一个Android 6.0示例GCM应用程序。



正如所说,在DOZE模式下,设备不会唤醒正常优先级GCM 。我想检查一下。



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


正常优先级。这是消息传递的默认优先级。普通优先级消息不会打开休眠设备上的网络连接,并且可能会延迟其传输以节省电量。对于时间不太敏感的消息(例如新电子邮件或其他数据的同步通知),请选择正常的递送优先级。

我测试了我的应用程序与此链接中的一些服务器代码。
https://stackoverflow.com/a/22169411/4242382



我从服务器发送的消息如下所示:

  $ 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发出命令来引发DOZE模式( link

    $ adb shell dumpsys battery unplug
    $ adb shell dumpsys deviceidle步骤

  • 从服务器发送消息(phpfiddle)

    预期行为:对于普通优先级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状态。在几秒钟内,交付的消息。



    两个建议:


    1. 如果您不打算使用Play Services 8.3.0,请更新至该版本。
    2. 使用 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)

    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?

    解决方案

    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.

    这篇关于Android DOZE模式GCM优先的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆