From aff7c622da59699e02d8593a7d3f094900b051c4 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Tue, 12 Jul 2022 19:33:20 -0700 Subject: [PATCH] Simplify IMMS#reportPerceptibleAsync() IMMS#mCurFocusedWindow is guaranteed to be associated with the current IME client process. As long as the calling process has the same window token, checking calledFromValidUserLocked() is just redundant and could even make it a bit unclear about what security model we are enforcing there. Bug: 34886274 Test: presubmit Change-Id: Iafb2b6d82fcccb4a33eceebff3d08b96fde8dc03 --- .../inputmethod/InputMethodManagerService.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index 4886e6e14c17c..1366177ea6ab8 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -3430,19 +3430,12 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub public void reportPerceptibleAsync(IBinder windowToken, boolean perceptible) { Objects.requireNonNull(windowToken, "windowToken must not be null"); synchronized (ImfLock.class) { - if (!calledFromValidUserLocked()) { + if (mCurFocusedWindow != windowToken || mCurPerceptible == perceptible) { return; } - final long ident = Binder.clearCallingIdentity(); - try { - if (mCurFocusedWindow == windowToken - && mCurPerceptible != perceptible) { - mCurPerceptible = perceptible; - updateSystemUiLocked(mImeWindowVis, mBackDisposition); - } - } finally { - Binder.restoreCallingIdentity(ident); - } + mCurPerceptible = perceptible; + Binder.withCleanCallingIdentity(() -> + updateSystemUiLocked(mImeWindowVis, mBackDisposition)); } }