From e257fbd9f664bee4601a2379c91e08a66335d99a Mon Sep 17 00:00:00 2001 From: Haoran Zhang Date: Wed, 19 Jul 2023 18:48:03 +0000 Subject: [PATCH] Force hiding fill UI when it's destroyed. The bug describes a scenaior where drop down UI is not removed even when tapping on other fields. Forcing hiding dropdown UI fix this issue. For reason why it would fix it needs more understanding. Test: atest CtsAutoFillServiceTestCases Bug: b/290917485 Change-Id: Id4940093aad5dcb290a494245052ba2ce9321aec --- .../android/view/autofill/AutofillManager.java | 8 ++++++++ .../view/autofill/IAutoFillManagerClient.aidl | 5 +++++ .../java/com/android/server/autofill/Session.java | 15 +++++++++++++++ .../android/server/autofill/ui/AutoFillUI.java | 8 ++++++++ .../com/android/server/autofill/ui/FillUi.java | 3 ++- 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/autofill/AutofillManager.java b/core/java/android/view/autofill/AutofillManager.java index 739c1bfccd3bf..d729d494e104a 100644 --- a/core/java/android/view/autofill/AutofillManager.java +++ b/core/java/android/view/autofill/AutofillManager.java @@ -4213,6 +4213,14 @@ public final class AutofillManager { } } + @Override + public void requestHideFillUiWhenDestroyed(int sessionId, AutofillId id) { + final AutofillManager afm = mAfm.get(); + if (afm != null) { + afm.post(() -> afm.requestHideFillUi(id, true)); + } + } + @Override public void notifyNoFillUi(int sessionId, AutofillId id, int sessionFinishedState) { final AutofillManager afm = mAfm.get(); diff --git a/core/java/android/view/autofill/IAutoFillManagerClient.aidl b/core/java/android/view/autofill/IAutoFillManagerClient.aidl index 51afe4cf784d0..917a974f992df 100644 --- a/core/java/android/view/autofill/IAutoFillManagerClient.aidl +++ b/core/java/android/view/autofill/IAutoFillManagerClient.aidl @@ -78,6 +78,11 @@ oneway interface IAutoFillManagerClient { */ void requestHideFillUi(int sessionId, in AutofillId id); + /** + * Requests hiding the fill UI when it's destroyed + */ + void requestHideFillUiWhenDestroyed(int sessionId, in AutofillId id); + /** * Notifies no fill UI will be shown, and also mark the state as finished if necessary (if * sessionFinishedState != 0). diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java index fb26f427dad70..70aff057c9ab1 100644 --- a/services/autofill/java/com/android/server/autofill/Session.java +++ b/services/autofill/java/com/android/server/autofill/Session.java @@ -2401,6 +2401,21 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState } } + @Override + public void requestHideFillUiWhenDestroyed(AutofillId id) { + synchronized (mLock) { + // NOTE: We allow this call in a destroyed state as the UI is + // asked to go away after we get destroyed, so let it do that. + try { + mClient.requestHideFillUiWhenDestroyed(this.id, id); + } catch (RemoteException e) { + Slog.e(TAG, "Error requesting to hide fill UI", e); + } + + mInlineSessionController.hideInlineSuggestionsUiLocked(id); + } + } + // AutoFillUiCallback @Override public void cancelSession() { diff --git a/services/autofill/java/com/android/server/autofill/ui/AutoFillUI.java b/services/autofill/java/com/android/server/autofill/ui/AutoFillUI.java index f92d38dc0deb9..d479dfb512ca5 100644 --- a/services/autofill/java/com/android/server/autofill/ui/AutoFillUI.java +++ b/services/autofill/java/com/android/server/autofill/ui/AutoFillUI.java @@ -95,6 +95,7 @@ public final class AutoFillUI { void requestShowFillUi(AutofillId id, int width, int height, IAutofillWindowPresenter presenter); void requestHideFillUi(AutofillId id); + void requestHideFillUiWhenDestroyed(AutofillId id); void startIntentSenderAndFinishSession(IntentSender intentSender); void startIntentSender(IntentSender intentSender, Intent intent); void dispatchUnhandledKey(AutofillId id, KeyEvent keyEvent); @@ -288,6 +289,13 @@ public final class AutoFillUI { } } + @Override + public void requestHideFillUiWhenDestroyed() { + if (mCallback != null) { + mCallback.requestHideFillUiWhenDestroyed(focusedId); + } + } + @Override public void startIntentSender(IntentSender intentSender) { if (mCallback != null) { diff --git a/services/autofill/java/com/android/server/autofill/ui/FillUi.java b/services/autofill/java/com/android/server/autofill/ui/FillUi.java index cdfe7bb4f4a78..cdd9ef4e1a76b 100644 --- a/services/autofill/java/com/android/server/autofill/ui/FillUi.java +++ b/services/autofill/java/com/android/server/autofill/ui/FillUi.java @@ -91,6 +91,7 @@ final class FillUi { void requestShowFillUi(int width, int height, IAutofillWindowPresenter windowPresenter); void requestHideFillUi(); + void requestHideFillUiWhenDestroyed(); void startIntentSender(IntentSender intentSender); void dispatchUnhandledKey(KeyEvent keyEvent); void cancelSession(); @@ -482,7 +483,7 @@ final class FillUi { } mCallback.onDestroy(); if (notifyClient) { - mCallback.requestHideFillUi(); + mCallback.requestHideFillUiWhenDestroyed(); } mDestroyed = true; }