Skip to main content

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

  1. Disconnect device from charger (required for Doze mode)
  2. Connect via ADB
  3. Unplug USB charging (if testing on physical device)
  4. Force device into idle state
  5. 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:
  • Test on Xiaomi (MIUI)
  • Test on Huawei (EMUI)
  • Test on Samsung (OneUI)
  • Test on Oppo (ColorOS)
  • Test on Vivo (FuntouchOS)
Verify that:
  1. openOEMSettings() opens the correct settings page
  2. The settings page allows whitelisting your app
  3. 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

Performance monitoring

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:
  • Wake lock is acquired successfully
  • Wake lock is released when done
  • App survives Doze mode when exempt
  • Battery optimization exemption can be requested
  • OEM settings open on supported devices
  • Power Save mode is detected correctly
  • Screen wake lock works in foreground
  • Battery impact is acceptable
  • App handles AppState changes correctly
  • Status refreshes when returning to foreground