From ef928f8a114b9d65ad4be2e319fe2278b61f7cf2 Mon Sep 17 00:00:00 2001 From: Julian Odell Date: Fri, 15 May 2020 11:24:44 -0700 Subject: [PATCH] Flush buffered data when session connects. Typically this data would have been flushed at the end of the first draw and there would otherwise be an extended delay before the data would be sent to the service. Test: make -j Test: Manually start WhatsApp - check for lost events Test: atest CtsContentCaptureServiceTestCases Bug: 154777879 Change-Id: Ia0a97e24ffcc1c189d5d0cd6b8888678fa48968e --- .../android/view/contentcapture/ContentCaptureSession.java | 7 ++++++- .../view/contentcapture/MainContentCaptureSession.java | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/contentcapture/ContentCaptureSession.java b/core/java/android/view/contentcapture/ContentCaptureSession.java index 39c7210d8dac6..301ce9f013e42 100644 --- a/core/java/android/view/contentcapture/ContentCaptureSession.java +++ b/core/java/android/view/contentcapture/ContentCaptureSession.java @@ -166,6 +166,8 @@ public abstract class ContentCaptureSession implements AutoCloseable { public static final int FLUSH_REASON_IDLE_TIMEOUT = 5; /** @hide */ public static final int FLUSH_REASON_TEXT_CHANGE_TIMEOUT = 6; + /** @hide */ + public static final int FLUSH_REASON_SESSION_CONNECTED = 7; /** @hide */ @IntDef(prefix = { "FLUSH_REASON_" }, value = { @@ -174,7 +176,8 @@ public abstract class ContentCaptureSession implements AutoCloseable { FLUSH_REASON_SESSION_STARTED, FLUSH_REASON_SESSION_FINISHED, FLUSH_REASON_IDLE_TIMEOUT, - FLUSH_REASON_TEXT_CHANGE_TIMEOUT + FLUSH_REASON_TEXT_CHANGE_TIMEOUT, + FLUSH_REASON_SESSION_CONNECTED }) @Retention(RetentionPolicy.SOURCE) public @interface FlushReason{} @@ -609,6 +612,8 @@ public abstract class ContentCaptureSession implements AutoCloseable { return "IDLE"; case FLUSH_REASON_TEXT_CHANGE_TIMEOUT: return "TEXT_CHANGE"; + case FLUSH_REASON_SESSION_CONNECTED: + return "CONNECTED"; default: return "UNKOWN-" + reason; } diff --git a/core/java/android/view/contentcapture/MainContentCaptureSession.java b/core/java/android/view/contentcapture/MainContentCaptureSession.java index 893d38dcfde71..6eb71f747be6f 100644 --- a/core/java/android/view/contentcapture/MainContentCaptureSession.java +++ b/core/java/android/view/contentcapture/MainContentCaptureSession.java @@ -273,6 +273,8 @@ public final class MainContentCaptureSession extends ContentCaptureSession { } else { mState = resultCode; mDisabled.set(false); + // Flush any pending data immediately as buffering forced until now. + flushIfNeeded(FLUSH_REASON_SESSION_CONNECTED); } if (sVerbose) { Log.v(TAG, "handleSessionStarted() result: id=" + mId + " resultCode=" + resultCode