Added leak canary

pull/207/head
M66B 3 years ago
parent 1ea9637a83
commit b02c31ed70

@ -42,3 +42,4 @@ FairEmail uses:
* [Lato font](https://fonts.google.com/specimen/Lato). By Łukasz Dziedzic. [Apache License 2.0](https://fonts.google.com/specimen/Lato#license). * [Lato font](https://fonts.google.com/specimen/Lato). By Łukasz Dziedzic. [Apache License 2.0](https://fonts.google.com/specimen/Lato#license).
* [Caladea font](https://fonts.google.com/specimen/Caladea). By Andrés Torresi, Carolina Giovanolli. [Apache License 2.0](https://fonts.google.com/specimen/Caladea#license). * [Caladea font](https://fonts.google.com/specimen/Caladea). By Andrés Torresi, Carolina Giovanolli. [Apache License 2.0](https://fonts.google.com/specimen/Caladea#license).
* [Apache Commons Compress](https://commons.apache.org/proper/commons-compress/). Copyright © 2002-2021 The Apache Software Foundation. All Rights Reserved. [Apache License 2.0](https://www.apache.org/licenses/). * [Apache Commons Compress](https://commons.apache.org/proper/commons-compress/). Copyright © 2002-2021 The Apache Software Foundation. All Rights Reserved. [Apache License 2.0](https://www.apache.org/licenses/).
* [LeakCanary](https://github.com/square/leakcanary). Copyright 2015 Square, Inc. [Apache License 2.0](https://github.com/square/leakcanary/blob/main/LICENSE.txt).

@ -385,6 +385,7 @@ dependencies {
def rxjava2_version = "2.2.21" def rxjava2_version = "2.2.21"
def svg_version = "1.4" def svg_version = "1.4"
def compress_version = "1.21" def compress_version = "1.21"
def canary_version = "2.8.1"
// https://developer.android.com/jetpack/androidx/releases/startup // https://developer.android.com/jetpack/androidx/releases/startup
implementation "androidx.startup:startup-runtime:$startup_version" implementation "androidx.startup:startup-runtime:$startup_version"
@ -585,4 +586,9 @@ dependencies {
// https://commons.apache.org/proper/commons-compress/ // https://commons.apache.org/proper/commons-compress/
// https://mvnrepository.com/artifact/org.apache.commons/commons-compress // https://mvnrepository.com/artifact/org.apache.commons/commons-compress
implementation "org.apache.commons:commons-compress:$compress_version" implementation "org.apache.commons:commons-compress:$compress_version"
// 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"
} }

@ -42,3 +42,4 @@ FairEmail uses:
* [Lato font](https://fonts.google.com/specimen/Lato). By Łukasz Dziedzic. [Apache License 2.0](https://fonts.google.com/specimen/Lato#license). * [Lato font](https://fonts.google.com/specimen/Lato). By Łukasz Dziedzic. [Apache License 2.0](https://fonts.google.com/specimen/Lato#license).
* [Caladea font](https://fonts.google.com/specimen/Caladea). By Andrés Torresi, Carolina Giovanolli. [Apache License 2.0](https://fonts.google.com/specimen/Caladea#license). * [Caladea font](https://fonts.google.com/specimen/Caladea). By Andrés Torresi, Carolina Giovanolli. [Apache License 2.0](https://fonts.google.com/specimen/Caladea#license).
* [Apache Commons Compress](https://commons.apache.org/proper/commons-compress/). Copyright © 2002-2021 The Apache Software Foundation. All Rights Reserved. [Apache License 2.0](https://www.apache.org/licenses/). * [Apache Commons Compress](https://commons.apache.org/proper/commons-compress/). Copyright © 2002-2021 The Apache Software Foundation. All Rights Reserved. [Apache License 2.0](https://www.apache.org/licenses/).
* [LeakCanary](https://github.com/square/leakcanary). Copyright 2015 Square, Inc. [Apache License 2.0](https://github.com/square/leakcanary/blob/main/LICENSE.txt).

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

@ -19,7 +19,6 @@ package eu.faircode.email;
Copyright 2018-2022 by Marcel Bokhorst (M66B) Copyright 2018-2022 by Marcel Bokhorst (M66B)
*/ */
import android.app.Activity;
import android.app.ActivityManager; import android.app.ActivityManager;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationManager; import android.app.NotificationManager;
@ -664,6 +663,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
.putBoolean("crash_reports", checked) .putBoolean("crash_reports", checked)
.apply(); .apply();
Log.setCrashReporting(checked); Log.setCrashReporting(checked);
Log.setupLeakCanary(checked);
} }
}); });

@ -154,6 +154,7 @@ import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.TrustManagerFactory;
import io.requery.android.database.CursorWindowAllocationException; import io.requery.android.database.CursorWindowAllocationException;
import leakcanary.LeakCanary;
public class Log { public class Log {
private static Context ctx; private static Context ctx;
@ -569,6 +570,18 @@ 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) { static void logExtras(Intent intent) {
if (intent != null) if (intent != null)
logBundle(intent.getExtras()); logBundle(intent.getExtras());

@ -1288,11 +1288,15 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
PendingIntent piWhy = PendingIntentCompat.getActivity( PendingIntent piWhy = PendingIntentCompat.getActivity(
this, ActivityView.PI_WHY, why, PendingIntent.FLAG_UPDATE_CURRENT); this, ActivityView.PI_WHY, why, PendingIntent.FLAG_UPDATE_CURRENT);
Intent dump = new Intent(this, ServiceUI.class).setAction("dump");
PendingIntent piDump = PendingIntentCompat.getService(
this, ServiceUI.PI_DUMP, dump, PendingIntent.FLAG_UPDATE_CURRENT);
// Build notification // Build notification
NotificationCompat.Builder builder = NotificationCompat.Builder builder =
new NotificationCompat.Builder(this, "service") new NotificationCompat.Builder(this, "service")
.setSmallIcon(R.drawable.baseline_compare_arrows_white_24) .setSmallIcon(R.drawable.baseline_compare_arrows_white_24)
.setContentIntent(piWhy) .setContentIntent(BuildConfig.DEBUG ? piDump : piWhy)
.setAutoCancel(false) .setAutoCancel(false)
.setShowWhen(false) .setShowWhen(false)
.setPriority(NotificationCompat.PRIORITY_MIN) .setPriority(NotificationCompat.PRIORITY_MIN)

@ -58,6 +58,7 @@ public class ServiceUI extends IntentService {
static final int PI_SNOOZE = 10; static final int PI_SNOOZE = 10;
static final int PI_IGNORED = 11; static final int PI_IGNORED = 11;
static final int PI_DELETE = 12; static final int PI_DELETE = 12;
static final int PI_DUMP = 13;
public ServiceUI() { public ServiceUI() {
this(ServiceUI.class.getName()); this(ServiceUI.class.getName());
@ -175,6 +176,10 @@ public class ServiceUI extends IntentService {
// ignore // ignore
break; break;
case "dump":
Log.checkCanary();
break;
default: default:
throw new IllegalArgumentException("Unknown UI action: " + parts[0]); throw new IllegalArgumentException("Unknown UI action: " + parts[0]);
} }

Loading…
Cancel
Save