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

Commit ac13265e authored by Adam He's avatar Adam He
Browse files

Moved buffer for VIEW_TEXT_CHANGED events to MainContentCaptureSession.

Bug: 121042846
Test: atest android.contentcaptureservice.cts.LoginActivityTest#testTextChangeBuffer
Test: atest CtsContentCaptureServiceTestCases
Change-Id: Ia0128c1c868d44da954e67b38dfb2bde6461b883
parent 76e986a2
Loading
Loading
Loading
Loading
+18 −5
Original line number Diff line number Diff line
@@ -258,14 +258,27 @@ public final class MainContentCaptureSession extends ContentCaptureSession {
            }
            mEvents = new ArrayList<>(MAX_BUFFER_SIZE);
        }

        if (!mEvents.isEmpty() && event.getType() == TYPE_VIEW_TEXT_CHANGED) {
            final ContentCaptureEvent lastEvent = mEvents.get(mEvents.size() - 1);

            // TODO(b/121045053): check if flags match
            if (lastEvent.getType() == TYPE_VIEW_TEXT_CHANGED
                    && lastEvent.getId().equals(event.getId())) {
                if (VERBOSE) {
                    Log.v(mTag, "Buffering VIEW_TEXT_CHANGED event, updated text = "
                            + event.getText());
                }
                lastEvent.setText(event.getText());
            } else {
                mEvents.add(event);
            }
        } else {
            mEvents.add(event);
        }

        final int numberEvents = mEvents.size();

        // TODO(b/120784831): need to optimize it so we buffer changes until a number of X are
        // buffered (either total or per autofillid). For
        // example, if the user typed "a", "b", "c" and the threshold is 3, we should buffer
        // "a" and "b" then send "abc".
        final boolean bufferEvent = numberEvents < MAX_BUFFER_SIZE;

        if (bufferEvent && !forceFlush) {