Deprecating ResultsReceiver usage in InputMethodManager
Previously, the ResultReceiver was passed to InputMethodManager#{show,hide}SoftInput and send along to IMS. With the changes of [1], requests from IMM are forwarded to InsetsController, where the resultReceiver was not passed, as we only send the requestedVisibleTypes to the system.
With the changes of this CL, we notify the resultReceiver in InputMethodManager, before passing the request to InsetsController.
Reason for deprecating:
The ResultReceiver is not reliable to be used for determining whether the IME is shown or not. The recommended usage would be to set a View.OnApplyWindowInsetsListener, which is invoked whenever the IME will show.
[1]: I8e3a74ee579f085cb582040fdba725e7a63d6b85
Test: blaze test \
--android_platforms=//buildenv/platforms/android:armeabi-v7a,//buildenv/platforms/android:arm64-v8a \
--config=android_local_adb \
--nocache_test_results \
--test_arg=--install_test_services \
--test_arg=--install_basic_services \
--runs_per_test=1 \
//javatests/com/google/android/apps/gmail/espresso:AccountSetupTest_hub_as_gmail_dev_offline_sapi_appcompat_master
Bug: 372199387
Flag: android.view.inputmethod.refactor_insets_controller
Change-Id: I6031229f2069e565360100a9a166c34272dcaff6
diff --git a/core/api/current.txt b/core/api/current.txt
index 75c9d71..0b8e139 100644
--- a/core/api/current.txt
+++ b/core/api/current.txt
@@ -56599,7 +56599,7 @@
method public java.util.Map<android.view.inputmethod.InputMethodInfo,java.util.List<android.view.inputmethod.InputMethodSubtype>> getShortcutInputMethodsAndSubtypes();
method @Deprecated public void hideSoftInputFromInputMethod(android.os.IBinder, int);
method public boolean hideSoftInputFromWindow(android.os.IBinder, int);
- method public boolean hideSoftInputFromWindow(android.os.IBinder, int, android.os.ResultReceiver);
+ method @Deprecated public boolean hideSoftInputFromWindow(android.os.IBinder, int, android.os.ResultReceiver);
method @Deprecated public void hideStatusIcon(android.os.IBinder);
method public void invalidateInput(@NonNull android.view.View);
method public boolean isAcceptingText();
@@ -56623,7 +56623,7 @@
method public void showInputMethodAndSubtypeEnabler(@Nullable String);
method public void showInputMethodPicker();
method public boolean showSoftInput(android.view.View, int);
- method public boolean showSoftInput(android.view.View, int, android.os.ResultReceiver);
+ method @Deprecated public boolean showSoftInput(android.view.View, int, android.os.ResultReceiver);
method @Deprecated public void showSoftInputFromInputMethod(android.os.IBinder, int);
method @Deprecated public void showStatusIcon(android.os.IBinder, String, @DrawableRes int);
method @FlaggedApi("android.view.inputmethod.connectionless_handwriting") public void startConnectionlessStylusHandwriting(@NonNull android.view.View, @Nullable android.view.inputmethod.CursorAnchorInfo, @NonNull java.util.concurrent.Executor, @NonNull android.view.inputmethod.ConnectionlessHandwritingCallback);
diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java
index 1e5c6d8..47fc437 100644
--- a/core/java/android/view/inputmethod/InputMethodManager.java
+++ b/core/java/android/view/inputmethod/InputMethodManager.java
@@ -2352,6 +2352,13 @@
* {@link #RESULT_HIDDEN}.
* @return {@code true} if a request was sent to system_server, {@code false} otherwise. Note:
* this does not return result of the request. For result use {@param resultReceiver} instead.
+ *
+ * @deprecated The {@link ResultReceiver} is not a reliable way of determining whether the
+ * Input Method is actually shown or hidden. If result is needed, use
+ * {@link android.view.WindowInsetsController#show} instead and set a
+ * {@link View.OnApplyWindowInsetsListener} and verify the provided {@link WindowInsets} for
+ * the visibility of IME. If result is not needed, use {@link #showSoftInput(View, int)}
+ * instead.
*/
public boolean showSoftInput(View view, @ShowFlags int flags, ResultReceiver resultReceiver) {
return showSoftInput(view, flags, resultReceiver, SoftInputShowHideReason.SHOW_SOFT_INPUT);
@@ -2399,6 +2406,14 @@
& WindowInsets.Type.ime()) == 0) {
ImeTracker.forLogging().onProgress(statsToken,
ImeTracker.PHASE_CLIENT_NO_ONGOING_USER_ANIMATION);
+ if (resultReceiver != null) {
+ final boolean imeReqVisible =
+ (viewRootImpl.getInsetsController().getRequestedVisibleTypes()
+ & WindowInsets.Type.ime()) != 0;
+ resultReceiver.send(
+ imeReqVisible ? InputMethodManager.RESULT_UNCHANGED_SHOWN
+ : InputMethodManager.RESULT_SHOWN, null);
+ }
// TODO(b/322992891) handle case of SHOW_IMPLICIT
viewRootImpl.getInsetsController().show(WindowInsets.Type.ime(),
false /* fromIme */, statsToken);
@@ -2531,6 +2546,13 @@
* {@link #RESULT_HIDDEN}.
* @return {@code true} if a request was sent to system_server, {@code false} otherwise. Note:
* this does not return result of the request. For result use {@param resultReceiver} instead.
+ *
+ * @deprecated The {@link ResultReceiver} is not a reliable way of determining whether the
+ * Input Method is actually shown or hidden. If result is needed, use
+ * {@link android.view.WindowInsetsController#hide} instead and set a
+ * {@link View.OnApplyWindowInsetsListener} and verify the provided {@link WindowInsets} for
+ * the visibility of IME. If result is not needed, use
+ * {@link #hideSoftInputFromView(View, int)} instead.
*/
public boolean hideSoftInputFromWindow(IBinder windowToken, @HideFlags int flags,
ResultReceiver resultReceiver) {
@@ -2569,6 +2591,14 @@
// TODO(b/322992891) handle case of HIDE_IMPLICIT_ONLY
final var viewRootImpl = servedView.getViewRootImpl();
if (viewRootImpl != null) {
+ if (resultReceiver != null) {
+ final boolean imeReqVisible =
+ (viewRootImpl.getInsetsController().getRequestedVisibleTypes()
+ & WindowInsets.Type.ime()) != 0;
+ resultReceiver.send(
+ !imeReqVisible ? InputMethodManager.RESULT_UNCHANGED_HIDDEN
+ : InputMethodManager.RESULT_HIDDEN, null);
+ }
viewRootImpl.getInsetsController().hide(WindowInsets.Type.ime());
}
return true;