From 235ee12b144433c086007216f3900bacc2273098 Mon Sep 17 00:00:00 2001 From: Feng Cao Date: Tue, 16 Feb 2021 20:20:44 -0800 Subject: [PATCH] Pass InlineSuggestionsRequest via autofill auth intent extras Bug: 159616829 Test: atest android.autofillservice.cts.inline.InlineAuthenticationTest Change-Id: Ifb4b60afe2c241011138d1c5fa8195585d53b82b --- core/api/current.txt | 1 + .../view/autofill/AutofillManager.java | 12 +++++++ .../com/android/server/autofill/Session.java | 31 +++++++++++++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/core/api/current.txt b/core/api/current.txt index 3efb78943bd72..81f5143601b9b 100644 --- a/core/api/current.txt +++ b/core/api/current.txt @@ -50589,6 +50589,7 @@ package android.view.autofill { field public static final String EXTRA_ASSIST_STRUCTURE = "android.view.autofill.extra.ASSIST_STRUCTURE"; field public static final String EXTRA_AUTHENTICATION_RESULT = "android.view.autofill.extra.AUTHENTICATION_RESULT"; field public static final String EXTRA_CLIENT_STATE = "android.view.autofill.extra.CLIENT_STATE"; + field public static final String EXTRA_INLINE_SUGGESTIONS_REQUEST = "android.view.autofill.extra.INLINE_SUGGESTIONS_REQUEST"; } public abstract static class AutofillManager.AutofillCallback { diff --git a/core/java/android/view/autofill/AutofillManager.java b/core/java/android/view/autofill/AutofillManager.java index 794181e388cf6..ef36db652a257 100644 --- a/core/java/android/view/autofill/AutofillManager.java +++ b/core/java/android/view/autofill/AutofillManager.java @@ -221,6 +221,18 @@ public final class AutofillManager { public static final String EXTRA_CLIENT_STATE = "android.view.autofill.extra.CLIENT_STATE"; + /** + * Intent extra: the {@link android.view.inputmethod.InlineSuggestionsRequest} in the + * autofill request. + * + *

This is filled in the authentication intent so the + * {@link android.service.autofill.AutofillService} can use it to create the inline + * suggestion {@link android.service.autofill.Dataset} in the response, if the original autofill + * request contains the {@link android.view.inputmethod.InlineSuggestionsRequest}. + */ + public static final String EXTRA_INLINE_SUGGESTIONS_REQUEST = + "android.view.autofill.extra.INLINE_SUGGESTIONS_REQUEST"; + /** @hide */ public static final String EXTRA_RESTORE_SESSION_TOKEN = "android.view.autofill.extra.RESTORE_SESSION_TOKEN"; diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java index 67f654e6360fb..9805a2e8ea3dd 100644 --- a/services/autofill/java/com/android/server/autofill/Session.java +++ b/services/autofill/java/com/android/server/autofill/Session.java @@ -91,6 +91,7 @@ import android.util.ArrayMap; import android.util.ArraySet; import android.util.LocalLog; import android.util.Log; +import android.util.Pair; import android.util.Slog; import android.util.SparseArray; import android.util.TimeUtils; @@ -221,6 +222,13 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState @GuardedBy("mLock") private final ArrayMap mViewStates = new ArrayMap<>(); + /** + * Tracks the most recent IME inline request and the corresponding request id, for regular + * autofill. + */ + @GuardedBy("mLock") + @Nullable private Pair mLastInlineSuggestionsRequest; + /** * Id of the View currently being displayed. */ @@ -330,7 +338,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState @GuardedBy("mLock") private ArrayList mAugmentedAutofillableIds; - @Nullable + @NonNull private final AutofillInlineSessionController mInlineSessionController; /** @@ -821,11 +829,14 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState /* isInlineRequest= */ true); if (inlineSuggestionsRequestConsumer != null) { final AutofillId focusedId = mCurrentViewId; + final int requestIdCopy = requestId; remoteRenderService.getInlineSuggestionsRendererInfo( new RemoteCallback((extras) -> { synchronized (mLock) { mInlineSessionController.onCreateInlineSuggestionsRequestLocked( - focusedId, inlineSuggestionsRequestConsumer, extras); + focusedId, inlineSuggestionsRequestCacheDecorator( + inlineSuggestionsRequestConsumer, requestIdCopy), + extras); } }, mHandler) ); @@ -3653,11 +3664,27 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState requestId, mContexts); return null; } + if (mLastInlineSuggestionsRequest != null + && mLastInlineSuggestionsRequest.first == requestId) { + fillInIntent.putExtra(AutofillManager.EXTRA_INLINE_SUGGESTIONS_REQUEST, + mLastInlineSuggestionsRequest.second); + } fillInIntent.putExtra(AutofillManager.EXTRA_ASSIST_STRUCTURE, context.getStructure()); fillInIntent.putExtra(AutofillManager.EXTRA_CLIENT_STATE, extras); return fillInIntent; } + @NonNull + private Consumer inlineSuggestionsRequestCacheDecorator( + @NonNull Consumer consumer, int requestId) { + return inlineSuggestionsRequest -> { + consumer.accept(inlineSuggestionsRequest); + synchronized (mLock) { + mLastInlineSuggestionsRequest = Pair.create(requestId, inlineSuggestionsRequest); + } + }; + } + private void startAuthentication(int authenticationId, IntentSender intent, Intent fillInIntent, boolean authenticateInline) { try {