From 840b42f66fff8898829140ae9e189a04c6120186 Mon Sep 17 00:00:00 2001 From: Jon Spivack Date: Fri, 26 Feb 2021 15:24:02 -0800 Subject: [PATCH] Pass Assistant web URI in NIU Actions The Task Overlay for the activity shown in Recents requests the AssistContent for that activity. If the content includes a web URI, this is added to the Intents sent by the NIU Actions buttons. Bug: 180157890 Test: Manual (tested with Chrome as the recent activity on local device) Test: TODO (b/179738220) Change-Id: I33c79e75678605693e0282e4ad82dc6af28957dd --- go/AndroidManifest.xml | 2 + .../quickstep/TaskOverlayFactoryGo.java | 80 +++++++++++++++++-- 2 files changed, 77 insertions(+), 5 deletions(-) diff --git a/go/AndroidManifest.xml b/go/AndroidManifest.xml index f36439db53..2671604f94 100644 --- a/go/AndroidManifest.xml +++ b/go/AndroidManifest.xml @@ -24,6 +24,8 @@ + + The type of View in which the overlay will be placed */ public static final class TaskOverlayGo extends TaskOverlay { + private static final String ASSIST_KEY_CONTENT = "content"; - private String mPackageName; + private String mNIUPackageName; + private int mTaskId; + private Bundle mAssistData; + private final Handler mMainThreadHandler; private TaskOverlayGo(TaskThumbnailView taskThumbnailView) { super(taskThumbnailView); + mMainThreadHandler = new Handler(Looper.getMainLooper()); } /** @@ -70,16 +87,39 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory { public void initOverlay(Task task, ThumbnailData thumbnail, Matrix matrix, boolean rotated) { getActionsView().updateDisabledFlags(DISABLED_NO_THUMBNAIL, thumbnail == null); - mPackageName = + mNIUPackageName = mApplicationContext.getResources().getString(R.string.niu_actions_package); - if (thumbnail == null || TextUtils.isEmpty(mPackageName)) { + if (thumbnail == null || TextUtils.isEmpty(mNIUPackageName)) { return; } getActionsView().updateDisabledFlags(DISABLED_ROTATED, rotated); boolean isAllowedByPolicy = thumbnail.isRealSnapshot; getActionsView().setCallbacks(new OverlayUICallbacksGoImpl(isAllowedByPolicy, task)); + + mTaskId = task.key.id; + AssistDataReceiverImpl receiver = new AssistDataReceiverImpl(); + receiver.setOverlay(this); + + try { + ActivityTaskManager.getService().requestAssistDataForTask(receiver, mTaskId, + mApplicationContext.getPackageName()); + } catch (RemoteException e) { + Log.e(TAG, "Unable to request AssistData"); + } + } + + /** + * Called when AssistDataReceiverImpl receives data from ActivityTaskManagerService's + * AssistDataRequester + */ + public void onAssistDataReceived(Bundle data) { + mMainThreadHandler.post(() -> { + if (data != null) { + mAssistData = data; + } + }); } private void sendNIUIntent(String actionType) { @@ -88,11 +128,21 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory { } private Intent createNIUIntent(String actionType) { - return new Intent(actionType) + Intent intent = new Intent(actionType) .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK) .addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION) - .setPackage(mPackageName) + .setPackage(mNIUPackageName) .putExtra(ELAPSED_NANOS, SystemClock.elapsedRealtimeNanos()); + + if (mAssistData != null) { + final AssistContent content = mAssistData.getParcelable(ASSIST_KEY_CONTENT); + Uri webUri = (content == null) ? null : content.getWebUri(); + if (webUri != null) { + intent.putExtra(ACTIONS_URL, webUri.toString()); + } + } + + return intent; } protected class OverlayUICallbacksGoImpl extends OverlayUICallbacksImpl @@ -130,6 +180,26 @@ public final class TaskOverlayFactoryGo extends TaskOverlayFactory { } } + /** + * Basic AssistDataReceiver. This is passed to ActivityTaskManagerService, which then requests + * the data. + */ + private static final class AssistDataReceiverImpl extends IAssistDataReceiver.Stub { + private TaskOverlayGo mOverlay; + + public void setOverlay(TaskOverlayGo overlay) { + mOverlay = overlay; + } + + @Override + public void onHandleAssistData(Bundle data) { + mOverlay.onAssistDataReceived(data); + } + + @Override + public void onHandleAssistScreenshot(Bitmap screenshot) {} + } + /** * Callbacks the Ui can generate. This is the only way for a Ui to call methods on the * controller.