From 2070234cce8811f587188e28c62f695e655204c3 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Mon, 17 Jan 2022 09:34:20 -0800 Subject: [PATCH] Make InputMethodManagerService#MSG_INITIALIZE_IME private With this CL, all the message IDs defined as IMMS#MSG_* become private constants. Message formats used in InputMethodManagerService#handleMessage() are now completely encapsulated within InputMethodManagerService. As a bonus, we can also make the following field and method private. * InputMethodManagerService#mCaller * InputMethodManagerService#executeOrSendMessage() This is still mechanical refactoring. There should be no observable behavior change. Bug: 192412909 Test: presubmit Change-Id: I37a4bf39e21955af0e677e576e4eb87d3105c8c6 --- .../InputMethodBindingController.java | 9 ++------- .../inputmethod/InputMethodManagerService.java | 16 ++++++++++------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java index 3af51f4ba55f4..db13deba1972b 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java @@ -18,8 +18,6 @@ package com.android.server.inputmethod; import static android.os.Trace.TRACE_TAG_WINDOW_MANAGER; -import static com.android.server.inputmethod.InputMethodManagerService.MSG_INITIALIZE_IME; - import android.annotation.NonNull; import android.annotation.Nullable; import android.app.PendingIntent; @@ -311,11 +309,8 @@ final class InputMethodBindingController { if (DEBUG) Slog.v(TAG, "Initiating attach with token: " + mCurToken); final InputMethodInfo info = mMethodMap.get(mSelectedMethodId); mSupportsStylusHw = info.supportsStylusHandwriting(); - // Dispatch display id for InputMethodService to update context display. - mService.executeOrSendMessage(mCurMethod, - mService.mCaller.obtainMessageIOOO(MSG_INITIALIZE_IME, - info.getConfigChanges(), mCurMethod, mCurToken, - mSupportsStylusHw)); + mService.executeOrSendInitializeIme(mCurMethod, mCurToken, + info.getConfigChanges(), mSupportsStylusHw); mService.scheduleNotifyImeUidToAudioService(mCurMethodUid); mService.reRequestCurrentClientSessionLocked(); } diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 254fc0aad48e4..6c68011bf31ad 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -228,10 +228,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub private static final int MSG_SHOW_SOFT_INPUT = 1020; private static final int MSG_HIDE_SOFT_INPUT = 1030; private static final int MSG_HIDE_CURRENT_INPUT_METHOD = 1035; - /** - * package-private because this is also used by {@link InputMethodBindingController}. - */ - static final int MSG_INITIALIZE_IME = 1040; + private static final int MSG_INITIALIZE_IME = 1040; private static final int MSG_CREATE_SESSION = 1050; private static final int MSG_REMOVE_IME_SURFACE = 1060; private static final int MSG_REMOVE_IME_SURFACE_FROM_WINDOW = 1061; @@ -288,7 +285,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub final WindowManagerInternal mWindowManagerInternal; final PackageManagerInternal mPackageManagerInternal; final InputManagerInternal mInputManagerInternal; - final HandlerCaller mCaller; + private final HandlerCaller mCaller; final boolean mHasFeature; private final ArrayMap> mAdditionalSubtypeMap = new ArrayMap<>(); @@ -2244,7 +2241,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } } - void executeOrSendMessage(IInterface target, Message msg) { + private void executeOrSendMessage(IInterface target, Message msg) { if (target.asBinder() instanceof Binder) { mCaller.sendMessage(msg); } else { @@ -2529,6 +2526,13 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } } + @AnyThread + void executeOrSendInitializeIme(@NonNull IInputMethod inputMethod, @NonNull IBinder token, + @android.content.pm.ActivityInfo.Config int configChanges, boolean supportStylusHw) { + executeOrSendMessage(inputMethod, mCaller.obtainMessageIOOO(MSG_INITIALIZE_IME, + configChanges, inputMethod, token, supportStylusHw)); + } + @AnyThread void scheduleNotifyImeUidToAudioService(int uid) { mCaller.removeMessages(MSG_NOTIFY_IME_UID_TO_AUDIO_SERVICE);