jimu-decompiled/sources/com/squareup/leakcanary/LeakCanary.java
2025-05-13 19:24:51 +02:00

92 lines
4.3 KiB
Java

package com.squareup.leakcanary;
import android.app.Application;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.text.format.Formatter;
import android.util.Log;
import com.squareup.leakcanary.internal.DisplayLeakActivity;
import com.squareup.leakcanary.internal.HeapAnalyzerService;
import com.squareup.leakcanary.internal.LeakCanaryInternals;
/* loaded from: classes.dex */
public final class LeakCanary {
private LeakCanary() {
throw new AssertionError();
}
public static void enableDisplayLeakActivity(Context context) {
LeakCanaryInternals.setEnabledBlocking(context, DisplayLeakActivity.class, true);
}
public static RefWatcher install(Application application) {
return refWatcher(application).listenerServiceClass(DisplayLeakService.class).excludedRefs(AndroidExcludedRefs.createAppDefaults().build()).buildAndInstall();
}
public static RefWatcher installedRefWatcher() {
RefWatcher refWatcher = LeakCanaryInternals.installedRefWatcher;
return refWatcher == null ? RefWatcher.DISABLED : refWatcher;
}
public static boolean isInAnalyzerProcess(Context context) {
Boolean bool = LeakCanaryInternals.isInAnalyzerProcess;
if (bool == null) {
bool = Boolean.valueOf(LeakCanaryInternals.isInServiceProcess(context, HeapAnalyzerService.class));
LeakCanaryInternals.isInAnalyzerProcess = bool;
}
return bool.booleanValue();
}
public static String leakInfo(Context context, HeapDump heapDump, AnalysisResult analysisResult, boolean z) {
String str;
PackageManager packageManager = context.getPackageManager();
String packageName = context.getPackageName();
try {
PackageInfo packageInfo = packageManager.getPackageInfo(packageName, 0);
String str2 = "In " + packageName + ":" + packageInfo.versionName + ":" + packageInfo.versionCode + ".\n";
String str3 = "";
if (analysisResult.leakFound) {
if (analysisResult.excludedLeak) {
str2 = str2 + "* EXCLUDED LEAK.\n";
}
String str4 = str2 + "* " + analysisResult.className;
if (!heapDump.referenceName.equals("")) {
str4 = str4 + " (" + heapDump.referenceName + ")";
}
str = str4 + " has leaked:\n" + analysisResult.leakTrace.toString() + "\n";
if (analysisResult.retainedHeapSize != -1) {
str = str + "* Retaining: " + Formatter.formatShortFileSize(context, analysisResult.retainedHeapSize) + ".\n";
}
if (z) {
str3 = "\n* Details:\n" + analysisResult.leakTrace.toDetailedString();
}
} else if (analysisResult.failure != null) {
str = str2 + "* FAILURE in 1.6.3 31007b4:" + Log.getStackTraceString(analysisResult.failure) + "\n";
} else {
str = str2 + "* NO LEAK FOUND.\n\n";
}
if (z) {
str3 = str3 + "* Excluded Refs:\n" + heapDump.excludedRefs;
}
return str + "* Reference Key: " + heapDump.referenceKey + "\n* Device: " + Build.MANUFACTURER + " " + Build.BRAND + " " + Build.MODEL + " " + Build.PRODUCT + "\n* Android Version: " + Build.VERSION.RELEASE + " API: " + Build.VERSION.SDK_INT + " LeakCanary: " + BuildConfig.LIBRARY_VERSION + " " + BuildConfig.GIT_SHA + "\n* Durations: watch=" + heapDump.watchDurationMs + "ms, gc=" + heapDump.gcDurationMs + "ms, heap dump=" + heapDump.heapDumpDurationMs + "ms, analysis=" + analysisResult.analysisDurationMs + "ms\n" + str3;
} catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException(e);
}
}
public static AndroidRefWatcherBuilder refWatcher(Context context) {
return new AndroidRefWatcherBuilder(context);
}
@Deprecated
public static void setDisplayLeakActivityDirectoryProvider(LeakDirectoryProvider leakDirectoryProvider) {
setLeakDirectoryProvider(leakDirectoryProvider);
}
public static void setLeakDirectoryProvider(LeakDirectoryProvider leakDirectoryProvider) {
LeakCanaryInternals.setLeakDirectoryProvider(leakDirectoryProvider);
}
}