From ee2c9824f9c4f73833796a24c1d0c52f801e8af4 Mon Sep 17 00:00:00 2001 From: Nikolas Havrikov Date: Fri, 12 Nov 2021 14:26:35 +0100 Subject: [PATCH] Extract binding current method logic Bug: 205676419 Test: make Change-Id: I9a345c94bea6c7b7183e57b6691ce8d474ce9fac --- .../InputMethodManagerService.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index c60e65e160c01..4ff4244f6c336 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -2356,7 +2356,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub @NonNull EditorInfo attribute, @StartInputFlags int startInputFlags, @StartInputReason int startInputReason) { // If no method is currently selected, do nothing. - if (getSelectedMethodId() == null) { + String selectedMethodId = getSelectedMethodId(); + if (selectedMethodId == null) { return InputBindResult.NO_IME; } @@ -2365,7 +2366,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub // party code. return new InputBindResult( InputBindResult.ResultCode.ERROR_SYSTEM_NOT_READY, - null, null, getSelectedMethodId(), getSequenceNumber(), false); + null, null, selectedMethodId, getSequenceNumber(), false); } if (!InputMethodUtils.checkIfPackageBelongsToUid(mAppOpsManager, cs.uid, @@ -2419,13 +2420,21 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } } - InputMethodInfo info = mMethodMap.get(getSelectedMethodId()); - if (info == null) { - throw new IllegalArgumentException("Unknown id: " + getSelectedMethodId()); - } - mBindingController.unbindCurrentMethodLocked(); + return bindCurrentMethodLocked(displayIdToShowIme); + } + + + @GuardedBy("mMethodMap") + @NonNull + private InputBindResult bindCurrentMethodLocked(int displayIdToShowIme) { + String selectedMethodId = getSelectedMethodId(); + InputMethodInfo info = mMethodMap.get(selectedMethodId); + if (info == null) { + throw new IllegalArgumentException("Unknown id: " + selectedMethodId); + } + Intent intent = createImeBindingIntent(info.getComponent()); setCurIntent(intent); @@ -2435,6 +2444,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub InputBindResult.ResultCode.SUCCESS_WAITING_IME_BINDING, null, null, getCurId(), getSequenceNumber(), false); } + setCurIntent(null); Slog.w(TAG, "Failure connecting to input method service: " + intent); return InputBindResult.IME_NOT_CONNECTED;