From 03c10c71a68c394a51f89e3f2427cfba1f77784d Mon Sep 17 00:00:00 2001 From: Sean Stout Date: Thu, 8 Apr 2021 13:39:59 -0700 Subject: [PATCH] Fix race condition triggered by quick stop/start of Dream If a Dream was running, then stopped and restarted in quick succession it was possible for it to fail to restart. It would do this because before starting a dream, there is a check to ensure that the requested dream is not already running. All dreams are started and stopped on a handler thread, because of this it is possible for the dream to still be running when #stopDream is called followed immediately by #startDream. This CL changes the check at the beginning of #startDreamLocked to ensure that the current dream is not in the process of waking before returning early which prevents this error from happening. Bug: 181523689 Test: adb shell input keyevent KEYCODE_WAKEUP && \ sleep .02 && \ adb shell input keyevent KEYCODE_SLEEP Change-Id: I0ba6f630f114df18c49e65ac1a72c8040db64817 --- .../java/com/android/server/dreams/DreamManagerService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/dreams/DreamManagerService.java b/services/core/java/com/android/server/dreams/DreamManagerService.java index e3eeb6c41d9f2..3a7220f7592f5 100644 --- a/services/core/java/com/android/server/dreams/DreamManagerService.java +++ b/services/core/java/com/android/server/dreams/DreamManagerService.java @@ -394,7 +394,8 @@ public final class DreamManagerService extends SystemService { private void startDreamLocked(final ComponentName name, final boolean isTest, final boolean canDoze, final int userId) { - if (Objects.equals(mCurrentDreamName, name) + if (!mCurrentDreamIsWaking + && Objects.equals(mCurrentDreamName, name) && mCurrentDreamIsTest == isTest && mCurrentDreamCanDoze == canDoze && mCurrentDreamUserId == userId) {