package com.ss.android.ugc.aweme.dmt_integration;

import X.0HH;
import X.2Pr;
import X.3X3;
import X.54Y;
import X.54a;
import X.5E9;
import X.5eS;
import X.5et;
import X.5fX;
import X.6Oa;
import X.6Zq;
import X.6aQ;
import X.6aR;
import X.6ld;
import X.6m1;
import X.6ma;
import X.6nr;
import X.6o6;
import X.6o7;
import X.6tB;
import X.74z;
import X.77r;
import X.7DE;
import X.7lW;
import X.7v5;
import X.7wQ;
import X.9Y3;
import X.C0690Mdh;
import X.C1381Moq;
import X.C1415MpO;
import X.C1627Mso;
import X.C2245N6q;
import X.C2959NYc;
import X.C3689Nky;
import X.C3936Nox;
import X.C3938Noz;
import X.C4157NsW;
import X.C4158NsX;
import X.C4159NsY;
import X.C4160NsZ;
import X.C4164Nsd;
import X.C4165Nse;
import X.C4167Nsg;
import X.C4169Nsi;
import X.C4170Nsj;
import X.C4171Nsk;
import X.C4173Nsm;
import X.C4174Nsn;
import X.C4183Nsw;
import X.C4184Nsx;
import X.C4185Nsy;
import X.C4188Nt1;
import X.C4191Nt4;
import X.C4195Nt8;
import X.C4196Nt9;
import X.C4209NtM;
import X.C4212NtP;
import X.C4213NtQ;
import X.C4222NtZ;
import X.C4589NzU;
import X.C4719O3u;
import X.C4723O3y;
import X.C6221Oki;
import X.FII;
import X.FUO;
import X.FWb;
import X.Foc;
import X.HF6;
import X.ILk;
import X.Lnj;
import X.Ls2;
import X.LsC;
import X.M12;
import X.MGK;
import X.MKR;
import X.MR5;
import X.NCR;
import X.NKV;
import X.NKW;
import X.NLV;
import X.NUY;
import X.OEY;
import X.POW;
import X.RXb;
import X.TSt;
import X.TnA;
import X.Tnh;
import android.app.Application;
import android.graphics.Typeface;
import android.os.Looper;
import android.util.Log;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.keva.Keva;
import com.google.gson.Gson;
import com.ss.android.ugc.aweme.framework.services.ServiceManager;
import com.ss.android.ugc.aweme.modeo.IModeoInit;
import com.ss.android.ugc.aweme.out.AVExternalServiceImpl;
import com.ss.android.ugc.aweme.services.IAVInitializer;
import com.ss.android.ugc.aweme.services.storage.AVStorageManagerImpl;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList;
import org.json.JSONException;
import org.json.JSONObject;

public class AVInitializerImpl implements IAVInitializer {
    public static boolean LIZ;
    public boolean LIZIZ;

    static {
        Covode.recordClassIndex(66217);
    }

    public void updateAB() {
        Keva.getRepo("ab_repo_cold_boot").storeInt("creative_tools_album_opti_2021_10", 9Y3.LIZ(9Y3.LIZ(), true, "creative_tools_album_opti_2021_10", 0));
    }

    public static IAVInitializer LIZ() {
        MethodCollector.i(3470);
        IAVInitializer iAVInitializer = (IAVInitializer) Lnj.LIZ(IAVInitializer.class, false);
        if (iAVInitializer != null) {
            MethodCollector.o(3470);
            return iAVInitializer;
        }
        Object LIZIZ2 = Lnj.LIZIZ(IAVInitializer.class, false);
        if (LIZIZ2 != null) {
            IAVInitializer iAVInitializer2 = (IAVInitializer) LIZIZ2;
            MethodCollector.o(3470);
            return iAVInitializer2;
        }
        if (Lnj.LLJI == null) {
            synchronized (IAVInitializer.class) {
                try {
                    if (Lnj.LLJI == null) {
                        Lnj.LLJI = new AVInitializerImpl();
                    }
                } catch (Throwable th) {
                    MethodCollector.o(3470);
                    throw th;
                }
            }
        }
        AVInitializerImpl aVInitializerImpl = (AVInitializerImpl) Lnj.LLJI;
        MethodCollector.o(3470);
        return aVInitializerImpl;
    }

    public void initAVEnv(Application application) {
        if (!this.LIZIZ) {
            74z.LIZ(application);
            7DE r0 = new 7DE(application);
            M12.LIZ(r0);
            FWb.LIZ = r0;
            C4222NtZ ntZ = new C4222NtZ();
            POW.LIZ(ntZ);
            6ma.LIZ = ntZ;
            this.LIZIZ = true;
        }
    }

    public void initMonitor(Application application) {
        C4213NtQ ntQ = NCR.LIZ;
        Objects.requireNonNull(application, "CreativeActivityMonitor: can't init with null application!");
        if (Looper.myLooper() != Looper.getMainLooper()) {
            throw new IllegalStateException("CreativeActivityMonitor: init must call in main thread!");
        } else if (!ntQ.LJ) {
            application.registerActivityLifecycleCallbacks(new C4212NtP(ntQ));
            ntQ.LJ = true;
        }
    }

