TikTok.apk(点击下载) / OXI.java


package X;

import android.os.Looper;
import com.bytedance.covode.number.Covode;
import com.ss.ugc.effectplatform.model.Effect;
import com.ss.ugc.effectplatform.model.algorithm.ExtendedUrlModel;
import com.ss.ugc.effectplatform.model.algorithm.ModelInfo;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import kotlin.g.b.m;

public final class OXI extends AbstractC62079OYy {
    public final OYD LIZ;
    public final OXQ LIZIZ;
    public final C61942OTr LIZJ;
    public final C62022OWt LIZLLL;
    public final String[] LJFF;
    public final int LJI;
    public final String LJII;

    static {
        Covode.recordClassIndex(119724);
    }

    /* JADX INFO: super call moved to the top of the method (can break code semantics) */
    public OXI(OYD oyd, OXQ oxq, C61942OTr oTr, C62022OWt oWt, String[] strArr, int i2) {
        super(null, oyd.LJJIJL);
        C21090sc.LIZ(oyd, oTr, oWt);
        this.LIZ = oyd;
        this.LIZIZ = oxq;
        this.LIZJ = oTr;
        this.LIZLLL = oWt;
        this.LJFF = strArr;
        this.LJI = i2;
        this.LJII = null;
    }

    /* JADX INFO: this call moved to the top of the method (can break code semantics) */
    public /* synthetic */ OXI(OYD oyd, OXQ oxq, C61942OTr oTr, C62022OWt oWt, String[] strArr, int i2, int i3) {
        this(oyd, oxq, oTr, oWt, (i3 & 16) != 0 ? null : strArr, (i3 & 32) != 0 ? 0 : i2);
    }

    private final Effect LIZ(ModelInfo modelInfo) {
        Effect effect = new Effect(null, null, null, null, null, null, null, null, null, null, 0, null, null, null, null, null, null, null, 0, 0, null, null, null, null, null, null, null, null, null, false, null, false, null, null, 0, null, null, 0, null, null, null, null, false, null, null, null, null, null, null, null, -1, 262143, null);
        effect.setName(modelInfo.getName());
        return effect;
    }

    private final ModelInfo LIZ(String str, int i2) {
        OXB LIZ2;
        C62012OWj<String, OXC> oWj;
        Collection<OXC> LIZ3;
        try {
            OXQ oxq = this.LIZIZ;
            if (!(oxq == null || (LIZ2 = oxq.LIZ(i2, false)) == null || (oWj = LIZ2.LIZ) == null || (LIZ3 = oWj.LIZ()) == null)) {
                for (OXC oxc : LIZ3) {
                    if (m.LIZ((Object) oxc.LIZ.getName(), (Object) str)) {
                        return oxc.LIZ;
                    }
                }
            }
        } catch (Exception e) {
            C62145Oac.LIZ.LIZ("effect_platform", "exception happens in getLatestModelInfo", e);
        }
        return null;
    }

    private final void LIZ(Effect effect, ModelInfo modelInfo, Exception exc) {
        List<String> url_list;
        C62049OXu oXu = new C62049OXu(exc);
        ExtendedUrlModel file_url = modelInfo.getFile_url();
        String str = null;
        boolean z = true;
        if (!(file_url == null || (url_list = file_url.getUrl_list()) == null || !(!url_list.isEmpty()) || url_list == null)) {
            str = url_list.get(0);
        }
        V v = this.LIZ.LJIJ.LIZ;
        if (v != null) {
            OYD oyd = this.LIZ;
            String name = modelInfo.getName();
            String version = modelInfo.getVersion();
            String oy5 = this.LIZ.LJJIIJZLJL.toString();
            C23760wv[] r5 = new C23760wv[2];
            r5[0] = C23820x1.LIZ("error_code", Integer.valueOf(oXu.LIZ));
            if (str == null) {
                str = "";
            }
            r5[1] = C23820x1.LIZ("download_url", str);
            Map LIZ2 = AnonymousClass1YE.LIZ(r5);
            String message = exc.getMessage();
            if (message != null && !AnonymousClass1ZS.LIZ((CharSequence) message)) {
                z = false;
            }
            C62038OXj.LIZ(v, false, oyd, name, version, oy5, LIZ2, z ? C23370wI.LIZ.LIZIZ(exc.getClass()).LIZJ() : exc.getMessage());
        }
        OXL oxl = this.LIZ.LJJIJ;
        if (oxl != null) {
            oxl.onModelDownloadError(effect, modelInfo, exc);
        }
    }

