package com.bytedance.crash;

import X.AnonymousClass7lW;
import X.C27008h1;
import X.C27558hu;
import X.C27798iI;
import X.C27878iQ;
import X.C27888iR;
import X.C27918iU;
import X.C28068ij;
import X.C28078ik;
import X.C28258j2;
import android.app.Application;
import android.content.Context;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import java.util.HashMap;
import java.util.Map;
import org.json.JSONObject;

public class MonitorCrash {
    public static volatile boolean sAppMonitorCrashInit;
    public Config mConfig;
    public AttachUserData mCustomData;
    public AttachUserData mCustomLongData;
    public HeaderParams mParams;
    public HashMap<String, String> mTagMap = new HashMap<>();

    public interface HeaderParams {
        static {
            Covode.recordClassIndex(25004);
        }

        Map<String, Object> getCommonParams();
    }

    static {
        Covode.recordClassIndex(25002);
    }

    public Config config() {
        return this.mConfig;
    }

    public MonitorCrash setCustomDataCallback(AttachUserData attachUserData) {
        this.mCustomData = attachUserData;
        return this;
    }

    public MonitorCrash withOtherHeaders(HeaderParams headerParams) {
        this.mParams = headerParams;
        return this;
    }

    public class Config {
        public String mAid;
        public String mChannel;
        public String mDeviceId;
        public String mPackageName;
        public String[] mSoList;
        public long mUID;
        public long mVersionInt = -1;
        public String mVersionStr;
        public boolean test;

        static {
            Covode.recordClassIndex(25003);
        }

        public Config setChannel(String str) {
            this.mChannel = str;
            C27558hu.LIZ();
            return this;
        }

        public Config setDeviceId(String str) {
            this.mDeviceId = str;
            C27558hu.LIZ();
            return this;
        }

        public Config setPackageName(String str) {
            this.mPackageName = str;
            C27558hu.LIZ();
            return this;
        }

        public Config setSoList(String[] strArr) {
            this.mSoList = strArr;
            C27558hu.LIZ();
            return this;
        }

        public Config setUID(long j) {
            this.mUID = j;
            C27558hu.LIZ();
            return this;
        }

        public Config() {
        }
    }

    public MonitorCrash addTags(String str, String str2) {
        this.mTagMap.put(str, str2);
        return this;
    }

    public void reportCustomErr(String str, String str2, Throwable th) {
        try {
            C27878iQ.LIZ((Object) this, th, (StackTraceElement[]) null, 0, str, true, (Map<String, String>) null, Thread.currentThread(), str2, "core_exception_monitor");
        } catch (Throwable unused) {
        }
    }

    public MonitorCrash(Context context, String str, long j, String str2) {
        Config config = new Config();
        this.mConfig = config;
        config.mAid = str;
        this.mConfig.mVersionInt = j;
        this.mConfig.mVersionStr = str2;
        C28078ik r2 = new C28078ik(this);
        C28078ik.LIZIZ = this;
        Object applicationContext = context.getApplicationContext();
        if (AnonymousClass7lW.LIZJ && applicationContext == null) {
            applicationContext = AnonymousClass7lW.LIZ;
        }
        C27798iI.LIZ((Application) applicationContext, context, new C28258j2(r2, this));
    }

    public static MonitorCrash init(Context context, String str, long j, String str2) {
        MethodCollector.i(14881);
        if (!sAppMonitorCrashInit) {
            synchronized (MonitorCrash.class) {
                try {
                    if (!sAppMonitorCrashInit) {
                        sAppMonitorCrashInit = true;
                        C27918iU.LIZ(context);
                        MonitorCrash monitorCrash = new MonitorCrash(context, str, j, str2);
                        return monitorCrash;
                    }
                } finally {
                    MethodCollector.o(14881);
                }
            }
        }
        MethodCollector.o(14881);
        return null;
    }

    public MonitorCrash(String str, long j, String str2, String str3) {
        Config config = new Config();
        this.mConfig = config;
        config.mAid = str;
        this.mConfig.mVersionInt = j;
        this.mConfig.mVersionStr = str2;
        this.mConfig.mPackageName = str3;
        new C28078ik(this);
    }

    public static MonitorCrash initSDK(Context context, String str, long j, String str2, String str3) {
        C27918iU.LIZ(context);
        MonitorCrash monitorCrash = new MonitorCrash(str, j, str2, str3);
        monitorCrash.config().setPackageName(str3);
        return monitorCrash;
    }

    public void reportEvent(String str, int i, JSONObject jSONObject, JSONObject jSONObject2, JSONObject jSONObject3) {
        C27008h1 r2 = new C27008h1();
        r2.LIZ("event_type", (Object) "exception");
        r2.LIZ("log_type", (Object) "service_monitor");
        r2.LIZ("timestamp", (Object) Long.valueOf(System.currentTimeMillis()));
        r2.LIZ("crash_time", (Object) Long.valueOf(System.currentTimeMillis()));
        r2.LIZ("process_name", (Object) C28068ij.LIZJ(C27798iI.LIZ));
        r2.LIZ("crash_thread_name", (Object) Thread.currentThread().getName());
        r2.LIZ("service", (Object) str);
        r2.LIZ("status", (Object) Integer.valueOf(i));
        if (jSONObject != null) {
            r2.LIZ("category", (Object) jSONObject);
        }
        if (jSONObject2 != null) {
            r2.LIZ("metric", (Object) jSONObject2);
        }
        r2.LIZ("sid", (Object) Long.valueOf(C27798iI.LIZJ));
        C27888iR.LIZ(this, r2);
    }

    public static MonitorCrash initSDK(Context context, String str, long j, String str2, String str3, String[] strArr) {
        C27918iU.LIZ(context);
        MonitorCrash monitorCrash = new MonitorCrash(str, j, str2, str3);
        Config config = monitorCrash.config();
        config.setPackageName(str3);
        config.setSoList(strArr);
        return monitorCrash;
    }
}
