From d6a60371969a45db7f9fe30a224dee5080377afc Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Tue, 3 Aug 2021 14:34:05 -0700 Subject: [PATCH] Remove inaccurate words "main thread" from IInputConnectionWrapper This is a clean-up CL for up my CL [1], which introduced InputConnection#getHandler() per request from the Chromium team. This CL only renames misleading and/or inaccurate code commends and field names. There should be no observable behavior change. Even before my change [1], IInputConnectionWrapper had been responsible for re-dispatching incoming IPCs onto the "UI thread" obtained from View#getHandler(), which is not guaranteed to be the "main thread" in some rare situations. With my change [1], the target thread is no longer limited to the UI thread. This CL removes misleading and confusing "main" terminology from the variable names and comments for future readers. [1]: Id9e579bb3e2966986cdcb1c34bc8cacfeca2e1a9 612cce92ad96eda1146c3abd2afa7aaa4d4f2b3f Bug: 26945674 Bug: 192412909 Test: presubmit Change-Id: Ibb31da4f66e8a6cd35f93c3ca1cc0f871dfb3b73 --- .../view/IInputConnectionWrapper.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/java/com/android/internal/view/IInputConnectionWrapper.java b/core/java/com/android/internal/view/IInputConnectionWrapper.java index 3e109c0dd3f54..65970a8e992de 100644 --- a/core/java/com/android/internal/view/IInputConnectionWrapper.java +++ b/core/java/com/android/internal/view/IInputConnectionWrapper.java @@ -61,7 +61,8 @@ public final class IInputConnectionWrapper extends IInputContext.Stub { @Nullable private InputConnection mInputConnection; - private final Looper mMainLooper; + @NonNull + private final Looper mLooper; private final Handler mH; private final Object mLock = new Object(); @@ -71,12 +72,12 @@ public final class IInputConnectionWrapper extends IInputContext.Stub { private final InputMethodManager mParentInputMethodManager; private final WeakReference mServedView; - public IInputConnectionWrapper(@NonNull Looper mainLooper, + public IInputConnectionWrapper(@NonNull Looper looper, @NonNull InputConnection inputConnection, @NonNull InputMethodManager inputMethodManager, @Nullable View servedView) { mInputConnection = inputConnection; - mMainLooper = mainLooper; - mH = new Handler(mMainLooper); + mLooper = looper; + mH = new Handler(mLooper); mParentInputMethodManager = inputMethodManager; mServedView = new WeakReference<>(servedView); } @@ -156,13 +157,13 @@ public final class IInputConnectionWrapper extends IInputContext.Stub { */ public void dumpDebug(ProtoOutputStream proto, long fieldId) { synchronized (mLock) { - // Check that the call is initiated in the main thread of the current InputConnection + // Check that the call is initiated in the target thread of the current InputConnection // {@link InputConnection#getHandler} since the messages to IInputConnectionWrapper are // executed on this thread. Otherwise the messages are dispatched to the correct thread // in IInputConnectionWrapper, but this is not wanted while dumpng, for performance // reasons. if ((mInputConnection instanceof DumpableInputConnection) - && Looper.myLooper() == mMainLooper) { + && mLooper.isCurrentThread()) { ((DumpableInputConnection) mInputConnection).dumpDebug(proto, fieldId); } } @@ -766,10 +767,9 @@ public final class IInputConnectionWrapper extends IInputContext.Stub { } private void dispatch(@NonNull Runnable runnable) { - // If we are calling this from the main thread, then we can call - // right through. Otherwise, we need to send the message to the - // main thread. - if (mMainLooper.isCurrentThread()) { + // If we are calling this from the target thread, then we can call right through. + // Otherwise, we need to send the message to the target thread. + if (mLooper.isCurrentThread()) { runnable.run(); return; }