package com.ss.android.ugc.aweme.legoImp.task.bpea;

import X.0Gp;
import X.2Pr;
import X.2te;
import X.2th;
import X.7lW;
import X.7xk;
import X.8Zd;
import X.8Ze;
import X.8ec;
import X.9EH;
import X.9Ft;
import X.9Fx;
import X.9LK;
import X.C0884RYa;
import X.C0886RYc;
import X.C0888RYe;
import X.C0897RYn;
import X.C0900RYq;
import X.C0906RYw;
import X.C0909RYz;
import X.LeS;
import X.LeY;
import X.PqI;
import X.RW3;
import X.RYB;
import X.RYC;
import X.RYP;
import X.RYT;
import X.RYV;
import X.RYY;
import X.RYZ;
import X.RZ0;
import X.RZ2;
import X.RZ4;
import X.RZD;
import X.RZH;
import X.RZI;
import X.RZM;
import X.RZQ;
import android.content.Context;
import android.os.SystemClock;
import android.util.Log;
import com.bytedance.bpea.basics.Cert;
import com.bytedance.covode.number.Covode;
import com.google.gson.j;
import com.google.gson.m;
import com.ss.android.ugc.aweme.compliance.api.services.monitor.IComplianceMonitorService;
import com.ss.android.ugc.aweme.compliance.common.serviceimpl.ComplianceMonitorServiceImpl;
import com.ss.android.ugc.aweme.ruler_adapter_api.RuleEngineSettingsModel;
import java.util.List;
import kotlin.h.b.n;
import kotlin.o.y;
import org.json.JSONObject;

public final class KidsBPEATask implements 8Ze {
    public final String LIZ = "BPEA";
    public String LIZIZ = "";
    public Context LIZJ;
    public final RYV LIZLLL = new RYV();
    public final RYT LJ = new RYT();
    public final RYZ LJFF = new RYZ();
    public final RZH LJI = new RZH();
    public final RZI LJII = new RZI();

    static {
        Covode.recordClassIndex(90747);
    }

    public final boolean meetTrigger() {
        return true;
    }

    public final String prefix() {
        return "task_";
    }

    public final boolean serialExecute() {
        return false;
    }

    public final int targetProcess() {
        return 1048575;
    }

    public final List triggerOtherLegoComponents() {
        return null;
    }

    public final 9Ft triggerType() {
        return 8Zd.LIZ(this);
    }

    public final 9Fx scenesType() {
        return 9Fx.DEFAULT;
    }

    public final 8ec type() {
        return 8ec.MAIN;
    }

    public final String key() {
        return getClass().getSimpleName();
    }

    public final void LIZ() {
        RuleEngineSettingsModel ruleEngineSettingsModel;
        boolean z;
        IComplianceMonitorService LJI2 = ComplianceMonitorServiceImpl.LJI();
        if (LJI2 != null) {
            ruleEngineSettingsModel = LJI2.LIZLLL();
        } else {
            ruleEngineSettingsModel = null;
        }
        boolean z2 = false;
        if (ruleEngineSettingsModel != null) {
            z = ruleEngineSettingsModel.getEnableRuleEngineForBpea();
            z2 = ruleEngineSettingsModel.getEnableRuleEngineForBpeaBlock();
        } else {
            z = false;
        }
        this.LJFF.LIZIZ = z;
        if (z2) {
            C0886RYc.LIZIZ(C0884RYa.RULER_FORBIDDEN, this.LJII);
            C0886RYc.LIZ(C0884RYa.RULER_FORBIDDEN, this.LJI);
            return;
        }
        C0886RYc.LIZIZ(C0884RYa.RULER_FORBIDDEN, this.LJI);
        C0886RYc.LIZ(C0884RYa.RULER_FORBIDDEN, this.LJII);
    }

