Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 15258ac8 authored by Jeff Brown's avatar Jeff Brown
Browse files

Fix power manager display wake lock bugs. (DO NOT MERGE)

Under certain circumstances, the power manager might continue to
hold the display wakelock long after the display had been turned
off due to the mDisplayReady flag having an incorrect value.

1. An inverted conditional caused DisplayPowerState to incorrectly
signal the screen on ready state.

2. The DisplayPowerController failed to clear the block screen on
flag in the case where the screen was turned off before it became
unblocked from turning on.  This could happen when the display was
rapidly turned on-off-on-off.

Bug: 13248135
Change-Id: I8faa3034695c83c8cd35613d81acccf40d22128d
parent 7f2c9e94
Loading
Loading
Loading
Loading
+56 −54
Original line number Diff line number Diff line
@@ -610,7 +610,6 @@ final class DisplayPowerController {
                        && mProximity == PROXIMITY_POSITIVE) {
                    mScreenOffBecauseOfProximity = true;
                    sendOnProximityPositiveWithWakelock();
                    setScreenOn(false);
                }
            } else if (mWaitingForNegativeProximity
                    && mScreenOffBecauseOfProximity
@@ -670,9 +669,12 @@ final class DisplayPowerController {
            mUsingScreenAutoBrightness = false;
        }

        // Animate the screen on or off.
        if (!mScreenOffBecauseOfProximity) {
            if (wantScreenOn(mPowerRequest.screenState)) {
        // Animate the screen on or off unless blocked.
        if (mScreenOffBecauseOfProximity) {
            // Screen off due to proximity.
            setScreenOn(false);
            unblockScreenOn();
        } else if (wantScreenOn(mPowerRequest.screenState)) {
            // Want screen on.
            // Wait for previous off animation to complete beforehand.
            // It is relatively short but if we cancel it and switch to the
@@ -710,6 +712,7 @@ final class DisplayPowerController {
        } else {
            // Want screen off.
            // Wait for previous on animation to complete beforehand.
            unblockScreenOn();
            if (!mElectronBeamOnAnimator.isStarted()) {
                if (!mElectronBeamOffAnimator.isStarted()) {
                    if (mPowerState.getElectronBeamLevel() == 0.0f) {
@@ -726,7 +729,6 @@ final class DisplayPowerController {
                }
            }
        }
        }

        // Report whether the display is ready for use.
        // We mostly care about the screen state here, ignoring brightness changes
@@ -762,15 +764,15 @@ final class DisplayPowerController {
    private void unblockScreenOn() {
        if (mScreenOnWasBlocked) {
            mScreenOnWasBlocked = false;
            if (DEBUG) {
                Slog.d(TAG, "Unblocked screen on after " +
                        (SystemClock.elapsedRealtime() - mScreenOnBlockStartRealTime) + " ms");
            long delay = SystemClock.elapsedRealtime() - mScreenOnBlockStartRealTime;
            if (delay > 1000 || DEBUG) {
                Slog.d(TAG, "Unblocked screen on after " + delay + " ms");
            }
        }
    }

    private void setScreenOn(boolean on) {
        if (!mPowerState.isScreenOn() == on) {
        if (mPowerState.isScreenOn() != on) {
            mPowerState.setScreenOn(on);
            if (on) {
                mNotifier.onScreenOn();
+8 −1
Original line number Diff line number Diff line
@@ -304,8 +304,15 @@ final class DisplayPowerState {

            int brightness = mScreenOn && mElectronBeamLevel > 0f ? mScreenBrightness : 0;
            if (mPhotonicModulator.setState(mScreenOn, brightness)) {
                if (DEBUG) {
                    Slog.d(TAG, "Screen ready");
                }
                mScreenReady = true;
                invokeCleanListenerIfNeeded();
            } else {
                if (DEBUG) {
                    Slog.d(TAG, "Screen not ready");
                }
            }
        }
    };
@@ -355,7 +362,7 @@ final class DisplayPowerState {
                        AsyncTask.THREAD_POOL_EXECUTOR.execute(mTask);
                    }
                }
                return mChangeInProgress;
                return !mChangeInProgress;
            }
        }

+3 −0
Original line number Diff line number Diff line
@@ -1135,6 +1135,9 @@ public final class PowerManagerService extends IPowerManager.Stub
        if (!mSystemReady || mDirty == 0) {
            return;
        }
        if (!Thread.holdsLock(mLock)) {
            Slog.wtf(TAG, "Power manager lock was not held when calling updatePowerStateLocked");
        }

        // Phase 0: Basic state updates.
        updateIsPoweredLocked(mDirty);