Revert "Revert "Use color extraction for arrow popup.""

This reverts commit 17fda29bf3.

Reason for revert: Fixing the memory leak

Leak was detected in caused launcher tapl tests to fail.
For instructions on how to debug leaks, see go/launcher-testing.
Using AS memory profiler, the color extractor class is holding
onto a reference to launcher that has already been destroyed.
The fix is to set the listener to null when view is closed.

Bug: 175329686
Test: run profiler in AS, open and close popups, and verify no leaks

Change-Id: I2d4a87f0481cbc88f3587dce91278e85ca113545
This commit is contained in:
Jonathan Miranda
2021-05-03 18:44:13 +00:00
committed by Jon Miranda
parent 30ffc3f95c
commit 21930da9a2
8 changed files with 296 additions and 85 deletions

View File

@@ -18,6 +18,7 @@ package com.android.launcher3;
import static android.animation.ValueAnimator.areAnimatorsEnabled;
import static com.android.launcher3.Utilities.getBoundsForViewInDragLayer;
import static com.android.launcher3.anim.Interpolators.DEACCEL_1_5;
import android.animation.Animator;
@@ -193,6 +194,7 @@ public class CellLayout extends ViewGroup {
private static final int INVALID_DIRECTION = -100;
private final Rect mTempRect = new Rect();
private final RectF mTempRectF = new RectF();
private static final Paint sPaint = new Paint();
@@ -1070,11 +1072,16 @@ public class CellLayout extends ViewGroup {
// Apply local extracted color if the DragView is an AppWidgetHostViewDrawable.
View view = dragObject.dragView.getContentView();
if (view instanceof LauncherAppWidgetHostView) {
Workspace workspace =
Launcher.getLauncher(dragObject.dragView.getContext()).getWorkspace();
Launcher launcher = Launcher.getLauncher(dragObject.dragView.getContext());
Workspace workspace = launcher.getWorkspace();
int screenId = workspace.getIdForScreen(this);
int pageId = workspace.getPageIndexForScreenId(screenId);
cellToRect(targetCell[0], targetCell[1], spanX, spanY, mTempRect);
// Now get the rect in drag layer coordinates.
getBoundsForViewInDragLayer(launcher.getDragLayer(), workspace, mTempRect, false,
mTempRectF);
Utilities.setRect(mTempRectF, mTempRect);
((LauncherAppWidgetHostView) view).handleDrag(mTempRect, pageId);
}
}