diff options
| author | Ming-Shin Lu <lumark@google.com> | 2020-09-28 01:35:31 +0800 |
|---|---|---|
| committer | Ming-Shin Lu <lumark@google.com> | 2020-11-25 23:32:49 +0800 |
| commit | 152eacec4f5e1c78eafd42abbcf62fc12b0eee33 (patch) | |
| tree | 1e40ce0edc22e8a911b70f1e89295e8f8cf06ec6 /core/java/android/inputmethodservice/InputMethodService.java | |
| parent | 976aa3d404547b6e535c1a8626ebb9f215076d5e (diff) | |
Let IME#onFinishInput called without dup onStartInput when screen-off
Also called IME#onStartInput without dup onFinishInput when screen-on,
to fix the long-standing IME input connection lifecycle issue when
device screen state changes.
Bug: 156215187
Bug: 26851566
Test: atest InputMethodStartInputLifecycleTest
Test: manual as below steps
0) Enable InputMethodService debug flag.
0-1) In Settings -> Develop options -> AppCompatibility Changes,
Select Gboard and then toggle
"FINISH_INPUT_NO_FALLBACK_CONNECTION" change.
1) Launch a app with focused a editor and show soft-input
2) When device screen turned-off, will see InputMethodService only
callbacks below logs:
CALL: doFinishInput
CALL: onFinishInputView
CALL: onFinishInput
3) When device screen turned-on, will see InputMethodService only
callbacks below logs:
CALL: onStartInput
CALL: onStartInputView
Change-Id: I8a657e75e274d842fb46b60375f6aeafeab96a59
Diffstat (limited to 'core/java/android/inputmethodservice/InputMethodService.java')
| -rw-r--r-- | core/java/android/inputmethodservice/InputMethodService.java | 29 |
1 files changed, 27 insertions, 2 deletions
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index ae260e16806f..4a5d831cd705 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -61,9 +61,12 @@ import android.annotation.IntDef; import android.annotation.MainThread; import android.annotation.NonNull; import android.annotation.Nullable; +import android.annotation.TestApi; import android.annotation.UiContext; import android.app.ActivityManager; import android.app.Dialog; +import android.compat.annotation.ChangeId; +import android.compat.annotation.EnabledSince; import android.compat.annotation.UnsupportedAppUsage; import android.content.Context; import android.content.pm.PackageManager; @@ -411,7 +414,29 @@ public class InputMethodService extends AbstractInputMethodService { @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) int mTheme = 0; - + + /** + * Finish the {@link InputConnection} when the device becomes + * {@link android.os.PowerManager#isInteractive non-interactive}. + * + * <p> + * If enabled by the current {@link InputMethodService input method}, the current input + * connection will be {@link InputMethodService#onFinishInput finished} whenever the devices + * becomes non-interactive. + * + * <p> + * If not enabled, the current input connection will instead be silently deactivated when the + * devices becomes non-interactive, and an {@link InputMethodService#onFinishInput + * onFinishInput()} {@link InputMethodService#onStartInput onStartInput()} pair is dispatched + * when the device becomes interactive again. + * + * @hide + */ + @TestApi + @ChangeId + @EnabledSince(targetSdkVersion = Build.VERSION_CODES.S) + public static final long FINISH_INPUT_NO_FALLBACK_CONNECTION = 156215187L; // This is a bug id. + LayoutInflater mInflater; TypedArray mThemeAttrs; @UnsupportedAppUsage @@ -2325,7 +2350,7 @@ public class InputMethodService extends AbstractInputMethodService { } void doStartInput(InputConnection ic, EditorInfo attribute, boolean restarting) { - if (!restarting) { + if (!restarting && mInputStarted) { doFinishInput(); } ImeTracing.getInstance().triggerServiceDump("InputMethodService#doStartInput", this); |
