package com.apm.insight.g;

import android.os.Looper;
import android.os.SystemClock;
import com.apm.insight.CrashType;
import com.apm.insight.ICrashCallback;
import com.apm.insight.ICrashFilter;
import com.apm.insight.IOOMCallback;
import com.apm.insight.e;
import com.apm.insight.k.h;
import com.apm.insight.l.e;
import com.apm.insight.l.f;
import com.apm.insight.l.j;
import com.apm.insight.nativecrash.NativeImpl;
import com.apm.insight.runtime.l;
import com.apm.insight.runtime.m;
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.lang.Thread;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import org.json.JSONArray;

/* JADX INFO: loaded from: classes.dex */
public final class a implements Thread.UncaughtExceptionHandler {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static a f5197a = null;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private static volatile boolean f5198i = false;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private static volatile ThreadLocal<Boolean> f5199j = new ThreadLocal<>();

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    private static volatile long f5200l = 10000;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    private static ArrayList<b> f5201m = new ArrayList<>();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private Thread.UncaughtExceptionHandler f5202b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private c f5203c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private c f5204d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private volatile int f5205e = 0;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private volatile int f5206f = 0;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private ConcurrentHashMap<String, Object> f5207g = new ConcurrentHashMap<>();

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private ConcurrentHashMap<String, Object> f5208h = new ConcurrentHashMap<>();

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    private JSONArray f5209k;

    private a() {
        Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
        if (defaultUncaughtExceptionHandler != this) {
            this.f5202b = defaultUncaughtExceptionHandler;
            Thread.setDefaultUncaughtExceptionHandler(this);
        }
    }

    public static void a(long j10) {
        f5200l = j10;
    }

    private void c(Thread thread, Throwable th) {
        Thread.UncaughtExceptionHandler uncaughtExceptionHandler = this.f5202b;
        if (uncaughtExceptionHandler == null || uncaughtExceptionHandler == this) {
            return;
        }
        uncaughtExceptionHandler.uncaughtException(thread, th);
    }

    private void d() {
        synchronized (this) {
            this.f5206f--;
        }
        long jUptimeMillis = SystemClock.uptimeMillis();
        while (this.f5206f != 0 && SystemClock.uptimeMillis() - jUptimeMillis < f5200l) {
            SystemClock.sleep(50L);
        }
    }

    private static void e() {
        File fileA = j.a(e.g());
        File fileA2 = j.a();
        if (f.b(fileA) && f.b(fileA2)) {
            return;
        }
        long jUptimeMillis = SystemClock.uptimeMillis();
        while (!h.a() && SystemClock.uptimeMillis() - jUptimeMillis < f5200l) {
            try {
                SystemClock.sleep(500L);
            } catch (Throwable unused) {
            }
        }
    }

    private static int f() {
        int iA = 0;
        for (int i10 = 0; i10 < f5201m.size(); i10++) {
            try {
                try {
                    iA |= f5201m.get(i10).a();
                } catch (Throwable th) {
                    com.apm.insight.c.a();
                    com.apm.insight.runtime.j.a(th, "NPTH_CATCH");
                }
            } catch (Throwable unused) {
            }
        }
        return iA;
    }

    private static Throwable g() {
        for (int i10 = 0; i10 < f5201m.size(); i10++) {
            try {
                f5201m.get(i10);
            } catch (Throwable unused) {
            }
        }
        if (Looper.getMainLooper() != Looper.myLooper()) {
            return null;
        }
        try {
            Looper.loop();
            return null;
        } catch (Throwable th) {
            return th;
        }
    }

    public final void b(c cVar) {
        this.f5204d = cVar;
    }

    @Override // java.lang.Thread.UncaughtExceptionHandler
    public final void uncaughtException(Thread thread, Throwable th) {
        do {
            th = a(thread, th);
        } while (th != null);
    }

    public static boolean b() {
        return f5198i;
    }

