package com.github.anrwatchdog; import android.os.Looper; import com.github.anrwatchdog.ANRError$$; import java.util.Comparator; import java.util.Map; import java.util.TreeMap; /* loaded from: classes2.dex */ public class ANRError extends Error { private static final long serialVersionUID = 1; public final long duration; public ANRError(ANRError$$._Thread _thread, long j) { super("Application Not Responding for at least " + j + " ms.", _thread); this.duration = j; } @Override // java.lang.Throwable public Throwable fillInStackTrace() { setStackTrace(new StackTraceElement[0]); return this; } public static ANRError New(long j, String str, boolean z) { final Thread thread = Looper.getMainLooper().getThread(); TreeMap treeMap = new TreeMap(new Comparator() { // from class: com.github.anrwatchdog.ANRError.1 @Override // java.util.Comparator public int compare(Thread thread2, Thread thread3) { if (thread2 == thread3) { return 0; } Thread thread4 = thread; if (thread2 == thread4) { return 1; } if (thread3 == thread4) { return -1; } return thread3.getName().compareTo(thread2.getName()); } }); for (Map.Entry entry : Thread.getAllStackTraces().entrySet()) { if (entry.getKey() == thread || (entry.getKey().getName().startsWith(str) && (z || entry.getValue().length > 0))) { treeMap.put(entry.getKey(), entry.getValue()); } } if (!treeMap.containsKey(thread)) { treeMap.put(thread, thread.getStackTrace()); } ANRError$$._Thread _thread = null; for (Map.Entry entry2 : treeMap.entrySet()) { _thread = new ANRError$$._Thread(_thread); } return new ANRError(_thread, j); } public static ANRError NewMainOnly(long j) { Thread thread = Looper.getMainLooper().getThread(); return new ANRError(new ANRError$$._Thread(null), j); } public static String getThreadTitle(Thread thread) { return thread.getName() + " (state = " + thread.getState() + ")"; } }