Standby Testing Using ADB Commands Notes By ShariqSP

Standby Testing Using ADB Commands

1. Setting Up ADB for Standby Testing

Android Debug Bridge (ADB) can simulate various power states, such as standby (sleep mode) and wake. These states are crucial for testing app behavior during low-power or background states. Follow these setup steps:

  1. Ensure ADB is installed and configured on your system as described in previous sections.
  2. Connect your device to your computer and verify the connection:
    adb devices
  3. Enable USB Debugging on your device:
    • Go to Settings > Developer Options and enable USB Debugging.

2. Simulating Standby States

Use ADB commands to put the device into standby mode, wake it up, or test other power-related states:

  • Turn Off the Screen (Sleep Mode):
    adb shell input keyevent 26
    • This simulates pressing the power button to turn off the screen and put the device in sleep mode.
  • Wake Up the Device:
    adb shell input keyevent 224
    • This wakes the device and turns the screen back on.
  • Unlock the Screen:
    adb shell input keyevent 82
    • This simulates pressing the unlock button (e.g., to access the home screen).
  • Simulate Long Idle States:
    adb shell dumpsys deviceidle force-idle
    • This forces the device into an idle state (Doze Mode) for testing apps under low-power conditions.

3. Testing App Behavior During Standby

Perform specific tests to ensure your app behaves correctly during standby or sleep:

  • Test Notifications:
    • Send a push notification while the device is in standby mode and verify it is delivered upon wake.
  • Background Services:
    • Check if background tasks (e.g., data sync) resume properly after the device wakes up.
  • Battery Optimization:
    • Use the following command to simulate power-saving modes and verify app performance:
      adb shell settings put global low_power 1

4. Monitoring Battery and Power Usage

Use ADB to monitor battery and power states during standby testing:

  • Check Battery Stats:
    adb shell dumpsys battery
    • This displays the current battery status, charge level, and other details.
  • Enable Power Save Mode:
    adb shell settings put global low_power 1
    • This enables battery saver mode for testing app performance under limited resources.
  • Disable Power Save Mode:
    adb shell settings put global low_power 0

5. Practical Testing Scenarios

Standby testing ensures that your app handles power transitions smoothly. Here are some scenarios:

  • Notification Testing: Send notifications to the device while it's in sleep mode and verify they appear correctly upon wake.
  • Data Synchronization: Test if background data syncing resumes when the device wakes from idle mode.
  • Power Mode Effects: Enable power-saving mode and verify reduced functionality or optimizations in the app.
  • Doze Mode Testing: Force the device into Doze Mode using:
    adb shell dumpsys deviceidle force-idle
    Verify that critical app functions (e.g., alarms, notifications) work as expected during and after Doze Mode.

By simulating standby and power-saving states, you can ensure your app maintains performance and functionality under various power conditions.