DO NOT MERGE Revert "DO NOT MERGE Revert "Handle dream restart""

This reverts commit 36acacd2a0.

Reason for revert: reland this with fix for b/270178573

Fix: 265110360
Fix: 260205205

Change-Id: I0eaa29021b4f8ffeb572877e5ecefbf5f1b4dd18
This commit is contained in:
Darrell Shi
2023-02-24 00:32:44 +00:00
parent aef78d6f99
commit 316e02f3a8

View File

@@ -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,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,