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

Commit fb12492d authored by Ahaan Ugale's avatar Ahaan Ugale
Browse files

ContentCapture: Notify when Composing region changes.

Sending the notification from the InputConnection layer reduces the
number of events that are handled (merged) by ContentCapture. We are
also able to handle composing span being removed; at the TextView layer,
we cannot do that as we don't know if the composing span will be added
back, which happens on typing).

Bug: 184311217
Test: manual - append chars, delete chars, replace text, move cursor to
 composing text, move cursor to remove composing span, drag cursor
Test: atest android.contentcaptureservice.cts.LoginActivityTest
Change-Id: I0e9d153cf7ba2734f38cb1b6044eb7b670fb34ad
parent 5c80e349
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -162,6 +162,17 @@ public class BaseInputConnection implements InputConnection {
        return false;
    }

    /**
     * Called after only the composing region is modified (so it isn't called if the text also
     * changes).
     * <p>
     * Default implementation does nothing.
     *
     * @hide
     */
    public void endComposingRegionEditInternal() {
    }

    /**
     * Default implementation calls {@link #finishComposingText()} and
     * {@code setImeConsumesInput(false)}.
@@ -468,6 +479,7 @@ public class BaseInputConnection implements InputConnection {
            // Note: sendCurrentText does nothing unless mFallbackMode is set
            sendCurrentText();
            endBatchEdit();
            endComposingRegionEditInternal();
        }
        return true;
    }
@@ -734,6 +746,7 @@ public class BaseInputConnection implements InputConnection {
            // Note: sendCurrentText does nothing unless mFallbackMode is set
            sendCurrentText();
            endBatchEdit();
            endComposingRegionEditInternal();
        }
        return true;
    }
+10 −2
Original line number Diff line number Diff line
@@ -10832,11 +10832,19 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener
            }
        }
        notifyContentCaptureTextChanged();
    }
    /**
     * Notifies the ContentCapture service that the text of the view has changed (only if
     * ContentCapture has been notified of this view's existence already).
     *
     * @hide
     */
    public void notifyContentCaptureTextChanged() {
        // TODO(b/121045053): should use a flag / boolean to keep status of SHOWN / HIDDEN instead
        // of using isLaidout(), so it's not called in cases where it's laid out but a
        // notifyAppeared was not sent.
        // ContentCapture
        if (isLaidOut() && isImportantForContentCapture() && getNotifiedContentCaptureAppeared()) {
            final ContentCaptureManager cm = mContext.getSystemService(ContentCaptureManager.class);
            if (cm != null && cm.isContentCaptureEnabled()) {
+6 −0
Original line number Diff line number Diff line
@@ -98,6 +98,12 @@ public class EditableInputConnection extends BaseInputConnection
        return false;
    }

    @Override
    public void endComposingRegionEditInternal() {
        // The ContentCapture service is interested in Composing-state changes.
        mTextView.notifyContentCaptureTextChanged();
    }

    @Override
    public void closeConnection() {
        super.closeConnection();