Upgrade to Pro — share decks privately, control downloads, hide ads and more …

How Battery Optimization Restrictions affect Notifications

How Battery Optimization Restrictions affect Notifications

This was meant to share my personal hassle while dealing with restrictions enforced by Doze mode and App Standby buckets in the context of Notifications. Since 6.0, Android is trying to introduce more restrictions to make battery saving more efficient for its users but sometimes it can make life a bit difficult for developers. Important thing is to be aware of how Doze and Standby works and what we can do about it. We can either embrace it or try to fight it.

This talk was given at Google I/O Extended meetup in Munich organized by GDG Android team.

Wahib Ul Haq

May 07, 2019
Tweet

More Decks by Wahib Ul Haq

Other Decks in Technology

Transcript

  1. How can we fight “Doze Mode”? As soon as the

    user wakes the device by moving it*, turning on the screen, or connecting a charger
  2. How can we fight “Doze Mode”? As soon as the

    user wakes the device by moving it*, turning on the screen, or connecting a charger Set critical alarms with setAnndAllowWhileIdle() & setExactAndAllowWhileIdle()
  3. How can we fight “Doze Mode”? As soon as the

    user wakes the device by moving it*, turning on the screen, or connecting a charger Set critical alarms with setAnndAllowWhileIdle() & setExactAndAllowWhileIdle() For Android P+ devices, High Priority FCM push messages will face no restriction https://developer.android.com/training/monitoring-device-state/doze-standby.html
  4. Over time, in cases of longer-term inactivity the system schedules

    maintenance windows less and less frequently, helping to reduce battery consumption
  5. FCM High Priority Deliver high priority messages immediately, wake a

    sleeping device when necessary and run some limited processing
  6. FCM High Priority Deliver high priority messages immediately, wake a

    sleeping device when necessary and run some limited processing High priority messages generally should result in user interaction with your app or its notifications https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message
  7. In our case it was a “Data Message” or “Silent

    Notification” without any UI interaction possible
  8. If FCM detects a pattern in which they don’t result

    in user interaction, your messages may be de-prioritised!!
  9. If FCM detects a pattern in which they don’t result

    in user interaction, your messages may be de-prioritised!!
  10. What brings app back to “active state”? Opening the app

    makes it active only for an hour or so, it then moves back
  11. What brings app back to “active state”? Opening the app

    makes it active only for an hour or so, it then moves back User interacted with notification can keeps it active for longer time ~ 12 hours
  12. What brings app back to “active state”? Opening the app

    makes it active only for an hour or so, it then moves back User interacted with notification can keeps it active for longer time ~ 12 hours App has a foreground service https://developer.android.com/training/monitoring-device-state/doze-standby.html
  13. Key Takeaways Be aware of limitations due to “Battery Optimization”

    Understand “Doze” and “App Standby” mechanism Test well and plan accordingly Use “FCM High Priority” but only where it makes sense and with due diligence