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

Commit 7c4912ba authored by Yohei Yukawa's avatar Yohei Yukawa
Browse files

Deprecate mRequestUpdateCursorAnchorInfoMonitorMode part 3

This is the third step towards deprecating

 InputMethodManager#mRequestUpdateCursorAnchorInfoMonitorMode,

which was introduced as a minimum implementation to support
CursorAnchorInfo API in EditText [1].

With this CL, mRequestUpdateCursorAnchorInfoMonitorMode is effectively
deprecated and does nothing except for methods marked with
@UnsupportedAppUsage.

All the remaining valid usages will be handled by the following newly
introduced fields:

 - Editor.InputMethodState#mUpdateCursorAnchorInfoMode
 - Editor.InputMethodState#mUpdateCursorAnchorInfoFilter

 [1]: I3c6b69bd9d79b199afe68d838f25effa6048e5cc
      cf8421df856a5950729ff1d0e73f21d480aa98fb

Bug: 236713697
Test: atest CtsInputMethodTestCases:InputMethodServiceTest#testOnUpdateCursorAnchorInfo
Test: atest CtsInputMethodTestCases:StylusHandwritingTest
Change-Id: I9fc930fbe39c3bdf913e3d7012fdd22805564d3b
parent 752bf17e
Loading
Loading
Loading
Loading
+6 −11
Original line number Diff line number Diff line
@@ -541,7 +541,9 @@ public final class InputMethodManager {

    /**
     * The monitor mode for {@link #updateCursorAnchorInfo(View, CursorAnchorInfo)}.
     * @deprecated This is kept for {@link UnsupportedAppUsage}.  Must not be used.
     */
    @Deprecated
    private int mRequestUpdateCursorAnchorInfoMonitorMode = REQUEST_UPDATE_CURSOR_ANCHOR_INFO_NONE;

    /**
@@ -2737,8 +2739,10 @@ public final class InputMethodManager {
     * Return true if the current input method wants to be notified when cursor/anchor location
     * is changed.
     *
     * @deprecated This method is kept for {@link UnsupportedAppUsage}.  Must not be used.
     * @hide
     */
    @Deprecated
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public boolean isCursorAnchorInfoEnabled() {
        synchronized (mH) {
@@ -2753,8 +2757,10 @@ public final class InputMethodManager {
    /**
     * Set the requested mode for {@link #updateCursorAnchorInfo(View, CursorAnchorInfo)}.
     *
     * @deprecated This method is kept for {@link UnsupportedAppUsage}.  Must not be used.
     * @hide
     */
    @Deprecated
    @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553)
    public void setUpdateCursorAnchorInfoMode(int flags) {
        synchronized (mH) {
@@ -2762,17 +2768,6 @@ public final class InputMethodManager {
        }
    }

    /**
     * Get the requested mode for {@link #updateCursorAnchorInfo(View, CursorAnchorInfo)}.
     *
     * @hide
     */
    public int getUpdateCursorAnchorInfoMode() {
        synchronized (mH) {
            return mRequestUpdateCursorAnchorInfoMonitorMode;
        }
    }

    /**
     * Report the current cursor location in its window.
     *
+15 −5
Original line number Diff line number Diff line
@@ -4599,20 +4599,22 @@ public class Editor {
                return;
            }
            // Skip if the IME has not requested the cursor/anchor position.
            if (!imm.isCursorAnchorInfoEnabled()) {
            final int knownCursorAnchorInfoModes =
                    InputConnection.CURSOR_UPDATE_IMMEDIATE | InputConnection.CURSOR_UPDATE_MONITOR;
            if ((mInputMethodState.mUpdateCursorAnchorInfoMode & knownCursorAnchorInfoModes) == 0) {
                return;
            }
            Layout layout = mTextView.getLayout();
            if (layout == null) {
                return;
            }
            int mode = imm.getUpdateCursorAnchorInfoMode();
            final int filter = mInputMethodState.mUpdateCursorAnchorInfoFilter;
            boolean includeEditorBounds =
                    (mode & InputConnection.CURSOR_UPDATE_FILTER_EDITOR_BOUNDS) != 0;
                    (filter & InputConnection.CURSOR_UPDATE_FILTER_EDITOR_BOUNDS) != 0;
            boolean includeCharacterBounds =
                    (mode & InputConnection.CURSOR_UPDATE_FILTER_CHARACTER_BOUNDS) != 0;
                    (filter & InputConnection.CURSOR_UPDATE_FILTER_CHARACTER_BOUNDS) != 0;
            boolean includeInsertionMarker =
                    (mode & InputConnection.CURSOR_UPDATE_FILTER_INSERTION_MARKER) != 0;
                    (filter & InputConnection.CURSOR_UPDATE_FILTER_INSERTION_MARKER) != 0;
            boolean includeAll =
                    (!includeEditorBounds && !includeCharacterBounds && !includeInsertionMarker);

@@ -4713,6 +4715,10 @@ public class Editor {
            }

            imm.updateCursorAnchorInfo(mTextView, builder.build());

            // Drop the immediate flag if any.
            mInputMethodState.mUpdateCursorAnchorInfoMode &=
                    ~InputConnection.CURSOR_UPDATE_IMMEDIATE;
        }
    }

@@ -7203,6 +7209,10 @@ public class Editor {
        boolean mSelectionModeChanged;
        boolean mContentChanged;
        int mChangedStart, mChangedEnd, mChangedDelta;
        @InputConnection.CursorUpdateMode
        int mUpdateCursorAnchorInfoMode;
        @InputConnection.CursorUpdateFilter
        int mUpdateCursorAnchorInfoFilter;
    }

    /**
+30 −0
Original line number Diff line number Diff line
@@ -9005,6 +9005,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
    public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
        if (onCheckIsTextEditor() && isEnabled()) {
            mEditor.createInputMethodStateIfNeeded();
            mEditor.mInputMethodState.mUpdateCursorAnchorInfoMode = 0;
            mEditor.mInputMethodState.mUpdateCursorAnchorInfoFilter = 0;
            outAttrs.inputType = getInputType();
            if (mEditor.mInputContentType != null) {
                outAttrs.imeOptions = mEditor.mInputContentType.imeOptions;
@@ -9060,6 +9063,33 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
        return null;
    }
    /**
     * Called back by the system to handle {@link InputConnection#requestCursorUpdates(int, int)}.
     *
     * @param cursorUpdateMode modes defined in {@link InputConnection.CursorUpdateMode}.
     * @param cursorUpdateFilter modes defined in {@link InputConnection.CursorUpdateFilter}.
     *
     * @hide
     */
    public void onRequestCursorUpdatesInternal(
            @InputConnection.CursorUpdateMode int cursorUpdateMode,
            @InputConnection.CursorUpdateFilter int cursorUpdateFilter) {
        mEditor.mInputMethodState.mUpdateCursorAnchorInfoMode = cursorUpdateMode;
        mEditor.mInputMethodState.mUpdateCursorAnchorInfoFilter = cursorUpdateFilter;
        if ((cursorUpdateMode & InputConnection.CURSOR_UPDATE_IMMEDIATE) == 0) {
            return;
        }
        if (isInLayout()) {
            // In this case, the view hierarchy is currently undergoing a layout pass.
            // IMM#updateCursorAnchorInfo is supposed to be called soon after the layout
            // pass is finished.
        } else {
            // This will schedule a layout pass of the view tree, and the layout event
            // eventually triggers IMM#updateCursorAnchorInfo.
            requestLayout();
        }
    }
    /**
     * If this TextView contains editable content, extract a portion of it
     * based on the information in <var>request</var> in to <var>outText</var>.
+11 −20
Original line number Diff line number Diff line
@@ -215,13 +215,15 @@ public final class EditableInputConnection extends BaseInputConnection
    public boolean requestCursorUpdates(int cursorUpdateMode) {
        if (DEBUG) Log.v(TAG, "requestUpdateCursorAnchorInfo " + cursorUpdateMode);

        // It is possible that any other bit is used as a valid flag in a future release.
        // We should reject the entire request in such a case.
        final int knownFlagMask = InputConnection.CURSOR_UPDATE_IMMEDIATE
                | InputConnection.CURSOR_UPDATE_MONITOR
                | InputConnection.CURSOR_UPDATE_FILTER_EDITOR_BOUNDS
        final int knownModeFlags = InputConnection.CURSOR_UPDATE_IMMEDIATE
                | InputConnection.CURSOR_UPDATE_MONITOR;
        final int knownFilterFlags = InputConnection.CURSOR_UPDATE_FILTER_EDITOR_BOUNDS
                | InputConnection.CURSOR_UPDATE_FILTER_INSERTION_MARKER
                | InputConnection.CURSOR_UPDATE_FILTER_CHARACTER_BOUNDS;

        // It is possible that any other bit is used as a valid flag in a future release.
        // We should reject the entire request in such a case.
        final int knownFlagMask = knownModeFlags | knownFilterFlags;
        final int unknownFlags = cursorUpdateMode & ~knownFlagMask;
        if (unknownFlags != 0) {
            if (DEBUG) {
@@ -237,21 +239,10 @@ public final class EditableInputConnection extends BaseInputConnection
            // CursorAnchorInfo is temporarily unavailable.
            return false;
        }
        mIMM.setUpdateCursorAnchorInfoMode(cursorUpdateMode);
        if ((cursorUpdateMode & InputConnection.CURSOR_UPDATE_IMMEDIATE) != 0) {
            if (mTextView == null) {
                // In this case, FLAG_CURSOR_ANCHOR_INFO_IMMEDIATE is silently ignored.
                // TODO: Return some notification code for the input method that indicates
                // FLAG_CURSOR_ANCHOR_INFO_IMMEDIATE is ignored.
            } else if (mTextView.isInLayout()) {
                // In this case, the view hierarchy is currently undergoing a layout pass.
                // IMM#updateCursorAnchorInfo is supposed to be called soon after the layout
                // pass is finished.
            } else {
                // This will schedule a layout pass of the view tree, and the layout event
                // eventually triggers IMM#updateCursorAnchorInfo.
                mTextView.requestLayout();
            }
        mIMM.setUpdateCursorAnchorInfoMode(cursorUpdateMode);  // for UnsupportedAppUsage
        if (mTextView != null) {
            mTextView.onRequestCursorUpdatesInternal(cursorUpdateMode & knownModeFlags,
                    cursorUpdateMode & knownFilterFlags);
        }
        return true;
    }