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

Commit 6e90ea03 authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Don't wait for brightness changes

On some devices, changing the brightness is quite slow, because the
change needs to wait for the vsync signal. However, when we are also
running a brightness change animation, as soon as the last change has
been sent there is a new one pending, leading to that we never reach
"clean" state in the PowerManagerService and thus we don't notify
clients about the state change, which can delay the animation for waking
up while dozing by as much as a second.

To fix this, if we only issue a brightness change, we don't block on
that because it's not relevant for us.

Bug: 22879546
Change-Id: Idad7e90c436bfbc38581fe8ce24d606e432b7952
parent b1cebd9e
Loading
Loading
Loading
Loading
+21 −9
Original line number Diff line number Diff line
@@ -341,7 +341,8 @@ final class DisplayPowerState {
        private int mPendingBacklight = INITIAL_BACKLIGHT;
        private int mActualState = INITIAL_SCREEN_STATE;
        private int mActualBacklight = INITIAL_BACKLIGHT;
        private boolean mChangeInProgress;
        private boolean mStateChangeInProgress;
        private boolean mBacklightChangeInProgress;

        public PhotonicModulator() {
            super("PhotonicModulator");
@@ -349,7 +350,9 @@ final class DisplayPowerState {

        public boolean setState(int state, int backlight) {
            synchronized (mLock) {
                if (state != mPendingState || backlight != mPendingBacklight) {
                boolean stateChanged = state != mPendingState;
                boolean backlightChanged = backlight != mPendingBacklight;
                if (stateChanged || backlightChanged) {
                    if (DEBUG) {
                        Slog.d(TAG, "Requesting new screen state: state="
                                + Display.stateToString(state) + ", backlight=" + backlight);
@@ -358,12 +361,15 @@ final class DisplayPowerState {
                    mPendingState = state;
                    mPendingBacklight = backlight;

                    if (!mChangeInProgress) {
                        mChangeInProgress = true;
                    boolean changeInProgress = mStateChangeInProgress || mBacklightChangeInProgress;
                    mStateChangeInProgress = stateChanged;
                    mBacklightChangeInProgress = backlightChanged;

                    if (!changeInProgress) {
                        mLock.notifyAll();
                    }
                }
                return !mChangeInProgress;
                return !mStateChangeInProgress;
            }
        }

@@ -375,7 +381,8 @@ final class DisplayPowerState {
                pw.println("  mPendingBacklight=" + mPendingBacklight);
                pw.println("  mActualState=" + Display.stateToString(mActualState));
                pw.println("  mActualBacklight=" + mActualBacklight);
                pw.println("  mChangeInProgress=" + mChangeInProgress);
                pw.println("  mStateChangeInProgress=" + mStateChangeInProgress);
                pw.println("  mBacklightChangeInProgress=" + mBacklightChangeInProgress);
            }
        }

@@ -392,10 +399,15 @@ final class DisplayPowerState {
                    stateChanged = (state != mActualState);
                    backlight = mPendingBacklight;
                    backlightChanged = (backlight != mActualBacklight);
                    if (!stateChanged && !backlightChanged) {
                        // All changed applied, notify outer class and wait for more.
                        mChangeInProgress = false;
                    if (!stateChanged) {
                        // State changed applied, notify outer class.
                        postScreenUpdateThreadSafe();
                        mStateChangeInProgress = false;
                    }
                    if (!backlightChanged) {
                        mBacklightChangeInProgress = false;
                    }
                    if (!stateChanged && !backlightChanged) {
                        try {
                            mLock.wait();
                        } catch (InterruptedException ex) { }