From a0dde9c9d603c073064162c1c780e5d4d5990a82 Mon Sep 17 00:00:00 2001 From: Ming-Shin Lu Date: Mon, 16 Jan 2023 10:20:45 +0000 Subject: [PATCH] Fix an errorprone for GuardedBy warning Moving all logic of IMMS#reportPerceptibleAsync into Binder.withCleanCallingIdentity() runnable parameter to ensure it can be guarded by ImfLock in the same code block. To avoid a false alarm lint error caught in CL[1] that the static analysis checker not be aware in runnable inner called updateSystemUiLocked has guarded by the ImfLock with running on the same thread outside the runnable. [1]: I12d99c15ae0d8965a21406d2495ce5cb18afaea0 Bug: 246309664 Test: make RUN_ERROR_PRONE=true services Change-Id: Ic7bc9227ce57a3a7c0c3c9726625cd6d0d6a1939 --- .../inputmethod/InputMethodManagerService.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 19108a883d2cd..a63b95c204b4c 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -3349,15 +3349,16 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub @BinderThread @Override public void reportPerceptibleAsync(IBinder windowToken, boolean perceptible) { - Objects.requireNonNull(windowToken, "windowToken must not be null"); - synchronized (ImfLock.class) { - if (mCurFocusedWindow != windowToken || mCurPerceptible == perceptible) { - return; + Binder.withCleanCallingIdentity(() -> { + Objects.requireNonNull(windowToken, "windowToken must not be null"); + synchronized (ImfLock.class) { + if (mCurFocusedWindow != windowToken || mCurPerceptible == perceptible) { + return; + } + mCurPerceptible = perceptible; + updateSystemUiLocked(); } - mCurPerceptible = perceptible; - Binder.withCleanCallingIdentity(() -> - updateSystemUiLocked(mImeWindowVis, mBackDisposition)); - } + }); } @GuardedBy("ImfLock.class")