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

Commit ef7f9416 authored by Darrell Shi's avatar Darrell Shi Committed by Android (Google) Code Review
Browse files

Merge changes from topic "dream-restart-reland" into tm-qpr-dev

* changes:
  Add oldDream to mPreviousDreams always when dreams overlap
  DO NOT MERGE Revert "DO NOT MERGE Revert "Handle dream restart""
parents aa009e21 01c6a7af
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;

/**
 * Internal controller for starting and stopping the current dream and managing related state.
@@ -119,10 +120,19 @@ final class DreamController {
                    + ", isPreviewMode=" + isPreviewMode + ", canDoze=" + canDoze
                    + ", userId=" + userId + ", reason='" + reason + "'");

            if (mCurrentDream != null) {
                mPreviousDreams.add(mCurrentDream);
            }
            final DreamRecord oldDream = mCurrentDream;
            mCurrentDream = new DreamRecord(token, name, isPreviewMode, canDoze, userId, wakeLock);
            if (oldDream != null) {
                if (Objects.equals(oldDream.mName, mCurrentDream.mName)) {
                    // We are attempting to start a dream that is currently waking up gently.
                    // Let's silently stop the old instance here to clear the dream state.
                    // This should happen after the new mCurrentDream is set to avoid announcing
                    // a "dream stopped" state.
                    stopDreamInstance(/* immediately */ true, "restarting same dream", oldDream);
                } else {
                    mPreviousDreams.add(oldDream);
                }
            }

            mCurrentDream.mDreamStartTime = SystemClock.elapsedRealtime();
            MetricsLogger.visible(mContext,