Merge changes from topic "stop-leaked-animators" into tm-dev am: a4ac1574bd

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18602917

Change-Id: Ia4c8792a5f2a4b068718faa2d3a3c4ab1b4c7c45
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Steven Terrell
2022-06-07 20:06:52 +00:00
committed by Automerger Merge Worker
2 changed files with 32 additions and 1 deletions

View File

@@ -17,6 +17,7 @@
package android.animation; package android.animation;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.SystemProperties;
import android.util.ArrayMap; import android.util.ArrayMap;
import android.util.ArraySet; import android.util.ArraySet;
import android.util.Log; import android.util.Log;
@@ -54,7 +55,10 @@ public class AnimationHandler {
private AnimationFrameCallbackProvider mProvider; private AnimationFrameCallbackProvider mProvider;
// Static flag which allows the pausing behavior to be globally disabled/enabled. // 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 * This paused list is used to store animators forcibly paused when the activity
@@ -96,6 +100,18 @@ public class AnimationHandler {
return sAnimatorHandler.get(); 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 * Disable the default behavior of pausing infinite animators when
* apps go into the background. * apps go into the background.
@@ -106,6 +122,19 @@ public class AnimationHandler {
sAnimatorPausingEnabled = enable; 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 * 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 * 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) { private void requestAnimatorsEnabledImpl(boolean enable, Object requestor) {
boolean wasEmpty = mAnimatorRequestors.isEmpty(); boolean wasEmpty = mAnimatorRequestors.isEmpty();
setAnimatorPausingEnabled(isPauseBgAnimationsEnabledInSystemProperties());
if (enable) { if (enable) {
mAnimatorRequestors.add(requestor); mAnimatorRequestors.add(requestor);
} else { } else {

View File

@@ -104,6 +104,7 @@ public abstract class Animator implements Cloneable {
@TestApi @TestApi
public static void setAnimatorPausingEnabled(boolean enable) { public static void setAnimatorPausingEnabled(boolean enable) {
AnimationHandler.setAnimatorPausingEnabled(enable); AnimationHandler.setAnimatorPausingEnabled(enable);
AnimationHandler.setOverrideAnimatorPausingSystemProperty(!enable);
} }
/** /**