diff options
| author | Chet Haase <chet@google.com> | 2022-06-07 20:28:11 +0000 |
|---|---|---|
| committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2022-06-07 20:28:11 +0000 |
| commit | 7e79d7c171b7ee818de3d1a73fc1d162231db366 (patch) | |
| tree | 909ecaec67d48f5b92ae6b1fe738e007df591152 /core/java/android/animation/AnimationHandler.java | |
| parent | f6541ab73ea751d222e41d98600ce52319e19eb8 (diff) | |
| parent | 339361ad29ca551e6f1808b121527d954558c5f5 (diff) | |
Allow system to disable behavior of pausing animators for bg apps am: 161732cf18 am: 339361ad29
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/18527682
Change-Id: Ib075c2aeea02f640a0487aa6ee61974186e50270
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
Diffstat (limited to 'core/java/android/animation/AnimationHandler.java')
| -rw-r--r-- | core/java/android/animation/AnimationHandler.java | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/core/java/android/animation/AnimationHandler.java b/core/java/android/animation/AnimationHandler.java index 7f6df2261fcc..57ab55a53e46 100644 --- a/core/java/android/animation/AnimationHandler.java +++ b/core/java/android/animation/AnimationHandler.java @@ -53,6 +53,9 @@ public class AnimationHandler { new ArrayList<>(); private AnimationFrameCallbackProvider mProvider; + // Static flag which allows the pausing behavior to be globally disabled/enabled. + private static boolean sAnimatorPausingEnabled = true; + /** * This paused list is used to store animators forcibly paused when the activity * went into the background (to avoid unnecessary background processing work). @@ -93,6 +96,15 @@ public class AnimationHandler { return sAnimatorHandler.get(); } + /** + * Disable the default behavior of pausing infinite animators when + * apps go into the background. + * + * @param enable Enable (default behavior) or disable background pausing behavior. + */ + public static void setAnimatorPausingEnabled(boolean enable) { + sAnimatorPausingEnabled = enable; + } /** * This is called when a window goes away. We should remove @@ -136,16 +148,19 @@ public class AnimationHandler { } else { mAnimatorRequestors.remove(requestor); } + if (!sAnimatorPausingEnabled) { + // Resume any animators that have been paused in the meantime, otherwise noop + // Leave logic above so that if pausing gets re-enabled, the state of the requestors + // list is valid + resumeAnimators(); + return; + } boolean isEmpty = mAnimatorRequestors.isEmpty(); if (wasEmpty != isEmpty) { // only paused/resume animators if there was a visibility change if (!isEmpty) { // If any requestors are enabled, resume currently paused animators - Choreographer.getInstance().removeFrameCallback(mPauser); - for (int i = mPausedAnimators.size() - 1; i >= 0; --i) { - mPausedAnimators.get(i).resume(); - } - mPausedAnimators.clear(); + resumeAnimators(); } else { // Wait before pausing to avoid thrashing animator state for temporary backgrounding Choreographer.getInstance().postFrameCallbackDelayed(mPauser, @@ -160,6 +175,14 @@ public class AnimationHandler { } } + private void resumeAnimators() { + Choreographer.getInstance().removeFrameCallback(mPauser); + for (int i = mPausedAnimators.size() - 1; i >= 0; --i) { + mPausedAnimators.get(i).resume(); + } + mPausedAnimators.clear(); + } + private Choreographer.FrameCallback mPauser = frameTimeNanos -> { if (mAnimatorRequestors.size() > 0) { // something enabled animators since this callback was scheduled - bail |
