From 321550e784d24cf595082010b62b276440809be8 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Mon, 17 Jan 2022 14:59:59 -0800 Subject: [PATCH] Move trace points to IMMS#onSessionCreated() This is a follow up CL to our previous CL [1], which introduced invocations of Trace.trace{Begin,End} into InputMethodManagerService.MethodCallback#sessionCreated() with trace tag: "IMMS.sessionCreated". In order to inline InputMethodManagerService.MethodCallback, this CL moves these Trace.trace{Begin,End} to InputMethodManagerService#onSessionCreated(), with renaming the tag to "IMMS.onSessionCreated". Other than that, there is no observable behavior change in this CL. [1]: I586341426916f9b9e0f1efe988894621972da4ff d663b62186a7678a7edfb5636c84978b38241c2b Bug: 167947940 Bug: 192412909 Test: presubmit Change-Id: I4135737825befff9e696f47c153a209de4adb0e3 --- .../InputMethodManagerService.java | 56 ++++++++++--------- 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 6c68011bf31ad..9dfa142cea1e0 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -1478,14 +1478,12 @@ public class InputMethodManagerService extends IInputMethodManager.Stub @Override public void sessionCreated(IInputMethodSession session) { - Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMMS.sessionCreated"); final long ident = Binder.clearCallingIdentity(); try { mParentIMMS.onSessionCreated(mMethod, session, mChannel); } finally { Binder.restoreCallingIdentity(ident); } - Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); } } @@ -2539,34 +2537,40 @@ public class InputMethodManagerService extends IInputMethodManager.Stub mCaller.obtainMessageI(MSG_NOTIFY_IME_UID_TO_AUDIO_SERVICE, uid).sendToTarget(); } - void onSessionCreated(IInputMethod method, IInputMethodSession session, - InputChannel channel) { - synchronized (ImfLock.class) { - if (mUserSwitchHandlerTask != null) { - // We have a pending user-switching task so it's better to just ignore this session. - channel.dispose(); - return; - } - IInputMethod curMethod = getCurMethodLocked(); - if (curMethod != null && method != null - && curMethod.asBinder() == method.asBinder()) { - if (mCurClient != null) { - clearClientSessionLocked(mCurClient); - mCurClient.curSession = new SessionState(mCurClient, - method, session, channel); - InputBindResult res = attachNewInputLocked( - StartInputReason.SESSION_CREATED_BY_IME, true); - if (res.method != null) { - executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO( - MSG_BIND_CLIENT, mCurClient.client, res)); - } + @BinderThread + void onSessionCreated(IInputMethod method, IInputMethodSession session, InputChannel channel) { + Trace.traceBegin(TRACE_TAG_WINDOW_MANAGER, "IMMS.onSessionCreated"); + try { + synchronized (ImfLock.class) { + if (mUserSwitchHandlerTask != null) { + // We have a pending user-switching task so it's better to just ignore this + // session. + channel.dispose(); return; } + IInputMethod curMethod = getCurMethodLocked(); + if (curMethod != null && method != null + && curMethod.asBinder() == method.asBinder()) { + if (mCurClient != null) { + clearClientSessionLocked(mCurClient); + mCurClient.curSession = new SessionState(mCurClient, + method, session, channel); + InputBindResult res = attachNewInputLocked( + StartInputReason.SESSION_CREATED_BY_IME, true); + if (res.method != null) { + executeOrSendMessage(mCurClient.client, mCaller.obtainMessageOO( + MSG_BIND_CLIENT, mCurClient.client, res)); + } + return; + } + } } - } - // Session abandoned. Close its associated input channel. - channel.dispose(); + // Session abandoned. Close its associated input channel. + channel.dispose(); + } finally { + Trace.traceEnd(TRACE_TAG_WINDOW_MANAGER); + } } @GuardedBy("ImfLock.class")