Test power-related issues

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.

Be sure to 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 commands to turn some of the features on and off.

Android Debug Bridge commands

You can use Android Debug Bridge shell commands to test several of the power management features.

For information on using ADB to put your device in Doze, see Testing 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 this command:

$ adb shell dumpsys battery unplug

And then use the following command:

$ adb shell am set-standby-bucket packagename active|working_set|frequent|rare
You can also use that 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

$ 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 this command:

$ adb shell cmd appops set packagename RUN_ANY_IN_BACKGROUND ignore

To remove background restrictions, run this 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.

Note: You can also use the device Settings > Battery saver screen to put the device in battery saver mode.

To simulate the device being unplugged, use the command:

$ adb shell dumpsys battery unplug

To test how the device behaves under low power conditions, use this command:

$ adb shell settings put global low_power 1

Once you have finished your testing, you can undo your manual device settings with this command:

$ adb shell dumpsys battery reset