Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
Close input session when the view is detached from the window.
Browse files Browse the repository at this point in the history
This is the 3rd trial to fix Bug 20820914.

In followig CLs, we have tried to address a input session
leak when the focused view is detached from the focused
window by relying on IMM#focusOut() but failed because of
regressions like Bug 21508503.
- Ib4bd70ce0305a6bde6a929bcc6ad20a2b8402a97
- I219394178e4172bc47864297f1418e677dba25e5
- Id6afc8fc64512225578c62557b96c7dc2e969adf
- Ib1b037594ebbb4ad4cf2d59e21c7a8ca9d8dc930
- I2228ae0c48ad3d9e0b55875f0dcb5ef8c55b0c5f

What we have learned from Bug 21508503 was that re-enabling
IMM#focusOut() probably requires much more work than we
thought.  Also relying on IMM#focusOut() might be overkill
because the situation in Bug 20820914 is really special where
the focused view is detached from the focused window hence
we should be able to be fix the issue more conservatively
by closing input session when and only when the focused
view is detached from the focused view, rather than
re-enabling IMM#focusOut() globally.

Bug: 20820914
Change-Id: Iaf3fe2c065b5bf91e49a729ba46262114bb6da88
  • Loading branch information
yukawa committed May 30, 2015
1 parent 650a913 commit b13f015
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/java/android/view/View.java
Original file line number Diff line number Diff line change
Expand Up @@ -14506,6 +14506,11 @@ void dispatchDetachedFromWindow() {
onDetachedFromWindow();
onDetachedFromWindowInternal();

InputMethodManager imm = InputMethodManager.peekInstance();
if (imm != null) {
imm.onViewDetachedFromWindow(this);
}

ListenerInfo li = mListenerInfo;
final CopyOnWriteArrayList<OnAttachStateChangeListener> listeners =
li != null ? li.mOnAttachStateChangeListeners : null;
Expand Down
16 changes: 16 additions & 0 deletions core/java/android/view/inputmethod/InputMethodManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -1320,6 +1320,22 @@ public void focusOut(View view) {
}
}

/**
* Call this when a view is being detached from a {@link android.view.Window}.
* @hide
*/
public void onViewDetachedFromWindow(View view) {
synchronized (mH) {
if (DEBUG) Log.v(TAG, "onViewDetachedFromWindow: " + view
+ " mServedView=" + mServedView
+ " hasWindowFocus=" + view.hasWindowFocus());
if (mServedView == view && view.hasWindowFocus()) {
mNextServedView = null;
scheduleCheckFocusLocked(view);
}
}
}

static void scheduleCheckFocusLocked(View view) {
ViewRootImpl viewRootImpl = view.getViewRootImpl();
if (viewRootImpl != null) {
Expand Down

0 comments on commit b13f015

Please sign in to comment.