    public void initialize(Application application) {
        int openAlbumOptiGroup;
        boolean z;
        5fX LIZ2;
        LsC<NUY, 2Pr> LIZJ;
        Foc LIZLLL;
        initAVEnv(application);
        if (RXb.LJFF.LIZJ()) {
            5E9.LIZ.LIZIZ();
        } else {
            FWb.LIZIZ.LIZ();
        }
        if (RXb.LJFF.LIZJ()) {
            openAlbumOptiGroup = Keva.getRepo("ab_repo_cold_boot").getInt("creative_tools_album_opti_2021_10", 0);
        } else {
            openAlbumOptiGroup = MR5.LIZ.getOpenAlbumOptiGroup();
        }
        if (openAlbumOptiGroup != 0) {
            z = true;
        } else {
            z = false;
        }
        C4723O3y.LIZ = z;
        C4719O3u.LIZLLL = C4191Nt4.LIZ;
        C4719O3u.LIZJ = new C4589NzU() {
            static {
                Covode.recordClassIndex(66218);
            }

            public final void LIZ(int i, String str) {
                6Zq.LIZIZ("FileAdapterAndroidR code:" + i + ", msg:" + str);
                TSt.LIZ("FileAdapterAndroidR code:" + i + ", msg:" + str + ", trace:" + Log.getStackTraceString(new Throwable()));
            }
        };
        6Oa r0 = new 6Oa();
        M12.LIZ(r0);
        C2959NYc.LIZ = r0;
        77r r02 = new 77r();
        M12.LIZ(r02);
        NLV.LIZ = r02;
        OEY oey = new OEY();
        M12.LIZ(oey);
        C3689Nky.LIZ = oey;
        if (!((Boolean) TnA.LIZ.getValue()).booleanValue()) {
            FWb.LIZIZ.LIZ().LJIIIIZZ().LIZ(new AVStorageManagerImpl());
        }
        LIZ = true;
        C4173Nsm nsm = new C4173Nsm(FWb.LIZIZ.LIZ());
        M12.LIZ(nsm);
        C4169Nsi nsi = C4171Nsk.LIZIZ;
        M12.LIZ(nsm);
        nsi.LIZ = nsm;
        C4165Nse nse = new C4165Nse(this);
        M12.LIZ(nse);
        C4164Nsd nsd = C4171Nsk.LIZJ;
        M12.LIZ(nse);
        nsd.LIZ = nse;
        LsC<? super NKW, 2Pr> lsC = NKV.LIZ;
        M12.LIZ(lsC);
        C4174Nsn nsn = C4171Nsk.LIZLLL;
        M12.LIZ(lsC);
        nsn.LIZ = lsC;
        LsC<? super 6o7, 2Pr> lsC2 = 6o6.LIZ;
        M12.LIZ(lsC2);
        C4170Nsj nsj = C4171Nsk.LJ;
        M12.LIZ(lsC2);
        nsj.LIZLLL = lsC2;
        boolean booleanValue = ((Boolean) 7v5.LIZ.getValue()).booleanValue();
        if (C4171Nsk.LIZ.compareAndSet(false, true)) {
            C4169Nsi nsi2 = C4171Nsk.LIZIZ;
            M12.LIZ(nsi2);
            C4167Nsg.LJII = nsi2;
            C4719O3u.LJ = C4185Nsy.LIZ;
            if (!booleanValue) {
                Application LIZ3 = nsi2.LIZ();
                if (LIZ3 != null) {
                    C4167Nsg.LIZIZ.LIZ(C4167Nsg.LJIIIZ, C4167Nsg.LIZ[0], LIZ3);
                    C4719O3u.LIZIZ.LIZ(C4719O3u.LJFF, C4719O3u.LIZ[0], LIZ3);
                }
                Boolean LIZJ2 = nsi2.LIZJ();
                if (LIZJ2 != null) {
                    boolean booleanValue2 = LIZJ2.booleanValue();
                    C4167Nsg.LIZJ.LIZ(C4167Nsg.LJIIIZ, C4167Nsg.LIZ[1], Boolean.valueOf(booleanValue2));
                }
                Gson LJ = nsi2.LJ();
                if (LJ != null) {
                    C4167Nsg.LIZLLL.LIZ(C4167Nsg.LJIIIZ, C4167Nsg.LIZ[2], LJ);
                }
                5et LJFF = nsi2.LJFF();
                if (LJFF != null) {
                    C4167Nsg.LJ.LIZ(C4167Nsg.LJIIIZ, C4167Nsg.LIZ[3], LJFF);
                }
                C2245N6q LJI = nsi2.LJI();
                if (LJI != null) {
                    C4167Nsg.LJFF.LIZ(C4167Nsg.LJIIIZ, C4167Nsg.LIZ[4], LJI);
                }
            }
            M12.LIZ(nsi2);
            C4159NsY.LIZIZ = nsi2;
            if (!booleanValue && (LIZLLL = nsi2.LIZLLL()) != null) {
                C4159NsY.LIZ.LIZ(C4159NsY.LIZJ, C4160NsZ.LIZ[0], LIZLLL);
            }
            C4164Nsd nsd2 = C4171Nsk.LIZJ;
            M12.LIZ(nsd2);
            C4158NsX.LIZLLL = nsd2;
            if (!booleanValue) {
                Ls2<Typeface> LIZ4 = nsd2.LIZ();
                if (LIZ4 != null) {
                    C4158NsX.LIZJ.LIZ(C4158NsX.LJ, C4158NsX.LIZ[1], LIZ4);
                }
                C4157NsW LIZIZ2 = nsd2.LIZIZ();
                if (LIZIZ2 != null) {
                    C4158NsX.LIZIZ.LIZ(C4158NsX.LJ, C4158NsX.LIZ[0], LIZIZ2);
                }
            }
            M12.LIZ(nsd2);
            NUY.LJIIL = nsd2;
            if (!booleanValue && NUY.LJIILIIL.compareAndSet(false, true) && (LIZJ = nsd2.LIZJ()) != null) {
                LIZJ.invoke(NUY.LJIILJJIL.LIZ());
            }
            C4174Nsn nsn2 = C4171Nsk.LIZLLL;
            M12.LIZ(nsn2);
            C4167Nsg.LJIIIIZZ = nsn2;
            if (!booleanValue && (LIZ2 = nsn2.LIZ()) != null) {
                C4167Nsg.LJI.LIZ(C4167Nsg.LJIIIZ, C4167Nsg.LIZ[5], LIZ2);
            }
            C4170Nsj nsj2 = C4171Nsk.LJ;
            if (booleanValue) {
                3X3.LIZ.LIZ(new C4183Nsw(nsj2));
                7wQ.LIZ.LIZ(new C4184Nsx(nsj2));
            } else {
                LsC<6nr, 2Pr> LIZ5 = nsj2.LIZ();
                if (LIZ5 != null) {
                    LIZ5.invoke(3X3.LIZ);
                }
                LsC<6nr, 2Pr> LIZIZ3 = nsj2.LIZIZ();
                if (LIZIZ3 != null) {
                    LIZIZ3.invoke(7wQ.LIZ);
                }
            }
            nsj2.LIZJ();
            LsC<? super 6aR, 2Pr> lsC3 = nsj2.LIZJ;
            if (lsC3 != null) {
                lsC3.invoke(6aQ.LIZ);
            }
        }
        C4209NtM.LIZLLL = new 2(this);
        M12.LIZ(application);
        C4196Nt9 nt9 = 5eS.LIZ;
        if (!nt9.LIZJ) {
            nt9.LIZIZ = new CopyOnWriteArrayList();
            Object applicationContext = application.getApplicationContext();
            if (7lW.LIZJ && applicationContext == null) {
                applicationContext = 7lW.LIZ;
            }
            ((Application) applicationContext).registerActivityLifecycleCallbacks(new C4195Nt8(nt9));
            nt9.LIZJ = true;
        }
        5eS.LIZ.LIZ(new C4188Nt1());
        54Y.LIZ = new 54a() {
            static {
                Covode.recordClassIndex(66220);
            }

            public final void LIZ(boolean z, String str, double d) {
                String str2;
                JSONObject jSONObject = new JSONObject();
                try {
                    jSONObject.put("duration", d);
                } catch (JSONException e) {
                    0HH.LIZ(e);
                }
                6tB r2 = new 6tB();
                r2.LIZ("methodName", str);
                if (z) {
                    str2 = "yes";
                } else {
                    str2 = "no";
                }
                r2.LIZ("is_nle", str2);
                C1415MpO.LIZ("nle_method_cost", jSONObject, r2.LIZ());
            }
        };
        if (MKR.LIZ() || MKR.LIZIZ()) {
            ILk.LIZJ.LIZ(application).LIZIZ(1);
        } else {
            ILk.LIZJ.LIZ(application).LIZIZ(0);
        }
        C0690Mdh.LIZ = ((Boolean) C6221Oki.LIZ.getValue()).booleanValue();
        C0690Mdh.LIZIZ = ((Boolean) C6221Oki.LIZIZ.getValue()).booleanValue();
        ((IModeoInit) ServiceManager.get().getService(IModeoInit.class)).initModeoEnv(application);
        C3938Noz noz = C3938Noz.LIZ;
        M12.LIZ(noz);
        C3936Nox.LIZ = noz;
        FII fii = FII.LIZ;
        M12.LIZ(fii);
        C1381Moq.LIZ = fii;
        MGK mgk = MGK.LIZ;
        M12.LIZ(mgk);
        C1627Mso.LIZ = mgk;
        FUO fuo = FUO.LIZ;
        M12.LIZ(fuo);
        HF6.LIZ = fuo;
        6ld r1 = new 6ld();
        M12.LIZ(r1);
        6m1.LIZ.remove(r1);
        6m1.LIZ.add(r1);
        if (((Boolean) Tnh.LJIIJJI.getValue()).booleanValue()) {
            AVExternalServiceImpl.LIZ().specialPlusService().isNeedShowSpecialPlusDirect();
        }
    }
}
