package com.ss.android.ugc.aweme.video.preload;

import X.AnonymousClass7R6;
import X.AnonymousClass7UR;
import X.AnonymousClass7dR;
import X.AnonymousClass7dW;
import X.AnonymousClass7e2;
import X.AnonymousClass8BE;
import X.AnonymousClass8BG;
import X.AnonymousClass8BK;
import X.AnonymousClass8BN;
import X.AnonymousClass8N3;
import X.AnonymousClass8NQ;
import X.AnonymousClass8NS;
import X.AnonymousClass8PM;
import X.AnonymousClass8U2;
import X.AnonymousClass8U3;
import X.AnonymousClass8U6;
import X.AnonymousClass8UC;
import X.C02697ac;
import X.C16248Bj;
import X.C16758Di;
import X.C20598Sc;
import X.C20958Tm;
import X.C20968Tn;
import X.C21008Tr;
import X.C21058Tw;
import android.os.Handler;
import android.os.HandlerThread;
import android.text.TextUtils;
import android.util.LruCache;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import java.io.File;
import java.util.List;
import java.util.Map;

public class VideoPreloadManagerV2 implements AnonymousClass8BG {
    public int LIZ;
    public Map<String, String> LIZIZ;
    public String LIZJ;
    public LruCache<String, Long> LIZLLL = new LruCache<>(1048576);
    public boolean LJ;
    public String LJFF = null;
    public String LJI = null;
    public String LJII = null;
    public String LJIIIIZZ = null;
    public String LJIIIZ = null;
    public String LJIIJ = null;
    public C20958Tm LJIIJJI;
    public final IVideoPreloadConfig LJIIL = AnonymousClass8BE.LIZ.LIZ();
    public AnonymousClass8UC LJIILIIL;
    public Handler LJIILJJIL;

    static {
        Covode.recordClassIndex(122872);
    }

    public final boolean LIZ(C16758Di r2, int i) {
        return AnonymousClass8BN.LIZ(this, r2, i);
    }

    public final boolean LIZ(C16758Di r2, int i, AnonymousClass8PM r4) {
        return AnonymousClass8BN.LIZ(this, r2, i, r4);
    }

    public final boolean LIZ(C16758Di r2, int i, List list, int i2, List list2, int i3) {
        return AnonymousClass8BN.LIZ(this, r2, i, list, i2, list2, i3);
    }

    public final boolean LIZIZ(C16758Di r2, int i, AnonymousClass8PM r4) {
        return AnonymousClass8BN.LIZIZ(this, r2, i, r4);
    }

    public final int LJIIJ(C16758Di r2) {
        return AnonymousClass8BN.LIZ(this, r2);
    }

    public final boolean LJIIJJI(C16758Di r2) {
        return AnonymousClass8BN.LIZIZ(this, r2);
    }

    public final boolean LIZ() {
        MethodCollector.i(8590);
        if (LIZIZ().isInited()) {
            MethodCollector.o(8590);
            return true;
        }
        synchronized (this) {
            try {
                if (LIZIZ().isInited()) {
                    return true;
                }
                LIZIZ().checkInit();
                LIZ((AnonymousClass8U6) new AnonymousClass8U6() {
                    static {
                        Covode.recordClassIndex(122873);
                    }

                    public final boolean LIZ() {
                        if (VideoPreloadManagerV2.this.LIZIZ != null) {
                            VideoPreloadManagerV2.this.LIZIZ().updateDnsBackupIpMap(VideoPreloadManagerV2.this.LIZIZ);
                        }
                        if (VideoPreloadManagerV2.this.LIZ > 0) {
                            VideoPreloadManagerV2.this.LIZIZ().setConcurrentNum(VideoPreloadManagerV2.this.LIZ);
                        }
                        if (!TextUtils.isEmpty(VideoPreloadManagerV2.this.LJFF)) {
                            VideoPreloadManagerV2.this.LIZIZ().setSmartPreloadAlgorithmJson(VideoPreloadManagerV2.this.LJFF);
                        }
                        if (!TextUtils.isEmpty(VideoPreloadManagerV2.this.LJI)) {
                            VideoPreloadManagerV2.this.LIZIZ().smartPreloadBusinessEvent(VideoPreloadManagerV2.this.LJI);
                        }
                        if (!TextUtils.isEmpty(VideoPreloadManagerV2.this.LJII)) {
                            VideoPreloadManagerV2.this.LIZIZ().setSmartPreloadPlayTaskAlgorithmJson(VideoPreloadManagerV2.this.LJII);
                        }
                        if (!TextUtils.isEmpty(VideoPreloadManagerV2.this.LJIIIIZZ)) {
                            VideoPreloadManagerV2.this.LIZIZ().smartPreloadPlayTaskBusinessEvent(VideoPreloadManagerV2.this.LJIIIIZZ);
                        }
                        if (!TextUtils.isEmpty(VideoPreloadManagerV2.this.LJIIIZ)) {
                            VideoPreloadManagerV2.this.LIZIZ().setTimelinessAlgorithmJson(VideoPreloadManagerV2.this.LJIIIZ);
                        }
                        if (!TextUtils.isEmpty(VideoPreloadManagerV2.this.LJIIJ)) {
                            VideoPreloadManagerV2.this.LIZIZ().smartTimelinessPreloadBusinessEvent(VideoPreloadManagerV2.this.LJIIJ);
                        }
                        VideoPreloadManagerV2.this.LIZIZ().updateAppState(VideoPreloadManagerV2.this.LJ);
                        return false;
                    }
                });
                MethodCollector.o(8590);
                return true;
            } finally {
                MethodCollector.o(8590);
            }
        }
    }

