From 182754e971d43dae5f89351fce41e50ab66afe9a Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Wed, 8 Mar 2023 11:01:18 -0500 Subject: [PATCH] Avoid callback leak in ComplicationHostViewController There is no reason to add the callback instead of just checking the state when it is needed, since we don't need to respond to state changes. This avoids the callback object leaking when new instances are created. Bug: 272019210 Test: atest ComplicationHostViewControllerTest Change-Id: I91d798a8130199a27ad134b30240a9073501d7fb --- .../ComplicationHostViewController.java | 14 ++------------ .../ComplicationHostViewControllerTest.java | 10 ---------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationHostViewController.java b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationHostViewController.java index 24e90f0666226..aad209090a21c 100644 --- a/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationHostViewController.java +++ b/packages/SystemUI/src/com/android/systemui/dreams/complication/ComplicationHostViewController.java @@ -61,9 +61,6 @@ public class ComplicationHostViewController extends ViewController>> mObserverCaptor; - @Captor - private ArgumentCaptor mCallbackCaptor; - @Complication.Category static final int COMPLICATION_CATEGORY = Complication.CATEGORY_SYSTEM; @@ -189,8 +186,6 @@ public class ComplicationHostViewControllerTest extends SysuiTestCase { // Dream entry animations finished. when(mDreamOverlayStateController.areEntryAnimationsFinished()).thenReturn(true); - final DreamOverlayStateController.Callback stateCallback = captureOverlayStateCallback(); - stateCallback.onStateChanged(); // Add a complication after entry animations are finished. final HashSet complications = new HashSet<>( @@ -223,9 +218,4 @@ public class ComplicationHostViewControllerTest extends SysuiTestCase { mObserverCaptor.capture()); return mObserverCaptor.getValue(); } - - private DreamOverlayStateController.Callback captureOverlayStateCallback() { - verify(mDreamOverlayStateController).addCallback(mCallbackCaptor.capture()); - return mCallbackCaptor.getValue(); - } }