The power management features released in Android 9 (API level 28) affect all apps running on this version, whether the apps target this version or not. It's important to make sure your app behaves properly on these devices.
Test your app's main use cases under a variety of conditions to see how the power management
features interact with each other. You can use Android
Debug Bridge (adb
) commands to turn some of the features on and off.
Android Debug Bridge (adb) commands
You can use adb
shell commands to test several of the power management features.
For information about using adb
to put your device in Doze, see
Test with Doze
and App Standby.
App Standby Buckets
You can use adb
to manually assign your app to an App Standby Bucket. To change an
app's bucket, first simulate unplugging the device using the following command:
$ adb shell dumpsys battery unplug
Use the following command to assign your app to a standby bucket:
$ adb shell am set-standby-bucket packagename active|working_set|frequent|rare
You can also use the preceding command to set multiple packages at once:
$ adb shell am set-standby-bucket package1 bucket1 package2 bucket2...
To check what bucket an app is in, run the following:
$ adb shell am get-standby-bucket packagename
If you don't pass a packagename parameter, the command lists the buckets for all apps.
An app can also find out its bucket at runtime by calling the new method
UsageStatsManager.getAppStandbyBucket()
.
Background restrictions
To manually apply background restrictions, run the following command:
$ adb shell cmd appops set packagename RUN_ANY_IN_BACKGROUND ignore
To remove background restrictions, run the following command:
$ adb shell cmd appops set packagename RUN_ANY_IN_BACKGROUND allow
Battery saver
There are several commands to test how your app behaves in low-power conditions.
To simulate the device being unplugged, use the following command:
$ adb shell dumpsys battery unplug
To test how the device behaves under low power conditions, use the following command:
$ adb shell settings put global low_power 1
After you finish testing, you can undo your manual device settings with the following command:
$ adb shell dumpsys battery reset