Fixes for proximity sensor behavior:
Add optional flag to Wakelock.release() to specify whether we should wait for proximity sensor to go negative before turning on the screen.
Clear the "waiting for proximity sensor to go negative" state when the power key is pressed.
Part of the fix for b/2243198 (Black screen lockup after ending call)
Change-Id: I813fdb7aa4192cd3384a25be9e59d7d4b90da53a
Signed-off-by: Mike Lockwood <lockwood@android.com>
diff --git a/services/java/com/android/server/PowerManagerService.java b/services/java/com/android/server/PowerManagerService.java
index 94cf6d4..444c8de 100644
--- a/services/java/com/android/server/PowerManagerService.java
+++ b/services/java/com/android/server/PowerManagerService.java
@@ -309,7 +309,7 @@
public void release() {
if (!mRefCounted || --mCount == 0) {
- PowerManagerService.this.releaseWakeLockLocked(mToken, false);
+ PowerManagerService.this.releaseWakeLockLocked(mToken, 0, false);
mHeld = false;
}
if (mCount < 0) {
@@ -556,7 +556,7 @@
}
public void binderDied() {
synchronized (mLocks) {
- releaseWakeLockLocked(this.binder, true);
+ releaseWakeLockLocked(this.binder, 0, true);
}
}
final int flags;
@@ -701,18 +701,18 @@
}
}
- public void releaseWakeLock(IBinder lock) {
+ public void releaseWakeLock(IBinder lock, int flags) {
int uid = Binder.getCallingUid();
if (uid != Process.myUid()) {
mContext.enforceCallingOrSelfPermission(android.Manifest.permission.WAKE_LOCK, null);
}
synchronized (mLocks) {
- releaseWakeLockLocked(lock, false);
+ releaseWakeLockLocked(lock, flags, false);
}
}
- private void releaseWakeLockLocked(IBinder lock, boolean death) {
+ private void releaseWakeLockLocked(IBinder lock, int flags, boolean death) {
int releaseUid;
String releaseName;
int releaseType;
@@ -744,7 +744,8 @@
} else if ((wl.flags & LOCK_MASK) == PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK) {
mProximityWakeLockCount--;
if (mProximityWakeLockCount == 0) {
- if (mProximitySensorActive) {
+ if (mProximitySensorActive &&
+ ((flags & PowerManager.WAIT_FOR_PROXIMITY_NEGATIVE) != 0)) {
// wait for proximity sensor to go negative before disabling sensor
if (mDebugProximitySensor) {
Log.d(TAG, "waiting for proximity sensor to go negative");
@@ -1923,6 +1924,11 @@
Log.d(TAG, "ignoring user activity while turning off screen");
return;
}
+ // Disable proximity sensor if if user presses power key while we are in the
+ // "waiting for proximity sensor to go negative" state.
+ if (mProximitySensorActive && mProximityWakeLockCount == 0) {
+ mProximitySensorActive = false;
+ }
if (mLastEventTime <= time || force) {
mLastEventTime = time;
if ((mUserActivityAllowed && !mProximitySensorActive) || force) {