Skip to content
Commit f87534c4 authored by Ming-Shin Lu's avatar Ming-Shin Lu
Browse files

Using WindowInsets API to hide keyboard on LockScreen when screen-off

This CL is aim to resolve InputMethodManager#hideSoftInputFromWindow
somehow may not succeed even the focused editor won't changed when
screen turned off.

As CL[1] that we introduced the new app compatibility setting
(FINISH_INPUT_NO_FALLBACK_CONNECTION) for IME apps which the
targetSdkVersion >= 31.

That settings slightly changes the behavior of invoking
InputMethodManager#hideSoftInputFromWindow when device screen is off.

Since when the device screen-off, system will finish the current input
connection and clear the served view on InputMethodManager in order to
resolve a long standing unexpected started input connection problem.

With that change, SystemUI side may not succeed to call
InputMethodManager#hideSoftInputFromWindow when device screen is Off
because InputMethodManager side thought the served connection has
finished. so InputMethodManager side by default will not pass the
hide request if there is no served editor or the served editor has
changed that differnce with the caller.

Generally, even with or without FINISH_INPUT_NO_FALLBACK_CONNECTION
behavior chagnge, we are not expecting the normal app will be able
to call hideSoftInputFromWindow when device screen is off, because
the window focus will be changed to NotificiationShade, so the hide
request won't be succeed because  of the served view change.

To make the minimun change for SystemUI use case, using
WindowInsetsController#hide(ime()) to fix the issue. Since
unlike IMM#hideSoftInputFromWindow that requires more restrictions
checking the caller's input connection state, WindowInsets API
natually tells InputMethodService to hide soft-keyboard if
WM thought the IME insets is still controllable by the window.

[1]: Id4e71a822bfde5fe6a263bbe094c0d238017efe1

Fix: 192644416
Test: manual as follow steps:
    0) from " Settings -> Develop options -> AppCompatibility Changes"
       -> Select Gboard app, make sure the
       "FINISH_INPUT_NO_FALLBACK_CONNECTION" has enabled.
    1) Select Gboard as default IME apps.
    2) Setup a password lock.
    3) Pressing power key to turn off and turn on the screen
    4) Swiping up to to make keyboard shown when the Password Lock
       focused the editor.
    5) Pressing power key to turn off and turn on the screen again
    6) Verify if keyboard is hidden as expected.
Test: atest KeyboardVisibilityControlTest
Test: atest InputMethodStartInputLifecycleTest

Change-Id: I1ab2f0c012ba26f78bb0132e1447e020a74cca43
parent 09cb5879
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment