Skip to content

Instantly share code, notes, and snippets.

@Julioevm
Forked from whileloop99/doze_mode_adb_commands.sh
Last active April 28, 2021 12:41
Show Gist options
  • Save Julioevm/088f5f4f8bd0cf92865c6b8128d421d2 to your computer and use it in GitHub Desktop.
Save Julioevm/088f5f4f8bd0cf92865c6b8128d421d2 to your computer and use it in GitHub Desktop.
adb commands to test Doze mode
#! /bin/zsh
#
# https://developer.android.com/training/monitoring-device-state/doze-standby
# https://stackoverflow.com/questions/31533972/how-to-shift-device-in-doze-mode-android-preview-m-marshmallow
# Buttery powered state
adb shell dumpsys battery | grep powered
# Unplug battery
adb shell dumpsys battery unplug
# Reset battery
adb shell dumpsys battery reset
# Dump Doze mode info
adb shell dumpsys deviceidle
# Enable Doze mode (may be required on Android Emulator)
adb shell dumpsys deviceidle enable
# Get status of Light Doze mode
adb shell dumpsys deviceidle get light
# Get status of Deep Doze mode
adb shell dumpsys deviceidle get deep
# Enter Light Doze mode (should be called several times to pass all phases)
adb shell dumpsys deviceidle step light
# Enter Light Doze mode (should be called several times to pass all phases)
adb shell dumpsys deviceidle step deep
# Force Doze mode
adb shell dumpsys deviceidle force-idle
# Exit forced Doze mode
adb shell dumpsys deviceidle unforce
# Force the system into idle mode
adb shell dumpsys deviceidle force-idle
# Exit idle mode
adb shell dumpsys deviceidle unforce
# Testing your app with App Standby
# To test the App Standby mode with your app:
# Configure a hardware device or virtual device with an Android 6.0 (API level 23) or higher system image.
# Connect the device to your development machine and install your app.
# Run your app and leave it active.
# Force the app into App Standby mode by running the following commands:
$ adb shell dumpsys battery unplug
$ adb shell am set-inactive <packageName> true
# Simulate waking your app using the following commands:
$ adb shell am set-inactive <packageName> false
$ adb shell am get-inactive <packageName>
# Observe the behavior of your app after waking it. Make sure the app recovers gracefully from standby mode.
# In particular, you should check if your app's Notifications and background jobs continue to function as expected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment