Android - Battery Optimization

History CapaInstaller Android Support

CapaInstaller uses an app as an agent for Android units.

  • The agent version 1.0.xxx was used until CapaInstaller release 5.7.100, then it was substituted with a new agent having the same functionality and other improvements.
  • The new agent is versioned 2.x.x.

Android History

In general Android has been a very open platform allowing apps to do a lot of stuff. Later Android releases have restricted applications much more and introduced newer device policy management concepts (Device Administrator / Device Owner / Profile Owner).

Previously an app could drain the battery quite fast if it wasn’t optimized. In newer Android versions from Android 6 and upwards, this has been optimized so apps are being “battery optimized”.

Battery optimization is being more and more restrictive, over the newer Android versions. Battery optimizations are firstly controlled by an individual app setting. The new CapaInstaller Agent prompts the user for preventing battery optimization. But even if the app is not battery optimized it will still be optimized and especially from Android 8 this they have further increased the battery optimizations. For further and deep technical explanations see: https://developer.android.com/topic/performance/power

In general, it can be given that these factors apply for determining whether an app should be optimized:

  • Battery optimization disabled for the app
  • Android version
  • App usage by the user
  • Priority push messages received
  • Privileged apps
  • Vendor-specific optimizations


In general, the CapaInstaller Agent will fulfill most of these factors except the user interaction part (The CapaInstaller agent is rarely clicked by the end-user), some may even have blacklisted the CapaInstaller Agent so the end-user will be unable to launch the app.

Vendor-specific optimizations

Several Android vendors (Samsung, Huawei, Motorola, etc..) have made their own “smart” battery optimizations. Some of these must be disabled manually.

  1. Open Settings.

  2. Tap Battery.

  3. Tap the ellipse and tap Battery optimization.

  4. Tap the down arrow and tap All apps.

  5. For the CapaInstaller Agent tap Not optimized to turn off battery optimization.

Optimized:

  • Application is not whitelisted
  • Application is optimized
  • Battery is optimized
  • The default state for all applications other than some Google system apps

Not Optimized:

  • Application is whitelisted
  • Application is not optimized
  • The application may drain your device battery more quickly
  • Battery optimizations are being ignored

Doze and App Standby

Starting from Android 6.0 (API level 23), Android introduces two power-saving features. Doze reduces battery consumption by deferring background CPU and network activity for apps when the device is unused for long periods of time. App Standby defers background network activity for apps with which the user has not recently interacted.

Doze Mode

If a user leaves a device unplugged and stationary for a period of time, with the screen off, the device enters Doze mode. In Doze mode, the system attempts to conserve battery by restricting the CapaInstaller agent's access to network and CPU-intensive services. It is also prevented from accessing the network and jobs and syncs are deferred.

Periodically, the system exits Doze for a brief time to let apps complete their deferred activities. During this maintenance window, the CapaInstaller agent runs all pending syncs, jobs, and gets access to the network.

App Standby

App Standby allows the system to determine that an app is idle when the user is not actively using it. The system makes this determination when the user does not touch the app for a certain period of time and none of the following conditions applies:

  • The user explicitly launches the app.
  • The app is currently in the foreground (visible to the user).

When the user plugs the device into a power supply, the system releases apps from the standby state, allowing them to freely access the network and to execute any pending jobs and syncs. If the device is idle for long periods of time, the system allows idle apps network access around once a day.


App Standby Buckets

Android 9 (API level 28) introduces a new battery management feature, App Standby Buckets. App Standby Buckets help the system prioritize apps' requests for resources based on how recently and how frequently the apps are used. Based on app usage patterns, each app is placed in one of five priority buckets. The system limits the device resources available to each app based on which bucket the app is in.


The buckets are:

  • Active: App is currently being used or was very recently used
    • No restrictions
  • Working set: App is in regular use
    • the Working set. Network access is deferred.
  • Frequent: App is often used, but not every day
    • the Frequent set. Network access is deferred and Push notifications is limited to 10 messages per day.
  • Rare: App is not frequently used
    • the Frequent set. Network access is deferred and Push notifications is limited to 5 messages per day.

Battery Saver improvements


Battery Saver applies restrictions to all applications on the device. When turned on, Battery Saver takes steps to reduce battery consumption such as stopping all applications from performing background work and disallowing network access to any application not in the foreground. The best official documentation is on Google’s Battery Saver support page.

Battery Saver is not new to Pie, but it has been improved in a couple of ways.

Although disabled out of the box, Battery Saver can either be turned on manually by the user or be configured to turn on automatically at some specified battery percentage (15% by default).


Battery Saver

Oreo

Pie

Out-of-box state

Off; Battery Saver does not automatically enable

Off; Battery Saver does not automatically enable

How to manually enable

From the Battery Saver menu (Settings -> Battery -> Battery Saver) or Quick Settings icon

From the Battery Saver menu (Settings -> Battery -> Battery Saver) or Quick Settings icon

Supported "turn on automatically at X%" percentages

Supports only 10% or 18%

Configurable from 5% to 75%

How to turn off Battery Saver

Manually from the Battery Saver menu / Quick Settings icon or by providing power to the device

Manually from the Battery Saver menu / Quick Settings icon.

Providing power to the device only disables Battery Saver while power is applied

What to do

In general, the CapaInstaller agent shall be at least 2.1.5 and it must be installed/configured to not allow battery optimization for the CapaInstaller agent (agent is prompting the user).

For Android versions above Android 8, the agent should be upgraded to version 2.2.x or newer in order to work with reoccurring callbacks to the CapaInstaller backend servers.

What shall we do with old agents, not responding?

If you have some agents which have not communicated with CapaInstaller for a long time, we recommend the following approach:

  1. Determine if this device is still in actual use? (Device is erased and sold, device obsolete and dropped in a drawer, the user is on absent, etc…..)
  2. Will this device be phased out within a few months anyway, then we can just ignore it.
  3. Ask the user of the device to open the CapaInstaller Agent. Just by opening the agent, it will probably try to call home.
  4. If the device doesn’t call home even though the app is started you can on agents 1.x.x press the burger menu and select “Call home” and on an agent, 2.x.x click the profiles tab and click the refresh symbol.
  5. Finally, it will be a good idea to update the CapaInstaller agent to version 2.2.x or newer.