翰林优商.apk(点击下载) / c.java


package com.kwai.filedownloader.download;

import android.os.Process;
import com.kwai.filedownloader.c.b;
import com.kwai.filedownloader.download.ConnectTask;
import com.kwai.filedownloader.download.e;
import com.kwai.filedownloader.e.d;
import com.kwai.filedownloader.e.f;
import com.kwai.filedownloader.exception.FileDownloadGiveUpRetryException;
import java.io.IOException;
import java.net.SocketException;

public final class c implements Runnable {
    private final String Of;
    private final int bHR;
    private final ConnectTask bIN;
    private final f bIO;
    private e bIP;
    final int bIQ;
    private final boolean bIo;
    private volatile boolean jA;

    public static class a {
        private String Of;
        private Boolean bIL;
        private f bIO;
        private final ConnectTask.a bIR = new ConnectTask.a();
        private Integer bIS;

        public final a a(f fVar) {
            this.bIO = fVar;
            return this;
        }

        public final c acE() {
            if (this.bIO == null || this.Of == null || this.bIL == null || this.bIS == null) {
                throw new IllegalArgumentException(f.j("%s %s %B", this.bIO, this.Of, this.bIL));
            }
            ConnectTask acn = this.bIR.acn();
            return new c(acn.bHR, this.bIS.intValue(), acn, this.bIO, this.bIL.booleanValue(), this.Of, (byte) 0);
        }

        public final a b(a aVar) {
            this.bIR.a(aVar);
            return this;
        }

        public final a c(b bVar) {
            this.bIR.a(bVar);
            return this;
        }

        public final a cQ(boolean z) {
            this.bIL = Boolean.valueOf(z);
            return this;
        }

        public final a e(Integer num) {
            this.bIS = num;
            return this;
        }

        public final a eP(int i) {
            this.bIR.eO(i);
            return this;
        }

        public final a gc(String str) {
            this.bIR.fZ(str);
            return this;
        }

        public final a gd(String str) {
            this.bIR.ga(str);
            return this;
        }

        public final a ge(String str) {
            this.Of = str;
            return this;
        }
    }

    private c(int i, int i2, ConnectTask connectTask, f fVar, boolean z, String str) {
        this.bHR = i;
        this.bIQ = i2;
        this.jA = false;
        this.bIO = fVar;
        this.Of = str;
        this.bIN = connectTask;
        this.bIo = z;
    }

    /* synthetic */ c(int i, int i2, ConnectTask connectTask, f fVar, boolean z, String str, byte b) {
        this(i, i2, connectTask, fVar, z, str);
    }

    public final void discard() {
        pause();
    }

    public final void pause() {
        this.jA = true;
        e eVar = this.bIP;
        if (eVar != null) {
            eVar.pause();
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:39:0x010a A[Catch:{ all -> 0x00f6 }] */
    /* JADX WARNING: Removed duplicated region for block: B:58:0x013c A[SYNTHETIC] */
    public final void run() {
        boolean z;
        Exception e;
        Process.setThreadPriority(10);
        long j = this.bIN.acm().bIa;
        com.kwai.filedownloader.kwai.b bVar = null;
        boolean z2 = false;
        while (!this.jA) {
            try {
                try {
                    bVar = this.bIN.acj();
                    int responseCode = bVar.getResponseCode();
                    if (d.bKs) {
                        d.e(this, "the connection[%d] for %d, is connected %s with requestHttpCode[%d]", Integer.valueOf(this.bIQ), Integer.valueOf(this.bHR), this.bIN.acm(), Integer.valueOf(responseCode));
                    }
                    if (responseCode != 206) {
                        if (responseCode != 200) {
                            throw new SocketException(f.j("Connection failed with request[%s] response[%s] http-state[%d] on task[%d-%d], which is changed after verify connection, so please try again.", this.bIN.getRequestHeader(), bVar.aa(), Integer.valueOf(responseCode), Integer.valueOf(this.bHR), Integer.valueOf(this.bIQ)));
                        }
                    }
                    try {
                        e.a aVar = new e.a();
                        if (!this.jA) {
                            e acR = aVar.eS(this.bHR).eR(this.bIQ).b(this.bIO).a(this).cS(this.bIo).d(bVar).c(this.bIN.acm()).gf(this.Of).acR();
                            this.bIP = acR;
                            acR.run();
                            if (this.jA) {
                                this.bIP.pause();
                            }
                            if (bVar != null) {
                                bVar.ab();
                                return;
                            }
                            return;
                        } else if (bVar != null) {
                            bVar.ab();
                            return;
                        } else {
                            return;
                        }
                    } catch (FileDownloadGiveUpRetryException | IOException | IllegalAccessException | IllegalArgumentException e2) {
                        e = e2;
                        z = true;
                    }
                } catch (FileDownloadGiveUpRetryException | IOException | IllegalAccessException | IllegalArgumentException e3) {
                    e = e3;
                    z = false;
                    try {
                        if (!this.bIO.e(e)) {
                            if (!z) {
                                this.bIO.a(e, 0);
                            } else {
                                e eVar = this.bIP;
                                if (eVar != null) {
                                    this.bIO.a(e, eVar.bIa - j);
                                } else {
                                    d.f(this, "it is valid to retry and connection is valid but create fetch-data-task failed, so give up directly with %s", e);
                                    this.bIO.a(e);
                                    if (bVar != null) {
                                        bVar.ab();
                                        return;
                                    }
                                    return;
                                }
                            }
                            z2 = z;
                        } else {
                            this.bIO.a(e);
                            if (bVar != null) {
                                bVar.ab();
                                return;
                            }
                            return;
                        }
                    } finally {
                        if (bVar != null) {
                            bVar.ab();
                        }
                    }
                }
            } catch (FileDownloadGiveUpRetryException | IOException | IllegalAccessException | IllegalArgumentException e4) {
                z = z2;
                e = e4;
                if (!this.bIO.e(e)) {
                }
            }
        }
        if (bVar != null) {
            bVar.ab();
        }
    }
}