diff options
| author | Feng Cao <fengcao@google.com> | 2020-02-28 11:39:56 -0800 |
|---|---|---|
| committer | Feng Cao <fengcao@google.com> | 2020-02-28 22:08:32 -0800 |
| commit | e65a97cef4e9a9b801e0ff985349d4059364ed59 (patch) | |
| tree | 8cbc262fcf182bce5626d333c7c1dba37bb6aa30 /core/java/android/inputmethodservice/InlineSuggestionSession.java | |
| parent | ec496000ec89664e2eaa6da610fbcd48374dbb62 (diff) | |
Populate the autofillId in the IMS EditorInfo
* So it can be checked against the autofillId from autofill manager
service
* Currently not checking due to race condition, will find a fix in
follow up CL
Test: manual verification
Bug: 149522488
Change-Id: I49457e33c7a1acb028023cb70f248805a96c5346
Diffstat (limited to 'core/java/android/inputmethodservice/InlineSuggestionSession.java')
| -rw-r--r-- | core/java/android/inputmethodservice/InlineSuggestionSession.java | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/core/java/android/inputmethodservice/InlineSuggestionSession.java b/core/java/android/inputmethodservice/InlineSuggestionSession.java index 1f12d2a6b659..25e90ee9833c 100644 --- a/core/java/android/inputmethodservice/InlineSuggestionSession.java +++ b/core/java/android/inputmethodservice/InlineSuggestionSession.java @@ -39,11 +39,12 @@ import java.util.function.Consumer; import java.util.function.Supplier; /** - * Maintains an active inline suggestion session. + * Maintains an active inline suggestion session with the autofill manager service. * * <p> - * Each session corresponds to one inline suggestion request, but there may be multiple callbacks - * with the inline suggestions response. + * Each session corresponds to one {@link InlineSuggestionsRequest} and one {@link + * IInlineSuggestionsResponseCallback}, but there may be multiple invocations of the response + * callback for the same field or different fields in the same component. */ class InlineSuggestionSession { @@ -60,6 +61,8 @@ class InlineSuggestionSession { @NonNull private final Supplier<String> mClientPackageNameSupplier; @NonNull + private final Supplier<AutofillId> mClientAutofillIdSupplier; + @NonNull private final Supplier<InlineSuggestionsRequest> mRequestSupplier; @NonNull private final Supplier<IBinder> mHostInputTokenSupplier; @@ -71,6 +74,7 @@ class InlineSuggestionSession { InlineSuggestionSession(@NonNull ComponentName componentName, @NonNull IInlineSuggestionsRequestCallback callback, @NonNull Supplier<String> clientPackageNameSupplier, + @NonNull Supplier<AutofillId> clientAutofillIdSupplier, @NonNull Supplier<InlineSuggestionsRequest> requestSupplier, @NonNull Supplier<IBinder> hostInputTokenSupplier, @NonNull Consumer<InlineSuggestionsResponse> responseConsumer) { @@ -78,6 +82,7 @@ class InlineSuggestionSession { mCallback = callback; mResponseCallback = new InlineSuggestionsResponseCallbackImpl(this); mClientPackageNameSupplier = clientPackageNameSupplier; + mClientAutofillIdSupplier = clientAutofillIdSupplier; mRequestSupplier = requestSupplier; mHostInputTokenSupplier = hostInputTokenSupplier; mResponseConsumer = responseConsumer; @@ -115,21 +120,30 @@ class InlineSuggestionSession { } } - private void handleOnInlineSuggestionsResponse(@NonNull InlineSuggestionsResponse response) { + private void handleOnInlineSuggestionsResponse(@NonNull AutofillId fieldId, + @NonNull InlineSuggestionsResponse response) { if (mInvalidated) { if (DEBUG) { Log.d(TAG, "handleOnInlineSuggestionsResponse() called on invalid session"); } return; } - // TODO(b/149522488): checking the current focused input field to make sure we don't send - // inline responses for previous input field + // TODO(b/149522488): Verify fieldId against {@code mClientAutofillIdSupplier.get()} using + // {@link AutofillId#equalsIgnoreSession(AutofillId)}. Right now, this seems to be + // falsely alarmed quite often, depending whether autofill suggestions arrive earlier + // than the IMS EditorInfo updates or not. if (!mComponentName.getPackageName().equals(mClientPackageNameSupplier.get())) { if (DEBUG) { - Log.d(TAG, "handleOnInlineSuggestionsResponse() called on the wrong package name"); + Log.d(TAG, + "handleOnInlineSuggestionsResponse() called on the wrong package " + + "name: " + mComponentName.getPackageName() + " v.s. " + + mClientPackageNameSupplier.get()); } return; } + if (DEBUG) { + Log.d(TAG, "IME receives response: " + response.getInlineSuggestions().size()); + } mResponseConsumer.accept(response); } @@ -152,7 +166,7 @@ class InlineSuggestionSession { if (session != null) { session.mHandler.sendMessage(obtainMessage( InlineSuggestionSession::handleOnInlineSuggestionsResponse, session, - response)); + fieldId, response)); } } } |
