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


package X;

import android.os.SystemClock;
import android.text.TextUtils;
import com.bytedance.covode.number.Covode;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import org.json.JSONException;

/* renamed from: X.6to  reason: invalid class name and case insensitive filesystem */
public abstract class AbstractC174716to implements AbstractRunnableC175136uU {
    public volatile AbstractC174966uD LIZ;
    public final C174146st LIZIZ;
    public final AtomicInteger LIZJ = new AtomicInteger();
    public final AtomicLong LIZLLL = new AtomicLong();
    public volatile List<C174866u3> LJ;
    public volatile C174726tp LJFF;
    public volatile String LJI;
    public volatile String LJII;
    public volatile C174816ty LJIIIIZZ;
    public volatile C174786tv LJIIIZ;
    public volatile int LJIIJ;
    public AtomicLong LJIIJJI = new AtomicLong(0);
    public AtomicLong LJIIL = new AtomicLong(0);
    public final AtomicInteger LJIILIIL = new AtomicInteger(0);
    public int LJIILJJIL = -1;

    static {
        Covode.recordClassIndex(120279);
    }

    public AbstractC174716to(AbstractC174966uD r4, C174146st r5) {
        this.LIZ = r4;
        this.LIZIZ = r5;
        this.LJIIJ = 0;
    }

    /* JADX WARNING: Removed duplicated region for block: B:37:0x00c2  */
    /* JADX WARNING: Removed duplicated region for block: B:57:0x0110  */
    /* JADX WARNING: Removed duplicated region for block: B:60:0x011b  */
    /* JADX WARNING: Removed duplicated region for block: B:66:0x0141  */
    /* JADX WARNING: Removed duplicated region for block: B:85:0x01a0  */
    /* JADX WARNING: Removed duplicated region for block: B:90:0x01ba  */
    private C175186uZ LIZIZ(String str, int i2, int i3, String str2) {
        String concat;
        String str3;
        String concat2;
        C174856u2 r3 = new C174856u2();
        if (str2 != null) {
            String upperCase = str2.toUpperCase();
            if ("GET".equals(upperCase) || "HEAD".equals(upperCase)) {
                r3.LIZIZ = upperCase;
                List<C174866u3> list = this.LJ;
                if (list != null && !list.isEmpty()) {
                    for (C174866u3 r2 : list) {
                        if (!"Range".equalsIgnoreCase(r2.LIZ) && !AnonymousClass18D.LIZJ.equalsIgnoreCase(r2.LIZ) && !"Proxy-Connection".equalsIgnoreCase(r2.LIZ) && !"Host".equalsIgnoreCase(r2.LIZ)) {
                            r3.LIZ(r2.LIZ, r2.LIZIZ);
                        }
                    }
                }
                if (i2 >= 0 && i3 > 0) {
                    concat = i2 + "-" + i3;
                } else if (i2 > 0) {
                    concat = i2 + "-";
                } else {
                    if (i2 < 0 && i3 > 0) {
                        concat = "-".concat(String.valueOf(i3));
                    }
                    r3.LIZ("Vpwp-Raw-Key", this.LJI);
                    if (C172546qJ.LJJII) {
                        try {
                            r3.LIZ("Vpwp-Type", this.LJIIIIZZ == null ? "preloader" : "proxy");
                            r3.LIZ("Vpwp-Key", this.LJII);
                            String str4 = "";
                            if (!(this.LJIIIIZZ == null || (str3 = this.LJIIIIZZ.LIZJ.LJI) == null)) {
                                str4 = str3;
                            }
                            if (!TextUtils.isEmpty(str4)) {
                                r3.LIZ("Vpwp-Mp-Range", str4);
                            }
                            r3.LIZ("Vpwp-Flag", String.valueOf(LJI()));
                        } catch (Throwable th) {
                            C177256xu.LIZLLL("AbsTask", C177256xu.LIZ(th), null);
                        }
                    }
                    r3.LIZ("X-ReqType", this.LJIIIIZZ != null ? "preload" : "play");
                    if (!C172546qJ.LJIIJ) {
                        r3.LIZ("local_url_index", String.valueOf(this.LJIIJ));
                        r3.LIZ("local_url_count", String.valueOf(this.LJIIIZ.LIZ != null ? this.LJIIIZ.LIZ.size() : -1));
                    }
                    if (str != null) {
                        throw new IllegalArgumentException("url is null");
                    } else if (str.startsWith("http://") || str.startsWith("https://")) {
                        r3.LIZ = str;
                        if (C172546qJ.LJIJJLI) {
                            r3.LIZ("Cache-Control", "no-cache");
                        }
                        if (this.LJIIIIZZ == null) {
                            C174016sg LIZ2 = C174016sg.LIZ();
                            r3.LIZLLL = LIZ2.LJII;
                            r3.LJ = LIZ2.LJIIIIZZ;
                            r3.LJFF = LIZ2.LJIIIZ;
                        } else {
                            C174646th LIZ3 = C174646th.LIZ();
                            r3.LIZLLL = LIZ3.LJIIIIZZ;
                            r3.LJ = LIZ3.LJIIIZ;
                            r3.LJFF = LIZ3.LJIIJ;
                        }
                        if (r3.LIZ != null) {
                            if (r3.LIZIZ == null) {
                                r3.LIZIZ = "GET";
                            }
                            C174726tp LIZ4 = C175196ua.LIZ(new C174756ts(r3, (byte) 0));
                            this.LJFF = LIZ4;
                            return LIZ4.LIZ();
                        }
                        throw new IllegalStateException("url is null");
                    } else {
                        throw new IllegalArgumentException("url should start with http:// or https://, url: ".concat(String.valueOf(str)));
                    }
                }
                if (!(concat == null || (concat2 = "bytes=".concat(String.valueOf(concat))) == null)) {
                    r3.LIZ("Range", concat2);
                }
                r3.LIZ("Vpwp-Raw-Key", this.LJI);
                if (C172546qJ.LJJII) {
                }
                r3.LIZ("X-ReqType", this.LJIIIIZZ != null ? "preload" : "play");
                if (!C172546qJ.LJIIJ) {
                }
                if (str != null) {
                }
            } else {
                throw new IllegalArgumentException("for now only GET and HEAD is support");
            }
        } else {
            throw new IllegalArgumentException("method is null");
        }
    }

