From 1bd7ccd90b611bae9ac1f2696382a54d0d3eb471 Mon Sep 17 00:00:00 2001 From: Jon Spivack Date: Wed, 2 Jun 2021 15:55:06 -0700 Subject: [PATCH] TaskOverlayFactoryGo: Keep persistent instance of AssistContentRequester Holding a reference to AssistContentRequester prevents it from being deleted by the garbage collector while it is still in use. Bug: 189985872 Test: Manual (Pixel 3A) Test: m -j RunLauncherGoGoogleRoboTests Change-Id: I204aab907175a171c496c3bd146a8b23d2bbcf16 --- .../quickstep/TaskOverlayFactoryGo.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java b/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java index 754782bd49..65cdcf06ba 100644 --- a/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java +++ b/go/quickstep/src/com/android/quickstep/TaskOverlayFactoryGo.java @@ -53,14 +53,17 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory { public static final int ERROR_PERMISSIONS = 1; private static final String TAG = "TaskOverlayFactoryGo"; - // Empty constructor required for ResourceBasedOverride - public TaskOverlayFactoryGo(Context context) {} + private AssistContentRequester mContentRequester; + + public TaskOverlayFactoryGo(Context context) { + mContentRequester = new AssistContentRequester(context); + } /** * Create a new overlay instance for the given View */ public TaskOverlayGo createOverlay(TaskThumbnailView thumbnailView) { - return new TaskOverlayGo(thumbnailView); + return new TaskOverlayGo(thumbnailView, mContentRequester); } /** @@ -72,9 +75,12 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory { private String mTaskPackageName; private String mWebUrl; private boolean mAssistPermissionsEnabled; + private AssistContentRequester mFactoryContentRequester; - private TaskOverlayGo(TaskThumbnailView taskThumbnailView) { + private TaskOverlayGo(TaskThumbnailView taskThumbnailView, + AssistContentRequester assistContentRequester) { super(taskThumbnailView); + mFactoryContentRequester = assistContentRequester; } /** @@ -105,9 +111,7 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory { } int taskId = task.key.id; - AssistContentRequester contentRequester = - new AssistContentRequester(mApplicationContext); - contentRequester.requestAssistContent(taskId, this::onAssistContentReceived); + mFactoryContentRequester.requestAssistContent(taskId, this::onAssistContentReceived); } /** Provide Assist Content to the overlay. */