mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-26 02:45:31 +01:00
Added leak canary
This commit is contained in:
@@ -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).
|
||||
* [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/).
|
||||
* [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 svg_version = "1.4"
|
||||
def compress_version = "1.21"
|
||||
def canary_version = "2.8.1"
|
||||
|
||||
// https://developer.android.com/jetpack/androidx/releases/startup
|
||||
implementation "androidx.startup:startup-runtime:$startup_version"
|
||||
@@ -585,4 +586,9 @@ dependencies {
|
||||
// https://commons.apache.org/proper/commons-compress/
|
||||
// https://mvnrepository.com/artifact/org.apache.commons/commons-compress
|
||||
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).
|
||||
* [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/).
|
||||
* [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.setupLeakCanary(crash_reports);
|
||||
|
||||
upgrade(this);
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package eu.faircode.email;
|
||||
Copyright 2018-2022 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
@@ -664,6 +663,7 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
|
||||
.putBoolean("crash_reports", checked)
|
||||
.apply();
|
||||
Log.setCrashReporting(checked);
|
||||
Log.setupLeakCanary(checked);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -154,6 +154,7 @@ 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;
|
||||
@@ -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) {
|
||||
if (intent != null)
|
||||
logBundle(intent.getExtras());
|
||||
|
||||
@@ -1288,11 +1288,15 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||
PendingIntent piWhy = PendingIntentCompat.getActivity(
|
||||
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
|
||||
NotificationCompat.Builder builder =
|
||||
new NotificationCompat.Builder(this, "service")
|
||||
.setSmallIcon(R.drawable.baseline_compare_arrows_white_24)
|
||||
.setContentIntent(piWhy)
|
||||
.setContentIntent(BuildConfig.DEBUG ? piDump : piWhy)
|
||||
.setAutoCancel(false)
|
||||
.setShowWhen(false)
|
||||
.setPriority(NotificationCompat.PRIORITY_MIN)
|
||||
|
||||
@@ -58,6 +58,7 @@ public class ServiceUI extends IntentService {
|
||||
static final int PI_SNOOZE = 10;
|
||||
static final int PI_IGNORED = 11;
|
||||
static final int PI_DELETE = 12;
|
||||
static final int PI_DUMP = 13;
|
||||
|
||||
public ServiceUI() {
|
||||
this(ServiceUI.class.getName());
|
||||
@@ -175,6 +176,10 @@ public class ServiceUI extends IntentService {
|
||||
// ignore
|
||||
break;
|
||||
|
||||
case "dump":
|
||||
Log.checkCanary();
|
||||
break;
|
||||
|
||||
default:
|
||||
throw new IllegalArgumentException("Unknown UI action: " + parts[0]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user