Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e6095023 authored by skxu's avatar skxu
Browse files

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
parent 06a8880e
Loading
Loading
Loading
Loading
+1 −8
Original line number Diff line number Diff line
@@ -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;
+21 −4
Original line number Diff line number Diff line
@@ -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);
            }
        }