From a4ed0cfcb6885beeb52f701bfc64c393b668f7ba Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Tue, 29 Mar 2016 19:06:36 -0700 Subject: [PATCH] Don't give IME focus to temporarily detached View. The root cause of Bug 18920212 is that when AutoCompleteTextView tries to show completion window upon text input, InputMethodManager#focusInLocked() can be called with a View that is temporarily detached, which should be ignored. Bug: 18920212 Change-Id: Ia79bbd8468f768d546354382b47b39dd31ef7bb5 --- .../java/android/view/inputmethod/InputMethodManager.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index 687990124a558..0932b3f36e4b4 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -1307,6 +1307,12 @@ public final class InputMethodManager { void focusInLocked(View view) { if (DEBUG) Log.v(TAG, "focusIn: " + dumpViewInfo(view)); + if (view != null && view.isTemporarilyDetached()) { + // This is a request from a view that is temporarily detached from a window. + if (DEBUG) Log.v(TAG, "Temporarily detached view, ignoring"); + return; + } + if (mCurRootView != view.getRootView()) { // This is a request from a window that isn't in the window with // IME focus, so ignore it. @@ -1332,6 +1338,7 @@ public final class InputMethodManager { // whenever we go into touch mode, so it ends up hiding // at times when we don't really want it to. For now it // seems better to just turn it all off. + // TODO: Check view.isTemporarilyDetached() when re-enable the following code. if (false && view.hasWindowFocus()) { mNextServedView = null; scheduleCheckFocusLocked(view); @@ -2315,6 +2322,7 @@ public final class InputMethodManager { sb.append(",focus=" + view.hasFocus()); sb.append(",windowFocus=" + view.hasWindowFocus()); sb.append(",window=" + view.getWindowToken()); + sb.append(",temporaryDetach=" + view.isTemporarilyDetached()); return sb.toString(); } }