package defpackage;

import java.lang.Thread;
import java.util.concurrent.atomic.AtomicBoolean;

/* JADX INFO: loaded from: classes2.dex */
class im1 implements Thread.UncaughtExceptionHandler {
    public final gl1 a;
    public final tn8 b;
    public final Thread.UncaughtExceptionHandler c;
    public final vl1 d;
    public final AtomicBoolean e = new AtomicBoolean(false);

    public interface a {
    }

    public im1(gl1 gl1Var, tn8 tn8Var, Thread.UncaughtExceptionHandler uncaughtExceptionHandler, vl1 vl1Var) {
        this.a = gl1Var;
        this.b = tn8Var;
        this.c = uncaughtExceptionHandler;
        this.d = vl1Var;
    }

    @Override // java.lang.Thread.UncaughtExceptionHandler
    public final void uncaughtException(Thread thread, Throwable th) {
        AtomicBoolean atomicBoolean = this.e;
        atomicBoolean.set(true);
        hh5 hh5Var = hh5.a;
        Thread.UncaughtExceptionHandler uncaughtExceptionHandler = this.c;
        try {
            try {
                if (thread == null) {
                    hh5Var.a("Crashlytics will not record uncaught exception; null thread", null);
                } else if (th == null) {
                    hh5Var.a("Crashlytics will not record uncaught exception; null throwable", null);
                } else if (!this.d.b()) {
                    this.a.a(this.b, thread, th);
                }
                if (uncaughtExceptionHandler != null) {
                    uncaughtExceptionHandler.uncaughtException(thread, th);
                } else {
                    System.exit(1);
                }
                atomicBoolean.set(false);
            } catch (Exception e) {
                hh5Var.a("An error occurred in the uncaught exception handler", e);
                if (uncaughtExceptionHandler != null) {
                    uncaughtExceptionHandler.uncaughtException(thread, th);
                } else {
                    System.exit(1);
                }
                atomicBoolean.set(false);
            }
        } catch (Throwable th2) {
            if (uncaughtExceptionHandler != null) {
                uncaughtExceptionHandler.uncaughtException(thread, th);
            } else {
                System.exit(1);
            }
            atomicBoolean.set(false);
            throw th2;
        }
    }
}
