summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Yohei Yukawa <yukawa@google.com> 2022-10-18 05:45:03 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2022-10-18 05:45:03 +0000
commitbb563d8c41b8b69406cafbdd78efc3fb8e155d97 (patch)
tree97848d0ba471c32684b051be9e5c625c70a8a97e
parent2e9489959c04f7d074cf17815ebe4185d51cd473 (diff)
parent699fc515e02390d8ca63391fd865993cd5216fb1 (diff)
Merge "Use WeakReference#refersTo() when possible"
-rw-r--r--core/java/android/view/inputmethod/InputMethodManager.java2
-rw-r--r--core/java/android/view/inputmethod/RemoteInputConnectionImpl.java18
2 files changed, 18 insertions, 2 deletions
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index d57061dc5e8c..867b8260ec5e 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -897,7 +897,7 @@ public final class InputMethodManager {
return mServedInputConnection != null
&& mServedInputConnection.isActive()
- && mServedInputConnection.getServedView() == view;
+ && mServedInputConnection.isAssociatedWith(view);
}
}
diff --git a/core/java/android/view/inputmethod/RemoteInputConnectionImpl.java b/core/java/android/view/inputmethod/RemoteInputConnectionImpl.java
index da036754268e..fa18eeceafd0 100644
--- a/core/java/android/view/inputmethod/RemoteInputConnectionImpl.java
+++ b/core/java/android/view/inputmethod/RemoteInputConnectionImpl.java
@@ -218,11 +218,27 @@ final class RemoteInputConnectionImpl extends IRemoteInputConnection.Stub {
return mParentInputMethodManager.isActive() && !isFinished();
}
- public View getServedView() {
+ private View getServedView() {
return mServedView.get();
}
/**
+ * Queries if the given {@link View} is associated with this {@link RemoteInputConnectionImpl}
+ * or not.
+ *
+ * @param view {@link View}.
+ * @return {@code true} if the given {@link View} is not null and is associated with this
+ * {@link RemoteInputConnectionImpl}.
+ */
+ @AnyThread
+ public boolean isAssociatedWith(@Nullable View view) {
+ if (view == null) {
+ return false;
+ }
+ return mServedView.refersTo(view);
+ }
+
+ /**
* Gets and resets {@link #mHasPendingImmediateCursorAnchorInfoUpdate}.
*
* <p>Calling this method resets {@link #mHasPendingImmediateCursorAnchorInfoUpdate}. This