From 84504a727dfffff414b994c8d09997827de891a5 Mon Sep 17 00:00:00 2001 From: Joanne Chung Date: Thu, 16 Feb 2023 19:46:25 +0800 Subject: [PATCH] Fix incorrect flush reason logged The event flush because of forcing flush but it is logged with full reason. This change add a new reason for force_flush and log the event if the reason is force_flush to help debugging. Bug: 216982223 Test: manual. Using allowed app and check the log Change-Id: I13365ce59e063f41cd0379fcf932e6b92cc7ee1e --- .../view/contentcapture/ContentCaptureSession.java | 7 ++++++- .../view/contentcapture/MainContentCaptureSession.java | 9 +++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/core/java/android/view/contentcapture/ContentCaptureSession.java b/core/java/android/view/contentcapture/ContentCaptureSession.java index ee86fc1414906..0da7e3b95863e 100644 --- a/core/java/android/view/contentcapture/ContentCaptureSession.java +++ b/core/java/android/view/contentcapture/ContentCaptureSession.java @@ -175,6 +175,8 @@ public abstract class ContentCaptureSession implements AutoCloseable { public static final int FLUSH_REASON_TEXT_CHANGE_TIMEOUT = 6; /** @hide */ public static final int FLUSH_REASON_SESSION_CONNECTED = 7; + /** @hide */ + public static final int FLUSH_REASON_FORCE_FLUSH = 8; @ChangeId @EnabledSince(targetSdkVersion = UPSIDE_DOWN_CAKE) @@ -188,7 +190,8 @@ public abstract class ContentCaptureSession implements AutoCloseable { FLUSH_REASON_SESSION_FINISHED, FLUSH_REASON_IDLE_TIMEOUT, FLUSH_REASON_TEXT_CHANGE_TIMEOUT, - FLUSH_REASON_SESSION_CONNECTED + FLUSH_REASON_SESSION_CONNECTED, + FLUSH_REASON_FORCE_FLUSH }) @Retention(RetentionPolicy.SOURCE) public @interface FlushReason{} @@ -666,6 +669,8 @@ public abstract class ContentCaptureSession implements AutoCloseable { return "TEXT_CHANGE"; case FLUSH_REASON_SESSION_CONNECTED: return "CONNECTED"; + case FLUSH_REASON_FORCE_FLUSH: + return "FORCE_FLUSH"; default: return "UNKOWN-" + reason; } diff --git a/core/java/android/view/contentcapture/MainContentCaptureSession.java b/core/java/android/view/contentcapture/MainContentCaptureSession.java index a98955862d7b9..8c040e482cdfa 100644 --- a/core/java/android/view/contentcapture/MainContentCaptureSession.java +++ b/core/java/android/view/contentcapture/MainContentCaptureSession.java @@ -459,7 +459,7 @@ public final class MainContentCaptureSession extends ContentCaptureSession { flushReason = FLUSH_REASON_SESSION_FINISHED; break; default: - flushReason = FLUSH_REASON_FULL; + flushReason = forceFlush ? FLUSH_REASON_FORCE_FLUSH : FLUSH_REASON_FULL; } flush(flushReason); @@ -555,8 +555,13 @@ public final class MainContentCaptureSession extends ContentCaptureSession { final int numberEvents = mEvents.size(); final String reasonString = getFlushReasonAsString(reason); + if (sDebug) { - Log.d(TAG, "Flushing " + numberEvents + " event(s) for " + getDebugState(reason)); + ContentCaptureEvent event = mEvents.get(numberEvents - 1); + String forceString = (reason == FLUSH_REASON_FORCE_FLUSH) ? ". The force flush event " + + ContentCaptureEvent.getTypeAsString(event.getType()) : ""; + Log.d(TAG, "Flushing " + numberEvents + " event(s) for " + getDebugState(reason) + + forceString); } if (mFlushHistory != null) { // Logs reason, size, max size, idle timeout