From 1755df787d0747c17a389abc535d8bc02a10caa4 Mon Sep 17 00:00:00 2001 From: Nikolas Havrikov Date: Fri, 18 Feb 2022 14:33:01 +0100 Subject: [PATCH 1/2] Fix showSoftInput crashing when no IME is enabled This CL adds a shortcut for bindCurrentMethod in InputMethodBindingController to return NO_IME instead of crashing in the rare case when no IME is enabled in the system. Bug: 220125769 Test: atest InputMethodServiceTest#testShowSoftInput_whenAllImesDisabled Change-Id: I7da6ed7f2b80331c469751b7091c340422df40a8 (cherry picked from commit 107035849e9f28c7ba96af0cb1caaa7bed80fd76) Merged-In:I7da6ed7f2b80331c469751b7091c340422df40a8 --- .../server/inputmethod/InputMethodBindingController.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java index b2f500a59ba96..d2d80ffde5328 100644 --- a/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java +++ b/services/core/java/com/android/server/inputmethod/InputMethodBindingController.java @@ -408,6 +408,11 @@ final class InputMethodBindingController { @GuardedBy("ImfLock.class") @NonNull InputBindResult bindCurrentMethod() { + if (mSelectedMethodId == null) { + Slog.e(TAG, "mSelectedMethodId is null!"); + return InputBindResult.NO_IME; + } + InputMethodInfo info = mMethodMap.get(mSelectedMethodId); if (info == null) { throw new IllegalArgumentException("Unknown id: " + mSelectedMethodId); From 87d1af1d805110a1a26773563e78549be20cf6ec Mon Sep 17 00:00:00 2001 From: Nikolas Havrikov Date: Wed, 16 Feb 2022 15:41:36 +0100 Subject: [PATCH 2/2] Simplify getImmDelegate in ImeFocusController This CL undoes part of [1] making removing a local variable. [1]: Id4c85be1c0eab51f167ba00fc355386f852c424d Test: make Change-Id: I6b890e5536c17dd53722e2c3a781c85dd9d6bdf0 (cherry picked from commit d90033999f0282cb1a5d70c66f8102dde3ea58b0) Merged-In:I6b890e5536c17dd53722e2c3a781c85dd9d6bdf0 --- core/java/android/view/ImeFocusController.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/core/java/android/view/ImeFocusController.java b/core/java/android/view/ImeFocusController.java index 3fc9f6bcbdeb3..b48b5258237f0 100644 --- a/core/java/android/view/ImeFocusController.java +++ b/core/java/android/view/ImeFocusController.java @@ -54,13 +54,11 @@ public final class ImeFocusController { @NonNull private InputMethodManagerDelegate getImmDelegate() { - InputMethodManagerDelegate delegate = mDelegate; - if (delegate != null) { - return delegate; + if (mDelegate == null) { + mDelegate = mViewRootImpl.mContext.getSystemService( + InputMethodManager.class).getDelegate(); } - delegate = mViewRootImpl.mContext.getSystemService(InputMethodManager.class).getDelegate(); - mDelegate = delegate; - return delegate; + return mDelegate; } /** Called when the view root is moved to a different display. */