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
This commit is contained in:
Erik Wolsheimer
2017-06-06 14:58:35 -07:00
parent 10ab15dee0
commit a43886bcaa

View File

@@ -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() {
Slog.i(TAG, "Performing gentle wake from dream.");
mController.stopDream(immediate);
synchronized (mLock) {
Slog.i(TAG, "Performing gentle wake from dream.");
mController.stopDream(immediate);
if (mStopDreamRunnable == this) {
mStopDreamRunnable = null;
}
}
}
});
};
mHandler.post(mStopDreamRunnable);
}
}