Testing Doze mode
Android’s Doze mode is triggered when the device is unplugged, stationary, and the screen is off for an extended period. You can force your device into Doze mode using ADB commands to test how your app behaves.
Prerequisites
- Android device or emulator connected via ADB
- USB debugging enabled on device
- ADB installed on your development machine
Force device into Doze mode
-
Disconnect device from charger (required for Doze mode)
-
Connect via ADB
-
Unplug USB charging (if testing on physical device)
-
Force device into idle state
-
Verify Doze mode is active
Exit Doze mode
To return the device to normal operation:
Always reset battery status after testing. Otherwise, your device may continue to report it’s unplugged even when connected to power.
Step through Doze mode states
To gradually simulate the Doze mode progression:
Debugging wake locks
Check if wake lock is held
Use ADB to inspect all active wake locks on the device:
This shows:
- Whether your wake lock is active
- How long it has been held
- The wake lock tag (if you specified one)
Example output
Check wake lock programmatically
Add debug logging to your app:
View all system wake locks
To see all wake locks from all apps:
Look for the “Wake Locks” section in the output.
Checking battery optimization status
Via ADB
Check if your app is whitelisted from battery optimizations:
Look for your app’s package name in the output.
Via app code
Add logging to verify exemption status:
Testing OEM-specific settings
Check device manufacturer
Manual testing checklist
For devices with aggressive battery optimization:
Verify that:
openOEMSettings() opens the correct settings page
- The settings page allows whitelisting your app
- Background functionality works after whitelisting
Common debugging scenarios
Scenario 1: Wake lock released unexpectedly
Symptoms: Background task stops running even though wake lock was acquired.
Debug steps:
Common causes:
- Wake lock timeout expired (default 24 hours)
- App was force-stopped by user
- OEM battery optimization killed the app
Scenario 2: Battery exemption not working
Symptoms: App still killed in background despite exemption.
Debug steps:
Common causes:
- Power Save mode is enabled (affects all apps)
- OEM-specific battery optimization not disabled
- App Standby restrictions
Scenario 3: Screen wake lock not working
Symptoms: Screen turns off despite calling enableScreenWakeLock().
Debug steps:
Common causes:
- Screen wake lock only works when app is in foreground
- Flag cleared when navigating between screens
- Another component disabled the flag
Track wake lock duration
Monitor battery impact
Wake locks can significantly impact battery life. Always release them when background work is complete.
Testing checklist
Before releasing your app, verify: