Skip blocking InputConnection APIs after unbind
InputConnectionWrapper has several synchronous methods which have a
timeout. If the application's UI thread hangs, all these synchronous
methods are blocked and IME stays on-screen.
This CL aims to improve the responsiveness of IMEs by rejecting
any blocking calls of InputConnection APIs once
IInputMethod#unbindInput() is issued by InputMethodManagerService
(IMMS).
Currently #unbindInput() is issued only from
IMMS#unbindCurrentClientLocked(), which basically means that the
previous application is losing the IME focus.
Underlying #onUnbindInput() signal is still immediately delivered
to the IME process, but it's just waiting to be consumed on the UI thread.
Hence in theory we can change the behavior of InputConnection seen
from the IME once the signal is delivered to the IME process.
This CL does not interrupt already blocked API calls, which is one of
future work for this scenario. This CL relies on:
A. IInputMethod is marked as oneway
B. IMMS guarantees that IInputMethod#bindInput() and
IInputMethod#unbindInput() are always paired without nesting,
and IInputMethod#startInput() is called 0 or more times only
during that pair.
In this case, the system guarantees that IInputMethod methods
will be called back in the IME process in the same order, and only
one IPC thread is handling those IPCs at the same time. See the
JavaDoc of IBinder#FLAG_ONEWAY for details.
Bug: 36897707
Test: Manual: using the apk in the linked bug:
1. Make sure that a valid InputConnection is established between
the test app and a test IME.
2. Let the test app start blocking the UI thread.
3. Let the test IME call InputConnection#getTextBeforeCursor()
three times.
4. Tap the Home button on the NavBar.
5. Make sure that the test app is immediately dismissed.
6. Make sure that InputConnection#getTextBeforeCursor() starts
returning immediately, once after the initial call was timed-
out after 2 sec (InputConnectionWrapper#MAX_WAIT_TIME_MILLIS)
Change-Id: I0f816c6ca4c5c0664962432b913f074605fedd27
2 files changed