From 27d44213821a8da063514bd4b0af509f4ff12c21 Mon Sep 17 00:00:00 2001 From: Wilson Wu Date: Tue, 6 Sep 2022 12:58:25 +0800 Subject: [PATCH] Improve lock annotation for InputMethodManager (2/N) In CL[1], we added @GuardedBy("mH") annotation for some fields which should be guarded by mH for lock annotation improvement. Annotate more fields we miss in CL[1]. [1]: I3b345da25841b328358d16695e3a29ee65ae8d83 Bug: b/236937383 Test: presubmit Change-Id: Ibee725dff3ff3d52f5b4d58e8bf2d8837dba665e --- .../view/inputmethod/InputMethodManager.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index b0075fa1132b9..bf5ec3dbfb033 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -446,6 +446,7 @@ public final class InputMethodManager { * {@code true} if next {@link ImeFocusController#onPostWindowFocus} needs to * restart input. */ + @GuardedBy("mH") private boolean mRestartOnNextWindowFocus = true; /** @@ -495,8 +496,11 @@ public final class InputMethodManager { private CompletionInfo[] mCompletions; // Cursor position on the screen. + @GuardedBy("mH") @UnsupportedAppUsage Rect mTmpCursorRect = new Rect(); + + @GuardedBy("mH") @UnsupportedAppUsage Rect mCursorRect = new Rect(); @@ -545,6 +549,7 @@ public final class InputMethodManager { * @deprecated New code should use {@code mCurBindState.mImeId}. */ @Deprecated + @GuardedBy("mH") @UnsupportedAppUsage String mCurId; @@ -586,6 +591,7 @@ public final class InputMethodManager { * @deprecated This is kept for {@link UnsupportedAppUsage}. Must not be used. */ @Deprecated + @GuardedBy("mH") private int mRequestUpdateCursorAnchorInfoMonitorMode = REQUEST_UPDATE_CURSOR_ANCHOR_INFO_NONE; /** @@ -594,7 +600,9 @@ public final class InputMethodManager { @GuardedBy("mH") private ImeInsetsSourceConsumer mImeInsetsConsumer; + @GuardedBy("mH") private final Pool mPendingEventPool = new SimplePool<>(20); + @GuardedBy("mH") private final SparseArray mPendingEvents = new SparseArray<>(20); private final DelegateImpl mDelegate = new DelegateImpl(); @@ -841,11 +849,13 @@ public final class InputMethodManager { */ @Override public boolean isRestartOnNextWindowFocus(boolean reset) { - final boolean result = mRestartOnNextWindowFocus; - if (reset) { - mRestartOnNextWindowFocus = false; + synchronized (mH) { + final boolean result = mRestartOnNextWindowFocus; + if (reset) { + mRestartOnNextWindowFocus = false; + } + return result; } - return result; } /**