From 3bad56345a9dd843cf77caacc46529c4ea513de8 Mon Sep 17 00:00:00 2001
From: M66B
Date: Thu, 4 Jan 2024 13:26:06 +0100
Subject: [PATCH] Refactoring
---
.../main/java/eu/faircode/email/ApplicationEx.java | 2 +-
.../main/java/eu/faircode/email/DebugHelper.java | 2 +-
.../main/java/eu/faircode/email/EmailService.java | 2 +-
app/src/main/java/eu/faircode/email/EntityLog.java | 2 +-
.../eu/faircode/email/FragmentOptionsMisc.java | 4 ++--
app/src/main/java/eu/faircode/email/Helper.java | 2 +-
app/src/main/java/eu/faircode/email/Log.java | 14 +++++++++-----
.../main/java/eu/faircode/email/MessageHelper.java | 2 +-
.../main/java/eu/faircode/email/SimpleTask.java | 2 +-
9 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/app/src/main/java/eu/faircode/email/ApplicationEx.java b/app/src/main/java/eu/faircode/email/ApplicationEx.java
index 0a4aad25cd..c2596b3f7a 100644
--- a/app/src/main/java/eu/faircode/email/ApplicationEx.java
+++ b/app/src/main/java/eu/faircode/email/ApplicationEx.java
@@ -481,7 +481,7 @@ public class ApplicationEx extends Application
if (version < BuildConfig.VERSION_CODE)
editor.remove("crash_report_count");
- if (!BuildConfig.TEST_RELEASE)
+ if (!Log.isTestRelease())
editor.remove("test1").remove("test2").remove("test3").remove("test4").remove("test5");
if (version < 468) {
diff --git a/app/src/main/java/eu/faircode/email/DebugHelper.java b/app/src/main/java/eu/faircode/email/DebugHelper.java
index 243e133b0b..4d99d3d9cf 100644
--- a/app/src/main/java/eu/faircode/email/DebugHelper.java
+++ b/app/src/main/java/eu/faircode/email/DebugHelper.java
@@ -277,7 +277,7 @@ public class DebugHelper {
autostart == null ? "?" : Boolean.toString(autostart == 0)));
boolean reporting = prefs.getBoolean("crash_reports", false);
- if (reporting || BuildConfig.TEST_RELEASE) {
+ if (reporting || Log.isTestRelease()) {
String uuid = prefs.getString("uuid", null);
sb.append(String.format("Bugsnag UUID: %s\r\n", uuid == null ? "-" : uuid));
}
diff --git a/app/src/main/java/eu/faircode/email/EmailService.java b/app/src/main/java/eu/faircode/email/EmailService.java
index 1b1b497eba..5f6422a49a 100644
--- a/app/src/main/java/eu/faircode/email/EmailService.java
+++ b/app/src/main/java/eu/faircode/email/EmailService.java
@@ -186,7 +186,7 @@ public class EmailService implements AutoCloseable {
long protocol_since = prefs.getLong("protocol_since", 0);
if (protocol_since == 0)
prefs.edit().putLong("protocol_since", now).apply();
- else if (protocol_since + PROTOCOL_LOG_DURATION < now && !BuildConfig.TEST_RELEASE)
+ else if (protocol_since + PROTOCOL_LOG_DURATION < now && !Log.isTestRelease())
prefs.edit().putBoolean("protocol", false).apply();
this.log = prefs.getBoolean("protocol", false);
this.ssl_harden = prefs.getBoolean("ssl_harden", false);
diff --git a/app/src/main/java/eu/faircode/email/EntityLog.java b/app/src/main/java/eu/faircode/email/EntityLog.java
index 3402d73072..6ac4a3165a 100644
--- a/app/src/main/java/eu/faircode/email/EntityLog.java
+++ b/app/src/main/java/eu/faircode/email/EntityLog.java
@@ -110,7 +110,7 @@ public class EntityLog {
if (context == null)
return;
if (type == Type.Debug &&
- !(BuildConfig.DEBUG || BuildConfig.TEST_RELEASE))
+ !(BuildConfig.DEBUG || Log.isTestRelease()))
return;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java
index 32ff4c805f..4849d53f9e 100644
--- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java
+++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java
@@ -1971,7 +1971,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
grpBitbucket.setVisibility(View.GONE);
grpAnnouncements.setVisibility(TextUtils.isEmpty(BuildConfig.ANNOUNCEMENT_URI)
? View.GONE : View.VISIBLE);
- grpTest.setVisibility(BuildConfig.TEST_RELEASE ? View.VISIBLE : View.GONE);
+ grpTest.setVisibility(Log.isTestRelease() ? View.VISIBLE : View.GONE);
setLastCleanup(prefs.getLong("last_cleanup", -1));
@@ -1986,7 +1986,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
(external == null ? null : external.getAbsolutePath()) + (emulated ? " emulated" : ""));
swExactAlarms.setEnabled(AlarmManagerCompatEx.canScheduleExactAlarms(getContext()));
- swTestIab.setVisibility(BuildConfig.DEBUG && BuildConfig.TEST_RELEASE ? View.VISIBLE : View.GONE);
+ swTestIab.setVisibility(BuildConfig.DEBUG && Log.isTestRelease() ? View.VISIBLE : View.GONE);
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
diff --git a/app/src/main/java/eu/faircode/email/Helper.java b/app/src/main/java/eu/faircode/email/Helper.java
index 54cc6ef66b..aef8f1bf7d 100644
--- a/app/src/main/java/eu/faircode/email/Helper.java
+++ b/app/src/main/java/eu/faircode/email/Helper.java
@@ -1356,7 +1356,7 @@ public class Helper {
html += "Locale: " + Html.escapeHtml(slocale.toString()) + "
";
if (language != null)
html += "Language: " + Html.escapeHtml(language) + "
";
- if ((reporting || BuildConfig.TEST_RELEASE) && uuid != null)
+ if ((reporting || Log.isTestRelease()) && uuid != null)
html += "UUID: " + Html.escapeHtml(uuid) + "
";
html += "
";
diff --git a/app/src/main/java/eu/faircode/email/Log.java b/app/src/main/java/eu/faircode/email/Log.java
index 7c89206e15..65c7fe9f1c 100644
--- a/app/src/main/java/eu/faircode/email/Log.java
+++ b/app/src/main/java/eu/faircode/email/Log.java
@@ -114,7 +114,7 @@ import javax.net.ssl.TrustManagerFactory;
public class Log {
private static Context ctx;
- private static final int MAX_CRASH_REPORTS = (BuildConfig.TEST_RELEASE ? 50 : 5);
+ private static final int MAX_CRASH_REPORTS = (Log.isTestRelease() ? 50 : 5);
private static final String TAG = "fairemail";
static final String TOKEN_REFRESH_REQUIRED =
@@ -386,7 +386,7 @@ public class Log {
}
static int getDefaultLogLevel() {
- return (BuildConfig.DEBUG || BuildConfig.TEST_RELEASE ? android.util.Log.INFO : android.util.Log.WARN);
+ return (BuildConfig.DEBUG || Log.isTestRelease() ? android.util.Log.INFO : android.util.Log.WARN);
}
private static void setupBugsnag(final Context context) {
@@ -435,7 +435,7 @@ public class Log {
@Override
public boolean onSession(@NonNull Session session) {
// opt-in
- return prefs.getBoolean("crash_reports", false) || BuildConfig.TEST_RELEASE;
+ return prefs.getBoolean("crash_reports", false) || Log.isTestRelease();
}
});
@@ -444,7 +444,7 @@ public class Log {
public boolean onError(@NonNull Event event) {
// opt-in
boolean crash_reports = prefs.getBoolean("crash_reports", false);
- if (!crash_reports && !BuildConfig.TEST_RELEASE)
+ if (!crash_reports && !Log.isTestRelease())
return false;
Throwable ex = event.getOriginalError();
@@ -549,7 +549,7 @@ public class Log {
Log.i("uuid=" + uuid);
client.setUser(uuid, null, null);
- if (prefs.getBoolean("crash_reports", false) || BuildConfig.TEST_RELEASE)
+ if (prefs.getBoolean("crash_reports", false) || Log.isTestRelease())
Bugsnag.startSession();
} catch (Throwable ex) {
Log.e(ex);
@@ -589,6 +589,10 @@ public class Log {
}
}
+ static boolean isTestRelease() {
+ return BuildConfig.TEST_RELEASE;
+ }
+
static void logExtras(Intent intent) {
if (intent != null)
logBundle(intent.getExtras());
diff --git a/app/src/main/java/eu/faircode/email/MessageHelper.java b/app/src/main/java/eu/faircode/email/MessageHelper.java
index f60c7c4647..1283667bd3 100644
--- a/app/src/main/java/eu/faircode/email/MessageHelper.java
+++ b/app/src/main/java/eu/faircode/email/MessageHelper.java
@@ -3810,7 +3810,7 @@ public class MessageHelper {
throw ex;
} catch (Throwable ex) {
Log.e(ex);
- if (BuildConfig.TEST_RELEASE)
+ if (Log.isTestRelease())
warnings.add(ex + "\n" + android.util.Log.getStackTraceString(ex));
else
warnings.add(Log.formatThrowable(ex, false));
diff --git a/app/src/main/java/eu/faircode/email/SimpleTask.java b/app/src/main/java/eu/faircode/email/SimpleTask.java
index 9d26840636..34f86598fa 100644
--- a/app/src/main/java/eu/faircode/email/SimpleTask.java
+++ b/app/src/main/java/eu/faircode/email/SimpleTask.java
@@ -168,7 +168,7 @@ public abstract class SimpleTask implements LifecycleObserver {
this.name = name;
this.started = new Date().getTime();
- if (BuildConfig.TEST_RELEASE)
+ if (Log.isTestRelease())
Log.breadcrumb("SimpleTask", args);
for (String key : args.keySet()) {