From 89825acce149cd1dfdad8c62283ff1952645e45a Mon Sep 17 00:00:00 2001 From: Feng Cao Date: Wed, 10 Jun 2020 11:22:54 -0700 Subject: [PATCH] Send empty response to IME when autofill session is destroyed * Note that usually the session is destroyed when the focus is already on a new input field in a different activity, so this action will be no-op most of the cases * But in case of augmented autofill service dynamically requesting a new autofill flow, this works well on clearing the existing suggestions on the current input field Test: manual Test: atest android.autofillservice.cts.inline Bug: 157515522 Bug: 158038231 Change-Id: I6cedb33737d822c3c3eb4ee127984c24c4307f7a --- .../AutofillInlineSessionController.java | 18 +++++++++++++++++- .../com/android/server/autofill/Session.java | 3 +++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/services/autofill/java/com/android/server/autofill/AutofillInlineSessionController.java b/services/autofill/java/com/android/server/autofill/AutofillInlineSessionController.java index 0ec8654f2a204..398ece4c18361 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillInlineSessionController.java +++ b/services/autofill/java/com/android/server/autofill/AutofillInlineSessionController.java @@ -77,8 +77,8 @@ final class AutofillInlineSessionController { if (mSession != null) { // Destroy the existing session. mSession.destroySessionLocked(); - mInlineFillUi = null; } + mInlineFillUi = null; // TODO(b/151123764): consider reusing the same AutofillInlineSession object for the // same field. mSession = new AutofillInlineSuggestionsRequestSession(mInputMethodManagerInternal, mUserId, @@ -86,6 +86,22 @@ final class AutofillInlineSessionController { mSession.onCreateInlineSuggestionsRequestLocked(); } + /** + * Destroys the current session. May send an empty response to IME to clear the suggestions if + * the focus didn't change to a different field. + * + * @param autofillId the currently focused view from the autofill session + */ + @GuardedBy("mLock") + void destroyLocked(@NonNull AutofillId autofillId) { + if (mSession != null) { + mSession.onInlineSuggestionsResponseLocked(InlineFillUi.emptyUi(autofillId)); + mSession.destroySessionLocked(); + mSession = null; + } + mInlineFillUi = null; + } + /** * Returns the {@link InlineSuggestionsRequest} provided by IME for the last request. * diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java index a9a0ab69f6335..c7490b3b991cd 100644 --- a/services/autofill/java/com/android/server/autofill/Session.java +++ b/services/autofill/java/com/android/server/autofill/Session.java @@ -3702,6 +3702,9 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState unlinkClientVultureLocked(); mUi.destroyAll(mPendingSaveUi, this, true); mUi.clearCallback(this); + if (mCurrentViewId != null) { + mInlineSessionController.destroyLocked(mCurrentViewId); + } mDestroyed = true; // Log metrics