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
This commit is contained in:
Nikolas Havrikov
2022-04-29 15:47:03 +02:00
parent 8bda7d7db3
commit 33dc7f89c8
2 changed files with 26 additions and 0 deletions

View File

@@ -275,6 +275,7 @@ final class InputMethodBindingController {
private final ServiceConnection mVisibleConnection = new ServiceConnection() {
@Override public void onBindingDied(ComponentName name) {
synchronized (ImfLock.class) {
mService.invalidateAutofillSessionLocked();
if (mVisibleBound) {
unbindVisibleConnection();
}
@@ -285,6 +286,9 @@ final class InputMethodBindingController {
}
@Override public void onServiceDisconnected(ComponentName name) {
synchronized (ImfLock.class) {
mService.invalidateAutofillSessionLocked();
}
}
};

View File

@@ -312,6 +312,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;
@@ -2169,6 +2178,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()
@@ -2788,6 +2798,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;
}
@@ -2825,6 +2836,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,