From be71ed8a8e2ea302abbd4a5a0e8b5adc53449e67 Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Thu, 13 Jun 2019 15:53:35 +0200 Subject: [PATCH] Reland "Prevent dismissing starting window when reopening app" If we are changing the visibility while the app is shortly before drawing it's first frame, we cleared out the draw state, leading to a hang. We also had this issue with starting windows, but that was a fix only for starting windows, but cascaded the underlying issue. Now, we only clear out the draw state if is has fully drawn - this covers the Chrome case but doesn't clear out draw state if it's just about to show. Test: go/wm-smoke Test: Open TTS settings, go back, open again Bug: 135084202 Fixes: 134561008 Change-Id: Icd318ffd7c63dd244e0812775af28cb1a182597e --- .../core/java/com/android/server/wm/AppWindowToken.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/services/core/java/com/android/server/wm/AppWindowToken.java b/services/core/java/com/android/server/wm/AppWindowToken.java index 4a9a3f71f90e5..deae923a334e4 100644 --- a/services/core/java/com/android/server/wm/AppWindowToken.java +++ b/services/core/java/com/android/server/wm/AppWindowToken.java @@ -79,6 +79,7 @@ import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_NORMAL; import static com.android.server.wm.WindowManagerService.UPDATE_FOCUS_WILL_PLACE_SURFACES; import static com.android.server.wm.WindowManagerService.logWithStack; import static com.android.server.wm.WindowState.LEGACY_POLICY_VISIBILITY; +import static com.android.server.wm.WindowStateAnimator.HAS_DRAWN; import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_AFTER_ANIM; import static com.android.server.wm.WindowStateAnimator.STACK_CLIP_BEFORE_ANIM; @@ -540,6 +541,14 @@ class AppWindowToken extends WindowToken implements WindowManagerService.AppFree // If the app was already visible, don't reset the waitingToShow state. if (isHidden()) { waitingToShow = true; + + // Let's reset the draw state in order to prevent the starting window to be + // immediately dismissed when the app still has the surface. + forAllWindows(w -> { + if (w.mWinAnimator.mDrawState == HAS_DRAWN) { + w.mWinAnimator.resetDrawState(); + } + }, true /* traverseTopToBottom */); } }