Android M Testing with Doze and App Standby

You probably all know that Google has started with the rollout of Android M (Marshmallow). Android app developers and testers must know the new features that are coming with the latest version of Android M. Next to the brand new permission system, Android M also introduces Doze and App standby to save battery.

If a user leaves a device unplugged and stationary for a period of time, with the screen off, the device enters Doze mode. In Doze mode, the system attempts to conserve battery by restricting apps’ access to network and CPU-intensive services. It also prevents apps from accessing the network and defers their jobs, syncs, and standard alarms.
Periodically, the system exits Doze for a brief time to let apps complete their deferred activities. During this maintenance window, the system runs all pending syncs, jobs, and alarms, and lets apps access the network. (Source: Google documentation)

In order to be sure that your app is able to handle Doze and app Standby, Google provided some documentation on that. Here are the steps to make sure your app handles Doze (instructions copied from the documentation):

Testing your app with Doze

You can test Doze mode by following these steps:

    1. Configure a hardware device or virtual device with an Android 6.0 (API level 23) or higher system image.
    2. Connect the device to your development machine and install your app.
    3. Run your app and leave it active.
    4. Force the system to cycle through Doze modes by running the following commands:
$ adb shell dumpsys battery unplug
$ adb shell dumpsys deviceidle step
$ adb shell dumpsys deviceidle -h
  1. Observe the behavior of your app after you reactivate the device. Make sure the app recovers gracefully when the device exits Doze.

Testing your app with App Standby

To test the App Standby mode with your app:

  1. Configure a hardware device or virtual device with an Android 6.0 (API level 23) or higher system image.
  2. Connect the device to your development machine and install your app.
  3. Run your app and leave it active.
  4. Force the app into App Standby mode by running the following commands:
    $ adb shell dumpsys battery unplug
    $ adb shell am set-inactive <packageName> true
  5. Simulate waking your app using the following commands:
    $ adb shell am set-inactive <packageName> false
    $ adb shell am get-inactive <packageName>
  6. 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.

The complete documentation about Doze and App Standby is here: http://developer.android.com/training/monitoring-device-state/doze-standby.html

If you are currently optimizing your app for Android M keep also Doze and App Standby in mind and do not only test for the new permissions.

#HappyTesting