OSDN Git Service

Make IMM more robust to spurious window focus-in
authorYohei Yukawa <yukawa@google.com>
Tue, 24 May 2016 23:35:17 +0000 (16:35 -0700)
committerYohei Yukawa <yukawa@google.com>
Tue, 24 May 2016 23:55:29 +0000 (23:55 +0000)
commit8e9214b4bd7e6a9d944ad1527199226e575a7530
tree5efa206d6ff37e72902b2c0d4ab7a0e063abed62
parentae02bfdd289f7172faeb57664ef47de8b547fa05
Make IMM more robust to spurious window focus-in

InputMethodManager (IMM) has a latch switch named IMM#mHasBeenInactive
to forcefully refresh IME focus state when an inactive client
(IMM#mActive == false) is gaining window focus.  However, it turns out
that there is a race condition where the latch could be unexpectedly
turned off. This is probably what we have been chasing in bug 25373872.

Imagine the following scenario:

  1. An app receives MSG_WINDOW_FOCUS_CHANGED w/ hasWindowFocus=false
  2. IMM inside the app receives MSG_SET_ACTIVE w/ active=false
  3. The app receives MSG_WINDOW_FOCUS_CHANGED w/ hasWindowFocus=true
  4. The app receives MSG_WINDOW_FOCUS_CHANGED w/ hasWindowFocus=false
  5. The app receives MSG_WINDOW_FOCUS_CHANGED w/ hasWindowFocus=true

Here, our current strategy has been:
  A. Turn on the latch when MSG_SET_ACTIVE (w/active=false) is handled.
  B. Turn off the latch and ask IMMS to start input when
     MSG_WINDOW_FOCUS_CHANGED (w/ hasWindowFocus=true) is handled.

The problem is that in the step B IMMS can reject the request if
WindowManagerService (WMS) tells that the window in question no longer
has window focus. This is not surprising because the app is
just handling messages in the message queue sequentially.  As a result,
the IME focus is not updated expectedly in the step 5, because the latch
is no longer enabled as we expected.

With this CL, the latch will be re-enabled if the app fails to start
input while IMM#mActive is false as a short-term solution.

In future we may want to address this issue in protocol level so that
we can address other known issues such as bug 26851566 at the same time.

Bug: 28281870
Change-Id: I60adb38013b063918b074c7b947649eada77b2c8
core/java/android/view/inputmethod/InputMethodManager.java