    public final void LIZIZ() {
        try {
            m LJFF2 = ComplianceMonitorServiceImpl.LJI().LJFF();
            if (LJFF2 != null) {
                j LIZJ2 = LJFF2.LIZJ("maxAppVersion");
                n.LIZIZ(LIZJ2, "");
                String LIZJ3 = LIZJ2.LIZJ();
                n.LIZIZ(LIZJ3, "");
                if (9EH.LJJIFFI.LIZLLL() <= Long.parseLong(LIZJ3)) {
                    RYP.LIZJ.LIZ(new JSONObject(LJFF2.toString()));
                }
            }
        } catch (Throwable unused) {
        }
    }

    public final String LIZJ() {
        boolean z;
        if (this.LIZIZ.length() == 0) {
            z = true;
        } else {
            z = false;
        }
        if (z) {
            try {
                String LIZ2 = 7xk.LIZ();
                if (LIZ2 == null) {
                    LIZ2 = "";
                }
                this.LIZIZ = LIZ2;
                2te.constructor-impl(2Pr.LIZ);
            } catch (Throwable th) {
                2te.constructor-impl(2th.LIZ(th));
            }
        }
        return this.LIZIZ;
    }

    public final void run(Context context) {
        Context context2;
        Object obj;
        long currentThreadTimeMillis = SystemClock.currentThreadTimeMillis();
        long nanoTime = System.nanoTime();
        if (context != null) {
            context2 = context.getApplicationContext();
            if (7lW.LIZJ && context2 == null) {
                context2 = 7lW.LIZ;
            }
        } else {
            context2 = null;
        }
        this.LIZJ = context2;
        RW3.LIZIZ = false;
        RW3.LIZJ = true;
        RYY.LIZ.LIZ((C0888RYe) new RZ4());
        C0886RYc.LIZ((C0906RYw) new RZM(this));
        C0886RYc.LIZ((C0906RYw) new RZQ(this));
        C0886RYc.LIZ((C0906RYw) new RZD(this));
        C0886RYc.LIZ(C0884RYa.EMPTY_CERT, new C0909RYz());
        C0886RYc.LIZ(C0884RYa.CONTENT_ILLEGAL, new RZ0());
        C0886RYc.LIZ((List<? extends RYB>) LeS.LIZIZ(new C0897RYn[]{this.LIZLLL, this.LJFF, this.LJ}));
        long nanoTime2 = System.nanoTime();
        LIZ();
        LIZIZ();
        long nanoTime3 = System.nanoTime();
        try {
            RYP.LIZJ.LIZIZ(PqI.LIZ.LIZ());
            obj = Integer.valueOf(Log.d("BPEATask", "setLocalConfig:" + PqI.LIZ.LIZ()));
            2te.constructor-impl(obj);
        } catch (Throwable th) {
            obj = 2th.LIZ(th);
            2te.constructor-impl(obj);
        }
        2te.exceptionOrNull-impl(obj);
        0Gp.LIZ(new RZ2(this, nanoTime2, nanoTime, nanoTime3, System.nanoTime(), SystemClock.currentThreadTimeMillis(), currentThreadTimeMillis));
    }

