Remove redundant instances of depth controller.
During each app launch, a new `MyDepthController` is instantiated, which
registers two of its methods as listeners for cross window blur and
opaqueness. This controller's usefulness spans that specific animation
only, but the listeners are never unregistered. This creates conflicts
when an opaqueness signal happens, which cause the background to flicker
(see videos).
Bug: 283335820
Test: manual, see videos in the bug
Flag: not needed, bug fix
Change-Id: I3dcb0b8ff0aa77bf3183a926889d0131b17bcaa4
diff --git a/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java b/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java
index 977163b..b1faf88 100644
--- a/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java
+++ b/quickstep/src/com/android/launcher3/QuickstepTransitionManager.java
@@ -1065,6 +1065,9 @@
new SurfaceControl.Transaction().remove(dimLayer).apply()));
}
+ backgroundRadiusAnim.addListener(
+ AnimatorListeners.forEndCallback(depthController::dispose));
+
return backgroundRadiusAnim;
}
diff --git a/quickstep/src/com/android/launcher3/statehandlers/DepthController.java b/quickstep/src/com/android/launcher3/statehandlers/DepthController.java
index d8458c9..7c62763 100644
--- a/quickstep/src/com/android/launcher3/statehandlers/DepthController.java
+++ b/quickstep/src/com/android/launcher3/statehandlers/DepthController.java
@@ -84,8 +84,7 @@
@Override
public void onViewDetachedFromWindow(View view) {
- CrossWindowBlurListeners.getInstance().removeListener(mCrossWindowBlurListener);
- mLauncher.getScrimView().removeOpaquenessListener(mOpaquenessListener);
+ removeSecondaryListeners();
}
};
rootView.addOnAttachStateChangeListener(mOnAttachListener);
@@ -96,6 +95,27 @@
}
/**
+ * Cleans up after this controller so it can be garbage collected without leaving traces.
+ */
+ public void dispose() {
+ removeSecondaryListeners();
+
+ if (mLauncher.getRootView() != null && mOnAttachListener != null) {
+ mLauncher.getRootView().removeOnAttachStateChangeListener(mOnAttachListener);
+ mOnAttachListener = null;
+ }
+ }
+
+ private void removeSecondaryListeners() {
+ if (mCrossWindowBlurListener != null) {
+ CrossWindowBlurListeners.getInstance().removeListener(mCrossWindowBlurListener);
+ }
+ if (mOpaquenessListener != null) {
+ mLauncher.getScrimView().removeOpaquenessListener(mOpaquenessListener);
+ }
+ }
+
+ /**
* Sets if the underlying activity is started or not
*/
public void setActivityStarted(boolean isStarted) {