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

import X.7Vp;
import X.7Vq;
import X.7he;
import X.7lW;
import X.7xc;
import X.8Ve;
import X.8YD;
import X.8Zd;
import X.8Ze;
import X.8e1;
import X.8e2;
import X.8eG;
import X.8eL;
import X.8ec;
import X.8lV;
import X.95p;
import X.95w;
import X.9EZ;
import X.9Ft;
import X.9Fx;
import X.9NO;
import X.9Ng;
import X.9Pr;
import X.9Y3;
import X.9bv;
import X.C1165Rdh;
import X.C1169Rdl;
import X.C1171Rdn;
import X.C1174Rdq;
import X.C1175Rdr;
import X.C1178Rdu;
import X.C1181Rdx;
import X.C1182Rdy;
import X.C1183Rdz;
import X.C1195ReB;
import X.C1218ReY;
import X.C1232Rem;
import X.Crj;
import X.Jrq;
import X.M12;
import X.MEB;
import X.MEC;
import X.Qx3;
import X.RU7;
import X.RU9;
import android.app.Application;
import android.content.Context;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import com.bytedance.covode.number.Covode;
import java.util.List;
import kotlin.h.b.n;

public final class ScalpelTask implements 8Ze {
    public static long LIZ;
    public static final C1195ReB LIZIZ = new C1195ReB((byte) 0);
    public final Crj LIZJ = 7he.LIZ(9EZ.LIZ);

    static {
        Covode.recordClassIndex(90598);
    }

    private final boolean LIZ() {
        return ((Boolean) this.LIZJ.getValue()).booleanValue();
    }

    public final boolean meetTrigger() {
        return true;
    }

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

    public final boolean serialExecute() {
        return false;
    }

    public final int targetProcess() {
        return 1;
    }

    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 static Context LIZ(Context context) {
        Context applicationContext = context.getApplicationContext();
        if (7lW.LIZJ && applicationContext == null) {
            return 7lW.LIZ;
        }
        return applicationContext;
    }

    public final void run(Context context) {
        C1165Rdh rdh;
        Application application;
        8Ve.LIZ.LIZ();
        if (LIZ() && 9Y3.LIZ(9Y3.LIZ(), true, "scalpel_enable_collecting", false)) {
            Application application2 = null;
            if (context != null && MEC.LIZ.LIZ()) {
                Context LIZ2 = LIZ(context);
                if (!(LIZ2 instanceof Application)) {
                    LIZ2 = null;
                }
                Application application3 = (Application) LIZ2;
                if (application3 != null) {
                    C1178Rdu rdu = new C1178Rdu();
                    rdu.LIZ = true;
                    rdu.LIZIZ = true;
                    rdu.LIZJ = true;
                    8e1 LIZ3 = 8e2.LIZ(8eG.FIXED);
                    LIZ3.LIZJ = 1;
                    LIZ3.LIZIZ = "scalpel_scene_thread";
                    rdu.LIZLLL = 8eL.LIZ(LIZ3.LIZ());
                    M12.LIZ(application3);
                    if (!C1181Rdx.LIZLLL) {
                        C1181Rdx.LJ = new C1183Rdz();
                        C1181Rdx.LIZJ = application3;
                        C1181Rdx.LJFF = new C1182Rdy();
                        Application application4 = C1181Rdx.LIZJ;
                        if (application4 != null) {
                            application4.registerActivityLifecycleCallbacks(C1181Rdx.LJFF);
                        }
                        C1181Rdx.LIZIZ = rdu;
                        C1181Rdx.LIZLLL = true;
                    }
                }
            }
            HandlerThread handlerThread = new HandlerThread("Scalpel");
            handlerThread.start();
            if (context == null) {
                n.LIZIZ();
            }
            Looper looper = handlerThread.getLooper();
            n.LIZIZ(looper, "");
            9bv r2 = new 9bv(context, looper);
            M12.LIZ(r2);
            if (!C1171Rdn.LIZLLL) {
                95w.LIZIZ = System.currentTimeMillis();
                C1171Rdn.LIZLLL = true;
                C1171Rdn.LIZIZ = r2;
                if (r2.LIZ().LIZJ() != null) {
                    C1232Rem rem = C1171Rdn.LIZIZ;
                    if (rem == null) {
                        n.LIZIZ();
                    }
                    Looper LIZJ2 = rem.LIZ().LIZJ();
                    if (LIZJ2 == null) {
                        n.LIZIZ();
                    }
                    Handler handler = new Handler(LIZJ2);
                    M12.LIZ(handler);
                    Jrq.LIZIZ = handler;
                }
                C1171Rdn.LIZJ.LIZ(r2);
                C1232Rem rem2 = C1171Rdn.LIZIZ;
                if (rem2 == null) {
                    n.LIZIZ();
                }
                C1171Rdn.LJ = new C1165Rdh(rem2.LIZ().LIZ(), Jrq.LIZ.LIZ());
                C1232Rem rem3 = C1171Rdn.LIZIZ;
                if (rem3 == null) {
                    n.LIZIZ();
                }
                Object applicationContext = rem3.LIZ().LIZ().getApplicationContext();
                if (7lW.LIZJ && applicationContext == null) {
                    applicationContext = 7lW.LIZ;
                }
                if ((applicationContext instanceof Application) && (application = (Application) applicationContext) != null) {
                    application.registerActivityLifecycleCallbacks(new C1175Rdr());
                }
                new Handler(Looper.getMainLooper()).postDelayed(95p.LIZ, 20000);
            }
            if (C1171Rdn.LIZLLL && (rdh = C1171Rdn.LJ) != null) {
                rdh.LIZIZ.postDelayed(new C1169Rdl(rdh), Qx3.LIZ(0, 45000));
                boolean LIZ4 = 7xc.LIZ(context);
                if (rdh.LIZJ == null) {
                    rdh.LIZJ = new 8lV(rdh.LIZ, LIZ4);
                }
                8lV r0 = rdh.LIZJ;
                if (r0 != null) {
                    r0.LIZ();
                }
            }
            if (context != null && MEB.LIZ.LIZ()) {
                9Pr.LIZ = true;
                7Vp LIZ5 = 7Vq.LIZIZ.LIZ();
                if (!9NO.LJ && LIZ()) {
                    9Ng.LIZ(true, 100, false);
                }
                RU9 ru9 = RU9.LIZ;
                C1174Rdq rdq = new C1174Rdq();
                Context LIZ6 = LIZ(context);
                if (LIZ6 instanceof Application) {
                    application2 = LIZ6;
                }
                rdq.LIZ = application2;
                rdq.LIZIZ = 8YD.LIZJ.LIZ(false);
                rdq.LIZJ = true;
                rdq.LJI = new RU7();
                rdq.LIZLLL = LIZ5.LIZ;
                rdq.LJ = LIZ5.LIZIZ;
                rdq.LJFF = new C1218ReY(context, LIZ5);
                ru9.LIZ(rdq);
            }
        }
    }
}
