From 5653dc2e9b783c74773ad1dd6c8ddb2cae5f3a61 Mon Sep 17 00:00:00 2001 From: M66B Date: Fri, 23 Aug 2019 15:22:35 +0200 Subject: [PATCH] Limit number of crash reports --- app/src/main/java/eu/faircode/email/Log.java | 7 +++++++ app/src/main/java/eu/faircode/email/WorkerCleanup.java | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/Log.java b/app/src/main/java/eu/faircode/email/Log.java index 1fbca4f9d2..0d05521a11 100644 --- a/app/src/main/java/eu/faircode/email/Log.java +++ b/app/src/main/java/eu/faircode/email/Log.java @@ -83,6 +83,7 @@ import javax.mail.Part; import javax.mail.internet.InternetAddress; public class Log { + private static final int MAX_CRASH_REPORTS = 5; private static final String TAG = "fairemail"; public static int d(String msg) { @@ -201,6 +202,12 @@ public class Log { config.beforeSend(new BeforeSend() { @Override public boolean run(@NonNull Report report) { + int count = prefs.getInt("crash_report_count", 0); + count++; + prefs.edit().putInt("crash_report_count", count).apply(); + if (count > MAX_CRASH_REPORTS) + return false; + Throwable ex = report.getError().getException(); if (ex instanceof MessagingException && diff --git a/app/src/main/java/eu/faircode/email/WorkerCleanup.java b/app/src/main/java/eu/faircode/email/WorkerCleanup.java index 9a65e9d9a4..f5cb2b8546 100644 --- a/app/src/main/java/eu/faircode/email/WorkerCleanup.java +++ b/app/src/main/java/eu/faircode/email/WorkerCleanup.java @@ -185,7 +185,10 @@ public class WorkerCleanup extends Worker { Log.i("End cleanup"); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); - prefs.edit().putLong("last_cleanup", new Date().getTime()).apply(); + prefs.edit() + .remove("crash_report_count") + .putLong("last_cleanup", new Date().getTime()) + .apply(); } }