From e1633addd38cb5c66f642556b8968293fd5dc5b0 Mon Sep 17 00:00:00 2001 From: Jeff Brown Date: Mon, 22 Jun 2015 19:24:24 -0700 Subject: [PATCH] Suppress pausing activities when screen off due to proximity. Pausing and resuming the in-call activity may have the side-effect of releasing and reacquiring the proximity sensor wake lock which can cause the system to enter a loop. Although in general it might be a good idea to pause activities whenever you can't see them, it makes more sense to treat the proximity sensor as temporarily suppressing rather than fully pausing activities. Bug: 21932251 Change-Id: Ie072cbe5984bec08f2c60c64ed8cc144534982db --- .../display/DisplayPowerController.java | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/services/core/java/com/android/server/display/DisplayPowerController.java b/services/core/java/com/android/server/display/DisplayPowerController.java index 35fbef6d289f6..8d2687ba9db9e 100644 --- a/services/core/java/com/android/server/display/DisplayPowerController.java +++ b/services/core/java/com/android/server/display/DisplayPowerController.java @@ -231,6 +231,9 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call // The elapsed real time when the screen on was blocked. private long mScreenOnBlockStartRealTime; + // True if we told the window manager policy that the screen was off. + private boolean mReportedScreenOffToPolicy; + // Remembers whether certain kinds of brightness adjustments // were recently applied so that we can decide how to transition. private boolean mAppliedAutoBrightness; @@ -764,24 +767,30 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call } catch (RemoteException ex) { // same process } - - // Tell the window manager what's happening. - // Temporarily block turning the screen on until the window manager is ready - // by leaving a black surface covering the screen. This surface is essentially - // the final state of the color fade animation. - boolean isOn = (state != Display.STATE_OFF); - if (wasOn && !isOn) { - unblockScreenOn(); - mWindowManagerPolicy.screenTurnedOff(); - } else if (!wasOn && isOn) { - if (mPowerState.getColorFadeLevel() == 0.0f) { - blockScreenOn(); - } else { - unblockScreenOn(); - } - mWindowManagerPolicy.screenTurningOn(mPendingScreenOnUnblocker); - } } + + // Tell the window manager policy when the screen is turned off or on unless it's due + // to the proximity sensor. We temporarily block turning the screen on until the + // window manager is ready by leaving a black surface covering the screen. + // This surface is essentially the final state of the color fade animation and + // it is only removed once the window manager tells us that the activity has + // finished drawing underneath. + final boolean isOff = (state == Display.STATE_OFF); + if (isOff && !mReportedScreenOffToPolicy && !mScreenOffBecauseOfProximity) { + mReportedScreenOffToPolicy = true; + unblockScreenOn(); + mWindowManagerPolicy.screenTurnedOff(); + } else if (!isOff && mReportedScreenOffToPolicy) { + mReportedScreenOffToPolicy = false; + if (mPowerState.getColorFadeLevel() == 0.0f) { + blockScreenOn(); + } else { + unblockScreenOn(); + } + mWindowManagerPolicy.screenTurningOn(mPendingScreenOnUnblocker); + } + + // Return true if the screen isn't blocked. return mPendingScreenOnUnblocker == null; } @@ -1086,6 +1095,7 @@ final class DisplayPowerController implements AutomaticBrightnessController.Call pw.println(" mAppliedLowPower=" + mAppliedLowPower); pw.println(" mPendingScreenOnUnblocker=" + mPendingScreenOnUnblocker); pw.println(" mPendingScreenOff=" + mPendingScreenOff); + pw.println(" mReportedScreenOffToPolicy=" + mReportedScreenOffToPolicy); pw.println(" mScreenBrightnessRampAnimator.isAnimating()=" + mScreenBrightnessRampAnimator.isAnimating());