The problem My Android automated tests are unreliable, because the tested activities are sometimes running and are sometimes paused.
The cause If my android device (a Samsung Galaxy S2) has its Lock Screen on, all activities are immediately put in Pause mode.
How can I programmatically disable the Lock Screen while my tests are running?
Here is what I tried and that produced no result at all (i.e., Lock Screen still active and pausing my activities).
Add the
android.permission.DISABLE_KEYGUARD
permission and useKeyguardLock.disableKeyguard()
as explained in the android doc.Set Window flags: FLAG_SHOW_WHEN_LOCKED, FLAG_TURN_SCREEN_ON, FLAG_DISMISS_KEYGUARD.
Use
WakeLock.acquire()
withPowerManager.FULL_WAKE_LOCK
,PowerManager.ACQUIRE_CAUSES_WAKEUP
,PowerManager.ON_AFTER_RELEASE
andPowerManager.SCREEN_BRIGHT_WAKE_LOCK
parameters.adb shell input keyevent 82