    public static void c(final String str) {
        if (str == null) {
            return;
        }
        try {
            m.a().a(new Runnable() { // from class: com.apm.insight.g.a.3
                @Override // java.lang.Runnable
                public final void run() {
                    try {
                        com.apm.insight.entity.a aVar = new com.apm.insight.entity.a();
                        aVar.a("data", (Object) str);
                        aVar.a("userdefine", (Object) 1);
                        com.apm.insight.entity.a aVarA = com.apm.insight.runtime.a.f.a().a(CrashType.CUSTOM_JAVA, aVar);
                        if (aVarA != null) {
                            com.apm.insight.k.d.a().c(aVarA.c());
                        }
                    } catch (Throwable unused) {
                    }
                }
            });
        } catch (Throwable unused) {
        }
    }

    public final void a(c cVar) {
        this.f5203c = cVar;
    }

    public static a a() {
        if (f5197a == null) {
            f5197a = new a();
        }
        return f5197a;
    }

    private static boolean b(Thread thread, Throwable th) {
        ICrashFilter iCrashFilterB = e.b().b();
        if (iCrashFilterB != null) {
            try {
                if (!iCrashFilterB.onJavaCrashFilter(th, thread)) {
                    return false;
                }
            } catch (Throwable unused) {
            }
        }
        return true;
    }

