androidwakelockpowermanager

How to test Wake Lock


I'm working on a fairly complex application and I am using alarms to wake the device when needed and to acquire a wake lock until the task is over. This happens in different places in code. I'm fairly certain my logic is correct but it's very hard to properly test it.

ADB seems to hold a wake lock of it's own.

How can I test to see if all my wake locks (System wide) are released and the device is actually asleep?


Solution

  • Just use the same Alarm to schedule some task after 20 minutes (this should be enough for any device enter on "sleep state"), this could be something like play a song or something that could notify you. Schedule the alarm without the wake lock, your task should fail.

    Remember to unplug your device from ADB.