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

Commit 4bbcccde authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Make AutofillSuggestionsController per-user" into main

parents 1795bab8 12fc7e38
Loading
Loading
Loading
Loading
+13 −20
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.server.inputmethod;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UserIdInt;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Slog;
@@ -39,7 +38,7 @@ final class AutofillSuggestionsController {
    private static final boolean DEBUG = false;
    private static final String TAG = AutofillSuggestionsController.class.getSimpleName();

    @NonNull private final InputMethodManagerService mService;
    @NonNull private final InputMethodBindingController mBindingController;

    /**
     * The host input token of the input method that is currently associated with this controller.
@@ -81,8 +80,8 @@ final class AutofillSuggestionsController {
    @Nullable
    private InlineSuggestionsRequestCallback mInlineSuggestionsRequestCallback;

    AutofillSuggestionsController(@NonNull InputMethodManagerService service) {
        mService = service;
    AutofillSuggestionsController(@NonNull InputMethodBindingController bindingController) {
        mBindingController = bindingController;
    }

    @GuardedBy("ImfLock.class")
@@ -97,21 +96,15 @@ final class AutofillSuggestionsController {
    }

    @GuardedBy("ImfLock.class")
    void onCreateInlineSuggestionsRequest(@UserIdInt int userId,
            InlineSuggestionsRequestInfo requestInfo, InlineSuggestionsRequestCallback callback,
            boolean touchExplorationEnabled) {
    void onCreateInlineSuggestionsRequest(InlineSuggestionsRequestInfo requestInfo,
            InlineSuggestionsRequestCallback callback, boolean touchExplorationEnabled) {
        clearPendingInlineSuggestionsRequest();
        mInlineSuggestionsRequestCallback = callback;

        if (userId != mService.getCurrentImeUserIdLocked()) {
            callback.onInlineSuggestionsUnsupported();
            return;
        }

        // Note that current user ID is guaranteed to be userId.
        final var imeId = mService.getSelectedMethodIdLocked();
        final InputMethodInfo imi = InputMethodSettingsRepository.get(userId).getMethodMap()
                .get(imeId);
        final var imeId = mBindingController.getSelectedMethodId();
        final InputMethodInfo imi = InputMethodSettingsRepository.get(mBindingController.mUserId)
                .getMethodMap().get(imeId);
        if (imi == null || !isInlineSuggestionsEnabled(imi, touchExplorationEnabled)) {
            callback.onInlineSuggestionsUnsupported();
            return;
@@ -119,7 +112,7 @@ final class AutofillSuggestionsController {

        mPendingInlineSuggestionsRequest = new CreateInlineSuggestionsRequest(
                requestInfo, callback, imi.getPackageName());
        if (mService.getCurMethodLocked() != null) {
        if (mBindingController.getCurMethod() != null) {
            // In the normal case when the IME is connected, we can make the request here.
            performOnCreateInlineSuggestionsRequest();
        } else {
@@ -137,7 +130,7 @@ final class AutofillSuggestionsController {
        if (mPendingInlineSuggestionsRequest == null) {
            return;
        }
        IInputMethodInvoker curMethod = mService.getCurMethodLocked();
        IInputMethodInvoker curMethod = mBindingController.getCurMethod();
        if (DEBUG) {
            Slog.d(TAG, "Performing onCreateInlineSuggestionsRequest. mCurMethod = " + curMethod);
        }
@@ -146,8 +139,8 @@ final class AutofillSuggestionsController {
                    new InlineSuggestionsRequestCallbackDecorator(
                            mPendingInlineSuggestionsRequest.mCallback,
                            mPendingInlineSuggestionsRequest.mPackageName,
                            mService.getCurTokenDisplayIdLocked(),
                            mService.getCurTokenLocked());
                            mBindingController.getCurTokenDisplayId(),
                            mBindingController.getCurToken());
            curMethod.onCreateInlineSuggestionsRequest(
                    mPendingInlineSuggestionsRequest.mRequestInfo, callback);
        } else {
@@ -212,7 +205,7 @@ final class AutofillSuggestionsController {
            }
            request.setHostDisplayId(mImeDisplayId);
            synchronized (ImfLock.class) {
                final IBinder curImeToken = mService.getCurTokenLocked();
                final IBinder curImeToken = mBindingController.getCurToken();
                if (mImeToken == curImeToken) {
                    mCurHostInputToken = request.getHostInputToken();
                }
+26 −3
Original line number Diff line number Diff line
@@ -48,6 +48,8 @@ import android.view.inputmethod.InputMethodManager;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.inputmethod.IInputMethod;
import com.android.internal.inputmethod.InlineSuggestionsRequestCallback;
import com.android.internal.inputmethod.InlineSuggestionsRequestInfo;
import com.android.internal.inputmethod.InputBindResult;
import com.android.internal.inputmethod.UnbindReason;
import com.android.server.EventLogTags;
@@ -68,6 +70,7 @@ final class InputMethodBindingController {
    @UserIdInt final int mUserId;
    @NonNull private final InputMethodManagerService mService;
    @NonNull private final Context mContext;
    @NonNull private final AutofillSuggestionsController mAutofillController;
    @NonNull private final PackageManagerInternal mPackageManagerInternal;
    @NonNull private final WindowManagerInternal mWindowManagerInternal;

@@ -122,6 +125,7 @@ final class InputMethodBindingController {
        mUserId = userId;
        mService = service;
        mContext = mService.mContext;
        mAutofillController = new AutofillSuggestionsController(this);
        mPackageManagerInternal = mService.mPackageManagerInternal;
        mWindowManagerInternal = mService.mWindowManagerInternal;
        mImeConnectionBindFlags = imeConnectionBindFlags;
@@ -282,7 +286,7 @@ final class InputMethodBindingController {
    private final ServiceConnection mVisibleConnection = new ServiceConnection() {
        @Override public void onBindingDied(ComponentName name) {
            synchronized (ImfLock.class) {
                mService.invalidateAutofillSessionLocked();
                mAutofillController.invalidateAutofillSession();
                if (isVisibleBound()) {
                    unbindVisibleConnection();
                }
@@ -294,7 +298,7 @@ final class InputMethodBindingController {

        @Override public void onServiceDisconnected(ComponentName name) {
            synchronized (ImfLock.class) {
                mService.invalidateAutofillSessionLocked();
                mAutofillController.invalidateAutofillSession();
            }
        }
    };
@@ -339,7 +343,7 @@ final class InputMethodBindingController {
                    mService.initializeImeLocked(mCurMethod, mCurToken);
                    mService.scheduleNotifyImeUidToAudioService(mCurMethodUid);
                    mService.reRequestCurrentClientSessionLocked();
                    mService.performOnCreateInlineSuggestionsRequestLocked();
                    mAutofillController.performOnCreateInlineSuggestionsRequest();
                }

                // reset Handwriting event receiver.
@@ -397,6 +401,24 @@ final class InputMethodBindingController {
        }
    };

    @GuardedBy("ImfLock.class")
    void invalidateAutofillSession() {
        mAutofillController.invalidateAutofillSession();
    }

    @GuardedBy("ImfLock.class")
    void onCreateInlineSuggestionsRequest(InlineSuggestionsRequestInfo requestInfo,
            InlineSuggestionsRequestCallback callback, boolean touchExplorationEnabled) {
        mAutofillController.onCreateInlineSuggestionsRequest(requestInfo, callback,
                touchExplorationEnabled);
    }

    @GuardedBy("ImfLock.class")
    @Nullable
    IBinder getCurHostInputToken() {
        return mAutofillController.getCurHostInputToken();
    }

    @GuardedBy("ImfLock.class")
    void unbindCurrentMethod() {
        if (isVisibleBound()) {
@@ -410,6 +432,7 @@ final class InputMethodBindingController {
        if (getCurToken() != null) {
            removeCurrentToken();
            mService.resetSystemUiLocked();
            mAutofillController.onResetSystemUi();
        }

        mCurId = null;
+5 −20
Original line number Diff line number Diff line
@@ -332,9 +332,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
    private final UserManagerInternal mUserManagerInternal;
    @MultiUserUnawareField
    private final InputMethodMenuController mMenuController;
    @MultiUserUnawareField
    @NonNull
    private final AutofillSuggestionsController mAutofillController;

    @GuardedBy("ImfLock.class")
    @MultiUserUnawareField
@@ -1304,7 +1301,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                    new HardwareKeyboardShortcutController(settings.getMethodMap(),
                            settings.getUserId());
            mMenuController = new InputMethodMenuController(this);
            mAutofillController = new AutofillSuggestionsController(this);
            mVisibilityStateComputer = new ImeVisibilityStateComputer(this);
            mVisibilityApplier = new DefaultImeVisibilityApplier(this);

@@ -1713,11 +1709,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        return methodList;
    }

    @GuardedBy("ImfLock.class")
    void performOnCreateInlineSuggestionsRequestLocked() {
        mAutofillController.performOnCreateInlineSuggestionsRequest();
    }

    /**
     * Gets enabled subtypes of the specified {@link InputMethodInfo}.
     *
@@ -2115,7 +2106,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
            if (DEBUG) {
                Slog.d(TAG, "Avoiding IME startup and unbinding current input method.");
            }
            invalidateAutofillSessionLocked();
            bindingController.invalidateAutofillSession();
            bindingController.unbindCurrentMethod();
            return InputBindResult.NO_EDITOR;
        }
@@ -2215,11 +2206,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        return deviceMethodId;
    }

    @GuardedBy("ImfLock.class")
    void invalidateAutofillSessionLocked() {
        mAutofillController.invalidateAutofillSession();
    }

    @GuardedBy("ImfLock.class")
    private boolean shouldPreventImeStartupLocked(
            @NonNull String selectedMethodId,
@@ -2408,7 +2394,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
        mImeWindowVis = 0;
        mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT;
        updateSystemUiLocked(mImeWindowVis, mBackDisposition);
        mAutofillController.onResetSystemUi();
    }

    @GuardedBy("ImfLock.class")
@@ -5470,8 +5455,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                    .isTouchExplorationEnabled(userId);

            synchronized (ImfLock.class) {
                mAutofillController.onCreateInlineSuggestionsRequest(userId, requestInfo, cb,
                        touchExplorationEnabled);
                getInputMethodBindingController(userId).onCreateInlineSuggestionsRequest(
                        requestInfo, cb, touchExplorationEnabled);
            }
        }

@@ -5539,7 +5524,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
                if (displayId != getCurTokenDisplayIdLocked()) {
                    return false;
                }
                curHostInputToken = mAutofillController.getCurHostInputToken();
                curHostInputToken = getInputMethodBindingController(userId).getCurHostInputToken();
                if (curHostInputToken == null) {
                    return false;
                }
@@ -5881,7 +5866,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.

            p.println("  mCurToken=" + getCurTokenLocked());
            p.println("  mCurTokenDisplayId=" + getCurTokenDisplayIdLocked());
            p.println("  mCurHostInputToken=" + mAutofillController.getCurHostInputToken());
            p.println("  mCurHostInputToken=" + bindingController.getCurHostInputToken());
            p.println("  mCurIntent=" + bindingController.getCurIntent());
            method = getCurMethodLocked();
            p.println("  mCurMethod=" + getCurMethodLocked());