    private final void LIZ(ModelInfo modelInfo, Exception exc) {
        C62145Oac.LIZ.LIZ("effect_platform", "model::" + modelInfo.getName() + ",info.getVersion() = " + modelInfo.getVersion() + ", size = " + String.valueOf(modelInfo.getType()) + " download failure", exc);
        C62025OWw LIZ2 = this.LIZLLL.LIZ(modelInfo.getName());
        if (LIZ2 == null) {
            throw exc;
        } else if (LIZ2 != null) {
            C62026OWx oWx = C62026OWx.LIZ;
            String LIZIZ2 = LIZ2.LIZIZ();
            if (LIZIZ2 == null) {
                m.LIZ();
            }
            if (!oWx.LIZ(LIZIZ2, modelInfo.getVersion())) {
                throw exc;
            }
        }
    }

    private final void LIZ(ArrayList<ModelInfo> arrayList) {
        Exception e;
        if (C39881hp.LIZ.LIZ(this.LIZ.LJJIIJ) || !(!arrayList.isEmpty())) {
            Iterator<ModelInfo> it = arrayList.iterator();
            while (it.hasNext()) {
                ModelInfo next = it.next();
                C62145Oac.LIZ.LIZ("effect_platform", "download model: " + next.getName() + ", version: " + next.getVersion());
                OXJ LIZ2 = OXJ.LIZIZ.LIZ();
                try {
                    OXL oxl = this.LIZ.LJJIJ;
                    if (oxl != null) {
                        m.LIZ((Object) next, "");
                        oxl.onModelDownloadStart(LIZ(next), next);
                    }
                    long LIZ3 = OXM.LIZ.LIZ();
                    m.LIZ((Object) next, "");
                    OY5 oy5 = this.LIZ.LJJIIJZLJL;
                    V v = this.LIZ.LJIIZILJ.LIZ;
                    long LIZ4 = v == null ? 0 : new C62048OXt(this.LIZLLL, v).LIZ(next, oy5);
                    if (LIZ4 > 0) {
                        Effect LIZ5 = LIZ(next);
                        long j = LIZ4 / ((long) OXO.LIZ);
                        C62145Oac.LIZ.LIZ("effect_platform", "model::" + next.getName() + ",version = " + next.getVersion() + ",size = " + String.valueOf(next.getType()) + " download success!");
                        next.setTotalSize(j / ((long) OXO.LIZ));
                        long LIZ6 = OXM.LIZ.LIZ() - LIZ3;
                        V v2 = this.LIZ.LJIJ.LIZ;
                        if (v2 != null) {
                            OYD oyd = this.LIZ;
                            String name = next.getName();
                            String version = next.getVersion();
                            String oy52 = this.LIZ.LJJIIJZLJL.toString();
                            C23760wv[] r10 = new C23760wv[2];
                            r10[0] = C23820x1.LIZ("size", Long.valueOf(j));
                            try {
                                r10[1] = C23820x1.LIZ("duration", Long.valueOf(LIZ6));
                                C62038OXj.LIZ(v2, true, oyd, name, version, oy52, AnonymousClass1YE.LIZ(r10), "");
                            } catch (Exception e2) {
                                e = e2;
                                m.LIZ((Object) next, "");
                                LIZ(LIZ(next), next, e);
                                LIZ(next, e);
                            }
                        }
                        OXL oxl2 = this.LIZ.LJJIJ;
                        if (oxl2 != null) {
                            oxl2.onModelDownloadSuccess(LIZ5, next, LIZ2.LIZ());
                        }
                        C21090sc.LIZ(next);
                        if (EnumC60611Nqy.ANDROID != EnumC60611Nqy.PC) {
                            String name2 = next.getName();
                            C62025OWw LIZ7 = C62025OWw.LJ.LIZ("");
                            LIZ7.LIZ(name2);
                            String LIZ8 = C62023OWu.LIZ(next);
                            if (LIZ8 == null) {
                                LIZ8 = "";
                            }
                            C21090sc.LIZ(LIZ8);
                            LIZ7.LIZ = LIZ8;
                            LIZ7.LIZIZ = next.getType();
                            LIZ7.LIZIZ(next.getVersion());
                            LIZ7.LIZJ = false;
                            OXG oxg = new OXG(LIZ7, next);
                            C62005OWc oWc = OXF.LIZ;
                            oWc.LIZ.lock();
                            try {
                                C62145Oac.LIZ.LIZ("AlgorithmModelInfoMemoryCache", "model: " + name2 + " write in cache!");
                                OXF.LIZIZ.put(name2, oxg);
                            } finally {
                                oWc.LIZ.unlock();
                            }
                        }
                    } else {
                        RuntimeException runtimeException = new RuntimeException("download model fail, downloadFileSize = ".concat(String.valueOf(LIZ4)));
                        LIZ(LIZ(next), next, runtimeException);
                        LIZ(next, runtimeException);
                    }
                } catch (Exception e3) {
                    e = e3;
                    m.LIZ((Object) next, "");
                    LIZ(LIZ(next), next, e);
                    LIZ(next, e);
                }
            }
            return;
        }
        C62145Oac.LIZ.LIZ("effect_platform", "download " + AnonymousClass1ZP.LJIIJJI(arrayList) + " failed!, network unavailable!", null);
        throw new OXP(10011, "network unavailable");
    }

