package com.apm.insight.h;

import android.text.TextUtils;
import androidx.annotation.Nullable;
import androidx.media3.common.C;
import com.apm.insight.e;
import com.apm.insight.l.f;
import com.apm.insight.l.j;
import com.apm.insight.nativecrash.NativeImpl;
import com.apm.insight.runtime.m;
import com.apm.insight.runtime.n;
import com.google.android.gms.measurement.internal.u1;
import java.io.File;
import java.util.HashMap;
import java.util.Map;

/* JADX INFO: loaded from: classes.dex */
public final class b {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static HashMap<String, String> f5228a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private Map<String, String> f5229b;

    public b(File file) {
        String strA;
        File fileC = j.c(file);
        if (!fileC.exists() || fileC.length() == 0 || (strA = NativeImpl.a(fileC.getAbsolutePath())) == null) {
            return;
        }
        String[] strArrSplit = strA.split("\n");
        this.f5229b = new HashMap();
        for (String str : strArrSplit) {
            String[] strArrSplit2 = str.split("=");
            if (strArrSplit2.length == 2) {
                this.f5229b.put(strArrSplit2[0], strArrSplit2[1]);
            }
        }
    }

    public static String a(String str) {
        return e.g().getFilesDir() + "/apminsight/selflib/lib" + str + ".so";
    }

    public static void b(final String str) {
        m.a().a(new Runnable() { // from class: com.apm.insight.h.b.1

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

            @Override // java.lang.Runnable
            public final void run() {
                String strA;
                b.b();
                if (b.c(str)) {
                    return;
                }
                n.a("updateSo", str);
                File file = new File(b.a(str));
                file.getParentFile().mkdirs();
                if (file.exists()) {
                    file.delete();
                }
                e.i().isDebugMode();
                try {
                    strA = c.a(e.g(), str, file);
                } catch (Throwable th) {
                    n.a("updateSoError", str);
                    com.apm.insight.c.a();
                    com.apm.insight.runtime.j.a(th, "NPTH_CATCH");
                    strA = null;
                }
                if (strA != null) {
                    if (this.f5230a) {
                        n.a("updateSoFailed", str);
                        return;
                    }
                    this.f5230a = true;
                    n.a("updateSoPostRetry", str);
                    m.a().a(this, C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS);
                    return;
                }
                b.f5228a.put(file.getName(), "2.0.0.8");
                try {
                    f.a(new File(e.g().getFilesDir() + "/apminsight/selflib/" + str + ".ver"), "2.0.0.8", false);
                } catch (Throwable unused) {
                }
                n.a("updateSoSuccess", str);
            }
        });
    }

    public final boolean d() {
        Map<String, String> map = this.f5229b;
        return (map == null || map.isEmpty() || TextUtils.isEmpty(this.f5229b.get("process_name")) || TextUtils.isEmpty(this.f5229b.get("crash_thread_name")) || TextUtils.isEmpty(this.f5229b.get("pid")) || TextUtils.isEmpty(this.f5229b.get("tid")) || TextUtils.isEmpty(this.f5229b.get("start_time")) || TextUtils.isEmpty(this.f5229b.get("crash_time")) || TextUtils.isEmpty(this.f5229b.get("signal_line"))) ? false : true;
    }

    @Nullable
    public final String e() {
        return this.f5229b.get("signal_line");
    }

    public final Map<String, String> f() {
        return this.f5229b;
    }

    public static String a() {
        return e.g().getFilesDir() + "/apminsight/selflib/";
    }

    public static /* synthetic */ void b() {
        if (f5228a == null) {
            f5228a = new HashMap<>();
            File file = new File(e.g().getFilesDir(), "/apminsight/selflib/");
            String[] list = file.list();
            if (list != null) {
                for (String str : list) {
                    if (str.endsWith(".ver")) {
                        try {
                            f5228a.put(u1.h(str, 4, 0), f.a(file.getAbsolutePath() + "/" + str, "\n"));
                        } catch (Throwable th) {
                            com.apm.insight.c.a();
                            com.apm.insight.runtime.j.a(th, "NPTH_CATCH");
                        }
                    } else if (!str.endsWith(".so")) {
                        f.a(new File(file, str));
                    }
                }
            }
        }
    }

    public static /* synthetic */ boolean c(String str) {
        return "2.0.0.8".equals(f5228a.get(str)) && new File(a(str)).exists();
    }
}
