Initial commit
This commit is contained in:
102
sources/com/squareup/leakcanary/AndroidRefWatcherBuilder.java
Normal file
102
sources/com/squareup/leakcanary/AndroidRefWatcherBuilder.java
Normal file
@@ -0,0 +1,102 @@
|
||||
package com.squareup.leakcanary;
|
||||
|
||||
import android.content.Context;
|
||||
import com.squareup.leakcanary.HeapDump;
|
||||
import com.squareup.leakcanary.Reachability;
|
||||
import com.squareup.leakcanary.internal.DisplayLeakActivity;
|
||||
import com.squareup.leakcanary.internal.FragmentRefWatcher;
|
||||
import com.squareup.leakcanary.internal.LeakCanaryInternals;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class AndroidRefWatcherBuilder extends RefWatcherBuilder<AndroidRefWatcherBuilder> {
|
||||
private static final long DEFAULT_WATCH_DELAY_MILLIS = TimeUnit.SECONDS.toMillis(5);
|
||||
private final Context context;
|
||||
private boolean watchActivities = true;
|
||||
private boolean watchFragments = true;
|
||||
private boolean enableDisplayLeakActivity = false;
|
||||
|
||||
AndroidRefWatcherBuilder(Context context) {
|
||||
this.context = context.getApplicationContext();
|
||||
}
|
||||
|
||||
public RefWatcher buildAndInstall() {
|
||||
if (LeakCanaryInternals.installedRefWatcher != null) {
|
||||
throw new UnsupportedOperationException("buildAndInstall() should only be called once.");
|
||||
}
|
||||
RefWatcher build = build();
|
||||
if (build != RefWatcher.DISABLED) {
|
||||
if (this.enableDisplayLeakActivity) {
|
||||
LeakCanaryInternals.setEnabledAsync(this.context, DisplayLeakActivity.class, true);
|
||||
}
|
||||
if (this.watchActivities) {
|
||||
ActivityRefWatcher.install(this.context, build);
|
||||
}
|
||||
if (this.watchFragments) {
|
||||
FragmentRefWatcher.Helper.install(this.context, build);
|
||||
}
|
||||
}
|
||||
LeakCanaryInternals.installedRefWatcher = build;
|
||||
return build;
|
||||
}
|
||||
|
||||
@Override // com.squareup.leakcanary.RefWatcherBuilder
|
||||
protected DebuggerControl defaultDebuggerControl() {
|
||||
return new AndroidDebuggerControl();
|
||||
}
|
||||
|
||||
@Override // com.squareup.leakcanary.RefWatcherBuilder
|
||||
protected ExcludedRefs defaultExcludedRefs() {
|
||||
return AndroidExcludedRefs.createAppDefaults().build();
|
||||
}
|
||||
|
||||
@Override // com.squareup.leakcanary.RefWatcherBuilder
|
||||
protected HeapDump.Listener defaultHeapDumpListener() {
|
||||
return new ServiceHeapDumpListener(this.context, DisplayLeakService.class);
|
||||
}
|
||||
|
||||
@Override // com.squareup.leakcanary.RefWatcherBuilder
|
||||
protected HeapDumper defaultHeapDumper() {
|
||||
return new AndroidHeapDumper(this.context, LeakCanaryInternals.getLeakDirectoryProvider(this.context));
|
||||
}
|
||||
|
||||
@Override // com.squareup.leakcanary.RefWatcherBuilder
|
||||
protected List<Class<? extends Reachability.Inspector>> defaultReachabilityInspectorClasses() {
|
||||
return AndroidReachabilityInspectors.defaultAndroidInspectors();
|
||||
}
|
||||
|
||||
@Override // com.squareup.leakcanary.RefWatcherBuilder
|
||||
protected WatchExecutor defaultWatchExecutor() {
|
||||
return new AndroidWatchExecutor(DEFAULT_WATCH_DELAY_MILLIS);
|
||||
}
|
||||
|
||||
@Override // com.squareup.leakcanary.RefWatcherBuilder
|
||||
protected boolean isDisabled() {
|
||||
return LeakCanary.isInAnalyzerProcess(this.context);
|
||||
}
|
||||
|
||||
public AndroidRefWatcherBuilder listenerServiceClass(Class<? extends AbstractAnalysisResultService> cls) {
|
||||
this.enableDisplayLeakActivity = DisplayLeakService.class.isAssignableFrom(cls);
|
||||
return heapDumpListener(new ServiceHeapDumpListener(this.context, cls));
|
||||
}
|
||||
|
||||
public AndroidRefWatcherBuilder maxStoredHeapDumps(int i) {
|
||||
LeakCanary.setLeakDirectoryProvider(new DefaultLeakDirectoryProvider(this.context, i));
|
||||
return self();
|
||||
}
|
||||
|
||||
public AndroidRefWatcherBuilder watchActivities(boolean z) {
|
||||
this.watchActivities = z;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AndroidRefWatcherBuilder watchDelay(long j, TimeUnit timeUnit) {
|
||||
return watchExecutor(new AndroidWatchExecutor(timeUnit.toMillis(j)));
|
||||
}
|
||||
|
||||
public AndroidRefWatcherBuilder watchFragments(boolean z) {
|
||||
this.watchFragments = z;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user