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
This commit is contained in:
Ahaan Ugale
2021-06-15 21:56:53 -07:00
parent fb12492de7
commit 01315b1089
2 changed files with 13 additions and 1 deletions

View File

@@ -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;
}

View File

@@ -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) {