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
This commit is contained in:
Jon Spivack 2021-06-02 15:55:06 -07:00
parent 8c46bba98e
commit 1bd7ccd90b
1 changed files with 11 additions and 7 deletions

View File

@ -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. */