From 72f823ba9e1c1be746b1d952c2f00c6dbd4cb11b Mon Sep 17 00:00:00 2001 From: Tsung-Mao Fang Date: Fri, 24 Dec 2021 11:01:30 +0800 Subject: [PATCH] Fix potential OOM problem Prior to this cl, there's a potential vulnerability to cache huge logging data in the memory. We send the log out when user didn't trigger any event in 1 min. However, if user keep triggering any log event in 1 min, then there's a change to preserve a huge number logs in the device memory. Then, it causes the OOM. The solution is to set a logging threshold, once the current logging number is larger than 150, then we simply send it out immediately and clean the device memory. Test: Log can be sent out after meeting the threshold. Fix: 211323528 Change-Id: I9d507e8d55d6b7f7e682369edf3b5334eb2856ae --- .../core/instrumentation/SettingsIntelligenceLogWriter.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/core/instrumentation/SettingsIntelligenceLogWriter.java b/src/com/android/settings/core/instrumentation/SettingsIntelligenceLogWriter.java index d963a5500d3..29e58717eff 100644 --- a/src/com/android/settings/core/instrumentation/SettingsIntelligenceLogWriter.java +++ b/src/com/android/settings/core/instrumentation/SettingsIntelligenceLogWriter.java @@ -48,6 +48,8 @@ public class SettingsIntelligenceLogWriter implements LogWriter { private static final String LOG = "logs"; private static final long MESSAGE_DELAY = DateUtils.MINUTE_IN_MILLIS; // 1 minute + // Based on the exp, 99.5% users collect less than 150 data in 1 minute. + private static final int CACHE_LOG_THRESHOLD = 150; private List mSettingsLogList; private SendLogHandler mLogHandler; @@ -128,7 +130,8 @@ public class SettingsIntelligenceLogWriter implements LogWriter { mLogHandler.post(() -> { mSettingsLogList.add(settingsLog); }); - if (action == SettingsEnums.ACTION_CONTEXTUAL_CARD_DISMISS) { + if (action == SettingsEnums.ACTION_CONTEXTUAL_CARD_DISMISS + || mSettingsLogList.size() >= CACHE_LOG_THRESHOLD) { // Directly send this event to notify SI instantly that the card is dismissed mLogHandler.sendLog(); } else {