From 325cf315e64e7698bee012737b64b3fc53473d23 Mon Sep 17 00:00:00 2001 From: Santos Cordon Date: Thu, 19 Aug 2021 01:11:07 +0100 Subject: [PATCH] WaitForNegativeProximity stopped with power button. If the device is in a state where it is waiting for negative proximity event to turn the screen back on (as with phone calls), this CL makes it so that power button will also turn the screen back on, even if proximity is still positive. Test: make phone call, cover prox, end call. Previously power button had no effect in this state, now it turns the screen back on. Bug: 190459207 Change-Id: I3ce33fe81e5ee0c0652517a8ce46632519ba73c6 --- .../server/display/DisplayPowerController.java | 1 - .../com/android/server/power/PowerManagerService.java | 11 ++++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index 110893765cbd4..abbe13ac260f8 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -2122,7 +2122,6 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call private void ignoreProximitySensorUntilChangedInternal() { if (!mIgnoreProximityUntilChanged - && mPowerRequest.useProximitySensor && mProximity == PROXIMITY_POSITIVE) { // Only ignore if it is still reporting positive (near) mIgnoreProximityUntilChanged = true; diff --git a/services/core/java/com/android/server/power/PowerManagerService.java b/services/core/java/com/android/server/power/PowerManagerService.java index db69158e63c16..3d47dcf4eadbd 100644 --- a/services/core/java/com/android/server/power/PowerManagerService.java +++ b/services/core/java/com/android/server/power/PowerManagerService.java @@ -533,6 +533,11 @@ public final class PowerManagerService extends SystemService // True if the proximity sensor reads a positive result. private boolean mProximityPositive; + // Indicates that we have already intercepted the power key to temporarily ignore the proximity + // wake lock and turn the screen back on. This should get reset when prox reads 'far' again + // (when {@link #mProximityPositive} is set to false). + private boolean mInterceptedPowerKeyForProximity; + // Screen brightness setting limits. public final float mScreenBrightnessMinimum; public final float mScreenBrightnessMaximum; @@ -3318,6 +3323,7 @@ public final class PowerManagerService extends SystemService public void onProximityNegative() { synchronized (mLock) { mProximityPositive = false; + mInterceptedPowerKeyForProximity = false; mDirty |= DIRTY_PROXIMITY_POSITIVE; userActivityNoUpdateLocked(Display.DEFAULT_DISPLAY_GROUP, mClock.uptimeMillis(), PowerManager.USER_ACTIVITY_EVENT_OTHER, 0, Process.SYSTEM_UID); @@ -4158,6 +4164,8 @@ public final class PowerManagerService extends SystemService } pw.println(); pw.println(" mRequestWaitForNegativeProximity=" + mRequestWaitForNegativeProximity); + pw.println(" mInterceptedPowerKeyForProximity=" + + mInterceptedPowerKeyForProximity); pw.println(" mSandmanScheduled=" + mSandmanScheduled); pw.println(" mBatteryLevelLow=" + mBatteryLevelLow); pw.println(" mLightDeviceIdleMode=" + mLightDeviceIdleMode); @@ -5989,8 +5997,9 @@ public final class PowerManagerService extends SystemService final DisplayPowerRequest displayPowerRequest = mDisplayGroupPowerStateMapper.getPowerRequestLocked( Display.DEFAULT_DISPLAY_GROUP); - if (displayPowerRequest.useProximitySensor && mProximityPositive) { + if (mProximityPositive && !mInterceptedPowerKeyForProximity) { mDisplayManagerInternal.ignoreProximitySensorUntilChanged(); + mInterceptedPowerKeyForProximity = true; return true; } }