summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Wilson Wu <wilsonwu@google.com> 2020-11-19 20:46:17 +0800
committer Wilson Wu <wilsonwu@google.com> 2020-11-30 17:12:05 +0800
commit02c934b09b65adc39cb00948afed2676e0426710 (patch)
tree74d1764271dc786eb8ba301f5c63f5d68a9a80a9
parent23a1669512cc2d827949c72d75acc3446bfdc007 (diff)
Prevent ANR when app is terminated abruptly
When app is forced stop, the removeImeSurface flow from DisplayImeController will be dropped in IMMS and IMS because some fields (IMMS#mShowRequested, IMS#mShowInputRequested..etc) still remain previous state. The launcher cannot receive keyevent at that time since IME surface remain and cause ANR. Calling hideCurrentInputLocked() to hide the IME surface when a IME client is removed. Bug: 167780081 Test: atest CtsInputMethodTestCases Test: Verify with issue reproduce steps: 1) Add another language to the keyboard 2) Open chrome and tap the EditText to show keyboard 3) Tap to show language swiching dialog 4) adb shell am force-stop com.android.chrome 5) adb shell input keyevent 8 6) Verify there is no ANR happen Change-Id: Ifb91111f7136952462678ff6d0a5e917abb5005e
-rw-r--r--core/java/com/android/internal/inputmethod/SoftInputShowHideReason.java8
-rw-r--r--services/core/java/com/android/server/inputmethod/InputMethodManagerService.java2
2 files changed, 9 insertions, 1 deletions
diff --git a/core/java/com/android/internal/inputmethod/SoftInputShowHideReason.java b/core/java/com/android/internal/inputmethod/SoftInputShowHideReason.java
index ffc7f05eb703..1553e2eb0793 100644
--- a/core/java/com/android/internal/inputmethod/SoftInputShowHideReason.java
+++ b/core/java/com/android/internal/inputmethod/SoftInputShowHideReason.java
@@ -48,7 +48,8 @@ import java.lang.annotation.Retention;
SoftInputShowHideReason.HIDE_DOCKED_STACK_ATTACHED,
SoftInputShowHideReason.HIDE_RECENTS_ANIMATION,
SoftInputShowHideReason.HIDE_BUBBLES,
- SoftInputShowHideReason.HIDE_SAME_WINDOW_FOCUSED_WITHOUT_EDITOR})
+ SoftInputShowHideReason.HIDE_SAME_WINDOW_FOCUSED_WITHOUT_EDITOR,
+ SoftInputShowHideReason.HIDE_REMOVE_CLIENT})
public @interface SoftInputShowHideReason {
/** Show soft input by {@link android.view.inputmethod.InputMethodManager#showSoftInput}. */
int SHOW_SOFT_INPUT = 0;
@@ -161,4 +162,9 @@ public @interface SoftInputShowHideReason {
* soft-input when the same window focused again to align with the same behavior prior to R.
*/
int HIDE_SAME_WINDOW_FOCUSED_WITHOUT_EDITOR = 20;
+
+ /**
+ * Hide soft input when a {@link com.android.internal.view.IInputMethodClient} is removed.
+ */
+ int HIDE_REMOVE_CLIENT = 21;
}
diff --git a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
index 0ceaf7748eba..5189945fc9ae 100644
--- a/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
+++ b/services/core/java/com/android/server/inputmethod/InputMethodManagerService.java
@@ -2284,6 +2284,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
}
if (mCurClient == cs) {
+ hideCurrentInputLocked(
+ mCurFocusedWindow, 0, null, SoftInputShowHideReason.HIDE_REMOVE_CLIENT);
if (mBoundToMethod) {
mBoundToMethod = false;
if (mCurMethod != null) {