From fac7bc9216ac56baaab526442296a1f4aa94f4a0 Mon Sep 17 00:00:00 2001 From: Pablo Gamito Date: Tue, 5 Oct 2021 15:59:48 +0200 Subject: [PATCH] Make sure the color background is only cleared once The cancel and finished callbacks are both run if we cancel the surface animation without restart and we only want to call clear once for everytime we call setbackground otherwise the background color counter would be out of sync and we might not remve the color background when expected Bug: 202141435 Change-Id: I0027d581b60c3acf0e02e66026d49c41435882ce --- .../java/com/android/server/wm/WindowContainer.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/services/core/java/com/android/server/wm/WindowContainer.java b/services/core/java/com/android/server/wm/WindowContainer.java index 841783d6b8cdf..c50558dc512c3 100644 --- a/services/core/java/com/android/server/wm/WindowContainer.java +++ b/services/core/java/com/android/server/wm/WindowContainer.java @@ -111,6 +111,7 @@ import java.util.ArrayList; import java.util.Comparator; import java.util.LinkedList; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; import java.util.function.BiFunction; import java.util.function.Consumer; import java.util.function.Function; @@ -2856,8 +2857,18 @@ class WindowContainer extends ConfigurationContainer< taskDisplayArea.setBackgroundColor(backgroundColor); } + // Atomic counter to make sure the clearColor callback is only called one. + // It will be called twice in the case we cancel the animation without restart + // (in that case it will run as the cancel and finished callbacks). + final AtomicInteger callbackCounter = new AtomicInteger(0); + final Runnable clearBackgroundColorHandler = () -> { + if (callbackCounter.getAndIncrement() == 0) { + taskDisplayArea.clearBackgroundColor(); + } + }; + final Runnable cleanUpCallback = isSettingBackgroundColor - ? taskDisplayArea::clearBackgroundColor : () -> {}; + ? clearBackgroundColorHandler : () -> {}; startAnimation(getPendingTransaction(), adapter, !isVisible(), ANIMATION_TYPE_APP_TRANSITION,