From 39dd49807430cacb012145f64fcc41c695c09313 Mon Sep 17 00:00:00 2001 From: Jagrut Desai Date: Fri, 28 Feb 2025 13:21:13 -0800 Subject: [PATCH] Fix SystemNav and Taskbar related Memory Leaks Test: Presubmit Bug: 398908322 Bug: 399884290 Flag: EXEMPT bugfix Change-Id: Idf1ed3ff154e64de523b477aa34b67cbcd3cf8b4 --- .../launcher3/taskbar/TaskbarLauncherStateController.java | 8 ++++++++ .../src/com/android/quickstep/AbsSwipeUpHandler.java | 8 +++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java index 10eb64a44a..b510e7ebb5 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java @@ -191,6 +191,8 @@ public class TaskbarLauncherStateController { private boolean mIsQsbInline; + private RecentsAnimationCallbacks mRecentsAnimationCallbacks; + private final DeviceProfile.OnDeviceProfileChangeListener mOnDeviceProfileChangeListener = new DeviceProfile.OnDeviceProfileChangeListener() { @Override @@ -295,6 +297,11 @@ public class TaskbarLauncherStateController { mIsDestroyed = true; mCanSyncViews = false; + if (mRecentsAnimationCallbacks != null) { + mRecentsAnimationCallbacks.removeListener(mTaskBarRecentsAnimationListener); + mRecentsAnimationCallbacks = null; + } + mIconAlignment.finishAnimation(); mLauncher.getHotseat().setIconsAlpha(1f, ALPHA_CHANNEL_TASKBAR_ALIGNMENT); @@ -315,6 +322,7 @@ public class TaskbarLauncherStateController { // If going to overview, stash the task bar // If going home, align the icons to hotseat AnimatorSet animatorSet = new AnimatorSet(); + mRecentsAnimationCallbacks = callbacks; // Update stashed flags first to ensure goingToUnstashedLauncherState() returns correctly. TaskbarStashController stashController = mControllers.taskbarStashController; diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java index c51f65942d..38d84987a9 100644 --- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java +++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java @@ -102,6 +102,7 @@ import android.window.PictureInPictureSurfaceTransaction; import android.window.TransitionInfo; import android.window.WindowAnimationState; +import androidx.annotation.CallSuper; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.UiThread; @@ -221,6 +222,7 @@ public abstract class AbsSwipeUpHandler< private final Runnable mLauncherOnDestroyCallback = () -> { ActiveGestureProtoLogProxy.logLauncherDestroyed(); + mRecentsView.removeOnScrollChangedListener(mOnRecentsScrollListener); mRecentsView = null; mContainer = null; mStateCallback.clearState(STATE_LAUNCHER_PRESENT); @@ -313,7 +315,7 @@ public abstract class AbsSwipeUpHandler< */ private static final int LOG_NO_OP_PAGE_INDEX = -1; - protected final TaskAnimationManager mTaskAnimationManager; + protected TaskAnimationManager mTaskAnimationManager; // Either RectFSpringAnim (if animating home) or ObjectAnimator (from mCurrentShift) otherwise private RunningWindowAnim[] mRunningWindowAnim; // Possible second animation running at the same time as mRunningWindowAnim @@ -1382,7 +1384,7 @@ public abstract class AbsSwipeUpHandler< && mIsTransientTaskbar && mContainerInterface.getTaskbarController() != null) { mContainerInterface.getTaskbarController() - .setUserIsNotGoingHome(endTarget != GestureState.GestureEndTarget.HOME); + .setUserIsNotGoingHome(endTarget != HOME); } float endShift = endTarget.isLauncher ? 1 : 0; @@ -2070,7 +2072,7 @@ public abstract class AbsSwipeUpHandler< * specific edge case: if we switch from A to B, and back to A before B appears, we need to * start A again to ensure it stays on top. */ - @androidx.annotation.CallSuper + @CallSuper protected void onRestartPreviouslyAppearedTask() { // Finish the controller here, since we won't get onTaskAppeared() for a task that already // appeared.