I've noticed very interesting behavior of Android that I cannot explain. I'm using the following code to wake up the phone and disable keyguard:
PowerManager.WakeLock mFullWakelock = mPowerManager.newWakeLock(
(PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
PowerManager.FULL_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP),
LOCK_TAG
);
mFullWakelock.acquire();
KeyguardManager keyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock(LOCK_TAG);
keyguardLock.disableKeyguard();
Imagine there is cycle of wake (programmatically)->disable keyguard (programmatically)->press power button (manually)->wake->disable keyguard. The cycle works great until I manually press Home button while the phone's keyguard is disabled. After that, phone does wake up but keyguard is no longer disabled programmatically. I'd appreciate any ideas!
The problem is that a keylock seems to expire whenever the user presses home button or opens a notification. So whenever this happens, you have to create a new keylock.
I used this solution and it worked great: https://stackoverflow.com/a/14519861/4098821