diff options
| -rw-r--r-- | core/java/android/view/ViewRootImpl.java | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java index 3006b5d5687c..e1312c19283a 100644 --- a/core/java/android/view/ViewRootImpl.java +++ b/core/java/android/view/ViewRootImpl.java @@ -3612,8 +3612,31 @@ public final class ViewRootImpl implements ViewParent, finishInputEvent(q, true); } else { if (q.mEvent instanceof KeyEvent) { + KeyEvent event = (KeyEvent)q.mEvent; + if (event.getAction() != KeyEvent.ACTION_UP) { + // If the window doesn't currently have input focus, then drop + // this event. This could be an event that came back from the + // IME dispatch but the window has lost focus in the meantime. + if (!mAttachInfo.mHasWindowFocus) { + Slog.w(TAG, "Dropping event due to no window focus: " + event); + finishInputEvent(q, true); + return; + } + } deliverKeyEventPostIme(q); } else { + MotionEvent event = (MotionEvent)q.mEvent; + if (event.getAction() != MotionEvent.ACTION_CANCEL + && event.getAction() != MotionEvent.ACTION_UP) { + // If the window doesn't currently have input focus, then drop + // this event. This could be an event that came back from the + // IME dispatch but the window has lost focus in the meantime. + if (!mAttachInfo.mHasWindowFocus) { + Slog.w(TAG, "Dropping event due to no window focus: " + event); + finishInputEvent(q, true); + return; + } + } final int source = q.mEvent.getSource(); if ((source & InputDevice.SOURCE_CLASS_TRACKBALL) != 0) { deliverTrackballEventPostIme(q); |