From 01315b10891d5a5d3a6b8af217538b793715cc90 Mon Sep 17 00:00:00 2001 From: Ahaan Ugale Date: Tue, 15 Jun 2021 21:56:53 -0700 Subject: [PATCH] ContentCapture: Don't ignore events with changed composing/selection span Currently, if the view has a TEXT_CHANGED event in the buffer with the same text, the new event is ignored, even if the Composing or Selection span is changed. Bug: 184311217 Test: manual - move cursor quickly and check flushed event Test: atest android.contentcaptureservice.cts.LoginActivityTest Change-Id: I4de28576b138225f4e64ed93bcb0b9dd3ed0095c --- .../android/view/contentcapture/ContentCaptureEvent.java | 9 +++++++++ .../view/contentcapture/MainContentCaptureSession.java | 5 ++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/contentcapture/ContentCaptureEvent.java b/core/java/android/view/contentcapture/ContentCaptureEvent.java index 1b1dc4a709cad..d982dc90e0ea7 100644 --- a/core/java/android/view/contentcapture/ContentCaptureEvent.java +++ b/core/java/android/view/contentcapture/ContentCaptureEvent.java @@ -285,6 +285,15 @@ public final class ContentCaptureEvent implements Parcelable { return this; } + boolean hasSameComposingSpan(@NonNull ContentCaptureEvent other) { + return mComposingStart == other.mComposingStart && mComposingEnd == other.mComposingEnd; + } + + boolean hasSameSelectionSpan(@NonNull ContentCaptureEvent other) { + return mSelectionStartIndex == other.mSelectionStartIndex + && mSelectionEndIndex == other.mSelectionEndIndex; + } + private int getComposingStart() { return mComposingStart; } diff --git a/core/java/android/view/contentcapture/MainContentCaptureSession.java b/core/java/android/view/contentcapture/MainContentCaptureSession.java index d8ac779ddc275..d0a2e771e097c 100644 --- a/core/java/android/view/contentcapture/MainContentCaptureSession.java +++ b/core/java/android/view/contentcapture/MainContentCaptureSession.java @@ -362,7 +362,10 @@ public final class MainContentCaptureSession extends ContentCaptureSession { final CharSequence lastText = lastEvent.getText(); final boolean bothNonEmpty = !TextUtils.isEmpty(lastText) && !TextUtils.isEmpty(text); - boolean equalContent = TextUtils.equals(lastText, text); + boolean equalContent = + TextUtils.equals(lastText, text) + && lastEvent.hasSameComposingSpan(event) + && lastEvent.hasSameSelectionSpan(event); if (equalContent) { addEvent = false; } else if (bothNonEmpty) {