From 79c5fed289ed9392dad9c62fa62d5801e1e9807c Mon Sep 17 00:00:00 2001 From: Nikolas Havrikov Date: Fri, 29 Apr 2022 15:47:03 +0200 Subject: [PATCH] Invalidate autofill session on IME disconnect Remember the latest InlineSuggestionsRequestCallback coming from the autofill service, so that its autofill session can be invalidated when the IME process is unbound or stopped. Test: atest InlineWebViewActivityTest#testAutofillOneDataset Bug: 226240255 Change-Id: I49cf295b95cec33b7eb404eab62b900014d09e26 (cherry picked from commit 33dc7f89c87e96bed3df9788076ad9395579025f) Merged-In: I49cf295b95cec33b7eb404eab62b900014d09e26 --- .../InputMethodBindingController.java | 4 ++++ .../InputMethodManagerService.java | 22 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java index 9195b68e7a8f2..86969ce1693c2 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java @@ -247,6 +247,7 @@ final class InputMethodBindingController { private final ServiceConnection mVisibleConnection = new ServiceConnection() { @Override public void onBindingDied(ComponentName name) { synchronized (ImfLock.class) { + mService.invalidateAutofillSessionLocked(); if (mVisibleBound) { unbindVisibleConnection(); } @@ -257,6 +258,9 @@ final class InputMethodBindingController { } @Override public void onServiceDisconnected(ComponentName name) { + synchronized (ImfLock.class) { + mService.invalidateAutofillSessionLocked(); + } } }; diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index ea2b1571c0ae8..1a1c265f568d6 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -313,6 +313,15 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub @Nullable private CreateInlineSuggestionsRequest mPendingInlineSuggestionsRequest; + /** + * A callback into the autofill service obtained from the latest call to + * {@link #onCreateInlineSuggestionsRequestLocked}, which can be used to invalidate an + * autofill session in case the IME process dies. + */ + @GuardedBy("ImfLock.class") + @Nullable + private IInlineSuggestionsRequestCallback mInlineSuggestionsRequestCallback; + @UserIdInt private int mLastSwitchUserId; @@ -2176,6 +2185,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub InlineSuggestionsRequestInfo requestInfo, IInlineSuggestionsRequestCallback callback, boolean touchExplorationEnabled) { clearPendingInlineSuggestionsRequestLocked(); + mInlineSuggestionsRequestCallback = callback; final InputMethodInfo imi = mMethodMap.get(getSelectedMethodIdLocked()); try { if (userId == mSettings.getCurrentUserId() @@ -2797,6 +2807,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub if (DEBUG) { Slog.d(TAG, "Avoiding IME startup and unbinding current input method."); } + invalidateAutofillSessionLocked(); mBindingController.unbindCurrentMethod(); return InputBindResult.NO_EDITOR; } @@ -2834,6 +2845,17 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub return mBindingController.bindCurrentMethod(); } + @GuardedBy("ImfLock.class") + void invalidateAutofillSessionLocked() { + if (mInlineSuggestionsRequestCallback != null) { + try { + mInlineSuggestionsRequestCallback.onInlineSuggestionsSessionInvalidated(); + } catch (RemoteException e) { + Slog.e(TAG, "Cannot invalidate autofill session.", e); + } + } + } + @GuardedBy("ImfLock.class") private boolean shouldPreventImeStartupLocked( @NonNull String selectedMethodId,