PaulR
PaulR

Reputation: 3293

If an app uses normal-priority GCM messages will it always have access to the network?

Sometimes when I receive a normal-priority GCM message in my Android app the network doesn't seem to be available. Do normal-priority GCM messages automatically grant an app temporary exemptions to Android M's new Doze and App Standby sleep conditions (namely restricting network access)?

Full Context: I've implemented an App prior to Android-M's release that uses a GCM messaging to tickle installed app instances to download updates on-demand. This is a best practice over polling for updates.

Android-M introduces Doze and AppStandby which seem able to restrict network access when apps aren't using the the new high-priority message type.

Should I switch these tickle messages to high-priority or will I have network access when I receive normal-priority messages? My testing with Android M Previews seems to indicate the network sometimes isn't available.

Upvotes: 1

Views: 466

Answers (1)

PaulR
PaulR

Reputation: 3293

Network access MIGHT be available and you should not switch your message type to high-priority just to ensure network access is available. You should only switch your message type if the GCM Message is of urgent need to a user on that device. A general rule would be that the notification would fall under the HIGH category when considering the guidance around creating notifications. If you currently use the same GCM messages for periodic sync requests as well as urgent messages you should separate them.

A little more detail on the "Network access MIGHT be available":

As of October 1st up-to-date versions of Google Play services correlate the delivery of GCM normal-priority messages with Doze's maintenance mode, so the network typically won't be restricted. A developer asking this question should consider that a robust app will typically deal with Doze and real-world network connectivity problems at the same time. The app would typically:

  • Not execute network work in the callbacks invoked when receiving GCM messages.
  • When a GCM message callback is received by the app the app would schedule work using GCMNetworkManager, JobScheduler, or at the very least SyncAdapter.

The network scheduling routines:

  • Correlate work execution within Doze maintenance windows.
  • Allow additional granular scheduling parameters that allow for better user experiences, particular with regard to battery life (Wifi vs Cellular, Charging, etc).
  • Acquire wakelocks to try to prevent the device from going asleep halfway through performing work. Doze will sometimes ignore wakelocks, such as at the end of the maintenance window.
  • Have built-in ways of indicating work is complete and rescheduling when appropriate.
  • Reschedule work using exponential back-off potentially providing a developer's server relief during outages as well as providing users with better battery life under network connectivity issues.

Note: When testing with a device, including one with Android M Preview, make sure Google Play services is fully up-to-date before testing (v8.1+). This typically requires opening the Google Play store app and accepting the Terms of Service.

Upvotes: 1

Related Questions