Do not apply keyguard's short timeout when the keyguard is hidden by another window.
Fixes bug b/2215852 (Music player doesn't grab screen wakelock)
Change-Id: I6c402cdb460d216314ad72e37dbcdc7e19518941
Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/policy/com/android/internal/policy/impl/KeyguardViewMediator.java b/policy/com/android/internal/policy/impl/KeyguardViewMediator.java
index 0fba17b3..bfa48ee 100644
--- a/policy/com/android/internal/policy/impl/KeyguardViewMediator.java
+++ b/policy/com/android/internal/policy/impl/KeyguardViewMediator.java
@@ -184,6 +184,9 @@
// answer whether the input should be restricted)
private boolean mShowing = false;
+ // true if the keyguard is hidden by another window
+ private boolean mHidden = false;
+
/**
* Helps remember whether the screen has turned on since the last time
* it turned off due to timeout. see {@link #onScreenTurnedOff(int)}
@@ -418,6 +421,16 @@
}
/**
+ * Notify us when the keyguard is hidden by another window
+ */
+ public void setHidden(boolean isHidden) {
+ synchronized (KeyguardViewMediator.this) {
+ mHidden = isHidden;
+ adjustUserActivityLocked();
+ }
+ }
+
+ /**
* Given the state of the keyguard, is the input restricted?
* Input is restricted when the keyguard is showing, or when the keyguard
* was suppressed by an app that disabled the keyguard or we haven't been provisioned yet.
@@ -860,12 +873,9 @@
if (DEBUG) Log.d(TAG, "handleShow");
if (!mSystemReady) return;
- // while we're showing, we control the wake state, so ask the power
- // manager not to honor request for userActivity.
- mRealPowerManager.enableUserActivity(false);
-
mKeyguardViewManager.show();
mShowing = true;
+ adjustUserActivityLocked();
try {
ActivityManagerNative.getDefault().closeSystemDialogs("lock");
} catch (RemoteException e) {
@@ -885,14 +895,18 @@
Log.w(TAG, "attempt to hide the keyguard while waking, ignored");
return;
}
- // When we go away, tell the poewr manager to honor requests from userActivity.
- mRealPowerManager.enableUserActivity(true);
mKeyguardViewManager.hide();
mShowing = false;
+ adjustUserActivityLocked();
}
}
+ private void adjustUserActivityLocked() {
+ // disable user activity if we are shown and not hidden
+ mRealPowerManager.enableUserActivity(!mShowing || mHidden);
+ }
+
/**
* Handle message sent by {@link #wakeWhenReadyLocked(int)}
* @param keyCode The key that woke the device.
diff --git a/policy/com/android/internal/policy/impl/PhoneWindowManager.java b/policy/com/android/internal/policy/impl/PhoneWindowManager.java
index cd06d33..e57fbe8 100755
--- a/policy/com/android/internal/policy/impl/PhoneWindowManager.java
+++ b/policy/com/android/internal/policy/impl/PhoneWindowManager.java
@@ -1446,12 +1446,14 @@
}
} else if (mHideLockScreen) {
if (mKeyguard.hideLw(false)) {
+ mKeyguardMediator.setHidden(true);
changes |= FINISH_LAYOUT_REDO_LAYOUT
| FINISH_LAYOUT_REDO_CONFIG
| FINISH_LAYOUT_REDO_WALLPAPER;
}
} else {
if (mKeyguard.showLw(false)) {
+ mKeyguardMediator.setHidden(false);
changes |= FINISH_LAYOUT_REDO_LAYOUT
| FINISH_LAYOUT_REDO_CONFIG
| FINISH_LAYOUT_REDO_WALLPAPER;