From c0f877a774e849b68a9668069470be7a93850c00 Mon Sep 17 00:00:00 2001 From: Joanne Date: Fri, 23 Sep 2022 17:59:27 +0800 Subject: [PATCH] Do not send event if the buffer is empty. Found many logs in bugreport that call sendEvents() even the buffer is empty. We should avoid unnecessary API call to reduce ipc spam. This change doesn't fix the potential ipc spam issue, only mitigates the issue. Bug: 231313913 Test: manual. Local add log and see the empty api call is skipped Change-Id: I9c8afc5ae2d06074900886cf5743b1ec61ccb973 --- .../view/contentcapture/MainContentCaptureSession.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/core/java/android/view/contentcapture/MainContentCaptureSession.java b/core/java/android/view/contentcapture/MainContentCaptureSession.java index 90384b5203154..c32ca9e2e2158 100644 --- a/core/java/android/view/contentcapture/MainContentCaptureSession.java +++ b/core/java/android/view/contentcapture/MainContentCaptureSession.java @@ -528,7 +528,12 @@ public final class MainContentCaptureSession extends ContentCaptureSession { @Override @UiThread void flush(@FlushReason int reason) { - if (mEvents == null) return; + if (mEvents == null || mEvents.size() == 0) { + if (sVerbose) { + Log.v(TAG, "Don't flush for empty event buffer."); + } + return; + } if (mDisabled.get()) { Log.e(TAG, "handleForceFlush(" + getDebugState(reason) + "): should not be when "