summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yohei Yukawa <yukawa@google.com> 2024-05-10 01:33:24 +0000
committer Yohei Yukawa <yukawa@google.com> 2024-05-10 01:33:24 +0000
commitb74d5b77b22a3d5b1051129addb25ae26706cdd5 (patch)
tree940e409c81c2aac9dc9227d8e0d5751d48c0f299
parent4250dc6f930fe4c82cb2ae642bf624cc09955cf8 (diff)
Move IMMS#mCurHostInputToken to AutofillSuggestionsController
This is a preparation before making AutofillSuggestionsController per-user instance. Apparently InputMethodManagerService#mCurHostInputToken, has been used only from AutofillSuggestionsController since it was originally introduced [1]. Such a data should live in the controller rather than InputMethodManagerService itself. This is a mechanical refactoring CL. There must be no observable behavior change. [1]: I268b09781e5eb7c77c4912efdc8fd5d6936ada27 Bug: 339358344 Test: atest CtsAutoFillServiceTestCases Test: atest CtsInputMethodTestCases Change-Id: I6529f81145b1a31a3438a23eca57106093b1ae07
-rw-r--r--services/core/java/com/android/server/inputmethod/AutofillSuggestionsController.java34
-rw-r--r--services/core/java/com/android/server/inputmethod/InputMethodManagerService.java34
2 files changed, 34 insertions, 34 deletions
diff --git a/services/core/java/com/android/server/inputmethod/AutofillSuggestionsController.java b/services/core/java/com/android/server/inputmethod/AutofillSuggestionsController.java
index 035a7485fe86..00bc7517bebd 100644
--- a/services/core/java/com/android/server/inputmethod/AutofillSuggestionsController.java
+++ b/services/core/java/com/android/server/inputmethod/AutofillSuggestionsController.java
@@ -40,6 +40,13 @@ final class AutofillSuggestionsController {
@NonNull private final InputMethodManagerService mService;
+ /**
+ * The host input token of the input method that is currently associated with this controller.
+ */
+ @GuardedBy("ImfLock.class")
+ @Nullable
+ private IBinder mCurHostInputToken;
+
private static final class CreateInlineSuggestionsRequest {
@NonNull final InlineSuggestionsRequestInfo mRequestInfo;
@NonNull final IInlineSuggestionsRequestCallback mCallback;
@@ -78,6 +85,17 @@ final class AutofillSuggestionsController {
}
@GuardedBy("ImfLock.class")
+ void onResetSystemUi() {
+ mCurHostInputToken = null;
+ }
+
+ @Nullable
+ @GuardedBy("ImfLock.class")
+ IBinder getCurHostInputToken() {
+ return mCurHostInputToken;
+ }
+
+ @GuardedBy("ImfLock.class")
void onCreateInlineSuggestionsRequest(@UserIdInt int userId,
InlineSuggestionsRequestInfo requestInfo, IInlineSuggestionsRequestCallback callback,
boolean touchExplorationEnabled) {
@@ -124,8 +142,7 @@ final class AutofillSuggestionsController {
mPendingInlineSuggestionsRequest.mCallback,
mPendingInlineSuggestionsRequest.mPackageName,
mService.getCurTokenDisplayIdLocked(),
- mService.getCurTokenLocked(),
- mService);
+ mService.getCurTokenLocked());
curMethod.onCreateInlineSuggestionsRequest(
mPendingInlineSuggestionsRequest.mRequestInfo, callback);
} else {
@@ -161,22 +178,20 @@ final class AutofillSuggestionsController {
* The decorator which validates the host package name in the
* {@link InlineSuggestionsRequest} argument to make sure it matches the IME package name.
*/
- private static final class InlineSuggestionsRequestCallbackDecorator
+ private final class InlineSuggestionsRequestCallbackDecorator
extends IInlineSuggestionsRequestCallback.Stub {
@NonNull private final IInlineSuggestionsRequestCallback mCallback;
@NonNull private final String mImePackageName;
private final int mImeDisplayId;
@NonNull private final IBinder mImeToken;
- @NonNull private final InputMethodManagerService mImms;
InlineSuggestionsRequestCallbackDecorator(
@NonNull IInlineSuggestionsRequestCallback callback, @NonNull String imePackageName,
- int displayId, @NonNull IBinder imeToken, @NonNull InputMethodManagerService imms) {
+ int displayId, @NonNull IBinder imeToken) {
mCallback = callback;
mImePackageName = imePackageName;
mImeDisplayId = displayId;
mImeToken = imeToken;
- mImms = imms;
}
@Override
@@ -195,7 +210,12 @@ final class AutofillSuggestionsController {
+ "].");
}
request.setHostDisplayId(mImeDisplayId);
- mImms.setCurHostInputToken(mImeToken, request.getHostInputToken());
+ synchronized (ImfLock.class) {
+ final IBinder curImeToken = mService.getCurTokenLocked();
+ if (mImeToken == curImeToken) {
+ mCurHostInputToken = request.getHostInputToken();
+ }
+ }
mCallback.onInlineSuggestionsRequest(request, callback);
}
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index 25e2e3a0b979..692e4ea88534 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -645,14 +645,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
private int mCurTokenDisplayId = INVALID_DISPLAY;
/**
- * The host input token of the current active input method.
- */
- @GuardedBy("ImfLock.class")
- @Nullable
- @MultiUserUnawareField
- private IBinder mCurHostInputToken;
-
- /**
* The display ID of the input method indicates the fallback display which returned by
* {@link #computeImeDisplayIdForTarget}.
*/
@@ -1840,21 +1832,6 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
}
/**
- * Sets current host input token.
- *
- * @param callerImeToken the token has been made for the current active input method
- * @param hostInputToken the host input token of the current active input method
- */
- void setCurHostInputToken(@NonNull IBinder callerImeToken, @Nullable IBinder hostInputToken) {
- synchronized (ImfLock.class) {
- if (!calledWithValidTokenLocked(callerImeToken)) {
- return;
- }
- mCurHostInputToken = hostInputToken;
- }
- }
-
- /**
* Gets enabled subtypes of the specified {@link InputMethodInfo}.
*
* @param imiId if null, returns enabled subtypes for the current {@link InputMethodInfo}.
@@ -2527,7 +2504,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
mBackDisposition = InputMethodService.BACK_DISPOSITION_DEFAULT;
updateSystemUiLocked(mImeWindowVis, mBackDisposition);
mCurTokenDisplayId = INVALID_DISPLAY;
- mCurHostInputToken = null;
+ mAutofillController.onResetSystemUi();
}
@GuardedBy("ImfLock.class")
@@ -5624,10 +5601,13 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
//TODO(b/150843766): Check if Input Token is valid.
final IBinder curHostInputToken;
synchronized (ImfLock.class) {
- if (displayId != mCurTokenDisplayId || mCurHostInputToken == null) {
+ if (displayId != mCurTokenDisplayId) {
+ return false;
+ }
+ curHostInputToken = mAutofillController.getCurHostInputToken();
+ if (curHostInputToken == null) {
return false;
}
- curHostInputToken = mCurHostInputToken;
}
return mInputManagerInternal.transferTouchGesture(sourceInputToken, curHostInputToken);
}
@@ -5949,7 +5929,7 @@ public final class InputMethodManagerService implements IInputMethodManagerImpl.
+ userData.mBindingController.isVisibleBound());
p.println(" mCurToken=" + getCurTokenLocked());
p.println(" mCurTokenDisplayId=" + mCurTokenDisplayId);
- p.println(" mCurHostInputToken=" + mCurHostInputToken);
+ p.println(" mCurHostInputToken=" + mAutofillController.getCurHostInputToken());
p.println(" mCurIntent=" + getCurIntentLocked());
method = getCurMethodLocked();
p.println(" mCurMethod=" + getCurMethodLocked());