    public final void LIZ(C0900RYq rYq, String str) {
        Integer num;
        String str2;
        JSONObject jSONObject;
        String str3;
        Integer num2;
        String str4;
        String str5;
        String str6;
        String[] strArr;
        Cert cert;
        Cert cert2;
        JSONObject jSONObject2 = new JSONObject();
        C0900RYq rYq2 = rYq;
        RYC ryc = rYq2.LIZ;
        if (ryc != null) {
            num = ryc.LJ;
        } else {
            num = null;
        }
        jSONObject2.put("entryCategory", num);
        jSONObject2.put("eventLevel", rYq2.LJFF.getValue());
        RYC ryc2 = rYq2.LIZ;
        if (ryc2 != null) {
            str2 = ryc2.LIZJ;
        } else {
            str2 = null;
        }
        jSONObject2.put("entryToken", str2);
        String str7 = str;
        jSONObject2.put("eventType", str7);
        jSONObject2.put("processName", LIZJ());
        jSONObject2.put("status", rYq2.LIZJ);
        JSONObject jSONObject3 = new JSONObject();
        jSONObject3.put("costTime", Float.valueOf(((float) rYq2.LJ.LIZIZ.LIZ()) / 1000000.0f));
        jSONObject3.put("threadCostTime", rYq2.LJ.LIZJ.LIZ());
        if (n.LIZ(rYq2.LIZIZ, "END_RULER_CHECK")) {
            Object obj = rYq2.LJI.get("rulerCost");
            if (!(obj instanceof Long)) {
                obj = null;
            }
            Long l = (Long) obj;
            if (l != null) {
                jSONObject3.put("rulerCost", Float.valueOf(((float) l.longValue()) / 1000000.0f));
            }
        }
        JSONObject jSONObject4 = new JSONObject();
        RYC ryc3 = rYq2.LIZ;
        if (ryc3 == null || (cert2 = ryc3.LIZIZ) == null) {
            jSONObject = null;
        } else {
            jSONObject = cert2.toJSON();
        }
        jSONObject4.put("cert", jSONObject);
        RYC ryc4 = rYq2.LIZ;
        if (ryc4 == null || (cert = ryc4.LIZIZ) == null) {
            str3 = null;
        } else {
            str3 = cert.certToken();
        }
        jSONObject4.put("certToken", str3);
        RYC ryc5 = rYq2.LIZ;
        if (ryc5 != null) {
            num2 = ryc5.LJ;
        } else {
            num2 = null;
        }
        jSONObject4.put("entryCategory", num2);
        RYC ryc6 = rYq2.LIZ;
        if (ryc6 != null) {
            str4 = ryc6.LIZJ;
        } else {
            str4 = null;
        }
        jSONObject4.put("entryToken", str4);
        jSONObject4.put("eventLevel", rYq2.LJFF.getValue());
        jSONObject4.put("costTime", Float.valueOf(((float) rYq2.LJ.LIZIZ.LIZ()) / 1000000.0f));
        jSONObject4.put("threadCostTime", rYq2.LJ.LIZJ.LIZ());
        jSONObject4.put("eventType", str7);
        jSONObject4.put("processName", LIZJ());
        jSONObject4.put("status", rYq2.LIZJ);
        jSONObject4.put("msg", rYq2.LIZLLL);
        RYC ryc7 = rYq2.LIZ;
        if (ryc7 == null || (strArr = ryc7.LIZLLL) == null || !LeY.LIZIZ(strArr, "contact")) {
            RYC ryc8 = rYq2.LIZ;
            if (!(ryc8 == null || (str6 = ryc8.LIZJ) == null)) {
                if (y.LIZIZ(str6, "locationSDK", false)) {
                    str5 = "bpea_event_locationSDK";
                } else if (y.LIZIZ(str6, "LiveCore", false)) {
                    str5 = "bpea_event_LiveCore";
                } else if (y.LIZIZ(str6, "camera", false)) {
                    str5 = "bpea_event_camera";
                } else if (y.LIZIZ(str6, "audio", false)) {
                    str5 = "bpea_event_microphone";
                } else if (y.LIZIZ(str6, "media", false)) {
                    str5 = "bpea_event_media";
                } else if (y.LIZIZ(str6, "permission", false)) {
                    str5 = "bpea_event_permission";
                } else if (y.LIZIZ(str6, "clipboard", false)) {
                    str5 = "bpea_event_clipboard";
                } else if (y.LIZIZ(str6, "location", false)) {
                    str5 = "bpea_event_location";
                }
            }
            str5 = "bpea_event";
        } else {
            str5 = "bpea_event_contact";
        }
        9LK.LIZ(str5, jSONObject2, jSONObject3, jSONObject4);
    }
}
