From 6495e3c93be9e6908e3d3c50e02a3a4095fbc7fe Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Thu, 20 Jan 2022 20:40:52 -0800 Subject: [PATCH] Clarify how IMMS#executeOrSendMessage() works This CL attempts to clarify how InputMethodManagerService#executeOrSendMessage() has been actually working, that is, probably to emulate oneway Binder IPC semantics in case the target IInterface object is an in-process Binder object, which is quite important to avoid dead-locks. However, using it for IInputMethod objects is overkill because we have never officially supported IMEs running in the system_server process. There is no reason to define MSG_* for those cases. As the initial step towards cleaning up those unnecessarily defined switch cases, this CL introduces a new overload method InputMethodManagerService#executeOrSendMessage(IInputMethod, Message) to make it clear that it always immediately invokes InputMethodManagerService#handleMessage() if the target is IInputMethod. The actual removal of InputMethodManagerService#executeOrSendMessage(IInputMethod, Message) will be done through subsequent CLs. To summarize, there should be no observable behavior change unless someone is surprisingly running InputMethodService in the system_server process. Bug: 215609403 Test: presubmit Change-Id: I0c4aab9a0974857e531be4fb1fc75980b36f4443 --- .../InputMethodManagerService.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index ec49b4768b749..25cb11f905a1b 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -97,7 +97,6 @@ import android.os.Bundle; import android.os.Debug; import android.os.Handler; import android.os.IBinder; -import android.os.IInterface; import android.os.LocaleList; import android.os.Message; import android.os.Parcel; @@ -2216,8 +2215,24 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } } - private void executeOrSendMessage(IInterface target, Message msg) { + // TODO(b/215609403): This method will be removed soon! + private void executeOrSendMessage(IInputMethod target, Message msg) { + if (target.asBinder() instanceof Binder) { + throw new UnsupportedOperationException( + "InputMethodService is not supported to run in the system_server"); + } + handleMessage(msg); + msg.recycle(); + } + + private void executeOrSendMessage(IInputMethodClient target, Message msg) { if (target.asBinder() instanceof Binder) { + // This is supposed to be emulating the one-way semantics when the IME client is + // system_server itself, which has not been explicitly prohibited so far while we have + // never ever officially supported such a use case... + // We probably should create a simple wrapper of IInputMethodClient as the first step + // to get rid of executeOrSendMessage() then should prohibit system_server to be the + // IME client for long term. mCaller.sendMessage(msg); } else { handleMessage(msg);