From d1ff9740c14fe144a2c67e953d0e4f9a7f8c6e46 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Wed, 4 Aug 2021 11:57:42 -0700 Subject: [PATCH] Lock down RemoteInputConnectionImpl#getInputConnection() This is a mechanical refactoring CL that locks down RemoteInputConnectionImpl#getInputConnection() as a private method. This is supposed to be helpful to to avoid future misuse of raw InputConnection instance outside RemoteInputConnectionImpl. Note that InputMethodManager#isAcceptingText() remains to have the same observable behavior in this CL. The key fact is that the following two fields are updated in an atomic way. * RemoteInputConnectionImpl#mInputConnection * RemoteInputConnectionImpl#mFinished Bug: 192412909 Test: presubmit Change-Id: Ic5fbc6213ad62df95fc0b7eef18bab1fd9fbdbf1 --- .../java/android/view/inputmethod/InputMethodManager.java | 3 +-- .../internal/inputmethod/RemoteInputConnectionImpl.java | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index 5f659a6afba91..ab7e5a92284f0 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -1381,8 +1381,7 @@ public final class InputMethodManager { public boolean isAcceptingText() { checkFocus(); synchronized (mH) { - return mServedInputConnection != null - && mServedInputConnection.getInputConnection() != null; + return mServedInputConnection != null && !mServedInputConnection.isFinished(); } } diff --git a/core/java/com/android/internal/inputmethod/RemoteInputConnectionImpl.java b/core/java/com/android/internal/inputmethod/RemoteInputConnectionImpl.java index 6f79fa117c6a1..2d44054e03723 100644 --- a/core/java/com/android/internal/inputmethod/RemoteInputConnectionImpl.java +++ b/core/java/com/android/internal/inputmethod/RemoteInputConnectionImpl.java @@ -86,13 +86,17 @@ public final class RemoteInputConnectionImpl extends IInputContext.Stub { * @return {@link InputConnection} to which incoming IPCs will be dispatched. */ @Nullable - public InputConnection getInputConnection() { + private InputConnection getInputConnection() { synchronized (mLock) { return mInputConnection; } } - private boolean isFinished() { + /** + * @return {@code true} until the target {@link InputConnection} receives + * {@link InputConnection#closeConnection()} as a result of {@link #deactivate()}. + */ + public boolean isFinished() { synchronized (mLock) { return mFinished; }