diff --git a/core/java/android/view/inputmethod/InputConnection.java b/core/java/android/view/inputmethod/InputConnection.java index 5f036a3488083..ccca031aad3f0 100644 --- a/core/java/android/view/inputmethod/InputConnection.java +++ b/core/java/android/view/inputmethod/InputConnection.java @@ -843,9 +843,14 @@ public interface InputConnection { /** * Called back when the connected IME switches between fullscreen and normal modes. * - *

Note: On {@link android.os.Build.VERSION_CODES#O} and later devices, input methods are no - * longer allowed to directly call this method at any time. To signal this event in the target - * application, input methods should always call + *

Editor authors: There is a bug on + * {@link android.os.Build.VERSION_CODES#O} and later devices that this method is called back + * on the main thread even when {@link #getHandler()} is overridden. This bug is fixed in + * {@link android.os.Build.VERSION_CODES#TIRAMISU}.

+ * + *

IME authors: On {@link android.os.Build.VERSION_CODES#O} and later + * devices, input methods are no longer allowed to directly call this method at any time. + * To signal this event in the target application, input methods should always call * {@link InputMethodService#updateFullscreenMode()} instead. This approach should work on API * {@link android.os.Build.VERSION_CODES#N_MR1} and prior devices.

* diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index c023c6ef04df9..5f659a6afba91 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -950,15 +950,15 @@ public final class InputMethodManager { } case MSG_REPORT_FULLSCREEN_MODE: { final boolean fullscreen = msg.arg1 != 0; - InputConnection ic = null; + RemoteInputConnectionImpl ic = null; synchronized (mH) { if (mFullscreenMode != fullscreen && mServedInputConnection != null) { - ic = mServedInputConnection.getInputConnection(); + ic = mServedInputConnection; mFullscreenMode = fullscreen; } } if (ic != null) { - ic.reportFullscreenMode(fullscreen); + ic.dispatchReportFullscreenMode(fullscreen); } return; } diff --git a/core/java/com/android/internal/inputmethod/RemoteInputConnectionImpl.java b/core/java/com/android/internal/inputmethod/RemoteInputConnectionImpl.java index d1bca85f8425e..6f79fa117c6a1 100644 --- a/core/java/com/android/internal/inputmethod/RemoteInputConnectionImpl.java +++ b/core/java/com/android/internal/inputmethod/RemoteInputConnectionImpl.java @@ -169,6 +169,23 @@ public final class RemoteInputConnectionImpl extends IInputContext.Stub { } } + /** + * Invoke {@link InputConnection#reportFullscreenMode(boolean)} or schedule it on the target + * thread associated with {@link InputConnection#getHandler()}. + * + * @param enabled the parameter to be passed to + * {@link InputConnection#reportFullscreenMode(boolean)}. + */ + public void dispatchReportFullscreenMode(boolean enabled) { + dispatch(() -> { + final InputConnection ic = getInputConnection(); + if (ic == null || !isActive()) { + return; + } + ic.reportFullscreenMode(enabled); + }); + } + @Override public void getTextAfterCursor(int length, int flags, ICharSequenceResultCallback callback) { dispatch(() -> {