From 66c564e390ea71576db7d4c1803b169cc98e987b Mon Sep 17 00:00:00 2001 From: Doris Liu Date: Thu, 26 Jan 2017 11:53:46 -0800 Subject: [PATCH] Work around a bug in an An app An app has Animators (NoPauseAnimatorWrapper) that does not check their listeners against null before cloning. The previous implementation of AnimatorSet has masked this issue. But the underlying bug should be fixed in this app. For now, work around the bug by adding a listener to all the child animators. BUG: 34736819 Test: Manual Change-Id: I968450aab62cf5d308e3b64e76dcf018178af67e --- core/java/android/animation/AnimatorSet.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/core/java/android/animation/AnimatorSet.java b/core/java/android/animation/AnimatorSet.java index d5814a30ac17..45440c941a13 100644 --- a/core/java/android/animation/AnimatorSet.java +++ b/core/java/android/animation/AnimatorSet.java @@ -174,6 +174,10 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim */ private long mPauseTime = -1; + // This is to work around a bug in b/34736819. This needs to be removed once play team + // fixes their side. + private AnimatorListenerAdapter mDummyListener = new AnimatorListenerAdapter() {}; + public AnimatorSet() { super(); mNodeMap.put(mDelayAnim, mRootNode); @@ -1018,6 +1022,8 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim } private void startAnimation() { + addDummyListener(); + // Register animation callback addAnimationCallback(mStartDelay); @@ -1062,6 +1068,20 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim } } + // This is to work around the issue in b/34736819, as the old behavior in AnimatorSet had + // masked a real bug in play movies. TODO: remove this and below once the root cause is fixed. + private void addDummyListener() { + for (int i = 1; i < mNodes.size(); i++) { + mNodes.get(i).mAnimation.addListener(mDummyListener); + } + } + + private void removeDummyListener() { + for (int i = 1; i < mNodes.size(); i++) { + mNodes.get(i).mAnimation.removeListener(mDummyListener); + } + } + private int findLatestEventIdForTime(long currentPlayTime) { int size = mEvents.size(); int latestId = mLastEventId; @@ -1107,6 +1127,7 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim tmpListeners.get(i).onAnimationEnd(this, mReversing); } } + removeDummyListener(); mSelfPulse = true; mReversing = false; } -- 2.11.0