    public final C175186uZ LIZ(String str, int i2, int i3, String str2) {
        int i4;
        String str3;
        String[] strArr;
        int i5;
        int i6;
        String str4 = str;
        boolean z = this.LJIIIIZZ != null;
        long elapsedRealtime = SystemClock.elapsedRealtime();
        int lastIndexOf = str4.lastIndexOf("&source_id=");
        String str5 = "";
        if (!z || C171546oh.LIZ() || TextUtils.isEmpty(str4)) {
            i4 = 0;
            str3 = str5;
            strArr = null;
        } else {
            String str6 = this.LJI;
            str3 = (lastIndexOf <= 0 || (i6 = lastIndexOf + 11) >= str4.length()) ? str5 : str4.substring(i6);
            strArr = !TextUtils.isEmpty(str6) ? str6.split("_") : null;
            long j = C16120kb.LIZJ;
            C16120kb.LIZJ = 0;
            AnonymousClass0ED.LIZ((Callable) new AnonymousClass6SL("video_api_request", new AnonymousClass28M().LIZ("duration", Long.toString(j > 0 ? SystemClock.elapsedRealtime() - j : 0)).LIZ("is_first", String.valueOf(AnonymousClass6SM.LIZ ? 1 : 0)).LIZ("group_id", str3).LIZ("bitRate", (strArr == null || strArr.length <= 3) ? str5 : strArr[3]).LIZ("video_type", (strArr == null || strArr.length <= 2) ? str5 : strArr[2]).LIZ("isBytevc1", (strArr == null || strArr.length <= 1) ? str5 : strArr[1]).LIZ("from_size", String.valueOf(i2)).LIZ("to_size", String.valueOf(i3)).LIZ()));
            i4 = 0;
            AnonymousClass6SM.LIZ = false;
        }
        if (lastIndexOf > 0 && z && !TextUtils.isEmpty(str4)) {
            str4 = str4.substring(i4, lastIndexOf);
        }
        C175186uZ LIZIZ2 = LIZIZ(str4, i2, i3, str2);
        if (z && !C171546oh.LIZ()) {
            AnonymousClass28M LIZ2 = new AnonymousClass28M().LIZ("feed_tab", C16120kb.LIZIZ.name()).LIZ("duration", String.valueOf(SystemClock.elapsedRealtime() - elapsedRealtime)).LIZ("is_first", String.valueOf(AnonymousClass6SM.LIZIZ ? 1 : 0)).LIZ("group_id", str3).LIZ("bitRate", (strArr == null || strArr.length <= 3) ? str5 : strArr[3]).LIZ("video_type", (strArr == null || strArr.length <= 2) ? str5 : strArr[2]);
            if (strArr != null) {
                i5 = 1;
                if (strArr.length > 1) {
                    str5 = strArr[1];
                }
            } else {
                i5 = 1;
            }
            AnonymousClass28M LIZ3 = LIZ2.LIZ("isBytevc1", str5).LIZ("from_size", String.valueOf(i2)).LIZ("to_size", String.valueOf(i3));
            if (LIZIZ2 == null || !LIZIZ2.LIZ()) {
                i5 = 0;
            }
            AnonymousClass0ED.LIZ((Callable) new AnonymousClass6SL("video_api_response", LIZ3.LIZ("is_success", String.valueOf(i5)).LIZ()));
            AnonymousClass6SM.LIZIZ = false;
            if (C16120kb.LIZLLL < 0) {
                C16120kb.LIZLLL = SystemClock.elapsedRealtime();
            }
        }
        return LIZIZ2;
    }

    public void LIZ() {
        if (this.LJIILIIL.compareAndSet(0, 1)) {
            LIZIZ();
        }
    }

    public final void LIZ(int i2) {
        C174726tp r1;
        if (i2 == 1 && (r1 = this.LJFF) != null) {
            r1.LIZ(null);
        }
    }

    public final void LIZ(int i2, int i3) {
        AbstractC174106sp r4 = C172546qJ.LJI;
        if (r4 != null && i2 > 0 && i3 >= 0) {
            int i4 = C172546qJ.LJIL;
            int LJI2 = LJI();
            if (i4 == 1 || (i4 == 2 && LJI2 == 1)) {
                int i5 = (int) ((((float) i3) / ((float) i2)) * 100.0f);
                if (i5 > 100) {
                    i5 = 100;
                }
                synchronized (this) {
                    int i6 = this.LJIILJJIL + C172546qJ.LJIILIIL;
                    if (i6 > 100) {
                        i6 = 100;
                    }
                    if ((i5 > i6 || i5 == 100) && this.LJIILJJIL != 100) {
                        this.LJIILJJIL = i5;
                        C174796tw.LIZIZ(new RunnableC174936uA(this, r4, LJI2, i2, i3));
                    }
                }
            }
        }
    }

    public final void LIZ(int i2, String str) {
        C174796tw.LIZIZ(new RunnableC175056uM(this, i2, str));
    }

    public final void LIZ(Exception exc, int i2) {
        C174726tp r0;
        if (i2 == 1 && (r0 = this.LJFF) != null) {
            r0.LIZ(exc);
        }
    }

    public final void LIZ(Exception exc, int i2, String str) {
        C174796tw.LIZIZ(new RunnableC174826tz(this, exc, i2, str));
    }

    public final void LIZ(String str) {
        AbstractC174106sp r1 = C172546qJ.LJI;
        if (r1 != null) {
            C174796tw.LIZIZ(new RunnableC174596tc(this, r1, str));
        }
    }

    public final void LIZ(String str, int i2, String str2) {
        C174796tw.LIZ(new RunnableC174156su(this, str, i2, str2));
    }

    public final void LIZ(String str, String str2, int i2, long j) {
        C174796tw.LIZIZ(new RunnableC172536qI(this, str, str2, i2, j));
    }

    public final void LIZ(String str, String str2, long j, long j2) {
        C174796tw.LIZIZ(new RunnableC172866qp(this, j, j2, str, str2));
    }

