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

Commit a43886bc authored by Erik Wolsheimer's avatar Erik Wolsheimer
Browse files

DO NOT MERGE Fix error caused by quick stopDream(false) + startDream() with same dream

Bug: 62147987
Bug: 28455483
Exempt-From-Owner-Approval: Will not merge to master
Change-Id: I4577c66d7d66c22c8b9e2ab0b50a59e97d7e9647
parent 10ab15de
Loading
Loading
Loading
Loading
+21 −4
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@ public final class DreamManagerService extends SystemService {
    private boolean mCurrentDreamCanDoze;
    private boolean mCurrentDreamIsDozing;
    private boolean mCurrentDreamIsWaking;
    private Runnable mStopDreamRunnable;
    private int mCurrentDreamDozeScreenState = Display.STATE_UNKNOWN;
    private int mCurrentDreamDozeScreenBrightness = PowerManager.BRIGHTNESS_DEFAULT;

@@ -353,6 +354,12 @@ public final class DreamManagerService extends SystemService {
                && mCurrentDreamCanDoze == canDoze
                && mCurrentDreamUserId == userId) {
            Slog.i(TAG, "Already in target dream.");
            // If dream is waking, cancel the wake.
            mCurrentDreamIsWaking = false;
            if (mStopDreamRunnable != null) {
                mHandler.removeCallbacks(mStopDreamRunnable);
                mStopDreamRunnable = null;
            }
            return;
        }

@@ -385,13 +392,23 @@ public final class DreamManagerService extends SystemService {
                mCurrentDreamIsWaking = true;
            }

            mHandler.post(new Runnable() {
            if (mStopDreamRunnable != null) {
                mHandler.removeCallbacks(mStopDreamRunnable);
                mStopDreamRunnable = null;
            }
            mStopDreamRunnable = new Runnable() {
                @Override
                public void run() {
                    synchronized (mLock) {
                        Slog.i(TAG, "Performing gentle wake from dream.");
                        mController.stopDream(immediate);
                        if (mStopDreamRunnable == this) {
                            mStopDreamRunnable = null;
                        }
            });
                    }
                }
            };
            mHandler.post(mStopDreamRunnable);
        }
    }