From 46aacef9c97bed88c5aa8b98d5bd2437b3ee7e41 Mon Sep 17 00:00:00 2001 From: Ming-Shin Lu Date: Mon, 24 May 2021 20:44:33 +0800 Subject: [PATCH] Wait enough time for WMS#waitForAnimationsToComplete As CL[1] added more log for tracking animating container in waitForAnimationsToComplete, which accidentally ignored waiting enough time when WindowAnimator#isAnimationScheduled has set but not yet having animating container, in case syncInputTransactions going too earily and tests might flaky when verifying input events should be touched but WindowAnimator is still animate, we should wait enough time when the animation scheduling to WindowAnimator. [1]: I2c0370d6abe0f726891cedd39b6f8fa9fd366e94 Bug: 188904558 Test: atest -bidt WindowUntrustedTouchTest --iteration 50 Change-Id: I3b009e23e7a43d0f450e7f4aef4d13c0f4e04547 --- .../com/android/server/wm/WindowManagerService.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index 8bee862c97689..745e45db5a281 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -8091,11 +8091,10 @@ public class WindowManagerService extends IWindowManager.Stub // This could prevent if there is no container animation, we still have to apply the // pending transaction and exit waiting. mAnimator.mNotifyWhenNoAnimation = true; - WindowContainer animatingContainer = null; - while (mAnimator.isAnimationScheduled() || timeoutRemaining > 0) { - animatingContainer = mRoot.getAnimatingContainer(TRANSITION | CHILDREN, - ANIMATION_TYPE_ALL); - if (animatingContainer == null) { + while (timeoutRemaining > 0) { + boolean isAnimating = mAnimator.isAnimationScheduled() + || mRoot.isAnimating(TRANSITION | CHILDREN, ANIMATION_TYPE_ALL); + if (!isAnimating) { break; } long startTime = System.currentTimeMillis(); @@ -8107,6 +8106,9 @@ public class WindowManagerService extends IWindowManager.Stub } mAnimator.mNotifyWhenNoAnimation = false; + WindowContainer animatingContainer; + animatingContainer = mRoot.getAnimatingContainer(TRANSITION | CHILDREN, + ANIMATION_TYPE_ALL); if (mAnimator.isAnimationScheduled() || animatingContainer != null) { Slog.w(TAG, "Timed out waiting for animations to complete," + " animatingContainer=" + animatingContainer