From 7a4e080f1cf909e491c9ad4c53ad3a7cf11cddc3 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Wed, 5 Oct 2022 16:21:22 -0700 Subject: [PATCH] Make IMMS#shouldPreventImeStartupLocked() more readable This is a mechanical refactoring with no behavior change for InputMethodManagerService#shouldPreventImeStartupLocked(), which was added recently [1]. Most likely return-early pattern would be more readable and maintainable for this kind of method. There must be no observable behavior change in this CL. [1]: Id0aaa496ee46532d0e97c236df7e073947ababcd 76a3c8c9b3a4971fab8fac544e49dfe8631f6059 Bug: 234882948 Test: presubmit Change-Id: Ic2d5164697523ec410b635b451fff1e4feb40830 --- .../InputMethodManagerService.java | 29 +++++++++---------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java index e89f973a8293b..4a008ed0e24ed 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java @@ -2603,23 +2603,20 @@ public final class InputMethodManagerService extends IInputMethodManager.Stub if (!mPreventImeStartupUnlessTextEditor) { return false; } - - final boolean imeVisibleAllowed = - isSoftInputModeStateVisibleAllowed(unverifiedTargetSdkVersion, startInputFlags); - - return !(imeVisibleAllowed - || mShowRequested - || isNonPreemptibleImeLocked(selectedMethodId)); - } - - /** Return {@code true} if the given IME is non-preemptible like the tv remote service. */ - @GuardedBy("ImfLock.class") - private boolean isNonPreemptibleImeLocked(@NonNull String selectedMethodId) { - final InputMethodInfo imi = mMethodMap.get(selectedMethodId); - if (imi != null) { - return ArrayUtils.contains(mNonPreemptibleInputMethods, imi.getPackageName()); + if (mShowRequested) { + return false; } - return false; + if (isSoftInputModeStateVisibleAllowed(unverifiedTargetSdkVersion, startInputFlags)) { + return false; + } + final InputMethodInfo imi = mMethodMap.get(selectedMethodId); + if (imi == null) { + return false; + } + if (ArrayUtils.contains(mNonPreemptibleInputMethods, imi.getPackageName())) { + return false; + } + return true; } @GuardedBy("ImfLock.class")