diff options
3 files changed, 32 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java index 6bb30c7b97f4..32e383a73821 100644 --- a/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java +++ b/packages/SystemUI/src/com/android/systemui/shade/NotificationPanelViewController.java @@ -253,6 +253,7 @@ import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Optional; +import java.util.Set; import java.util.function.Consumer; import javax.inject.Inject; @@ -449,6 +450,9 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump private final ShadeHeadsUpTrackerImpl mShadeHeadsUpTracker = new ShadeHeadsUpTrackerImpl(); private final ShadeFoldAnimatorImpl mShadeFoldAnimator = new ShadeFoldAnimatorImpl(); + @VisibleForTesting + Set<Animator> mTestSetOfAnimatorsUsed; + private boolean mShowIconsWhenExpanded; private int mIndicationBottomPadding; private int mAmbientIndicationBottomPadding; @@ -4149,6 +4153,8 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump } private void setAnimator(ValueAnimator animator) { + // TODO(b/341163515): Should we clean up the old animator? + registerAnimatorForTest(animator); mHeightAnimator = animator; if (animator == null && mPanelUpdateWhenAnimatorEnds) { mPanelUpdateWhenAnimatorEnds = false; @@ -4193,6 +4199,7 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump private ValueAnimator createHeightAnimator(float targetHeight, float overshootAmount) { float startExpansion = mOverExpansion; ValueAnimator animator = ValueAnimator.ofFloat(mExpandedHeight, targetHeight); + registerAnimatorForTest(animator); animator.addUpdateListener( animation -> { if (overshootAmount > 0.0f @@ -4210,6 +4217,12 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump return animator; } + private void registerAnimatorForTest(Animator animator) { + if (mTestSetOfAnimatorsUsed != null) { + mTestSetOfAnimatorsUsed.add(animator); + } + } + /** Update the visibility of {@link NotificationPanelView} if necessary. */ private void updateVisibility() { mView.setVisibility(shouldPanelBeVisible() ? VISIBLE : INVISIBLE); diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerBaseTest.java b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerBaseTest.java index 8e3290748039..4d32cc423ded 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerBaseTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerBaseTest.java @@ -40,6 +40,7 @@ import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import android.animation.Animator; import android.annotation.IdRes; import android.content.ContentResolver; import android.content.res.Configuration; @@ -207,12 +208,15 @@ import kotlinx.coroutines.test.TestScope; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; +import org.mockito.junit.MockitoJUnit; +import org.mockito.junit.MockitoRule; import org.mockito.stubbing.Answer; +import java.util.HashSet; import java.util.List; import java.util.Optional; @@ -387,9 +391,11 @@ public class NotificationPanelViewControllerBaseTest extends SysuiTestCase { protected FragmentHostManager.FragmentListener mFragmentListener; + @Rule(order = 200) + public MockitoRule mMockitoRule = MockitoJUnit.rule(); + @Before public void setup() { - MockitoAnnotations.initMocks(this); mFeatureFlags.set(Flags.LOCKSCREEN_ENABLE_LANDSCAPE, false); mFeatureFlags.set(Flags.QS_USER_DETAIL_SHORTCUT, false); @@ -761,6 +767,9 @@ public class NotificationPanelViewControllerBaseTest extends SysuiTestCase { @Override public void onOpenStarted() {} }); + // Create a set to which the class will add all animators used, so that we can + // verify that they are all stopped. + mNotificationPanelViewController.mTestSetOfAnimatorsUsed = new HashSet<>(); ArgumentCaptor<View.OnAttachStateChangeListener> onAttachStateChangeListenerArgumentCaptor = ArgumentCaptor.forClass(View.OnAttachStateChangeListener.class); verify(mView, atLeast(1)).addOnAttachStateChangeListener( @@ -822,13 +831,20 @@ public class NotificationPanelViewControllerBaseTest extends SysuiTestCase { @After public void tearDown() { + List<Animator> leakedAnimators = null; if (mNotificationPanelViewController != null) { mNotificationPanelViewController.mBottomAreaShadeAlphaAnimator.cancel(); mNotificationPanelViewController.cancelHeightAnimator(); + leakedAnimators = mNotificationPanelViewController.mTestSetOfAnimatorsUsed.stream() + .filter(Animator::isRunning).toList(); + mNotificationPanelViewController.mTestSetOfAnimatorsUsed.forEach(Animator::cancel); } if (mMainHandler != null) { mMainHandler.removeCallbacksAndMessages(null); } + if (leakedAnimators != null) { + assertThat(leakedAnimators).isEmpty(); + } } protected void setBottomPadding(int stackBottom, int lockIconPadding, int indicationPadding, diff --git a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java index e1cdda440976..65364053f109 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/shade/NotificationPanelViewControllerTest.java @@ -705,6 +705,7 @@ public class NotificationPanelViewControllerTest extends NotificationPanelViewCo } @Test + @Ignore("b/341163515 - fails to clean up animators correctly") public void testSwipeWhileLocked_notifiesKeyguardState() { mStatusBarStateController.setState(KEYGUARD); |