From 2ec9aee1e183235f4304c859308dafc833ef17cc Mon Sep 17 00:00:00 2001 From: Jason Chiu Date: Thu, 28 May 2020 16:05:53 +0800 Subject: [PATCH] Send metrics log of card dismiss event to SI instantly The 1 minute send delay of the original log writer makes the dismissed card list in SI is not up to date, which causes some dismissed card reappears. Bug: 157211258 Test: manual Change-Id: I0780a444e10a60c0cc7006b3bd65d37b33707134 --- .../SettingsIntelligenceLogWriter.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/com/android/settings/core/instrumentation/SettingsIntelligenceLogWriter.java b/src/com/android/settings/core/instrumentation/SettingsIntelligenceLogWriter.java index 30d83810b85..d963a5500d3 100644 --- a/src/com/android/settings/core/instrumentation/SettingsIntelligenceLogWriter.java +++ b/src/com/android/settings/core/instrumentation/SettingsIntelligenceLogWriter.java @@ -128,7 +128,12 @@ public class SettingsIntelligenceLogWriter implements LogWriter { mLogHandler.post(() -> { mSettingsLogList.add(settingsLog); }); - mLogHandler.scheduleSendLog(); + if (action == SettingsEnums.ACTION_CONTEXTUAL_CARD_DISMISS) { + // Directly send this event to notify SI instantly that the card is dismissed + mLogHandler.sendLog(); + } else { + mLogHandler.scheduleSendLog(); + } } @VisibleForTesting @@ -136,7 +141,7 @@ public class SettingsIntelligenceLogWriter implements LogWriter { final int size = settingsLogs.size(); final ByteArrayOutputStream bout = new ByteArrayOutputStream(); final DataOutputStream output = new DataOutputStream(bout); - // Data is "size, length, bytearray, length, bytearray ..." + // The data format is "size, length, byte array, length, byte array ..." try { output.writeInt(size); for (SettingsLog settingsLog : settingsLogs) { @@ -159,14 +164,19 @@ public class SettingsIntelligenceLogWriter implements LogWriter { private class SendLogHandler extends Handler { - public SendLogHandler(Looper looper) { + SendLogHandler(Looper looper) { super(looper); } - public void scheduleSendLog() { + void scheduleSendLog() { removeCallbacks(mSendLogsRunnable); postDelayed(mSendLogsRunnable, MESSAGE_DELAY); } + + void sendLog() { + removeCallbacks(mSendLogsRunnable); + post(mSendLogsRunnable); + } } private final Runnable mSendLogsRunnable = () -> {