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
This commit is contained in:
Jason Chiu
2020-05-28 16:05:53 +08:00
parent 1e0789355e
commit 2ec9aee1e1

View File

@@ -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 = () -> {