Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2ec9aee1 authored by Jason Chiu's avatar Jason Chiu
Browse files

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
parent 1e078935
Loading
Loading
Loading
Loading
+14 −4
Original line number Diff line number Diff line
@@ -128,15 +128,20 @@ public class SettingsIntelligenceLogWriter implements LogWriter {
        mLogHandler.post(() -> {
            mSettingsLogList.add(settingsLog);
        });
        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
    static byte[] serialize(List<SettingsLog> settingsLogs) {
        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 = () -> {