[null,null,["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Test power-related issues\n\nThe power management features released in Android 9 (API level 28) affect all apps running on\nthis version, whether the apps target this version or not. It's important to make sure your app\nbehaves properly on these devices.\n\nTest your app's main use cases under a variety of conditions to see how the power management\nfeatures interact with each other. You can use [Android\nDebug Bridge (`adb`)](/studio/command-line/adb) commands to turn some of the features on and off.\n\n### Android Debug Bridge (adb) commands\n\nYou can use `adb` shell commands to test several of the power management features.\n\nFor information about using `adb` to put your device in Doze, see\n[Test with Doze\nand App Standby](/training/monitoring-device-state/doze-standby#testing_doze_and_app_standby).\n\n#### App Standby Buckets\n\nYou can use `adb` to manually assign your app to an App Standby Bucket. To change an\napp's bucket, first simulate unplugging the device using the following command: \n\n```\n$ adb shell dumpsys battery unplug\n```\n\nUse the following command to assign your app to a standby bucket: \n\n```\n$ adb shell am set-standby-bucket \u003cvar translate=\"no\"\u003epackagename\u003c/var\u003e active|working_set|frequent|rare\n```\n\nYou can also use the preceding command to set multiple packages at once: \n\n```\n$ adb shell am set-standby-bucket \u003cvar translate=\"no\"\u003epackage1\u003c/var\u003e \u003cvar translate=\"no\"\u003ebucket1\u003c/var\u003e \u003cvar translate=\"no\"\u003epackage2\u003c/var\u003e \u003cvar translate=\"no\"\u003ebucket2\u003c/var\u003e...\n```\n\nTo check what bucket an app is in, run the following: \n\n```\n$ adb shell am get-standby-bucket \u003cvar translate=\"no\"\u003epackagename\u003c/var\u003e\n```\n\nIf you don't pass a \u003cvar translate=\"no\"\u003epackagename\u003c/var\u003e parameter, the command lists the buckets for all apps.\nAn app can also find out its bucket at runtime by calling the new method\n[`UsageStatsManager.getAppStandbyBucket()`](/reference/android/app/usage/UsageStatsManager#getAppStandbyBucket()).\n\n#### Background restrictions\n\nTo manually apply background restrictions, run the following command: \n\n```\n$ adb shell cmd appops set \u003cvar translate=\"no\"\u003epackagename\u003c/var\u003e RUN_ANY_IN_BACKGROUND ignore\n```\n\nTo remove background restrictions, run the following command: \n\n```\n$ adb shell cmd appops set \u003cvar translate=\"no\"\u003epackagename\u003c/var\u003e RUN_ANY_IN_BACKGROUND allow\n```\n\n#### Battery saver\n\nThere are several commands to test how your app behaves in low-power conditions.\n| **Note:** You can also use the device **Settings \\\u003e Battery saver** screen to put the device in battery saver mode.\n\nTo simulate the device being unplugged, use the following command: \n\n```\n$ adb shell dumpsys battery unplug\n```\n\nTo test how the device behaves under low power conditions, use the following command: \n\n```\n$ adb shell settings put global low_power 1\n```\n\nAfter you finish testing, you can undo your manual device settings with the following\ncommand: \n\n```\n$ adb shell dumpsys battery reset\n```"]]