    private final boolean LIZ(String str) {
        boolean LIZ2 = this.LIZJ.LIZ(C61943OTs.LIZ("model") + str);
        if (LIZ2) {
            C62145Oac.LIZ.LIZ("effect_platform", "model: " + str + " is built in resource");
        }
        return LIZ2;
    }

    private final boolean LIZIZ(String[] strArr) {
        if (strArr == null) {
            return true;
        }
        for (String str : strArr) {
            if (!LIZ(str)) {
                return false;
            }
        }
        return true;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:9:0x004a, code lost:
        if (r0 == null) goto L_0x004c;
     */
    /* JADX WARNING: Removed duplicated region for block: B:19:0x00a2  */
    /* JADX WARNING: Removed duplicated region for block: B:54:0x01f0 A[SYNTHETIC] */
    public final ArrayList<ModelInfo> LIZ(int i2, String[] strArr, OXB oxb) {
        boolean z;
        ModelInfo modelInfo;
        OXI oxi = this;
        C21090sc.LIZ(oxb);
        ArrayList<ModelInfo> arrayList = new ArrayList<>();
        if (strArr != null) {
            int length = strArr.length;
            boolean z2 = false;
            int i3 = 0;
            while (i3 < length) {
                String str = strArr[i3];
                String LIZ2 = C62026OWx.LIZ.LIZ(str);
                ModelInfo LIZ3 = oxi.LIZ(LIZ2, i2);
                if (LIZ3 == null) {
                    C62145Oac.LIZ.LIZ("effect_platform", LIZ2 + " not exist in server");
                    OXQ oxq = oxi.LIZIZ;
                    if (oxq != null) {
                        modelInfo = oxq.LIZ(i2, LIZ2, z2);
                    } else {
                        modelInfo = null;
                    }
                    Looper mainLooper = Looper.getMainLooper();
                    m.LIZ((Object) mainLooper, "");
                    if (!m.LIZ(mainLooper.getThread(), Thread.currentThread())) {
                        C62145Oac.LIZ.LIZ("effect_platform", "fetch single model: " + LIZ2 + " from server");
                        OXQ oxq2 = oxi.LIZIZ;
                        if (oxq2 != null) {
                            modelInfo = oxq2.LIZ(i2, LIZ2);
                        }
                        C62145Oac.LIZ.LIZ("effect_platform", "model: " + LIZ2 + " fetched failed!", null);
                    }
                    if (modelInfo != null) {
                        LIZ3 = modelInfo;
                        z = true;
                        if (LIZ3 == null) {
                            String version = LIZ3.getVersion();
                            int type = LIZ3.getType();
                            if (oxi.LIZ(str)) {
                                float parseFloat = Float.parseFloat(C62026OWx.LIZ.LIZIZ(str));
                                float parseFloat2 = Float.parseFloat(version);
                                int LIZJ2 = C62026OWx.LIZ.LIZJ(str);
                                boolean z3 = Float.compare(parseFloat, parseFloat2) == 0;
                                boolean z4 = LIZJ2 == type;
                                if (z3 && z4) {
                                    i3++;
                                    oxi = this;
                                    z2 = false;
                                }
                            }
                            C62025OWw LIZ4 = oxi.LIZLLL.LIZ(LIZ2);
                            if (LIZ4 == null) {
                                C62145Oac.LIZ.LIZ("effect_platform", "local model is null with name: ".concat(String.valueOf(LIZ2)));
                            }
                            if (LIZ4 != null) {
                                if (!C21560tN.LIZ.LIZ(LIZ4.LIZIZ(), LIZ3.getVersion())) {
                                    C62145Oac.LIZ.LIZ("effect_platform", "model " + LIZ4.LIZ() + " version not equals, local model version:" + LIZ4.LIZIZ() + ", lastest model: " + LIZ3.getVersion());
                                } else if (LIZ4.LIZJ() != LIZ3.getType()) {
                                    C62145Oac.LIZ.LIZ("effect_platform", "model " + LIZ4.LIZ() + " size not equals, local model size:" + LIZ4.LIZJ() + ", lastest model: " + LIZ3.getType());
                                } else if (!C21560tN.LIZ.LIZ(LIZ4.LIZLLL(), C62023OWu.LIZ(LIZ3))) {
                                    C62145Oac.LIZ.LIZ("effect_platform", "model " + LIZ4.LIZ() + " md5 not equals, local model size:" + LIZ4.LIZLLL() + ", lastest model: " + C62023OWu.LIZ(LIZ3));
                                } else {
                                    i3++;
                                    oxi = this;
                                    z2 = false;
                                }
                            }
                            ExtendedUrlModel file_url = z ? LIZ3.getFile_url() : oxb.LIZ(LIZ2);
                            ModelInfo modelInfo2 = new ModelInfo(null, null, null, null, 0, 0, 0, 127, null);
                            modelInfo2.setName(LIZ2);
                            modelInfo2.setVersion(version);
                            modelInfo2.setFile_url(file_url);
                            modelInfo2.setType(type);
                            arrayList.add(modelInfo2);
                            i3++;
                            oxi = this;
                            z2 = false;
                        } else {
                            throw new RuntimeException("model: " + LIZ2 + " not exist in server");
                        }
                    }
                    C62145Oac.LIZ.LIZ("effect_platform", "model: " + LIZ2 + " fetched failed!", null);
                }
                z = false;
                if (LIZ3 == null) {
                }
            }
        }
        return arrayList;
    }

    public final List<C62025OWw> LIZ(String[] strArr) {
        if (strArr == null || strArr.length == 0) {
            return new ArrayList();
        }
        ArrayList arrayList = new ArrayList();
        for (String str : strArr) {
            C62025OWw LIZ2 = this.LIZLLL.LIZ(C62026OWx.LIZ.LIZ(str));
            if (LIZ2 != null) {
                arrayList.add(LIZ2);
            } else if (LIZ(str)) {
                C62024OWv oWv = C62025OWw.LJ;
                String str2 = C61943OTs.LIZ("model") + str;
                C21090sc.LIZ(str2);
                C62025OWw LIZ3 = oWv.LIZ("file:///android_asset://".concat(String.valueOf(str2)));
                String LIZIZ2 = C62026OWx.LIZ.LIZIZ(str);
                int LIZJ2 = C62026OWx.LIZ.LIZJ(str);
                LIZ3.LIZIZ(LIZIZ2);
                LIZ3.LIZIZ = LIZJ2;
                arrayList.add(LIZ3);
            }
        }
        return arrayList;
    }

    @Override // X.AbstractC62079OYy
    public final void LIZ() {
        OXB LIZ2;
        String[] strArr = this.LJFF;
        if (strArr != null) {
            C62005OWc oWc = OXN.LIZ;
            oWc.LIZ.lock();
            try {
                int i2 = this.LJI;
                OXQ oxq = this.LIZIZ;
                if (oxq == null || (LIZ2 = oxq.LIZ(i2, true)) == null) {
                    throw new RuntimeException("model list with " + i2 + " not found!");
                }
                LIZ(LIZ(i2, strArr, LIZ2));
                oWc.LIZ.unlock();
            } catch (Exception e) {
                C62145Oac.LIZ.LIZ("effect_platform", "fetchModels: " + AnonymousClass1YG.LJIIIZ(strArr) + " exception happens!", e);
                if (!LIZIZ(strArr)) {
                    throw e;
                }
            } catch (Throwable th) {
                oWc.LIZ.unlock();
                throw th;
            }
        }
    }

    @Override // X.AbstractC62079OYy
    public final void LIZIZ() {
    }
}