From 063ae10a70aa27438f275e652e877897037aec83 Mon Sep 17 00:00:00 2001 From: Steven Terrell Date: Wed, 25 May 2022 19:05:19 +0000 Subject: [PATCH] Use System Property to Control Animator Pausing This change sets the default behavior of animator pausing by checking if a system property is set and useing that value if present else it defaults to true. This should allow the use of build properties to be able to toggle the behavior. Bug: 233391022 Test: Manual, adding logging to verify the values being set by the call to the sysprop library. Ignore-AOSP-First: Testing internal change, will cherry pick to AOSP. Change-Id: Ib1b34585c564bf4f310441c6856412a798022900 --- .../android/animation/AnimationHandler.java | 32 ++++++++++++++++++- core/java/android/animation/Animator.java | 1 + 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/core/java/android/animation/AnimationHandler.java b/core/java/android/animation/AnimationHandler.java index 1cb2574ae8b75..7e814af3451da 100644 --- a/core/java/android/animation/AnimationHandler.java +++ b/core/java/android/animation/AnimationHandler.java @@ -17,6 +17,7 @@ package android.animation; import android.os.SystemClock; +import android.os.SystemProperties; import android.util.ArrayMap; import android.util.ArraySet; import android.util.Log; @@ -54,7 +55,10 @@ public class AnimationHandler { private AnimationFrameCallbackProvider mProvider; // Static flag which allows the pausing behavior to be globally disabled/enabled. - private static boolean sAnimatorPausingEnabled = true; + private static boolean sAnimatorPausingEnabled = isPauseBgAnimationsEnabledInSystemProperties(); + + // Static flag which prevents the system property from overriding sAnimatorPausingEnabled field. + private static boolean sOverrideAnimatorPausingSystemProperty = false; /** * This paused list is used to store animators forcibly paused when the activity @@ -96,6 +100,18 @@ public class AnimationHandler { return sAnimatorHandler.get(); } + /** + * System property that controls the behavior of pausing infinite animators when an app + * is moved to the background. + * + * @return the value of 'framework.pause_bg_animations.enabled' system property + */ + private static boolean isPauseBgAnimationsEnabledInSystemProperties() { + if (sOverrideAnimatorPausingSystemProperty) return sAnimatorPausingEnabled; + return SystemProperties + .getBoolean("framework.pause_bg_animations.enabled", true); + } + /** * Disable the default behavior of pausing infinite animators when * apps go into the background. @@ -106,6 +122,19 @@ public class AnimationHandler { sAnimatorPausingEnabled = enable; } + /** + * Prevents the setAnimatorPausingEnabled behavior from being overridden + * by the 'framework.pause_bg_animations.enabled' system property value. + * + * This is for testing purposes only. + * + * @param enable Enable or disable (default behavior) overriding the system + * property. + */ + public static void setOverrideAnimatorPausingSystemProperty(boolean enable) { + sOverrideAnimatorPausingSystemProperty = enable; + } + /** * This is called when a window goes away. We should remove * it from the requestors list to ensure that we are counting requests correctly and not @@ -143,6 +172,7 @@ public class AnimationHandler { private void requestAnimatorsEnabledImpl(boolean enable, Object requestor) { boolean wasEmpty = mAnimatorRequestors.isEmpty(); + setAnimatorPausingEnabled(isPauseBgAnimationsEnabledInSystemProperties()); if (enable) { mAnimatorRequestors.add(requestor); } else { diff --git a/core/java/android/animation/Animator.java b/core/java/android/animation/Animator.java index f69decb087f31..a9d14df8bcf4d 100644 --- a/core/java/android/animation/Animator.java +++ b/core/java/android/animation/Animator.java @@ -104,6 +104,7 @@ public abstract class Animator implements Cloneable { @TestApi public static void setAnimatorPausingEnabled(boolean enable) { AnimationHandler.setAnimatorPausingEnabled(enable); + AnimationHandler.setOverrideAnimatorPausingSystemProperty(!enable); } /**