Battery longevity on mobile devices depends heavily on operating system power-management subsystems. Android includes an aggressive battery-saving architecture known as Doze Mode. When a device is unplugged, stationary, and left with its screen off for a prolonged period, Android enters deep Doze, cutting off background network access, deferring synchronization tasks, and ignoring partial wake locks until periodic “maintenance windows” open.
For mobile application developers, testing whether background services, WorkManager tasks, and Firebase Cloud Messaging (FCM) high-priority notifications function reliably in Doze mode presents a physical dilemma. Under normal conditions, Doze mode requires disconnecting the USB cable, setting the phone down on a flat surface, and waiting several hours for inactivity thresholds to elapse. By utilizing the Android Debug Bridge (ADB), developers can bypass physical timers, simulate battery disconnections, and step through Doze mode states instantly while retaining live debugging connectivity.
Prerequisites and USB Debugging Setup
Ensure your Android device has Developer Options and USB Debugging active:
- Go to Settings > About phone and tap Build number seven times.
- In Settings > System > Developer options, enable USB debugging.
- Connect the phone to your computer and confirm connectivity in your terminal:
adb devices
Simulating Battery Disconnection While Connected via USB
By default, Android refuses to enter Doze mode if it detects that the device is charging. Because ADB communication typically operates over a powered USB cable, you must instruct the battery service to spoof an unplugged state:
adb shell dumpsys battery unplug
Your phone status bar immediately changes from charging to discharging, even though the physical USB data connection remains intact.
Forcing Android into Deep Doze Mode
To bypass all delay timers and immediately force the device into the deepest Doze sleep state:
adb shell dumpsys deviceidle force-idle
When this command executes, Android locks down background execution. To verify the active state, query the deviceidle subsystem:
adb shell dumpsys deviceidle get deep
The console will output IDLE, indicating the device is fully asleep.
Stepping Through Doze State Transitions
Android transitions through several distinct phases before reaching full idle: ACTIVE > INACTIVE > IDLE_PENDING > SENSING > LOCATING > IDLE > IDLE_MAINTENANCE. To observe how your application responds during each step:
# Step to the next sequential Doze state
adb shell dumpsys deviceidle step deep
Each time you run the step command, Android advances one stage. When it reaches IDLE_MAINTENANCE, Android temporarily opens network access to let queued sync jobs run before returning to IDLE.
Testing Light Doze Mode in Android
In addition to deep Doze, Android supports Light Doze, which activates quickly whenever the screen is turned off—even while the user is walking or carrying the phone in a pocket:
# Step through Light Doze states
adb shell dumpsys deviceidle step light
# Check current light idle state
adb shell dumpsys deviceidle get light
Testing Whitelisted App Standby Exemptions
If your application requires persistent background execution (such as a VoIP calling service or medical monitor), test adding and removing it from the battery optimization whitelist:
# Add your app package to the Doze whitelist
adb shell dumpsys deviceidle whitelist +com.example.myapp
# Remove your app from the whitelist
adb shell dumpsys deviceidle whitelist -com.example.myapp
# Print all currently whitelisted apps
adb shell dumpsys deviceidle whitelist
Resetting Device Battery and Doze States
Once your testing is complete, restore the phone’s battery subsystem to real hardware charging status and disable forced idle overrides:
# Disable forced idle state
adb shell dumpsys deviceidle unforce
# Reset the battery subsystem to real hardware status
adb shell dumpsys battery reset
The phone recognizes the physical USB power source again and resumes standard power management.