From 5c232e497012011a9cdbb5a6848c53ae5c4d13f6 Mon Sep 17 00:00:00 2001 From: Nikolas Havrikov Date: Thu, 11 Nov 2021 18:15:23 +0100 Subject: [PATCH] Move binding current method to controller Bug: 205676419 Test: make Change-Id: I53855a72869a608891f55ca99101f0be9b65efde --- .../InputMethodBindingController.java | 12 ++++++++++++ .../inputmethod/InputMethodManagerService.java | 18 ++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java index 10fcb23b071ad..37ae7f2e3efbc 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java @@ -31,6 +31,7 @@ import android.os.IBinder; import android.os.Process; import android.os.SystemClock; import android.os.Trace; +import android.os.UserHandle; import android.util.ArrayMap; import android.util.Slog; import android.view.inputmethod.InputMethodInfo; @@ -341,4 +342,15 @@ final class InputMethodBindingController { mCurId = null; mService.clearCurMethodLocked(); } + + @GuardedBy("mMethodMap") + boolean bindCurrentInputMethodServiceLocked(ServiceConnection conn, int flags) { + if (mCurIntent == null || conn == null) { + Slog.e(TAG, "--- bind failed: service = " + mCurIntent + ", conn = " + conn); + return false; + } + return mContext.bindServiceAsUser(mCurIntent, conn, flags, + new UserHandle(mSettings.getCurrentUserId())); + } + } diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index b64904d338cbd..6a43b41724623 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -1984,17 +1984,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub return true; } - @GuardedBy("mMethodMap") - private boolean bindCurrentInputMethodServiceLocked(ServiceConnection conn, int flags) { - Intent service = getCurIntent(); - if (service == null || conn == null) { - Slog.e(TAG, "--- bind failed: service = " + service + ", conn = " + conn); - return false; - } - return mContext.bindServiceAsUser(service, conn, flags, - new UserHandle(mSettings.getCurrentUserId())); - } - @Override public List getInputMethodList(@UserIdInt int userId) { if (UserHandle.getCallingUserId() != userId) { @@ -2511,7 +2500,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub Intent intent = createImeBindingIntent(info.getComponent()); setCurIntent(intent); - if (bindCurrentInputMethodServiceLocked(intent, getMainConnection(), + if (mBindingController.bindCurrentInputMethodServiceLocked(intent, getMainConnection(), mImeConnectionBindFlags)) { addFreshWindowTokenLocked(displayIdToShowIme, info.getId()); return new InputBindResult( @@ -3211,7 +3200,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub showInputToken)); mInputShown = true; if (hasConnection() && !isVisibleBound()) { - bindCurrentInputMethodServiceLocked(getVisibleConnection(), IME_VISIBLE_BIND_FLAGS); + mBindingController.bindCurrentInputMethodServiceLocked(getVisibleConnection(), + IME_VISIBLE_BIND_FLAGS); setVisibleBound(true); } res = true; @@ -3227,7 +3217,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub Slog.w(TAG, "Force disconnect/connect to the IME in showCurrentInputLocked()"); ServiceConnection connection = getMainConnection(); mContext.unbindService(connection); - bindCurrentInputMethodServiceLocked(connection, + mBindingController.bindCurrentInputMethodServiceLocked(connection, mImeConnectionBindFlags); } else { if (DEBUG) {