    public final boolean LIZ(C16758Di r3) {
        if (!LIZIZ().isInited()) {
            return false;
        }
        if (r3 != null) {
            if (r3.getHitBitrate() == null) {
                r3.setHitBitrate(AnonymousClass7dR.LIZ.LJFF(r3.getSourceId()));
            }
            if (TextUtils.isEmpty(r3.getDashVideoId())) {
                r3.setDashVideoId(AnonymousClass7dR.LIZ.LJIIIZ(r3.getSourceId()));
            }
        }
        return LIZIZ().isCache(r3);
    }

    public final boolean LIZ(C16758Di r11, int i, AnonymousClass8PM r13, AnonymousClass8BK r14, List<C16758Di> list, int i2, List<C16758Di> list2, int i3) {
        C16758Di r3 = r11;
        if (!AnonymousClass7e2.LIZ((C16248Bj) r3) || !LIZIZ().isInited()) {
            return false;
        }
        int i4 = i;
        AnonymousClass8PM r4 = r13;
        AnonymousClass8BK r5 = r14;
        return LIZ((AnonymousClass8U6) new C20968Tn(this, i4, r3, r4, r5, list, i2, list2, i3));
    }

    public final C20958Tm LJFF() {
        return LIZIZ();
    }

    public final String LJI() {
        return LIZIZ().getNetworkLibName();
    }

    public final boolean LJII() {
        return LIZIZ().supportPreloadObservable();
    }

    public final int LJIIIIZZ() {
        if (this.LJIIJJI != null) {
            return LIZIZ().startMethodHook();
        }
        return -1;
    }

    private synchronized AnonymousClass8UC LJIIIZ() {
        AnonymousClass8UC r0;
        MethodCollector.i(7981);
        if (this.LJIILIIL == null) {
            this.LJIILIIL = new AnonymousClass8NS();
        }
        r0 = this.LJIILIIL;
        MethodCollector.o(7981);
        return r0;
    }

    public final File LIZJ() {
        if (LIZIZ().isInited()) {
            return LIZIZ().getCacheFile();
        }
        return null;
    }

    public final void LJ() {
        if (LIZIZ().isInited()) {
            LIZIZ().cancelAll();
        }
    }

    private synchronized Handler LJIIJ() {
        Handler handler;
        IVideoPreloadConfig iVideoPreloadConfig;
        MethodCollector.i(8202);
        if (this.LJIILJJIL == null && (iVideoPreloadConfig = this.LJIIL) != null && iVideoPreloadConfig.useSyncPreloadStyle()) {
            HandlerThread handlerThread = new HandlerThread("VideoPreloadHandlerThread");
            handlerThread.start();
            this.LJIILJJIL = new Handler(handlerThread.getLooper());
        }
        handler = this.LJIILJJIL;
        MethodCollector.o(8202);
        return handler;
    }

    public final C20958Tm LIZIZ() {
        MethodCollector.i(8404);
        C20958Tm r0 = this.LJIIJJI;
        if (r0 != null) {
            MethodCollector.o(8404);
            return r0;
        }
        synchronized (this) {
            try {
                if (this.LJIIJJI == null) {
                    C20958Tm LIZ2 = LJIIIZ().LIZ(this.LJIIL.getExperiment().PreloadTypeExperiment());
                    this.LJIIJJI = LIZ2;
                    this.LIZJ = LIZ2.getNetworkLibName();
                }
            } catch (Throwable th) {
                MethodCollector.o(8404);
                throw th;
            }
        }
        C20958Tm r02 = this.LJIIJJI;
        MethodCollector.o(8404);
        return r02;
    }

