From ff66a00ebba767890a95501b3b8ae4ee7c215447 Mon Sep 17 00:00:00 2001 From: Nikolas Havrikov Date: Wed, 10 Nov 2021 18:03:15 +0100 Subject: [PATCH] Encapsulate mVisibleBound in IMMS This is a step in a refactoring and will be superseded by follow-up commits. Bug: 205676419 Test: make Change-Id: Ie90aea7b91d4bf2b2e34e587a752e6717b4f84d8 --- .../InputMethodManagerService.java | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index dd6c22e9b1cd5..9289907b3ed16 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -351,6 +351,18 @@ public class InputMethodManagerService extends IInputMethodManager.Stub @GuardedBy("mMethodMap") private int mMethodMapUpdateCount = 0; + /** + * Indicates whether {@link #getVisibleConnection} is currently in use. + */ + private boolean isVisibleBound() { + return mVisibleBound; + } + + private void setVisibleBound(boolean visibleBound) { + mVisibleBound = visibleBound; + } + private boolean mVisibleBound = false; + /** * Used to bring IME service up to visible adjustment while it is being shown. */ @@ -361,9 +373,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub private final ServiceConnection mVisibleConnection = new ServiceConnection() { @Override public void onBindingDied(ComponentName name) { synchronized (mMethodMap) { - if (mVisibleBound) { + if (isVisibleBound()) { mContext.unbindService(getVisibleConnection()); - mVisibleBound = false; + setVisibleBound(false); } } } @@ -374,7 +386,6 @@ public class InputMethodManagerService extends IInputMethodManager.Stub @Override public void onServiceDisconnected(ComponentName name) { } }; - boolean mVisibleBound = false; // Ongoing notification private NotificationManager mNotificationManager; @@ -2673,9 +2684,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub @GuardedBy("mMethodMap") void unbindCurrentMethodLocked() { - if (mVisibleBound) { + if (isVisibleBound()) { mContext.unbindService(getVisibleConnection()); - mVisibleBound = false; + setVisibleBound(false); } if (hasConnection()) { @@ -3246,10 +3257,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub executeOrSendMessage(mCurMethod, mCaller.obtainMessageIIOOO(MSG_SHOW_SOFT_INPUT, getImeShowFlagsLocked(), reason, mCurMethod, resultReceiver, showInputToken)); mInputShown = true; - if (hasConnection() && !mVisibleBound) { + if (hasConnection() && !isVisibleBound()) { bindCurrentInputMethodServiceLocked( getCurIntent(), getVisibleConnection(), IME_VISIBLE_BIND_FLAGS); - mVisibleBound = true; + setVisibleBound(true); } res = true; } else { @@ -3355,9 +3366,9 @@ public class InputMethodManagerService extends IInputMethodManager.Stub } else { res = false; } - if (hasConnection() && mVisibleBound) { + if (hasConnection() && isVisibleBound()) { mContext.unbindService(getVisibleConnection()); - mVisibleBound = false; + setVisibleBound(false); } mInputShown = false; mShowRequested = false; @@ -5303,7 +5314,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub + " client=" + mCurFocusedWindowClient); focusedWindowClient = mCurFocusedWindowClient; p.println(" mCurId=" + getCurId() + " mHaveConnection=" + hasConnection() - + " mBoundToMethod=" + mBoundToMethod + " mVisibleBound=" + mVisibleBound); + + " mBoundToMethod=" + mBoundToMethod + " mVisibleBound=" + isVisibleBound()); p.println(" mCurToken=" + getCurToken()); p.println(" mCurTokenDisplayId=" + mCurTokenDisplayId); p.println(" mCurHostInputToken=" + mCurHostInputToken);