A canary in a coal mine

This commit is contained in:
M66B 2022-04-13 08:17:38 +02:00
parent 562496d48b
commit 5825de59c3
9 changed files with 79 additions and 18 deletions

View File

@ -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"
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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);
}
}

View File

@ -182,7 +182,7 @@ public class ApplicationEx extends Application
});
Log.setup(this);
Log.setupLeakCanary(crash_reports);
CoalMine.setup(crash_reports);
upgrade(this);

View File

@ -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);
}
});

View File

@ -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());

View File

@ -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:

View File

@ -246,6 +246,7 @@ public abstract class SimpleTask<T> implements LifecycleObserver {
}
}
});
CoalMine.watch(SimpleTask.this, "Task done=" + name);
}
});

View File

@ -72,6 +72,7 @@ public class TwoStateOwner implements LifecycleOwner {
owned = false;
destroy();
owner.getLifecycle().removeObserver(this);
CoalMine.watch(TwoStateOwner.this, "State done=" + aname);
}
});
}

View File

@ -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 <http://www.gnu.org/licenses/>.
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) {
}
}