    public final void LIZLLL() {
        if (LIZIZ().isInited()) {
            LIZ((AnonymousClass8U6) new AnonymousClass8U2(this));
        }
    }

    public final void LIZIZ(AnonymousClass7UR r1) {
        LIZ(r1);
    }

    public final void LIZ(AnonymousClass7UR r2) {
        LIZIZ().addPreloadCallback(r2);
    }

    public final C20958Tm LIZ(AnonymousClass8NQ r2) {
        return LJIIIZ().LIZ(r2);
    }

    public final void LJ(C16758Di r2) {
        LIZ((AnonymousClass8U6) new C21008Tr(this, r2));
    }

    private boolean LIZ(AnonymousClass8U6 r3) {
        IVideoPreloadConfig iVideoPreloadConfig = this.LJIIL;
        if (iVideoPreloadConfig == null || !iVideoPreloadConfig.useSyncPreloadStyle()) {
            return r3.LIZ();
        }
        if (LJIIJ() == null) {
            return true;
        }
        LJIIJ().post(r3);
        return true;
    }

    public final long LIZIZ(String str) {
        if (LIZIZ().isInited()) {
            return LIZIZ().getVideoSize(str);
        }
        return -1;
    }

    public final long LIZLLL(C16758Di r3) {
        if (r3 == null || !LIZIZ().isInited()) {
            return -1;
        }
        return LIZIZ().getVideoSize(r3.getBitRatedRatioUri());
    }

    public final void LJFF(C16758Di r2) {
        if (LIZIZ().isInited()) {
            LIZIZ().cancelPreload(r2);
        }
    }

    public final AnonymousClass7R6 LJI(C16758Di r2) {
        if (r2 == null || !LIZIZ().isInited()) {
            return null;
        }
        return LIZIZ().readTimeInfo(r2);
    }

    public final List<C02697ac> LJII(C16758Di r2) {
        if (LIZIZ().isInited()) {
            return LIZIZ().getSingleTimeDownloadList(r2);
        }
        return null;
    }

    public final List<AnonymousClass7dW> LJIIIIZZ(C16758Di r2) {
        if (LIZIZ().isInited()) {
            return LIZIZ().getRequestInfoList(r2);
        }
        return null;
    }

    public final AnonymousClass7dW LJIIIZ(C16758Di r2) {
        if (LIZIZ().isInited()) {
            return LIZIZ().getRequestInfo(r2);
        }
        return null;
    }

    public final long LIZ(String str) {
        if (LIZIZ().isInited()) {
            return LIZIZ().getPreloadedSize(str);
        }
        return -1;
    }

    public final boolean LIZIZ(C16758Di r3) {
        if (!LIZIZ().isInited() || !LIZ(r3) || !LIZIZ().isCacheCompleted(r3)) {
            return false;
        }
        return true;
    }

    public final int LIZJ(C16758Di r3) {
        if (!LIZIZ().isInited()) {
            return -1;
        }
        if (r3 != null) {
            if (r3.getHitBitrate() == null) {
                r3.setHitBitrate(AnonymousClass7dR.LIZ.LJFF(r3.getSourceId()));
            }
            if (TextUtils.isEmpty(r3.getDashVideoId())) {
                r3.setDashVideoId(AnonymousClass7dR.LIZ.LJIIIZ(r3.getSourceId()));
            }
        }
        return LIZIZ().cacheSize(r3);
    }

    public final void LIZ(AnonymousClass8N3 r2) {
        if (r2 != null && this.LJIIJJI != null) {
            LIZIZ().addDownloadProgressListener(r2);
        }
    }

    public final void LIZ(Map<String, String> map) {
        if (LIZIZ().isInited()) {
            LIZ((AnonymousClass8U6) new C21058Tw(this, map));
        } else {
            this.LIZIZ = map;
        }
    }

    public final long LIZ(long j, boolean z) {
        if (!z) {
            return LIZIZ().tryToClearAndGetCachesByUsedTime(j, false);
        }
        LIZ((AnonymousClass8U6) new AnonymousClass8U3(this, j));
        return -1;
    }

    public final Object LIZ(C16758Di r2, String str, String[] strArr) {
        LIZ();
        return LIZIZ().proxyUrl(r2, str, strArr);
    }

    public final void LIZ(C16758Di r7, String str, C20598Sc r9) {
        if (LIZIZ().isInited()) {
            LIZIZ().copyCache(r7, str, true, false, r9);
        }
    }
}
