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

Commit 73473726 authored by Galia Peycheva's avatar Galia Peycheva Committed by Android (Google) Code Review
Browse files

Merge "Handle dream restart"

parents cc6191e3 4bd7a879
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.NoSuchElementException;
import java.util.Objects;
import java.util.UUID;

/**
@@ -152,10 +153,20 @@ 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 (!oldDream.mWakingGently) {
                    // We will stop these previous dreams once the new dream is started.
                    mPreviousDreams.add(oldDream);
                } else 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);
                }
            }

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