From fa4839d23eeb5b3a07d9ee75470d56b3df654c32 Mon Sep 17 00:00:00 2001 From: TYM Tsai Date: Mon, 1 May 2023 00:23:53 +0000 Subject: [PATCH] Stop to show fill dialog if IME is showing Because the request to show the fill dialog and the IME is asynchronous. To reduce the fill dialog appearing on the IME, check to see if the IME shows it before showing the fill dialog. This change does not fully resolve the IME and fill dialog showing at the same time but can mitigate the problem. More details see the bug. When supported fill dialog flag is appended, the view of parameter will be null. So remove to check the view is not null when appending the reset fill dialog flag. Bug: 236436818 Test: atest CtsAutoFillServiceTestCases Change-Id: I4dbfaa1ae398ec067652418f7dd66ced305ea5f7 --- core/java/android/view/autofill/AutofillManager.java | 2 +- .../server/autofill/AutofillInlineSessionController.java | 7 +++++++ .../AutofillInlineSuggestionsRequestSession.java | 9 +++++++++ .../java/com/android/server/autofill/Session.java | 6 ++++++ 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/autofill/AutofillManager.java b/core/java/android/view/autofill/AutofillManager.java index e39b3a182b280..bee4d1ffc0cb6 100644 --- a/core/java/android/view/autofill/AutofillManager.java +++ b/core/java/android/view/autofill/AutofillManager.java @@ -1744,7 +1744,7 @@ public final class AutofillManager { mForAugmentedAutofillOnly = false; } - if ((flags & FLAG_SUPPORTS_FILL_DIALOG) != 0 && view != null) { + if ((flags & FLAG_SUPPORTS_FILL_DIALOG) != 0) { flags |= FLAG_RESET_FILL_DIALOG_STATE; } diff --git a/services/autofill/java/com/android/server/autofill/AutofillInlineSessionController.java b/services/autofill/java/com/android/server/autofill/AutofillInlineSessionController.java index dd5e58a94d154..cac3c20ec3e03 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillInlineSessionController.java +++ b/services/autofill/java/com/android/server/autofill/AutofillInlineSessionController.java @@ -206,4 +206,11 @@ final class AutofillInlineSessionController { } return false; } + + boolean isImeShowing() { + if (mSession != null) { + return mSession.isImeShowing(); + } + return false; + } } diff --git a/services/autofill/java/com/android/server/autofill/AutofillInlineSuggestionsRequestSession.java b/services/autofill/java/com/android/server/autofill/AutofillInlineSuggestionsRequestSession.java index a089f3ddcb86b..468b9ab5710e7 100644 --- a/services/autofill/java/com/android/server/autofill/AutofillInlineSuggestionsRequestSession.java +++ b/services/autofill/java/com/android/server/autofill/AutofillInlineSuggestionsRequestSession.java @@ -106,6 +106,8 @@ final class AutofillInlineSuggestionsRequestSession { @GuardedBy("mLock") private boolean mImeSessionInvalidated = false; + private boolean mImeShowing = false; + AutofillInlineSuggestionsRequestSession( @NonNull InputMethodManagerInternal inputMethodManagerInternal, int userId, @NonNull ComponentName componentName, @NonNull Handler handler, @NonNull Object lock, @@ -320,6 +322,7 @@ final class AutofillInlineSuggestionsRequestSession { if (mDestroyed) { return; } + mImeShowing = imeInputViewStarted; if (mImeCurrentFieldId != null) { boolean imeInputStartedChanged = (mImeInputStarted != imeInputStarted); boolean imeInputViewStartedChanged = (mImeInputViewStarted != imeInputViewStarted); @@ -364,6 +367,12 @@ final class AutofillInlineSuggestionsRequestSession { } } + boolean isImeShowing() { + synchronized (mLock) { + return !mDestroyed && mImeShowing; + } + } + /** * Internal implementation of {@link IInlineSuggestionsRequestCallback}. */ diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java index 3736262e06732..f6a380aba4e2c 100644 --- a/services/autofill/java/com/android/server/autofill/Session.java +++ b/services/autofill/java/com/android/server/autofill/Session.java @@ -4281,6 +4281,12 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState return false; } + if (mInlineSessionController.isImeShowing()) { + // IME is showing, fallback to normal suggestions UI + // Note: only work when inline suggestions supported + return false; + } + synchronized (mLock) { if (mLastFillDialogTriggerIds == null || !ArrayUtils.contains(mLastFillDialogTriggerIds, filledId)) {