From e6095023e7a496da6a3c55b7977e472ee0630b77 Mon Sep 17 00:00:00 2001 From: skxu Date: Fri, 3 Dec 2021 18:39:47 +0000 Subject: [PATCH] Change when to create inline fill request Check if IME supports inline suggestions with touch exploration, before sending inline fill request Fixes: 207007377 Test: atest InlineLoginActivityTest Change-Id: Ice499eb15381de4d947bd77f90f19812b8442afc --- .../com/android/server/autofill/Session.java | 9 +------ .../InputMethodManagerService.java | 25 ++++++++++++++++--- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/services/autofill/java/com/android/server/autofill/Session.java b/services/autofill/java/com/android/server/autofill/Session.java index 76ee728fdb07a..e0fa67f64c4c7 100644 --- a/services/autofill/java/com/android/server/autofill/Session.java +++ b/services/autofill/java/com/android/server/autofill/Session.java @@ -103,7 +103,6 @@ import android.util.Slog; import android.util.SparseArray; import android.util.TimeUtils; import android.view.KeyEvent; -import android.view.accessibility.AccessibilityManager; import android.view.autofill.AutofillId; import android.view.autofill.AutofillManager; import android.view.autofill.AutofillManager.SmartSuggestionMode; @@ -367,8 +366,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState @Nullable private ClientSuggestionsSession mClientSuggestionsSession; - private final AccessibilityManager mAccessibilityManager; - // TODO(b/216576510): Share one BroadcastReceiver between all Sessions instead of creating a // new one per Session. private final BroadcastReceiver mDelayedFillBroadcastReceiver = @@ -518,10 +515,7 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState return; } - // If a11y touch exploration is enabled, then we do not send an inline fill request - // to the regular af service, because dropdown UI is easier to use. - if (mPendingInlineSuggestionsRequest.isServiceSupported() - && !mAccessibilityManager.isTouchExplorationEnabled()) { + if (mPendingInlineSuggestionsRequest.isServiceSupported()) { mPendingFillRequest = new FillRequest(mPendingFillRequest.getId(), mPendingFillRequest.getFillContexts(), mPendingFillRequest.getClientState(), @@ -1064,7 +1058,6 @@ final class Session implements RemoteFillService.FillServiceCallbacks, ViewState mRemoteFillService = serviceComponentName == null ? null : new RemoteFillService(context, serviceComponentName, userId, this, bindInstantServiceAllowed); - mAccessibilityManager = AccessibilityManager.getInstance(context); mActivityToken = activityToken; mHasCallback = hasCallback; mUiLatencyHistory = uiLatencyHistory; diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 7068ed13376f1..0b7e39136feb3 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -130,6 +130,7 @@ import android.view.WindowManager; import android.view.WindowManager.DisplayImePolicy; import android.view.WindowManager.LayoutParams; import android.view.WindowManager.LayoutParams.SoftInputModeFlags; +import android.view.accessibility.AccessibilityManager; import android.view.autofill.AutofillId; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InlineSuggestionsRequest; @@ -287,6 +288,9 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub private final InputMethodMenuController mMenuController; private final InputMethodBindingController mBindingController; + // TODO(b/219056452): Use AccessibilityManagerInternal instead. + private final AccessibilityManager mAccessibilityManager; + /** * Cache the result of {@code LocalServices.getService(AudioManagerInternal.class)}. * @@ -1627,6 +1631,7 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub mAppOpsManager = mContext.getSystemService(AppOpsManager.class); mUserManager = mContext.getSystemService(UserManager.class); mUserManagerInternal = LocalServices.getService(UserManagerInternal.class); + mAccessibilityManager = AccessibilityManager.getInstance(context); mHasFeature = context.getPackageManager().hasSystemFeature( PackageManager.FEATURE_INPUT_METHODS); mPlatformCompat = IPlatformCompat.Stub.asInterface( @@ -1995,12 +2000,13 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub @GuardedBy("ImfLock.class") private void onCreateInlineSuggestionsRequestLocked(@UserIdInt int userId, - InlineSuggestionsRequestInfo requestInfo, IInlineSuggestionsRequestCallback callback) { + InlineSuggestionsRequestInfo requestInfo, IInlineSuggestionsRequestCallback callback, + boolean touchExplorationEnabled) { final InputMethodInfo imi = mMethodMap.get(getSelectedMethodIdLocked()); try { IInputMethodInvoker curMethod = getCurMethodLocked(); - if (userId == mSettings.getCurrentUserId() && imi != null - && imi.isInlineSuggestionsEnabled() && curMethod != null) { + if (userId == mSettings.getCurrentUserId() && curMethod != null + && imi != null && isInlineSuggestionsEnabled(imi, touchExplorationEnabled)) { final IInlineSuggestionsRequestCallback callbackImpl = new InlineSuggestionsRequestCallbackDecorator(callback, imi.getPackageName(), mCurTokenDisplayId, getCurTokenLocked(), @@ -2014,6 +2020,13 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub } } + private static boolean isInlineSuggestionsEnabled(InputMethodInfo imi, + boolean touchExplorationEnabled) { + return imi.isInlineSuggestionsEnabled() + && (!touchExplorationEnabled + || imi.supportsInlineSuggestionsWithTouchExploration()); + } + /** * The decorator which validates the host package name in the * {@link InlineSuggestionsRequest} argument to make sure it matches the IME package name. @@ -5197,8 +5210,12 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub @Override public void onCreateInlineSuggestionsRequest(@UserIdInt int userId, InlineSuggestionsRequestInfo requestInfo, IInlineSuggestionsRequestCallback cb) { + // Get the device global touch exploration state before lock to avoid deadlock. + boolean touchExplorationEnabled = mAccessibilityManager.isTouchExplorationEnabled(); + synchronized (ImfLock.class) { - onCreateInlineSuggestionsRequestLocked(userId, requestInfo, cb); + onCreateInlineSuggestionsRequestLocked(userId, requestInfo, cb, + touchExplorationEnabled); } }