diff --git a/app/build.gradle b/app/build.gradle
index 71431a26c5..53f438e1ad 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -590,5 +590,5 @@ dependencies {
// https://github.com/square/leakcanary
// https://square.github.io/leakcanary/getting_started/
// https://mvnrepository.com/artifact/com.squareup.leakcanary/leakcanary-android
- implementation "com.squareup.leakcanary:leakcanary-android:$canary_version"
+ debugImplementation "com.squareup.leakcanary:leakcanary-android:$canary_version"
}
diff --git a/app/src/debug/java/eu.faircode.email/CoalMine.java b/app/src/debug/java/eu.faircode.email/CoalMine.java
new file mode 100644
index 0000000000..efaca244e0
--- /dev/null
+++ b/app/src/debug/java/eu.faircode.email/CoalMine.java
@@ -0,0 +1,41 @@
+package eu.faircode.email;
+
+/*
+ This file is part of FairEmail.
+
+ FairEmail is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ FairEmail is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with FairEmail. If not, see .
+
+ Copyright 2018-2022 by Marcel Bokhorst (M66B)
+*/
+
+import leakcanary.AppWatcher;
+import leakcanary.LeakCanary;
+
+public class CoalMine {
+ static void setup(boolean enabled) {
+ LeakCanary.Config config = LeakCanary.getConfig().newBuilder()
+ .dumpHeap(enabled && BuildConfig.DEBUG)
+ .build();
+ LeakCanary.setConfig(config);
+ LeakCanary.INSTANCE.showLeakDisplayActivityLauncherIcon(BuildConfig.DEBUG);
+ }
+
+ static void check() {
+ LeakCanary.INSTANCE.dumpHeap();
+ }
+
+ static void watch(Object object, String reason) {
+ //AppWatcher.INSTANCE.getObjectWatcher().expectWeaklyReachable(object, reason);
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/java/eu/faircode/email/ApplicationEx.java b/app/src/main/java/eu/faircode/email/ApplicationEx.java
index 75cf59bdb9..dda5a9d262 100644
--- a/app/src/main/java/eu/faircode/email/ApplicationEx.java
+++ b/app/src/main/java/eu/faircode/email/ApplicationEx.java
@@ -182,7 +182,7 @@ public class ApplicationEx extends Application
});
Log.setup(this);
- Log.setupLeakCanary(crash_reports);
+ CoalMine.setup(crash_reports);
upgrade(this);
diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java
index 358dca988f..feb6a242b4 100644
--- a/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java
+++ b/app/src/main/java/eu/faircode/email/FragmentOptionsMisc.java
@@ -658,12 +658,11 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit()
- .remove("crash_reports_asked")
.remove("crash_report_count")
.putBoolean("crash_reports", checked)
.apply();
Log.setCrashReporting(checked);
- Log.setupLeakCanary(checked);
+ CoalMine.setup(checked);
}
});
diff --git a/app/src/main/java/eu/faircode/email/Log.java b/app/src/main/java/eu/faircode/email/Log.java
index c46db44a99..61aa9c84a3 100644
--- a/app/src/main/java/eu/faircode/email/Log.java
+++ b/app/src/main/java/eu/faircode/email/Log.java
@@ -154,7 +154,6 @@ import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import io.requery.android.database.CursorWindowAllocationException;
-import leakcanary.LeakCanary;
public class Log {
private static Context ctx;
@@ -570,18 +569,6 @@ public class Log {
}
}
- static void setupLeakCanary(boolean enabled) {
- LeakCanary.Config config = LeakCanary.getConfig().newBuilder()
- .dumpHeap(enabled && BuildConfig.DEBUG)
- .build();
- LeakCanary.setConfig(config);
- LeakCanary.INSTANCE.showLeakDisplayActivityLauncherIcon(BuildConfig.DEBUG);
- }
-
- static void checkCanary() {
- LeakCanary.INSTANCE.dumpHeap();
- }
-
static void logExtras(Intent intent) {
if (intent != null)
logBundle(intent.getExtras());
diff --git a/app/src/main/java/eu/faircode/email/ServiceUI.java b/app/src/main/java/eu/faircode/email/ServiceUI.java
index 89d70b614c..5cf91249ec 100644
--- a/app/src/main/java/eu/faircode/email/ServiceUI.java
+++ b/app/src/main/java/eu/faircode/email/ServiceUI.java
@@ -25,6 +25,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
+import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.core.app.RemoteInput;
@@ -177,7 +178,7 @@ public class ServiceUI extends IntentService {
break;
case "dump":
- Log.checkCanary();
+ CoalMine.check();
break;
default:
diff --git a/app/src/main/java/eu/faircode/email/SimpleTask.java b/app/src/main/java/eu/faircode/email/SimpleTask.java
index 2d6ef7fab1..6e21c61ed1 100644
--- a/app/src/main/java/eu/faircode/email/SimpleTask.java
+++ b/app/src/main/java/eu/faircode/email/SimpleTask.java
@@ -246,6 +246,7 @@ public abstract class SimpleTask implements LifecycleObserver {
}
}
});
+ CoalMine.watch(SimpleTask.this, "Task done=" + name);
}
});
diff --git a/app/src/main/java/eu/faircode/email/TwoStateOwner.java b/app/src/main/java/eu/faircode/email/TwoStateOwner.java
index 22bb7b2893..2a0cf88ae0 100644
--- a/app/src/main/java/eu/faircode/email/TwoStateOwner.java
+++ b/app/src/main/java/eu/faircode/email/TwoStateOwner.java
@@ -72,6 +72,7 @@ public class TwoStateOwner implements LifecycleOwner {
owned = false;
destroy();
owner.getLifecycle().removeObserver(this);
+ CoalMine.watch(TwoStateOwner.this, "State done=" + aname);
}
});
}
diff --git a/app/src/release/java/eu.faircode.email/CoalMine.java b/app/src/release/java/eu.faircode.email/CoalMine.java
new file mode 100644
index 0000000000..41ad346d51
--- /dev/null
+++ b/app/src/release/java/eu.faircode.email/CoalMine.java
@@ -0,0 +1,31 @@
+package eu.faircode.email;
+
+/*
+ This file is part of FairEmail.
+
+ FairEmail is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ FairEmail is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with FairEmail. If not, see .
+
+ Copyright 2018-2022 by Marcel Bokhorst (M66B)
+*/
+
+public class CoalMine {
+ static void setup(boolean enabled) {
+ }
+
+ static void check() {
+ }
+
+ static void watch(Object object, String reason) {
+ }
+}