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
This commit is contained in:
Lucas Silva
2023-03-08 11:01:18 -05:00
parent dc94ae961f
commit 182754e971
2 changed files with 2 additions and 22 deletions

View File

@@ -61,9 +61,6 @@ public class ComplicationHostViewController extends ViewController<ConstraintLay
@VisibleForTesting
boolean mIsAnimationEnabled;
// Whether dream entry animations are finished.
private boolean mEntryAnimationsFinished = false;
@Inject
protected ComplicationHostViewController(
@Named(SCOPED_COMPLICATIONS_LAYOUT) ConstraintLayout view,
@@ -78,14 +75,6 @@ public class ComplicationHostViewController extends ViewController<ConstraintLay
mComplicationCollectionViewModel = viewModel;
mDreamOverlayStateController = dreamOverlayStateController;
mDreamOverlayStateController.addCallback(new DreamOverlayStateController.Callback() {
@Override
public void onStateChanged() {
mEntryAnimationsFinished =
mDreamOverlayStateController.areEntryAnimationsFinished();
}
});
// Whether animations are enabled.
mIsAnimationEnabled = secureSettings.getFloatForUser(
Settings.Global.ANIMATOR_DURATION_SCALE, 1.0f, UserHandle.USER_CURRENT) != 0.0f;
@@ -159,7 +148,8 @@ public class ComplicationHostViewController extends ViewController<ConstraintLay
// Complications to be added before dream entry animations are finished are set
// to invisible and are animated in.
if (!mEntryAnimationsFinished && mIsAnimationEnabled) {
if (!mDreamOverlayStateController.areEntryAnimationsFinished()
&& mIsAnimationEnabled) {
view.setVisibility(View.INVISIBLE);
}
mComplications.put(id, viewHolder);

View File

@@ -92,9 +92,6 @@ public class ComplicationHostViewControllerTest extends SysuiTestCase {
@Captor
private ArgumentCaptor<Observer<Collection<ComplicationViewModel>>> mObserverCaptor;
@Captor
private ArgumentCaptor<DreamOverlayStateController.Callback> 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<ComplicationViewModel> 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();
}
}