From daa6695c2ee8f7a8a9d724e4169ced4d28edc54d Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Wed, 17 Nov 2021 15:21:32 -0800 Subject: Add IMM#invalidateInput() Historically TextView#setText() has internally called InputMethodManager#restartInput(View) simply because the text seen from the IME is going to be out-of-sync. Although this behavior is semantically helpful for IMEs, especially after the initial surrounding text information became available in EditorInfo, issuing a sync IPC from the calling thread (UI thread actually) is not plausible from the performance perspective. This CL fills this gap by adding a new API InputMethodManager#invalidateInput(View) for the scenario where apps independently modify the text with keeping other text metadata such as input-type to be the same. All the observable behaviors from the IME remain to be the same as InputMethodManager#restartInput(View). For instance, any pending tasks that are already issued with InputMethodService#getCurrentInputConnection() will be effectively cancelled by using a recently added mechanism [1]. [1]: I383c3958d2ac1a8d217706509fa12a92b381bbb3 Fix: 203086369 Test: atest -c CtsInputMethodTestCases:InputMethodStartInputLifecycleTest Change-Id: I3161755779080f98bcef0e47dd0c5247d8a3a256 --- .../android/inputmethodservice/AbstractInputMethodService.java | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'core/java/android/inputmethodservice/AbstractInputMethodService.java') diff --git a/core/java/android/inputmethodservice/AbstractInputMethodService.java b/core/java/android/inputmethodservice/AbstractInputMethodService.java index 4ecd15e002ef..75beacfb12f3 100644 --- a/core/java/android/inputmethodservice/AbstractInputMethodService.java +++ b/core/java/android/inputmethodservice/AbstractInputMethodService.java @@ -67,6 +67,16 @@ public abstract class AbstractInputMethodService extends WindowProviderService implements KeyEvent.Callback { private InputMethod mInputMethod; + /** + * @return {@link InputMethod} instance returned from {@link #onCreateInputMethodInterface()}. + * {@code null} if {@link #onCreateInputMethodInterface()} is not yet called. + * @hide + */ + @Nullable + protected final InputMethod getInputMethodInternal() { + return mInputMethod; + } + /** * Keep the strong reference to {@link InputMethodServiceInternal} to ensure that it will not be * garbage-collected until {@link AbstractInputMethodService} gets garbage-collected. -- cgit v1.2.3