Search code examples
androidbattery

What is exactly "Adaptive battery", and what does it mean for app developers?


Background

Google has announced on Google IO 2018 something that's called "Adaptive battery":

https://youtu.be/ogfYd705cRs?t=3562

As a user, this sounds promising, but as a developer, this could be an issue in some cases.

The problem

They said it checks which apps are used more often using AI, and that the "OS adapts to your usage pattern" :

Adaptive Battery uses on-device machine learning to figure out which apps you’ll use in the next few hours and which you won’t use until later, if at all today

To me it sounds like it might be yet another step in the "war against background processing apps".

What I've found

Since this is very new, I haven't found anything of how it works, and if developers should be concerned about it and need to change apps.

Only things I've found are articles from user-point-of-view.

The questions

  1. What is exactly "Adaptive battery"?

  2. Should developers be worried when it's being enabled?

  3. Which app components, background-processing classes, alarms, wakelocks, syncing classes, background/foreground services etc... - might be affected by it?

  4. If indeed it can affect the nature of the app, is there any API to check if it's enabled, and act accordingly? If so, how?

  5. How does it compare to other battery-saving mechanisms?


Solution

  • I agree, this “Adaptive Battery” sounds concerning. This new version of Android, named Android P, “puts AI at the core of the operating system and focuses on intelligent and simple experiences.” (1) On the developer’s blog, they quote, “For developers, Android P beta offers a range of ways to take advantage of these new smarts, especially when it comes to increasing engagement with your apps.” (1) It is pretty obvious that while they are trying to make their OS better for the general public, they have not forgotten their developers.

    The two things that are the most concerning with Android P are the Adaptive Battery and Background Restrictions changes. I will try to answer your five questions to the best of my ability, but of course with Android P being in beta, not everything is ironed out yet.

    1. What exactly is “Adaptive Battery?”

    “In Android P we’ve partnered with DeepMind on a new feature we call Adaptive Battery that optimizes how apps use battery”(1). What Android is using DeepMind for is categorizing apps into different “App Standby buckets” which range from “active” to “rare.” Based on which standby bucket the application is put into, it will vary the restrictions on alarms, jobs, network and high-priority Firebase Cloud messages.

    These buckets are: Active – meaning the app is currently being used. Working set – meaning the app is in regular use. Frequent – meaning the app is often used, but not every day. Rare – meaning the app is not frequently used. Obviously these buckets are not clear cut because they are dependent on the DeepMind AI that Android P is implementing. Please follow this link for a better explanation on what the buckets are and how they are used. Also, this link is the Appendix for Power management restrictions, that will also shed light on the Adaptive Battery.

    They also say “If your app is optimized for Doze, App Standby, and Background Limits, Adaptive Battery should work well for you right out of the box. We recommend testing your app in each of the four buckets.”

    2. Should developers be worried when it’s being enabled?

    It looks like developers might have some cause for concern if they do not plan for this. Looking through the power management appendix I linked above, the biggest changes are how long jobs and alarms are deferred. However, it looks like if you force jobs or alarms, then they will fire.

    I think, for developers, it would be wise to heed their warning of optimizing your application for Doze, App Standby and Background Limits. And if that is not the route you want to go, I would highly recommend at least make sure to test your app in each of the four buckets.

    3. Which app components might be affected by it?

    Because Android P is still in beta, these are subject to change. For now, the only app components that would be effected would be: Jobs, Alarms, Network, and Firebase Cloud Messaging. These are all effected differently based on the standby bucket that DeepMind decides they should be in.

    Another note, I mentioned background restrictions and was going to elaborate a little on it here, because it is similar to Adaptive Battery in the sense of its limiting powers. Background Restrictions point out applications that have been using battery in the background, and allows users to put restrictions on them. “When an app is restricted, its background jobs, alarms, services, and network access are affected.” So if a user deems your application as taking too many resources, you will get restricted and it seems as if this is like being put into a low priority standby bucket. There are however, ways in the Android P API to check whether your app is restricted, which will be helpful towards developers.

    4. If indeed it can affect the nature of the app, is there any API to check if it’s enabled, and act accordingly?

    Yes, there are calls in the API that can tell you which bucket that you are in, and whether your app is being restricted as I said before. For example, you can find out what bucket that your application is currently in by calling: UsageStatsManager.getAppStandbyBucket()

    Also, there are great ways to test your application using the Android Debug Bridge in each of these buckets. Just follow this link.

    5. How does it compare to other battery-saving mechanisms?

    This type of bucket battery saving way, to my knowledge, has never been implemented before. This is a new experience. However, I know that the background restrictions have been available since Android Oreo, where the users could see what apps were acting out. However, in Oreo the users could only see what apps were sucking battery, but couldn’t place restrictions.

    An interesting example I found here: “So, for example, let’s say you really only look at Instagram at night. In that case, Adaptive Battery will learn this behavior and keep the app in sleep mode during the day, then wake it up when you’re most likely to use it.” That is an example they gave for Android P for how DeepMind will work to place applications into these standby buckets.

    Overall, I do think that this is a good step for Android, who has always been plagued by battery issues. As long as developers are not spamming their users with wake locks, notifications, or other things that aren’t necessary, this really shouldn’t impact their application too much. However, this does make it so developers have to put in more work, like checking what bucket they are in and acting accordingly. Time will tell if this is a good step for Android.

    Links

    1. (1) - https://android-developers.googleblog.com/2018/05/whats-new-in-android-p-beta.html#androidbeta
    2. (2) - https://developer.android.com/preview/features/power#buckets
    3. (3) - https://developer.android.com/preview/features/power-details
    4. (4) - https://www.howtogeek.com/352364/how-android-p-will-increase-battery-life/