Android: remove or disable programmatically the Lock Screen on Samsung Galaxy S2 device

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 use KeyguardLock.disableKeyguard() as explained in the android doc.
  • Set Window flags: FLAG_SHOW_WHEN_LOCKED, FLAG_TURN_SCREEN_ON, FLAG_DISMISS_KEYGUARD.
  • Use WakeLock.acquire() with PowerManager.FULL_WAKE_LOCK, PowerManager.ACQUIRE_CAUSES_WAKEUP, PowerManager.ON_AFTER_RELEASE and PowerManager.SCREEN_BRIGHT_WAKE_LOCK parameters.
  • adb shell input keyevent 82

Leave a Comment