Initial commit
This commit is contained in:
66
sources/com/squareup/leakcanary/AndroidWatchExecutor.java
Normal file
66
sources/com/squareup/leakcanary/AndroidWatchExecutor.java
Normal file
@@ -0,0 +1,66 @@
|
||||
package com.squareup.leakcanary;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.os.HandlerThread;
|
||||
import android.os.Looper;
|
||||
import android.os.MessageQueue;
|
||||
import com.squareup.leakcanary.Retryable;
|
||||
|
||||
/* loaded from: classes.dex */
|
||||
public final class AndroidWatchExecutor implements WatchExecutor {
|
||||
static final String LEAK_CANARY_THREAD_NAME = "LeakCanary-Heap-Dump";
|
||||
private final Handler backgroundHandler;
|
||||
private final long initialDelayMillis;
|
||||
private final Handler mainHandler = new Handler(Looper.getMainLooper());
|
||||
private final long maxBackoffFactor;
|
||||
|
||||
public AndroidWatchExecutor(long j) {
|
||||
HandlerThread handlerThread = new HandlerThread(LEAK_CANARY_THREAD_NAME);
|
||||
handlerThread.start();
|
||||
this.backgroundHandler = new Handler(handlerThread.getLooper());
|
||||
this.initialDelayMillis = j;
|
||||
this.maxBackoffFactor = Long.MAX_VALUE / j;
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void postToBackgroundWithDelay(final Retryable retryable, final int i) {
|
||||
this.backgroundHandler.postDelayed(new Runnable() { // from class: com.squareup.leakcanary.AndroidWatchExecutor.3
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
if (retryable.run() == Retryable.Result.RETRY) {
|
||||
AndroidWatchExecutor.this.postWaitForIdle(retryable, i + 1);
|
||||
}
|
||||
}
|
||||
}, this.initialDelayMillis * ((long) Math.min(Math.pow(2.0d, i), this.maxBackoffFactor)));
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void postWaitForIdle(final Retryable retryable, final int i) {
|
||||
this.mainHandler.post(new Runnable() { // from class: com.squareup.leakcanary.AndroidWatchExecutor.1
|
||||
@Override // java.lang.Runnable
|
||||
public void run() {
|
||||
AndroidWatchExecutor.this.waitForIdle(retryable, i);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* JADX INFO: Access modifiers changed from: private */
|
||||
public void waitForIdle(final Retryable retryable, final int i) {
|
||||
Looper.myQueue().addIdleHandler(new MessageQueue.IdleHandler() { // from class: com.squareup.leakcanary.AndroidWatchExecutor.2
|
||||
@Override // android.os.MessageQueue.IdleHandler
|
||||
public boolean queueIdle() {
|
||||
AndroidWatchExecutor.this.postToBackgroundWithDelay(retryable, i);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override // com.squareup.leakcanary.WatchExecutor
|
||||
public void execute(Retryable retryable) {
|
||||
if (Looper.getMainLooper().getThread() == Thread.currentThread()) {
|
||||
waitForIdle(retryable, 0);
|
||||
} else {
|
||||
postWaitForIdle(retryable, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user