diff options
| author | 2024-05-21 23:59:22 +0900 | |
|---|---|---|
| committer | 2024-05-21 23:59:22 +0900 | |
| commit | 12fc7e3806f1010de5decb8287ab2830a511628a (patch) | |
| tree | c28037e63775f2d8f29ee3be56d46184872d32a1 | |
| parent | 4c1803f8d38085f29148bef72fbec74703e9812d (diff) | |
Make AutofillSuggestionsController per-user
This CL makes AutofillSuggestionsController per user instance by
making it be owned by InputMethodBindingController, which is already
instantiated for each user.
By doing InputMethodManagerService does not need to work as a
trampoline between AutofillSuggestionsController and
InputMethodBindingController.
While this is not a pure mechanical change, if there was any
observable behavior change it would be considered to be a semantic bug
that needs to be addressed sooner or later. So far existing end-to-end
tests have been passing successfully.
Test: presubmit
Fix: 339358344
Change-Id: I23125b27e7eb7d096dcb8e6fc10581b106cb6329
3 files changed, 44 insertions, 43 deletions
diff --git a/services/core/java/com/android/server/inputmethod/AutofillSuggestionsController.java b/services/core/java/com/android/server/inputmethod/AutofillSuggestionsController.java index a3b1a2df9577..0749edce97a1 100644 --- a/services/core/java/com/android/server/inputmethod/AutofillSuggestionsController.java +++ b/services/core/java/com/android/server/inputmethod/AutofillSuggestionsController.java @@ -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(); } diff --git a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java index ad9995097639..8191ee14adff 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java @@ -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. @@ -398,6 +402,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()) { unbindVisibleConnection(); @@ -410,6 +432,7 @@ final class InputMethodBindingController { if (getCurToken() != null) { removeCurrentToken(); mService.resetSystemUiLocked(); + mAutofillController.onResetSystemUi(); } mCurId = null; diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 3138034ee8fa..c2d1b2f72a2f 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -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 @@ -1296,7 +1293,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); @@ -1705,11 +1701,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. return methodList; } - @GuardedBy("ImfLock.class") - void performOnCreateInlineSuggestionsRequestLocked() { - mAutofillController.performOnCreateInlineSuggestionsRequest(); - } - /** * Gets enabled subtypes of the specified {@link InputMethodInfo}. * @@ -2106,7 +2097,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; } @@ -2206,11 +2197,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. } @GuardedBy("ImfLock.class") - void invalidateAutofillSessionLocked() { - mAutofillController.invalidateAutofillSession(); - } - - @GuardedBy("ImfLock.class") private boolean shouldPreventImeStartupLocked( @NonNull String selectedMethodId, @StartInputFlags int startInputFlags, @@ -2398,7 +2384,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. mImeWindowVis = 0; mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT; updateSystemUiLocked(mImeWindowVis, mBackDisposition); - mAutofillController.onResetSystemUi(); } @GuardedBy("ImfLock.class") @@ -5460,8 +5445,8 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. .isTouchExplorationEnabled(userId); synchronized (ImfLock.class) { - mAutofillController.onCreateInlineSuggestionsRequest(userId, requestInfo, cb, - touchExplorationEnabled); + getInputMethodBindingController(userId).onCreateInlineSuggestionsRequest( + requestInfo, cb, touchExplorationEnabled); } } @@ -5529,7 +5514,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl. if (displayId != getCurTokenDisplayIdLocked()) { return false; } - curHostInputToken = mAutofillController.getCurHostInputToken(); + curHostInputToken = getInputMethodBindingController(userId).getCurHostInputToken(); if (curHostInputToken == null) { return false; } @@ -5871,7 +5856,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()); |