diff options
author | TYM Tsai <tymtsai@google.com> | 2020-05-04 23:11:24 +0800 |
---|---|---|
committer | TYM Tsai <tymtsai@google.com> | 2020-05-25 15:09:44 +0800 |
commit | 81cbe29a1ce566921acd5aa6c4d2cc1b35748407 (patch) | |
tree | 95ed71a981ed548523cffb3ec21eeb4d8e557376 /services/autofill/java | |
parent | 81fd503701c09bd1d60647f366291a051f01c8fb (diff) |
Handle input method switch properly for inline suggestions
Expired the old response while received input method subtype changed.
When user next tap on an autofill field, trigger a new fill request for
the new input method.
Bug: 150483555
Test: manual switch imput method
Test: atest CtsAutoFillServiceTestCases
Change-Id: I97be067db3a79d2481c05aeb59875ec24514199d
Diffstat (limited to 'services/autofill/java')
3 files changed, 70 insertions, 0 deletions
diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java index c6a54fc3d206..9432678b7d2b 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerService.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerService.java @@ -249,6 +249,9 @@ public final class AutofillManagerService resolver.registerContentObserver(Settings.Global.getUriFor( Settings.Global.AUTOFILL_MAX_VISIBLE_DATASETS), false, observer, UserHandle.USER_ALL); + resolver.registerContentObserver(Settings.Secure.getUriFor( + Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE), false, observer, + UserHandle.USER_ALL); } @Override // from AbstractMasterSystemService @@ -263,6 +266,9 @@ public final class AutofillManagerService case Settings.Global.AUTOFILL_MAX_VISIBLE_DATASETS: setMaxVisibleDatasetsFromSettings(); break; + case Settings.Secure.SELECTED_INPUT_METHOD_SUBTYPE: + handleInputMethodSwitch(userId); + break; default: Slog.w(TAG, "Unexpected property (" + property + "); updating cache instead"); // fall through @@ -273,6 +279,23 @@ public final class AutofillManagerService } } + private void handleInputMethodSwitch(@UserIdInt int userId) { + // TODO(b/156903336): Used the SettingsObserver with a background thread maybe slow to + // respond to the IME switch in certain situations. + // See: services/core/java/com/android/server/FgThread.java + // In particular, the shared background thread could be doing relatively long-running + // operations like saving state to disk (in addition to simply being a background priority), + // which can cause operations scheduled on it to be delayed for a user-noticeable amount + // of time. + + synchronized (mLock) { + final AutofillManagerServiceImpl service = peekServiceForUserLocked(userId); + if (service != null) { + service.onSwitchInputMethod(); + } + } + } + private void onDeviceConfigChange(@NonNull Set<String> keys) { for (String key : keys) { switch (key) { diff --git a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java index 1aeb19bb4a9e..96b593d9682f 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java +++ b/services/autofill/java/com/android/server/autofill/AutofillManagerServiceImpl.java @@ -1564,6 +1564,16 @@ final class AutofillManagerServiceImpl } } + void onSwitchInputMethod() { + synchronized (mLock) { + final int sessionCount = mSessions.size(); + for (int i = 0; i < sessionCount; i++) { + final Session session = mSessions.valueAt(i); + session.onSwitchInputMethodLocked(); + } + } + } + @Override public String toString() { return "AutofillManagerServiceImpl: [userId=" + mUserId diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java index 086a8be6d6cf..7957726a5a7a 100644 --- a/services/autofill/java/com/android/server/autofill/Session.java +++ b/services/autofill/java/com/android/server/autofill/Session.java @@ -311,6 +311,43 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState */ private final AssistDataReceiverImpl mAssistReceiver = new AssistDataReceiverImpl(); + void onSwitchInputMethodLocked() { + if (mExpiredResponse) { + return; + } + + if (shouldExpireResponseOnInputMethodSwitch()) { + // Set the old response expired, so the next action (ACTION_VIEW_ENTERED) can trigger + // a new fill request. + mExpiredResponse = true; + } + } + + private boolean shouldExpireResponseOnInputMethodSwitch() { + // One of below cases will need a new fill request to update the inline spec for the new + // input method. + // 1. The autofill provider supports inline suggestion and the render service is available. + // 2. Had triggered the augmented autofill and the render service is available. Whether the + // augmented autofill triggered by: + // a. Augmented autofill only + // b. The autofill provider respond null + if (mService.getRemoteInlineSuggestionRenderServiceLocked() == null) { + return false; + } + + if (isInlineSuggestionsEnabledByAutofillProviderLocked()) { + return true; + } + + final ViewState state = mViewStates.get(mCurrentViewId); + if (state != null + && (state.getState() & ViewState.STATE_TRIGGERED_AUGMENTED_AUTOFILL) != 0) { + return true; + } + + return false; + } + /** * TODO(b/151867668): improve how asynchronous data dependencies are handled, without using * CountDownLatch. |