    public static boolean c() {
        Boolean bool = f5199j.get();
        return bool != null && bool.booleanValue();
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:103:0x01cf A[Catch: all -> 0x01d3, TRY_LEAVE, TryCatch #7 {all -> 0x01d3, blocks: (B:101:0x01c9, B:103:0x01cf), top: B:155:0x01c9 }] */
    /* JADX WARN: Removed duplicated region for block: B:108:0x01d7  */
    /* JADX WARN: Removed duplicated region for block: B:115:0x01eb  */
    /* JADX WARN: Removed duplicated region for block: B:141:0x00bb A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:24:0x0067  */
    /* JADX WARN: Removed duplicated region for block: B:42:0x00ae  */
    /* JADX WARN: Removed duplicated region for block: B:46:0x00b9 A[ADDED_TO_REGION] */
    /* JADX WARN: Removed duplicated region for block: B:59:0x0104  */
    /* JADX WARN: Removed duplicated region for block: B:60:0x0107  */
    /* JADX WARN: Removed duplicated region for block: B:69:0x0132 A[Catch: all -> 0x011a, TRY_LEAVE, TryCatch #10 {all -> 0x011a, blocks: (B:64:0x0116, B:67:0x011c, B:69:0x0132), top: B:161:0x0116 }] */
    /* JADX WARN: Removed duplicated region for block: B:76:0x0161  */
    /* JADX WARN: Removed duplicated region for block: B:82:0x018e  */
    /* JADX WARN: Removed duplicated region for block: B:89:0x01a7  */
    /* JADX WARN: Type inference failed for: r20v0, types: [com.apm.insight.g.a] */
    /* JADX WARN: Type inference failed for: r2v10 */
    /* JADX WARN: Type inference failed for: r2v15 */
    /* JADX WARN: Type inference failed for: r2v2 */
    /* JADX WARN: Type inference failed for: r2v20, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r2v21 */
    /* JADX WARN: Type inference failed for: r2v22 */
    /* JADX WARN: Type inference failed for: r2v23 */
    /* JADX WARN: Type inference failed for: r2v25 */
    /* JADX WARN: Type inference failed for: r2v26 */
    /* JADX WARN: Type inference failed for: r2v3 */
    /* JADX WARN: Type inference failed for: r2v35 */
    /* JADX WARN: Type inference failed for: r2v36 */
    /* JADX WARN: Type inference failed for: r2v37 */
    /* JADX WARN: Type inference failed for: r2v38 */
    /* JADX WARN: Type inference failed for: r2v6 */
    /* JADX WARN: Type inference failed for: r2v9 */
    /* JADX WARN: Type inference failed for: r4v0 */
    /* JADX WARN: Type inference failed for: r4v1, types: [int] */
    /* JADX WARN: Type inference failed for: r4v10 */
    /* JADX WARN: Type inference failed for: r4v11 */
    /* JADX WARN: Type inference failed for: r4v16 */
    /* JADX WARN: Type inference failed for: r4v17 */
    /* JADX WARN: Type inference failed for: r4v18 */
    /* JADX WARN: Type inference failed for: r4v19 */
    /* JADX WARN: Type inference failed for: r4v20 */
    /* JADX WARN: Type inference failed for: r4v21, types: [int] */
    /* JADX WARN: Type inference failed for: r4v23 */
    /* JADX WARN: Type inference failed for: r4v24 */
    /* JADX WARN: Type inference failed for: r4v25, types: [boolean] */
    /* JADX WARN: Type inference failed for: r4v29 */
    /* JADX WARN: Type inference failed for: r4v30 */
    /* JADX WARN: Type inference failed for: r4v31 */
    /* JADX WARN: Type inference failed for: r4v32 */
    /* JADX WARN: Type inference failed for: r4v33 */
    /* JADX WARN: Type inference failed for: r4v34 */
    /* JADX WARN: Type inference failed for: r4v4 */
    /* JADX WARN: Type inference failed for: r5v0 */
    /* JADX WARN: Type inference failed for: r5v1, types: [long] */
    /* JADX WARN: Type inference failed for: r5v10, types: [long] */
    /* JADX WARN: Type inference failed for: r5v11 */
    /* JADX WARN: Type inference failed for: r5v12 */
    /* JADX WARN: Type inference failed for: r5v13, types: [long] */
    /* JADX WARN: Type inference failed for: r5v14 */
    /* JADX WARN: Type inference failed for: r5v15 */
    /* JADX WARN: Type inference failed for: r5v16 */
    /* JADX WARN: Type inference failed for: r5v17 */
    /* JADX WARN: Type inference failed for: r5v2 */
    /* JADX WARN: Type inference failed for: r5v3, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r5v4 */
    /* JADX WARN: Type inference failed for: r5v5 */
    /* JADX WARN: Type inference failed for: r5v6 */
    /* JADX WARN: Type inference failed for: r5v7 */
    /* JADX WARN: Type inference failed for: r5v8 */
    /* JADX WARN: Type inference failed for: r5v9, types: [long] */
    /* JADX WARN: Type inference failed for: r8v0, types: [com.apm.insight.g.c] */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private Throwable a(Thread thread, Throwable th) {
        boolean zC;
        boolean z10;
        CrashType crashType;
        ?? r22;
        ?? r52;
        ?? r42;
        boolean z11;
        boolean z12;
        ?? r23;
        ?? r53;
        ?? r43;
        JSONArray jSONArrayA;
        String strA;
        ?? r44;
        ?? ValueOf;
        boolean zB;
        if (this.f5205e >= 3) {
            return null;
        }
        this.f5205e++;
        this.f5206f++;
        if (f5198i) {
            f5199j.set(Boolean.TRUE);
        }
        f5198i = true;
        long jCurrentTimeMillis = System.currentTimeMillis();
        boolean z13 = false;
        boolean z14 = (com.apm.insight.runtime.a.b.c() == -1 || jCurrentTimeMillis - com.apm.insight.runtime.a.b.c() <= e.i().getLaunchCrashInterval()) && !(e.n() && e.q() == 0);
        try {
            zC = com.apm.insight.l.m.c(th);
            if (zC) {
                try {
                    boolean z15 = com.apm.insight.l.m.d(th);
                    z10 = z15;
                } catch (Throwable unused) {
                    z10 = false;
                }
            }
        } catch (Throwable unused2) {
            zC = false;
        }
        try {
            if (z14) {
                try {
                    crashType = CrashType.LAUNCH;
                } catch (Throwable th2) {
                    th = th2;
                    z11 = false;
                    r22 = z10;
                    r52 = jCurrentTimeMillis;
                    r42 = 1;
                    try {
                        if (!com.apm.insight.l.m.c(th)) {
                        }
                        if (!z13) {
                        }
                    } catch (Throwable th3) {
                        if (!z13) {
                            if (r22 != 0 && !z11) {
                                try {
                                    a(thread, th, z14, r52);
                                } catch (Throwable unused3) {
                                    throw th3;
                                }
                            }
                            e();
                            d();
                            c(thread, th);
                            throw th3;
                        }
                        synchronized (this) {
                            this.f5206f -= r42;
                            this.f5205e -= r42;
                            return g();
                        }
                    }
                }
            } else {
                try {
                    crashType = CrashType.JAVA;
                } catch (Throwable th4) {
                    th = th4;
                    r22 = z10;
                    r52 = jCurrentTimeMillis;
                    r42 = 1;
                    z11 = false;
                    if (!com.apm.insight.l.m.c(th)) {
                    }
                    if (!z13) {
                    }
                }
            }
            String strA2 = e.a(jCurrentTimeMillis, crashType, zC, false);
            File file = new File(j.a(e.g()), strA2);
            ?? r54 = "logEventStack";
            String strA3 = a(new File(file, "logEventStack"), th, thread, z10);
            if ((f() & 1) != 0) {
                z12 = true;
                try {
                    jSONArrayA = com.apm.insight.entity.b.a(th, thread, file);
                    this.f5209k = jSONArrayA;
                    if (jSONArrayA != null || z12) {
                        try {
                            strA = e.a(jCurrentTimeMillis, z14 ? CrashType.LAUNCH : CrashType.JAVA, zC, true);
                            File file2 = new File(j.a(e.g()), strA);
                            file.renameTo(file2);
                            new File(file2, "logEventStack");
                            r44 = "logEventStack";
                        } catch (Throwable th5) {
                            th = th5;
                            z11 = false;
                            r23 = z10;
                            r53 = jCurrentTimeMillis;
                            r43 = 1;
                            z13 = z12;
                            r22 = r23;
                            r42 = r43;
                            r52 = r53;
                            if (!com.apm.insight.l.m.c(th)) {
                                com.apm.insight.a.a(th);
                            }
                            if (!z13) {
                                if (r22 != 0 && !z11) {
                                    a(thread, th, z14, r52);
                                }
                                e();
                                d();
                                c(thread, th);
                                return null;
                            }
                            synchronized (this) {
                                this.f5206f -= r42;
                                this.f5205e -= r42;
                            }
                            return g();
                        }
                    } else {
                        strA = strA2;
                        r44 = jSONArrayA;
                    }
                    com.apm.insight.a.d();
                    com.apm.insight.k.b.a().b();
                    z11 = com.apm.insight.runtime.a.a("exception_modules", "oom_callback") != 1;
                    if (z10 && z11) {
                        r44 = z14;
                        r54 = jCurrentTimeMillis;
                        try {
                            a(thread, th, r44, r54);
                        } catch (Throwable th6) {
                            th = th6;
                            r23 = z10;
                            r53 = jCurrentTimeMillis;
                            r43 = 1;
                            z13 = z12;
                            r22 = r23;
                            r42 = r43;
                            r52 = r53;
                            if (!com.apm.insight.l.m.c(th)) {
                            }
                            if (!z13) {
                            }
                        }
                    }
                    ValueOf = String.valueOf(z14);
                    com.apm.insight.a.a((Object) "[uncaughtException] isLaunchCrash=".concat(ValueOf));
                    com.apm.insight.a.a.a();
                    zB = b(thread, th);
                } catch (Throwable th7) {
                    th = th7;
                    r23 = z10;
                    r53 = jCurrentTimeMillis;
                    r43 = 1;
                    z11 = false;
                }
                try {
                } catch (Throwable th8) {
                    th = th8;
                    r23 = ValueOf;
                    r43 = r44;
                    r53 = r54;
                    z13 = z12;
                    r22 = r23;
                    r42 = r43;
                    r52 = r53;
                    if (!com.apm.insight.l.m.c(th)) {
                    }
                    if (!z13) {
                    }
                }
                if (!zB) {
                    c cVar = this.f5203c;
                    if (cVar == null || !z14) {
                        ValueOf = z10;
                        r54 = jCurrentTimeMillis;
                        r44 = 1;
                        if (zB) {
                            ?? r82 = this.f5204d;
                            ValueOf = ValueOf;
                            r44 = r44;
                            r54 = r54;
                            if (r82 != 0) {
                                r82.a(r54, thread, th, strA, strA3, z12);
                                com.apm.insight.a.a((Object) ("[uncaughtException] mLaunchCrashDisposer " + th.toString()));
                                ValueOf = ValueOf;
                                r44 = r44;
                                r54 = r54;
                            }
                        }
                        if (z12) {
                            if (ValueOf != 0 && !z11) {
                                a(thread, th, z14, r54);
                            }
                            e();
                            d();
                            c(thread, th);
                        } else {
                            synchronized (this) {
                                this.f5206f -= r44;
                                this.f5205e -= r44;
                            }
                            return g();
                        }
                    } else {
                        ValueOf = z10;
                        r54 = jCurrentTimeMillis;
                        r44 = 1;
                        cVar.a(jCurrentTimeMillis, thread, th, strA, strA3, z12);
                        com.apm.insight.a.a((Object) ("[uncaughtException] mLaunchCrashDisposer " + th.toString()));
                    }
                    if (z12) {
                    }
                }
            } else {
                if (strA3 != null) {
                    if (e.i().isCrashIgnored(strA3)) {
                    }
                    jSONArrayA = com.apm.insight.entity.b.a(th, thread, file);
                    this.f5209k = jSONArrayA;
                    if (jSONArrayA != null) {
                        strA = strA2;
                        r44 = jSONArrayA;
                        com.apm.insight.a.d();
                        com.apm.insight.k.b.a().b();
                        if (com.apm.insight.runtime.a.a("exception_modules", "oom_callback") != 1) {
                        }
                        if (z10) {
                            r44 = z14;
                            r54 = jCurrentTimeMillis;
                            a(thread, th, r44, r54);
                        }
                        ValueOf = String.valueOf(z14);
                        com.apm.insight.a.a((Object) "[uncaughtException] isLaunchCrash=".concat(ValueOf));
                        com.apm.insight.a.a.a();
                        zB = b(thread, th);
                        if (!zB) {
                        }
                    }
                }
                z12 = false;
                jSONArrayA = com.apm.insight.entity.b.a(th, thread, file);
                this.f5209k = jSONArrayA;
                if (jSONArrayA != null) {
                }
            }
        } catch (Throwable unused4) {
        }
        return null;
    }

    public final boolean b(String str) {
        return this.f5207g.containsKey(str);
    }

    private String a(File file, Throwable th, Thread thread, boolean z10) {
        String absolutePath = file.getAbsolutePath();
        this.f5208h.put(file.getName(), file);
        try {
            file.getParentFile().mkdirs();
            file.createNewFile();
            NativeImpl.c(absolutePath);
        } catch (Throwable unused) {
        }
        String strA = null;
        if (z10) {
            int iH = NativeImpl.h(absolutePath);
            if (iH > 0) {
                try {
                    e.g();
                    NativeImpl.a(iH, com.apm.insight.l.a.b());
                    NativeImpl.a(iH, "\n");
                    NativeImpl.a(iH, th.getMessage());
                    NativeImpl.a(iH, "\n");
                    NativeImpl.a(iH, th.getClass().getName());
                    if (th.getMessage() != null) {
                        NativeImpl.a(iH, ": ");
                        NativeImpl.a(iH, th.getMessage());
                    }
                    NativeImpl.a(iH, "\n");
                    NativeImpl.a(iH, thread.getName());
                    NativeImpl.a(iH, "\n");
                } catch (Throwable unused2) {
                }
                try {
                    NativeImpl.a(iH, "stack:");
                    NativeImpl.a(iH, "\n");
                } catch (Throwable unused3) {
                }
                com.apm.insight.l.m.a(th, iH);
                NativeImpl.b(iH);
            }
        } else {
            try {
                FileOutputStream fileOutputStream = new FileOutputStream(file, true);
                try {
                    StringBuilder sb = new StringBuilder();
                    e.g();
                    sb.append(com.apm.insight.l.a.b());
                    sb.append("\n");
                    fileOutputStream.write(sb.toString().getBytes());
                    fileOutputStream.write((th.getMessage() + "\n").getBytes());
                    fileOutputStream.write((th + "\n").getBytes());
                    fileOutputStream.write((thread.getName() + "\n").getBytes());
                } catch (Throwable unused4) {
                }
                try {
                    fileOutputStream.write("stack:\n".getBytes());
                } catch (Throwable unused5) {
                }
                try {
                    strA = com.apm.insight.l.m.a(th, new PrintStream(fileOutputStream), Looper.getMainLooper() == Looper.myLooper() ? new e.a() { // from class: com.apm.insight.g.a.1

                        /* JADX INFO: renamed from: a, reason: collision with root package name */
                        private boolean f5210a = false;

                        @Override // com.apm.insight.l.e.a
                        public final boolean a(String str) {
                            if (!this.f5210a && str.contains("android.os.Looper.loop")) {
                                this.f5210a = true;
                            }
                            return !this.f5210a;
                        }
                    } : new e.a());
                    com.apm.insight.a.a((Closeable) fileOutputStream);
                } catch (Throwable th2) {
                    try {
                        th.printStackTrace(new PrintStream(fileOutputStream));
                    } catch (Throwable th3) {
                        try {
                            fileOutputStream.write("err:\n".getBytes());
                            fileOutputStream.write((th2 + "\n").getBytes());
                            fileOutputStream.write((th3 + "\n").getBytes());
                        } catch (Throwable unused6) {
                        }
                    }
                }
                com.apm.insight.a.a((Closeable) fileOutputStream);
            } catch (Throwable unused7) {
            }
        }
        return strA;
    }

    public final void a(Thread thread, Throwable th, boolean z10, com.apm.insight.entity.a aVar) {
        List<ICrashCallback> listC;
        CrashType crashType;
        if (z10) {
            listC = l.a().b();
            crashType = CrashType.LAUNCH;
        } else {
            listC = l.a().c();
            crashType = CrashType.JAVA;
        }
        for (ICrashCallback iCrashCallback : listC) {
            long jUptimeMillis = SystemClock.uptimeMillis();
            try {
                if (iCrashCallback instanceof com.apm.insight.b) {
                    ((com.apm.insight.b) iCrashCallback).a(crashType, com.apm.insight.l.m.a(th), thread, this.f5209k);
                } else {
                    iCrashCallback.onCrash(crashType, com.apm.insight.l.m.a(th), thread);
                }
                aVar.b("callback_cost_" + iCrashCallback.getClass().getName(), String.valueOf(SystemClock.uptimeMillis() - jUptimeMillis));
            } catch (Throwable th2) {
                com.apm.insight.a.b(th2);
                aVar.b("callback_err_".concat(iCrashCallback.getClass().getName()), String.valueOf(SystemClock.uptimeMillis() - jUptimeMillis));
            }
        }
    }

    private void a(Thread thread, Throwable th, boolean z10, long j10) {
        List<IOOMCallback> listA = l.a().a();
        CrashType crashType = z10 ? CrashType.LAUNCH : CrashType.JAVA;
        for (IOOMCallback iOOMCallback : listA) {
            try {
                if (iOOMCallback instanceof com.apm.insight.b) {
                    ((com.apm.insight.b) iOOMCallback).a(crashType, th, thread, j10, this.f5209k);
                } else {
                    iOOMCallback.onCrash(crashType, th, thread, j10);
                }
            } catch (Throwable th2) {
                com.apm.insight.a.b(th2);
            }
        }
    }

    public final void a(String str) {
        this.f5207g.put(str, new Object());
    }

    public static void a(final Throwable th) {
        if (th == null) {
            return;
        }
        try {
            m.a().a(new Runnable() { // from class: com.apm.insight.g.a.2
                @Override // java.lang.Runnable
                public final void run() {
                    try {
                        com.apm.insight.entity.a aVarA = com.apm.insight.entity.a.a(System.currentTimeMillis(), com.apm.insight.e.g(), th);
                        aVarA.a("userdefine", (Object) 1);
                        com.apm.insight.entity.a aVarA2 = com.apm.insight.runtime.a.f.a().a(CrashType.CUSTOM_JAVA, aVarA);
                        if (aVarA2 != null) {
                            com.apm.insight.k.d.a().c(aVarA2.c());
                        }
                    } catch (Throwable unused) {
                    }
                }
            });
        } catch (Throwable unused) {
        }
    }
}
