From a9156d61fbfd348ac587e9cc579db2669b571745 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa <yukawa@google.com> Date: Tue, 16 Jan 2024 11:12:39 +0000 Subject: [PATCH] Simplify RemoteInputConnectionImpl#finishComposingText*() With my previous CLs [1][2], we can generally assume the following things. - InputConnection#closeConnection() always gets called when it becomes invalidated, including the case when the IME has switched to another IME client. - Each implementation of InputConnection#closeConnection() is expected to do appropriate clean up including finishing composing text. {Base,Editable}InputConnection actually do this correctly. With that it should be safe for #finishComposingText*() to follow the same pattern about isActive(). [1]: I234309c5880c9fe0b299b8bd0f8862796d4dda0d 9f9afe526d1f8ad17c628fc9e1e839725ffe913e [2]: If2a03bc84d318775fd4a197fa43acde086eda442 aaa38c9f1ae019f0fe8c3ba80630f26e582cc89c Bug: 35301295 Bug: 291826769 Test: presubmit Merged-In: If913701bf8555f5d76fceb272e38a99f5e243bbe Change-Id: If913701bf8555f5d76fceb272e38a99f5e243bbe --- .../view/inputmethod/RemoteInputConnectionImpl.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/core/java/android/view/inputmethod/RemoteInputConnectionImpl.java b/core/java/android/view/inputmethod/RemoteInputConnectionImpl.java index 52965c334b08..46ccef3c0102 100644 --- a/core/java/android/view/inputmethod/RemoteInputConnectionImpl.java +++ b/core/java/android/view/inputmethod/RemoteInputConnectionImpl.java @@ -830,11 +830,7 @@ final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub { return; // cancelled } InputConnection ic = getInputConnection(); - // Note we do NOT check isActive() here, because this is safe - // for an IME to call at any time, and we need to allow it - // through to clean up our state after the IME has switched to - // another client. - if (ic == null) { + if (ic == null || !isActive()) { Log.w(TAG, "finishComposingTextFromImm on inactive InputConnection"); return; } @@ -858,11 +854,7 @@ final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub { return; // cancelled } InputConnection ic = getInputConnection(); - // Note we do NOT check isActive() here, because this is safe - // for an IME to call at any time, and we need to allow it - // through to clean up our state after the IME has switched to - // another client. - if (ic == null) { + if (ic == null && !isActive()) { Log.w(TAG, "finishComposingText on inactive InputConnection"); return; } -- GitLab