mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-05 00:23:09 +02:00
Added leak canary
This commit is contained in:
@@ -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