    /* JADX WARNING: Removed duplicated region for block: B:43:0x014f  */
    /* JADX WARNING: Removed duplicated region for block: B:58:? A[RETURN, SYNTHETIC] */
    public final void LIZ(Throwable th, String str, int i2) {
        C172576qM r6;
        C31721Nh r7;
        C174726tp r4 = this.LJFF;
        if (r4 != null && !r4.LJFF) {
            r4.LJFF = true;
            try {
                if (r4.LIZJ != null) {
                    if (r4.LIZJ.LIZLLL != null) {
                        long currentTimeMillis = System.currentTimeMillis();
                        if (r4.LIZ instanceof AnonymousClass0ZZ) {
                            ((AnonymousClass0ZZ) r4.LIZ).doCollect();
                        }
                        Object obj = r4.LIZJ.LIZLLL.LIZ.LJFF;
                        if (obj instanceof C31721Nh) {
                            r7 = (C31721Nh) obj;
                            r7.LJ = r4.LIZLLL;
                            r7.LJFF = r4.LJ;
                            r7.LJII = currentTimeMillis;
                            r7.LJJJIL = i2;
                        } else {
                            r7 = null;
                        }
                        if (th == null) {
                            AnonymousClass0SC.LIZ(currentTimeMillis - r4.LIZLLL, r4.LIZLLL, r4.LIZIZ.LIZ, r4.LIZJ.LIZ("X-TT-LOGID", ""), r7);
                            C177256xu.LIZIZ("HttpCall", "api_succeed, from: " + str + ", cost: " + (currentTimeMillis - r4.LIZLLL) + ", netInfo: " + r7 + ", url: " + r4.LIZIZ.LIZ, null);
                        } else {
                            if (r7 == null && (r4.LIZ instanceof AbstractC09290Za)) {
                                Object requestInfo = ((AbstractC09290Za) r4.LIZ).getRequestInfo();
                                if (requestInfo instanceof C31721Nh) {
                                    r7 = (C31721Nh) requestInfo;
                                    r7.LJ = r4.LIZLLL;
                                    r7.LJFF = r4.LJ;
                                    r7.LJII = currentTimeMillis;
                                    r7.LJJJIL = i2;
                                }
                            }
                            if (!(r7 == null || r7.LJJIFFI == null)) {
                                try {
                                    r7.LJJIFFI.put("ex", th.getMessage());
                                } catch (JSONException unused) {
                                }
                            }
                            if (r7 != null && (th instanceof C39884FlR)) {
                                r7.LJJI = ((C39884FlR) th).getRequestLog();
                            }
                            AnonymousClass0SC.LIZ(currentTimeMillis - r4.LIZLLL, r4.LIZLLL, r4.LIZIZ.LIZ, r4.LIZJ.LIZ("X-TT-LOGID", ""), r7, th);
                            r6 = null;
                            C177256xu.LIZLLL("HttpCall", "api_error, from: " + str + ", cost: " + (currentTimeMillis - r4.LIZLLL) + ", netInfo: " + r7 + ", url: " + r4.LIZIZ.LIZ + ", error: " + th.getMessage(), null);
                            if (r4.LIZJ.LJ == null) {
                                C174836u0 r5 = C175036uK.LIZ;
                                String str2 = r4.LIZIZ.LIZ;
                                if (str2 != null) {
                                    r6 = r5.LIZ.get(str2);
                                }
                                long currentTimeMillis2 = System.currentTimeMillis();
                                C31721Nh r52 = new C31721Nh();
                                r52.LJ = r4.LIZLLL;
                                r52.LJFF = r4.LJ;
                                r52.LJII = currentTimeMillis2;
                                r52.LJJJIL = i2;
                                if (r6 != null) {
                                    r52.LIZ = r6.LJI;
                                }
                                if (th == null) {
                                    AnonymousClass0SC.LIZ(currentTimeMillis2 - r4.LIZLLL, r4.LIZLLL, r4.LIZIZ.LIZ, r4.LIZJ.LIZ("X-TT-LOGID", ""), r52);
                                    return;
                                } else {
                                    AnonymousClass0SC.LIZ(currentTimeMillis2 - r4.LIZLLL, r4.LIZLLL, r4.LIZIZ.LIZ, r4.LIZJ.LIZ("X-TT-LOGID", ""), r52, th);
                                    return;
                                }
                            } else {
                                return;
                            }
                        }
                    }
                    r6 = null;
                    if (r4.LIZJ.LJ == null) {
                    }
                }
            } catch (Throwable unused2) {
            }
        }
    }

    public final void LIZ(boolean z, String str, int i2, int i3, String str2, String str3) {
        AbstractC174106sp r2 = C172546qJ.LJI;
        if (r2 != null) {
            C174796tw.LIZIZ(new RunnableC174956uC(this, r2, z, str, i2, i3, str2, str3));
        }
    }

    public final void LIZIZ() {
        C174726tp r1 = this.LJFF;
        this.LJFF = null;
        if (r1 != null) {
            r1.LIZIZ();
        }
    }

    public final boolean LIZJ() {
        return this.LJIILIIL.get() == 1;
    }

    public final void LIZLLL() {
        this.LJIILIIL.compareAndSet(0, 2);
        this.LJFF = null;
    }

    public final boolean LJ() {
        return this.LJIILIIL.get() == 2;
    }

    public final void LJFF() {
        if (LIZJ()) {
            throw new AnonymousClass2UE();
        }
    }

    public final int LJI() {
        return this.LJIIIIZZ != null ? this.LJIIIIZZ.LIZJ.LIZ : this.LIZ instanceof AnonymousClass2CV ? 1 : 0;
    }

    public final void LJII() {
        this.LJIIJJI.getAndAdd(SystemClock.elapsedRealtime() - this.LJIIL.get());
    }

    public final void LJIIIIZZ() {
        this.LJIIL.set(SystemClock.elapsedRealtime());
    }

    public final void LJIIIZ() {
        this.LJIIJJI.set(0);
        this.LJIIL.set(0);
    }
}