Android 10 introduces a Battery Saver schedule option called Based on routine. This option lets an app chosen by the OEM provide signals to the system for more intelligent Battery Saver scheduling. This option requires configuration, and is optional to implement.
Device configuration
This section describes how to configure your device for the Based on routine option.
Provider specification
To notify the Settings UI that the device is configured correctly, use your
config overlay to override the value config_batterySaverScheduleProvider with
the package name of your app. For example, if you want the app package
com.google.android.apps.turbo to control the Based on routine setting, set
this config value:
<string name="config_batterySaverScheduleProvider" translatable="false">
com.google.android.apps.turbo</string>
To verify, build your image, flash it to a device, and navigate to Settings
Battery > Battery Saver > Battery Saver schedule. The Based on routine option appears.
Default off threshold
The config_dynamicPowerSavingsDefaultDisableThreshold field specifies a
battery level at which the system turns off Battery Saver if the Based on
routine scheduler turned it on. The system default is 80%, but you can change
it.
App configuration
This section describes how to configure your app to use the Based on routine option.
Permissions
The APIs necessary for an app to enable routine Battery Saver are protected by
the android.permission.POWER_SAVER permission. This is a signature or
privileged permission. This means that the app must be in a priv-app directory
on the system image, and you must explicitly grant this permission.
For privileged apps, you must grant permissions in a system configuration XML
file in the /etc/permissions/ directory on the same partition as the app. For
example, to grant the android.permission.POWER_SAVER permission to an app with
the package name com.google.android.apps.turbo:
<!-- File located at /etc/permissions/privapp-permissions-DEVICE_NAME.xml -->
<permissions>
<privapp-permissions package="com.google.android.apps.turbo">
<permission name="android.permission.POWER_SAVER"/>
</privapp-permissions>
</permissions>
If you don't pregrant this permission to the app on the system image, the app can't acquire the permission or call the APIs successfully. The system doesn't provide feedback beyond standard permission errors, so it's critical to verify that the app can call the APIs and observe their effects.
Installation
For Based on routine to work properly, you must preinstall the app on the
system image with the required permission. Give only one app the
android.permission.POWER_SAVER permission and let it control the Based on
routine APIs. The feature's behavior is unsupported and unspecified if more
than one app tries to use the permission and APIs.
Trigger routine Battery Saver
This section describes how your app can trigger Based on routine Battery Saver using the provided APIs.
APIs
If setup is successful, the OEM app specified in the config can successfully
call the associated method in PowerManager to trigger Battery Saver:
public boolean setDynamicPowerSaveHint(boolean powerSaveHint, int disableThreshold)
If the Based on routine Battery Saver schedule option is enabled and the app
calls this method with a true value for powerSaveHint, Battery Saver turns
on. Specify disableThreshold so that if the app can't communicate with the
system, the system still knows the battery percentage at which it's safe to turn
off Battery Saver.
This API is subject to user overrides and Battery Saver snoozing in the same way as the percentage-based automatic Battery Saver. See the API documentation for more information.
To verify that the APIs are called successfully, query global settings to
confirm that the backing setting value changed according to the API calls.
For example, if you select Based on routine Battery Saver mode and the app
calls setDynamicPowerSaveHint(true, 10), the global settings have these
values:
automatic_power_save_mode: 1
dynamic_power_savings_disable_threshold: 10
dynamic_power_savings_enabled: 1
If you then call setDynamicPowerSaveHint(false, 25), the values are:
automatic_power_save_mode: 1
dynamic_power_savings_disable_threshold: 25
dynamic_power_savings_enabled: 0
You can check these values by using this adb command:
adb shell settings get global <setting-name>
Verification
There's no automated way to verify this feature because the OEM determines the behavior that triggers Based on routine Battery Saver mode. OEMs must test their integration to verify the behavior meets expectations. Specifically, verify that the device can perform the following tasks:
- Based on percentage: If you select Based on percentage in the Battery Saver schedule UI and select 15%, Battery Saver turns on automatically only when the battery reaches 15%.
- Based on routine: If you select Based on routine in the Battery
Saver schedule UI, Battery Saver turns on when the app calls the API with
true. Additionally, Battery Saver automatically turns off if the device charges to the indicated threshold level and is unplugged. - None: If you select None in the Battery Saver schedule UI, Battery Saver never turns on automatically.
- Manual override: If the app turns on Battery Saver and you manually override Battery Saver to turn it off (using Quick Settings, Settings, or other methods), it stays off until you either turn it back on manually or plug in the device.