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. Battery Optimization Restrictions Meets Notifications Wahib Ul Haq Google IO

    Extended 07.05.2019 #Munich
  2. Source: https://phandroid.com

  3. https://xda-cdn.com

  4. None
  5. None
  6. 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
  7. 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()
  8. 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
  9. Over time, in cases of longer-term inactivity the system schedules

    maintenance windows less and less frequently, helping to reduce battery consumption
  10. Use Cases

  11. FCM High Priority

  12. FCM High Priority Deliver high priority messages immediately, wake a

    sleeping device when necessary and run some limited processing
  13. 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
  14. In our case it was a “Data Message” or “Silent

    Notification” without any UI interaction possible
  15. What if we use “high priority”? Who is stopping us?

  16. If FCM detects a pattern in which they don’t result

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

    in user interaction, your messages may be de-prioritised!!
  18. App Standby Modes http://codinginfinite.com

  19. App Standby Modes http://codinginfinite.com

  20. What brings app back to “active state”? Opening the app

    makes it active only for an hour or so, it then moves back
  21. 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
  22. 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
  23. How can you debug?

  24. ADB FTW Doze App Standby

  25. Developer Options (9.0+)

  26. Whitelisting App Min Sdk >= 23 REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission in AndroidManifest.xml

  27. Whitelisting App Min Sdk >= 23 REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission in AndroidManifest.xml

  28. 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
  29. Thanks for listening! @wahibhaq

  30. None