diff --git a/app/src/debug/java/eu.faircode.email/CoalMine.java b/app/src/debug/java/eu.faircode.email/CoalMine.java index efaca244e0..7bf693de7b 100644 --- a/app/src/debug/java/eu.faircode.email/CoalMine.java +++ b/app/src/debug/java/eu.faircode.email/CoalMine.java @@ -19,13 +19,49 @@ package eu.faircode.email; Copyright 2018-2022 by Marcel Bokhorst (M66B) */ -import leakcanary.AppWatcher; +import androidx.annotation.NonNull; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +import kotlin.Unit; +import kotlin.jvm.functions.Function2; import leakcanary.LeakCanary; +import shark.HeapField; +import shark.HeapObject; +import shark.ObjectInspector; +import shark.ObjectReporter; public class CoalMine { static void setup(boolean enabled) { + List inspectors = new ArrayList<>(LeakCanary.getConfig().getObjectInspectors()); + inspectors.add(new ObjectInspector() { + @Override + public void inspect(@NonNull ObjectReporter reporter) { + String clazz = SimpleTask.class.getName(); + reporter.whenInstanceOf(clazz, new Function2() { + @Override + public Unit invoke(ObjectReporter reporter, HeapObject.HeapInstance instance) { + HeapField fname = instance.get(clazz, "name"); + if (fname != null) { + String name = fname.getValue().readAsJavaString(); + reporter.getNotLeakingReasons().add("name=" + name); + } + HeapField fstarted = instance.get(clazz, "started"); + if (fstarted != null) { + Long started = fstarted.getValue().getAsLong(); + if (started != null) + reporter.getNotLeakingReasons().add("started=" + new Date(started)); + } + return null; + } + }); + } + }); LeakCanary.Config config = LeakCanary.getConfig().newBuilder() .dumpHeap(enabled && BuildConfig.DEBUG) + .objectInspectors(inspectors) .build(); LeakCanary.setConfig(config); LeakCanary.INSTANCE.showLeakDisplayActivityLauncherIcon(BuildConfig.DEBUG);