Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 472e5c38 authored by Taran Singh's avatar Taran Singh
Browse files

Incorporate API feedback: CAI requestCursorUpdates()

1. Use intDef for CurosrUpdateFilter
2. overload requestCursorUpdates(mode, filter)
3. additional details in javadoc

Fix: 218314883
Bug: 210039666
Test: atest CtsInputMethodTestCases

Change-Id: I1dc5acac4f968b2a2d1780f2ee6c0145c7dcbbaa
parent 3e4365b8
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -52948,6 +52948,7 @@ package android.view.inputmethod {
    method public default boolean performSpellCheck();
    method public boolean reportFullscreenMode(boolean);
    method public boolean requestCursorUpdates(int);
    method public default boolean requestCursorUpdates(int, int);
    method public boolean sendKeyEvent(android.view.KeyEvent);
    method public boolean setComposingRegion(int, int);
    method public default boolean setComposingRegion(int, int, @Nullable android.view.inputmethod.TextAttribute);
+20 −0
Original line number Diff line number Diff line
@@ -433,6 +433,26 @@ public final class RemoteInputConnection implements InputConnection {
                mCancellationGroup, MAX_WAIT_TIME_MILLIS);
    }

    @Override
    @AnyThread
    public boolean requestCursorUpdates(@CursorUpdateMode int cursorUpdateMode,
            @CursorUpdateFilter int cursorUpdateFilter) {
        if (mCancellationGroup.isCanceled()) {
            return false;
        }

        final InputMethodServiceInternal ims = mImsInternal.getAndWarnIfNull();
        if (ims == null) {
            return false;
        }

        final int displayId = ims.getContext().getDisplayId();
        final CompletableFuture<Boolean> value =
                mInvoker.requestCursorUpdates(cursorUpdateMode, cursorUpdateFilter, displayId);
        return CompletableFutureUtil.getResultOrFalse(value, TAG, "requestCursorUpdates()",
                mCancellationGroup, MAX_WAIT_TIME_MILLIS);
    }

    @AnyThread
    public Handler getHandler() {
        // Nothing should happen when called from input method.
+3 −1
Original line number Diff line number Diff line
@@ -575,7 +575,9 @@ public final class CursorAnchorInfo implements Parcelable {
    }

    /**
     * Returns {@link EditorBoundsInfo} editor related bounds.
     * Returns {@link EditorBoundsInfo} for the current editor, or {@code null} if IME is not
     * subscribed with {@link InputConnection#CURSOR_UPDATE_FILTER_EDITOR_BOUNDS}
     * or {@link InputConnection#CURSOR_UPDATE_MONITOR}.
     */
    @Nullable
    public EditorBoundsInfo getEditorBoundsInfo() {
+3 −3
Original line number Diff line number Diff line
@@ -30,13 +30,13 @@ import java.util.Objects;
public final class EditorBoundsInfo implements Parcelable {

    /**
     * Container of rectangular position of Editor in the current window.
     * The bounding box of the of currently focused text editor in local coordinates.
     */
    private final RectF mEditorBounds;

    /**
     * Container of rectangular position of Editor with additional padding around for initiating
     * Stylus Handwriting in the current window.
     * The bounding box of the of currently focused text editor with additional padding around it
     * for initiating Stylus Handwriting in the current window.
     */
    private final RectF mHandwritingBounds;

+45 −0
Original line number Diff line number Diff line
@@ -1042,6 +1042,23 @@ public interface InputConnection {
     */
    int CURSOR_UPDATE_FILTER_INSERTION_MARKER = 1 << 4;

    /**
     * @hide
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(value = {CURSOR_UPDATE_IMMEDIATE, CURSOR_UPDATE_MONITOR}, flag = true,
            prefix = { "CURSOR_UPDATE_" })
    @interface CursorUpdateMode{}

    /**
     * @hide
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef(value = {CURSOR_UPDATE_FILTER_EDITOR_BOUNDS, CURSOR_UPDATE_FILTER_CHARACTER_BOUNDS,
            CURSOR_UPDATE_FILTER_INSERTION_MARKER}, flag = true,
            prefix = { "CURSOR_UPDATE_FILTER_" })
    @interface CursorUpdateFilter{}

    /**
     * Called by the input method to ask the editor for calling back
     * {@link InputMethodManager#updateCursorAnchorInfo(android.view.View, CursorAnchorInfo)} to
@@ -1062,6 +1079,34 @@ public interface InputConnection {
     */
    boolean requestCursorUpdates(int cursorUpdateMode);

    /**
     * Called by the input method to ask the editor for calling back
     * {@link InputMethodManager#updateCursorAnchorInfo(android.view.View, CursorAnchorInfo)} to
     * notify cursor/anchor locations.
     *
     * @param cursorUpdateMode combination of update modes:
     * {@link #CURSOR_UPDATE_IMMEDIATE}, {@link #CURSOR_UPDATE_MONITOR}
     * @param cursorUpdateFilter any combination of data filters:
     * {@link #CURSOR_UPDATE_FILTER_CHARACTER_BOUNDS}, {@link #CURSOR_UPDATE_FILTER_EDITOR_BOUNDS},
     * {@link #CURSOR_UPDATE_FILTER_INSERTION_MARKER}.
     *
     * <p>Pass {@code 0} to disable them. However, if an unknown flag is provided, request will be
     * rejected and method will return {@code false}.</p>
     * @return {@code true} if the request is scheduled. {@code false} to indicate that when the
     *         application will not call {@link InputMethodManager#updateCursorAnchorInfo(
     *         android.view.View, CursorAnchorInfo)}.
     *         Since Android {@link android.os.Build.VERSION_CODES#N} until
     *         {@link android.os.Build.VERSION_CODES#TIRAMISU}, this API returned {@code false} when
     *         the target application does not implement this method.
     */
    default boolean requestCursorUpdates(@CursorUpdateMode int cursorUpdateMode,
            @CursorUpdateFilter int cursorUpdateFilter) {
        if (cursorUpdateFilter == 0) {
            return requestCursorUpdates(cursorUpdateMode);
        }
        return false;
    }

    /**
     * Called by the system to enable application developers to specify a dedicated thread on which
     * {@link InputConnection} methods are called back.
Loading