summaryrefslogtreecommitdiff
path: root/core/java/android/inputmethodservice/InputMethodService.java
diff options
context:
space:
mode:
authorYohei Yukawa <yukawa@google.com>2021-11-17 15:21:32 -0800
committerYohei Yukawa <yukawa@google.com>2021-11-17 15:21:32 -0800
commitdaa6695c2ee8f7a8a9d724e4169ced4d28edc54d (patch)
treebcc962f4bb9ee9895596b31da922385e62ee1a97 /core/java/android/inputmethodservice/InputMethodService.java
parent2e9ec744b607e23a7f93f8aa0a1008fc541a2841 (diff)
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
Diffstat (limited to 'core/java/android/inputmethodservice/InputMethodService.java')
-rw-r--r--core/java/android/inputmethodservice/InputMethodService.java25
1 files changed, 24 insertions, 1 deletions
diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java
index aa3c3611fc7d..e02a01e5887e 100644
--- a/core/java/android/inputmethodservice/InputMethodService.java
+++ b/core/java/android/inputmethodservice/InputMethodService.java
@@ -135,6 +135,7 @@ import com.android.internal.inputmethod.ImeTracing;
import com.android.internal.inputmethod.InputMethodPrivilegedOperations;
import com.android.internal.inputmethod.InputMethodPrivilegedOperationsRegistry;
import com.android.internal.view.IInlineSuggestionsRequestCallback;
+import com.android.internal.view.IInputContext;
import com.android.internal.view.InlineSuggestionsRequestInfo;
import java.io.FileDescriptor;
@@ -1063,8 +1064,30 @@ public class InputMethodService extends AbstractInputMethodService {
public final void removeImeSurface() {
InputMethodService.this.scheduleImeSurfaceRemoval();
}
+
+ /**
+ * {@inheritDoc}
+ * @hide
+ */
+ @Override
+ public final void invalidateInputInternal(@NonNull EditorInfo editorInfo,
+ @NonNull IInputContext inputContext, int sessionId) {
+ if (mStartedInputConnection instanceof RemoteInputConnection) {
+ final RemoteInputConnection ric = (RemoteInputConnection) mStartedInputConnection;
+ if (!ric.isSameConnection(inputContext)) {
+ // This is not an error, and can be safely ignored.
+ if (DEBUG) {
+ Log.d(TAG, "ignoring invalidateInput() due to context mismatch.");
+ }
+ return;
+ }
+ editorInfo.makeCompatible(getApplicationInfo().targetSdkVersion);
+ getInputMethodInternal().restartInput(new RemoteInputConnection(ric, sessionId),
+ editorInfo);
+ }
+ }
}
-
+
/**
* Information about where interesting parts of the input method UI appear.
*/