360手机助手 v3.3.0版本的 MD5 值为:127c345ad16bbebee6e347381328afd0

以下内容为反编译后的 bg.java 源代码,内容仅作参考


package com.qihoo.d.a;

import com.qihoo.speedometer.Config;
import com.qihoo.speedometer.TraceFileUtil;
import com.qihoo.speedometer.measurements.HttpTask;
import java.io.File;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.RandomAccessFile;
import java.io.StringWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import java.util.concurrent.Executors;

public class bg {

    public static int f4258a = 20000;

    public static int f4259b = f4258a + Config.MEASUREMENT_END_PROGRESS;
    public static int c = 1;
    public static int d = 2;
    public static int e = 3;
    public static int f = 4;
    public static int g = 5;
    public static int h = 6;
    public static int i = 7;
    public static int j = 16;
    public static int k = 17;
    public static int l = 32;
    public static int m = 33;
    public static int n = 48;
    public static int o = 64;
    public static int p = 65;
    public static int q = 66;
    public static int r = 83;
    public static int s = 84;
    public static int t = 0;
    public static int u = 1;
    public static int v = 2;
    public static int w = 3;
    public static int x = 0;
    public static int y = 2;
    public static int z = 3;
    aw B;
    private String C;
    private String D;
    private String E;
    private String F;
    private String G;
    private int H;
    private int I;
    private int J;
    private String K;
    private av Q;
    private int R;
    private int S;
    private long T;
    private long U;
    private long V;
    private long W;
    private long X;
    private long Y;
    private long Z;
    private long aC;
    private String aG;
    private int aa;
    private boolean ab;
    private int ac;
    private int ad;
    private byte[] ae;
    private boolean af;
    private boolean ag;
    private long ah;
    private long ai;
    private boolean au;
    private boolean av;
    private List aH = new ArrayList();
    private aj aI = am.f();
    private bd aJ = am.a();
    private boolean O = false;
    private ao P = null;
    bc A = null;
    private boolean aj = false;
    private boolean ak = false;
    private boolean al = false;
    private boolean am = false;
    private long an = 0;
    private com.qihoo.d.b.s ao = null;
    private String ap = null;
    private String aq = null;
    private String ar = null;
    private int as = 1;
    private boolean at = false;
    private long aD = 0;
    private long aE = 0;
    private int aF = 0;
    private boolean ax = true;
    private boolean L = true;
    private boolean ay = false;
    private int az = 0;
    private int aA = 0;
    private long aB = 0;
    private boolean M = false;
    private boolean N = false;
    private long aw = 0;

    private void a(String str) {
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  ProcHttpParam start...");
        }
        if (this.aa != y) {
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  ProcHttpParam 1111...");
                return;
            }
            return;
        }
        aw awVar = new aw();
        awVar.a(str);
        long c2 = this.B.c();
        long c3 = awVar.c();
        if (c2 != 0 && c2 != c3) {
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "]   ProcHttpParam 2222...");
            }
        } else if (this.ah > 0 && c3 > 0 && c3 != this.ah) {
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  ProcHttpParam 3333...");
            }
        } else {
            String trim = str.trim();
            this.C = trim;
            this.B.a(trim);
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  ProcHttpParam   " + str);
            }
        }
    }

    private boolean a(int i2, long j2, int i3) {
        return r() && this.aI.a(this.H, i2, j2, i3);
    }

    private boolean a(long j2, int i2, byte[] bArr) {
        if (r() && this.aI.a(this.H, j2, bArr, i2)) {
            if (this.ax && !this.ab && this.ac != bl.TORRENT_STATUS_UNKNOWN.ordinal()) {
                int h2 = this.A.h();
                if (h2 == 0) {
                    return false;
                }
                byte[] bArr2 = new byte[h2 * 20];
                for (int i3 = 0; i3 < h2; i3++) {
                    byte[] g2 = this.A.g(i3);
                    if (g2 == null) {
                        return true;
                    }
                    System.arraycopy(g2, 0, bArr2, i3 * 20, 20);
                }
                this.aI.a(this.H, bArr2, h2 * 20);
                this.ab = true;
            }
            return true;
        }
        return false;
    }

    public boolean a(String str, String str2) {
        HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str).openConnection();
        if (this.ap != null) {
            httpURLConnection.setRequestProperty("Cookie", this.ap);
        }
        if (this.aq != null) {
            httpURLConnection.setRequestProperty("User-Agent", this.aq);
        }
        if (this.ar != null) {
            httpURLConnection.setRequestProperty("Referer", this.ar);
        }
        httpURLConnection.connect();
        if (httpURLConnection.getResponseCode() != 200) {
            j(510);
            httpURLConnection.disconnect();
            return false;
        }
        InputStream inputStream = httpURLConnection.getInputStream();
        this.ah = httpURLConnection.getContentLength();
        RandomAccessFile randomAccessFile = new RandomAccessFile(str2, "rw");
        byte[] bArr = new byte[8192];
        int i2 = 0;
        while (true) {
            if (this.am || (this.an >= this.ah && this.ah > 0)) {
                break;
            }
            int read = inputStream.read(bArr, i2, 1024);
            if (read > 0) {
                this.an += read;
                this.ao.a(read, true, System.currentTimeMillis());
                if (com.qihoo.d.b.a.f == 4) {
                    this.aD += read;
                } else {
                    this.aE += read;
                }
                i2 += read;
                if (i2 + 1024 > 8192) {
                    randomAccessFile.write(bArr, 0, i2);
                    i2 = 0;
                }
            } else if (this.an == 0) {
                this.R = v;
                this.I = 20506;
            } else {
                this.ah = this.an;
            }
        }
        if (i2 > 0) {
            randomAccessFile.write(bArr, 0, i2);
        }
        httpURLConnection.disconnect();
        randomAccessFile.close();
        if ((this.ah > 0 && this.an >= this.ah) || (this.ah == 0 && this.an > 0)) {
            if (this.ah == 0) {
                this.ah = this.an;
            }
            new File(str2).renameTo(new File(this.D));
            j(0);
        }
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.a("TaskID:[" + this.H + "] Urldownload lFileLen:" + this.ah + " urlDownloadLen:" + this.an);
        }
        return true;
    }

    private void b(String str) {
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  ProcP2PParam start...");
        }
        if (this.aa != z) {
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  ProcP2PParam 1111...");
                return;
            }
            return;
        }
        if ((this.S & 1) > 0) {
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  ProcP2PParam 222...");
                return;
            }
            return;
        }
        if (this.R != t) {
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  ProcP2PParam 3333...");
                return;
            }
            return;
        }
        aw awVar = new aw();
        awVar.a(str);
        if (!awVar.a().equals(this.B.a())) {
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  ProcP2PParam http set error...");
                return;
            }
            return;
        }
        long c2 = this.B.c();
        long c3 = awVar.c();
        if (c2 != 0 && c2 != c3) {
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  ProcP2PParam 55555...");
                return;
            }
            return;
        }
        if (this.ah > 0 && c3 > 0 && c3 != this.ah) {
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  ProcP2PParam 66666...");
                return;
            }
            return;
        }
        this.B.a(str);
        this.S = this.B.d();
        if ((this.S & 1) > 0) {
            this.Q.a(this.B.b(), this.B.c(), this.H, this.B.e());
            this.Q.b(5);
            this.az = 1;
        }
        if ((this.S & 1) > 0) {
            this.Q.a();
        }
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  ProcP2PParam   " + str);
        }
        this.aw = System.currentTimeMillis() - this.V;
    }

    private String c(String str) {
        String str2;
        int lastIndexOf = str.lastIndexOf(TraceFileUtil.FILE_EXTENSION_SEPARATOR);
        if (lastIndexOf >= 0) {
            str2 = str.substring(lastIndexOf);
            str = str.substring(0, lastIndexOf);
        } else {
            str2 = Config.INVALID_IP;
        }
        int i2 = 1;
        String str3 = str;
        while (true) {
            if (!new File(str3 + str2).exists() && !com.qihoo.d.b.a.d(str3 + str2)) {
                com.qihoo.d.b.a.e(str3 + str2);
                return str3 + str2;
            }
            str3 = str + i2;
            i2++;
        }
    }

    private void j(int i2) {
        if (this.R != t) {
            return;
        }
        if (i2 == 0) {
            this.R = u;
            this.I = 0;
            return;
        }
        if (i2 < 501 || i2 > 511) {
            return;
        }
        if (this.N && !this.M) {
            this.P.b(1);
            this.M = true;
        } else if ((this.S & 1) <= 0 || this.au) {
            this.R = v;
        }
        this.I = i2;
        this.J = n;
        this.av = true;
    }

    private boolean q() {
        if (!r()) {
            return false;
        }
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.a("TaskID:[" + this.H + "] RenameMsg start.....");
        }
        return this.aI.a(this.H, this.D);
    }

    private boolean r() {
        if (!this.af) {
            long f2 = this.A.f();
            if (f2 == 0) {
                return false;
            }
            if (this.R == u) {
                return true;
            }
            if ((this.S & 1) <= 0) {
                this.ax = false;
            }
            byte[] m2 = this.A.m();
            if (!this.aI.a(this.H, this.D, f2, m2, m2.length, this.L, this.ax)) {
                return false;
            }
            this.af = true;
        }
        return true;
    }

    private boolean s() {
        if (new File(this.D).exists()) {
            this.R = u;
        } else if (new File(this.E).exists()) {
            t();
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  RestoreLength:" + this.A.i());
            }
        } else if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "] " + this.E + " not exists");
        }
        return true;
    }

    private boolean t() {
        if (this.R != t) {
            return false;
        }
        int[] iArr = {(int) u()};
        iArr[0] = iArr[0] - 16;
        if (iArr[0] <= 0) {
            if (!com.qihoo.d.b.a.c) {
                return false;
            }
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  LoadBitmap getRestoreFileLen <= 0");
            return false;
        }
        byte[] bArr = new byte[iArr[0]];
        long[] jArr = new long[1];
        int a2 = com.qihoo.d.b.a.a(this.F, bArr, iArr, jArr);
        if (a2 == 1) {
            this.ah = jArr[0];
            this.ai = jArr[0];
            if (this.A.f() == 0) {
                this.A.a(jArr[0]);
            }
            bb bbVar = new bb();
            c cVar = new c();
            cVar.a(bArr, iArr[0]);
            bbVar.a(jArr[0]);
            this.A.b(cVar.a(bbVar.d() + (-1)) ? ((cVar.c() - 1) * bbVar.c()) + (jArr[0] - ((bbVar.d() - 1) * bbVar.c())) : cVar.c() * bbVar.c());
            for (int i2 = 0; i2 < bbVar.d(); i2++) {
                if (cVar.a(i2)) {
                    this.A.f(i2);
                }
            }
        } else {
            if (a2 != 2) {
                return false;
            }
            this.ah = jArr[0];
            this.ai = jArr[0];
            if (this.A.f() == 0) {
                this.A.a(jArr[0]);
            }
            this.A.a(bArr, 0, iArr[0]);
        }
        return true;
    }

    private long u() {
        long j2;
        Exception e2;
        try {
            RandomAccessFile randomAccessFile = new RandomAccessFile(this.F, "r");
            j2 = randomAccessFile.length();
            try {
                randomAccessFile.close();
            } catch (Exception e3) {
                e2 = e3;
                if (com.qihoo.d.b.a.c) {
                    StringWriter stringWriter = new StringWriter();
                    e2.printStackTrace(new PrintWriter(stringWriter));
                    com.qihoo.d.b.p.a("TaskID:[" + this.H + "] getRestoreFileLen throw exception!" + stringWriter.toString());
                }
                return j2;
            }
        } catch (Exception e4) {
            j2 = 0;
            e2 = e4;
        }
        return j2;
    }

    public void a(int i2) {
        ae d2;
        if (this.O && this.ac != bl.TORRENT_STATUS_UNKNOWN.ordinal() && this.R == t && f() && this.aa == z && (d2 = this.A.d(i2)) != null) {
            if (d2.d() != br.eP2pTypeTcp) {
            }
            while (d2.h()) {
                int[] iArr = new int[1];
                int[] iArr2 = new int[1];
                int[] iArr3 = new int[1];
                if (!this.A.a(i2, iArr3, iArr, iArr2)) {
                    if (com.qihoo.d.b.a.c) {
                        com.qihoo.d.b.p.b("TaskID:[" + this.H + "] cid:" + i2 + "AllocSlice fail ErrCode:" + this.A.c());
                        return;
                    }
                    return;
                } else {
                    if (com.qihoo.d.b.a.c) {
                        com.qihoo.d.b.p.b("TaskID:[" + this.H + "] cid:" + i2 + " SendRequest Index:" + iArr3[0] + " Start: " + iArr[0] + " End:" + iArr2[0]);
                    }
                    if (!this.Q.c(i2, iArr3[0], iArr[0], iArr2[0])) {
                        this.A.e(i2);
                        return;
                    }
                }
            }
        }
    }

    public void a(long j2) {
        if (this.O && this.R == t && this.aa == z) {
            if (this.B.f()) {
                this.I = 20103;
                this.R = v;
                this.J = j;
            }
            if (com.qihoo.d.b.a.f != 0) {
                this.X = j2;
            } else if (j2 - this.X > 15000 && this.P.c(j2) == 0) {
                this.R = v;
                this.J = s;
                this.I = 512;
            }
            if (f()) {
                if (j2 - this.U > 1000 || j2 < this.U) {
                    if (!this.ak) {
                        if ((this.S & 1) > 0) {
                            this.Q.d();
                            this.Q.c();
                            Vector p2 = this.A.p();
                            int i2 = 0;
                            while (true) {
                                int i3 = i2;
                                if (i3 >= p2.size()) {
                                    break;
                                }
                                a(((Integer) p2.get(i3)).intValue());
                                i2 = i3 + 1;
                            }
                        }
                        if (this.aj) {
                            d();
                            e();
                            b(j2);
                        }
                        int a2 = this.P.a(j2);
                        if (this.as != a2) {
                            this.A.a(a2);
                            this.as = a2;
                        }
                    } else if (!this.al) {
                        this.P.c();
                        this.A.d();
                        this.aI.a(this.H, true);
                        this.al = true;
                        Executors.newCachedThreadPool().submit(new bh(this));
                    }
                    this.U = j2;
                }
            }
        }
    }

    public boolean a() {
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "] task Unint ...");
        }
        this.P.a();
        this.A.b();
        com.qihoo.d.b.a.f(this.D);
        this.P = null;
        this.A = null;
        this.O = false;
        return false;
    }

    public boolean a(int i2, int i3) {
        new String();
        String d2 = this.P.d(i2);
        if (d2.length() > 0) {
            this.aH.add(d2);
        }
        if (this.Y == -1) {
            this.Y = System.currentTimeMillis() - this.V;
        }
        if (!this.O) {
            return false;
        }
        if (this.R != t) {
            this.A.e(i2);
            this.P.f(i2);
            return false;
        }
        if (!f()) {
            this.A.e(i2);
            this.P.f(i2);
            return true;
        }
        if (!this.P.a(i2, i3)) {
            this.A.e(i2);
            this.P.f(i2);
            if (this.ai <= 0 || this.P.j()) {
                return false;
            }
            if (com.qihoo.d.b.a.f == 1 || com.qihoo.d.b.a.f == 2) {
                this.R = v;
                this.J = r;
            } else {
                p();
                this.ai = 0L;
            }
            return true;
        }
        if (this.A.f() == 0) {
            this.ah = this.P.d();
            if (this.ah > 0) {
                this.A.a(this.ah);
            }
        }
        if (this.ai > 0 && this.ai != this.P.d() && this.P.d() > 0) {
            if (com.qihoo.d.b.a.f == 1 || com.qihoo.d.b.a.f == 2) {
                this.R = v;
                this.J = r;
            } else {
                p();
            }
        }
        return true;
    }

    public boolean a(int i2, int i3, int i4) {
        if (i3 != 0) {
            return true;
        }
        this.I = i4;
        this.R = v;
        this.J = d;
        return true;
    }

    public boolean a(int i2, int i3, int i4, int i5) {
        if (!this.O) {
            return false;
        }
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "] cid:" + i2 + "  OnNotifyP2PDataReq  Index: " + i3 + "  start:" + i4 + " Len:" + i5);
        }
        if (i3 > this.A.h() || i5 == 0) {
            return false;
        }
        long g2 = (i3 * this.A.g()) + i4;
        if (g2 > this.A.f()) {
            return false;
        }
        if (!this.Q.a(i2, i3, i4, i5)) {
            return true;
        }
        return a(i2, g2, i5);
    }

    public boolean a(int i2, int i3, int i4, int i5, byte[] bArr) {
        if (!this.O || !f()) {
            return false;
        }
        if (!a((i3 * this.A.g()) + i4, i5, bArr)) {
            this.A.e(i2);
            return false;
        }
        this.Q.a(i2, i5);
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "] cid:" + i2 + "  OnNotifyP2PData Index:" + i3 + " Start:" + i4 + "  len:" + i5);
        }
        if (!this.A.a(i2, i3, i4, i4 + i5)) {
            int c2 = this.A.c();
            if (c2 == 316) {
                a(i2);
            } else if (c2 != 315) {
                this.A.e(i2);
            }
        }
        return true;
    }

    public boolean a(int i2, int i3, byte[] bArr) {
        if (!this.O) {
            return false;
        }
        this.Q.a(i2, i3, bArr);
        if (!f()) {
            return true;
        }
        this.A.a(i2, bArr, i3);
        a(i2);
        return true;
    }

    public boolean a(int i2, long j2, int i3, byte[] bArr) {
        com.qihoo.d.b.a.u += i3;
        if (com.qihoo.d.b.a.f == 4) {
            this.aD += i3;
        } else {
            this.aE += i3;
        }
        if (!this.O) {
            return false;
        }
        if (this.R != t) {
            this.P.f(i2);
            this.A.e(i2);
            return false;
        }
        if (!f()) {
            this.P.f(i2);
            this.A.e(i2);
            return false;
        }
        if (!this.P.a(i2, j2, i3, bArr)) {
            this.P.f(i2);
            this.A.e(i2);
            return false;
        }
        if (!a(j2, i3, bArr)) {
            this.P.f(i2);
            this.A.e(i2);
            return false;
        }
        if (!this.A.a(i2, j2, j2 + i3)) {
            int c2 = this.A.c();
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "] cid:" + i2 + " offset:" + j2 + " len:" + i3 + "  WriteRange faile! errcode:" + c2);
            }
            this.P.f(i2);
            this.A.e(i2);
            if (c2 == 316) {
                d();
                e();
            }
        }
        return true;
    }

    public boolean a(int i2, long j2, int i3, byte[] bArr, int i4, int i5) {
        return false;
    }

    public boolean a(int i2, String str, String str2) {
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + i2 + "] task init ...");
        }
        this.aJ.a();
        String trim = str.trim();
        this.H = i2;
        this.C = trim;
        this.D = c(str2);
        this.E = this.D + ".temp";
        this.F = this.D + ".temp!";
        this.G = this.D + ".trt";
        this.ah = 0L;
        this.ai = 0L;
        this.B = new aw();
        this.B.a(trim);
        this.T = System.currentTimeMillis();
        this.U = this.T;
        this.V = this.T;
        this.W = this.T;
        this.X = this.T;
        this.Y = -1L;
        this.Z = -1L;
        this.I = 0;
        this.J = 0;
        this.R = t;
        this.aa = x;
        this.ac = bl.TORRENT_STATUS_UNKNOWN.ordinal();
        this.ad = 0;
        this.ae = null;
        this.ab = false;
        this.S = this.B.d();
        if (com.qihoo.d.b.a.y == 2 || com.qihoo.d.b.a.d <= 10) {
            this.S = 2;
        }
        this.af = false;
        this.ag = false;
        this.K = null;
        this.ak = false;
        this.al = false;
        this.am = false;
        this.an = 0L;
        this.av = false;
        this.au = false;
        this.at = com.qihoo.d.b.m.a(str2);
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "]   m_bWindows: " + this.at);
        }
        this.P = new ao();
        this.Q = new av();
        this.A = new bc(this.H);
        if ((this.S & 2) > 0) {
            this.P.a(this.H);
            this.A.b(2);
        }
        if ((this.S & 1) > 0) {
            this.Q.a(this.B.b(), this.B.c(), i2, this.B.e());
            this.Q.b(5);
            this.az = 1;
        } else {
            this.az = 0;
        }
        this.A.c(2);
        this.A.a();
        this.ah = this.B.c();
        if (this.ah > 0) {
            this.A.a(this.ah);
        }
        s();
        this.O = true;
        return true;
    }

    public boolean a(int i2, byte[] bArr, int i3, int i4, int i5) {
        if (!this.O) {
            return false;
        }
        this.au = !this.Q.a(i2, bArr, i3, i4, i5);
        if (this.au && this.av) {
            this.R = v;
            this.J = k;
        }
        return this.au ? false : true;
    }

    public boolean a(bi biVar) {
        if (!this.O) {
            return false;
        }
        long currentTimeMillis = System.currentTimeMillis();
        if (this.ak) {
            biVar.d = this.an;
            biVar.f4262b = this.ah;
            biVar.g = 0L;
            biVar.f = this.an;
            biVar.c = this.an;
            biVar.e = 0L;
            biVar.n = this.R;
            biVar.o = this.aa;
            biVar.t = this.D;
            biVar.u = this.P.o();
            biVar.k = 0;
            biVar.h = this.aD;
            biVar.i = this.aE;
            biVar.l = this.ao.b(5, currentTimeMillis);
            biVar.p = 16384;
            biVar.q = 0;
            biVar.r = null;
            biVar.s = 0L;
            biVar.w = this.aB;
            biVar.v = this.aA;
            biVar.x = this.az == 2 ? 1 : 0;
        } else {
            biVar.d = this.A.j();
            biVar.f4262b = this.A.f();
            biVar.g = this.A.l();
            biVar.f = this.A.k();
            biVar.c = this.A.j() + this.A.i();
            biVar.e = 0L;
            biVar.n = this.R;
            biVar.o = this.aa;
            biVar.t = this.D;
            biVar.u = this.P.o();
            biVar.h = this.aD;
            biVar.i = this.aE;
            biVar.l = this.P.c(currentTimeMillis);
            biVar.k = this.Q.a(currentTimeMillis);
            biVar.p = 16384;
            biVar.q = this.A.n();
            biVar.r = this.A.m();
            biVar.s = this.P.l() + biVar.g;
            biVar.w = this.aB;
            biVar.v = this.aA;
            biVar.x = this.az == 2 ? 1 : 0;
        }
        if (this.V != this.W) {
            biVar.m = (int) ((biVar.d * 1000) / (this.W - this.V));
        } else if (currentTimeMillis > this.V) {
            biVar.m = (int) ((biVar.d * 1000) / (currentTimeMillis - this.V));
        } else {
            biVar.m = 0;
            if (currentTimeMillis < this.V) {
                this.U = currentTimeMillis;
                this.V = currentTimeMillis;
                this.W = currentTimeMillis;
                this.X = currentTimeMillis;
            }
        }
        biVar.f4261a = this.H;
        biVar.j = 0;
        if (biVar.l != 0 || biVar.k != 0 || this.aa != z) {
            this.T = currentTimeMillis;
        }
        if (com.qihoo.d.b.a.g != 0 && this.aa == z && this.R == t) {
            if (this.N && !this.M && currentTimeMillis - this.T > 10000) {
                this.P.b(2);
                this.M = true;
            }
            if (com.qihoo.d.b.a.y == 2) {
                com.qihoo.d.b.a.g = 10;
            }
            if (currentTimeMillis - this.T > com.qihoo.d.b.a.g * 1000 && ((biVar.f4262b > 0 && biVar.f4262b != biVar.c) || biVar.f4262b == 0)) {
                this.R = w;
                this.J = o;
            }
        }
        return true;
    }

    public boolean a(k kVar) {
        int[] iArr = new int[1];
        if (!this.Q.a(kVar, iArr)) {
            return false;
        }
        return d(iArr[0]);
    }

    public boolean a(String str, String str2, String[] strArr) {
        this.P.a(str, str2, strArr);
        if (str.equals("agent")) {
            this.aq = str2;
        } else if (str.equals("cookie")) {
            this.ap = str2;
        } else if (str.equals("refer")) {
            this.ar = str2;
        } else if (str.equals("checkdata")) {
            this.ax = Integer.parseInt(str2) > 0;
        } else if (str.equals("writefile")) {
            this.L = Integer.parseInt(str2) > 0;
        } else if (str.equals("tfw")) {
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  TFWMode:" + str2);
            }
            if (Integer.parseInt(str2) == 1) {
                this.P.b(1);
            } else {
                this.N = Integer.parseInt(str2) > 0;
            }
        } else if (str.equals("maxconnect")) {
            if (com.qihoo.d.b.a.y != 2) {
                this.as = Integer.parseInt(str2);
                if (this.as <= 0) {
                    this.as = 1;
                } else if (this.as > 5) {
                    this.as = 5;
                }
                if (this.at) {
                    this.A.a(this.as);
                }
            }
        } else if (str.equals("limitspeed")) {
            int parseInt = Integer.parseInt(str2);
            if (parseInt <= 0) {
                parseInt = 102400;
            }
            com.qihoo.d.b.a.G = parseInt;
        } else if (str.equals("pdown")) {
            b(str2);
        } else if (str.equals(HttpTask.TYPE)) {
            a(str2);
        }
        return true;
    }

    public boolean a(String str, String[] strArr, int i2) {
        if (!this.O) {
            this.aF = 1;
            return false;
        }
        if (this.Z == -1) {
            this.Z = System.currentTimeMillis() - this.V;
        }
        if (this.R != t) {
            this.aF = 2;
            return true;
        }
        if (!f()) {
            this.aF = 3;
            return true;
        }
        if (i2 > 0) {
            this.aG = strArr[0];
        }
        if (!this.P.a(str, strArr, i2)) {
            this.aF = 4;
            j(this.P.f());
            return true;
        }
        this.aF = 5;
        this.aj = true;
        d();
        e();
        return true;
    }

    public boolean a(boolean z2) {
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "] DeleteTask .... DeleteFile:" + z2);
        }
        if (!this.O) {
            return false;
        }
        if ((this.S & 1) > 0) {
            this.Q.b();
        }
        if ((this.S & 2) > 0) {
            this.P.c();
        }
        if (this.R == u) {
        }
        this.aI.a(this.H, z2);
        this.A.d();
        String m2 = m();
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "] DeleteTask ...." + m2);
        }
        this.aa = y;
        this.W = System.currentTimeMillis();
        this.am = true;
        return true;
    }

    public void b(long j2) {
        an d2;
        if (this.O && this.R == t && f() && (d2 = this.P.d(j2)) != null) {
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "] cid:" + d2.f + " Task PickBadHttps!");
            }
            this.A.e(d2.f);
            if (this.P.a(d2) != 0) {
            }
        }
    }

    public boolean b() {
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "] StartTask ....strPdown:" + this.C + " FileName:" + this.D);
        }
        if (!this.O) {
            return false;
        }
        this.T = System.currentTimeMillis();
        if (this.R == u) {
            return true;
        }
        if ((this.S & 2) > 0 && !this.P.a(this.B.a(), this.ah)) {
            j(this.P.f());
        }
        if ((this.S & 1) > 0) {
            this.Q.a();
        }
        this.aa = z;
        this.V = System.currentTimeMillis();
        this.W = this.V;
        return true;
    }

    public boolean b(int i2) {
        if (!this.O) {
            return false;
        }
        if (this.R != t || !f()) {
            return true;
        }
        if (!this.P.e(i2)) {
            return false;
        }
        String[] strArr = new String[1];
        if (!this.P.a(i2, strArr)) {
            this.P.a(i2, f4259b, new int[1], new int[1], strArr);
            return false;
        }
        if (this.A.a(i2, strArr[0], 80)) {
            e();
            return true;
        }
        this.P.a(i2, f4259b, new int[1], new int[1], strArr);
        return false;
    }

    public boolean b(int i2, int i3) {
        if (!this.O) {
            return false;
        }
        int[] iArr = new int[1];
        String[] strArr = new String[1];
        int[] iArr2 = {this.P.c(i2)};
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "] cid:" + i2 + " APIErr:" + iArr2[0] + " reason:" + i3 + " OnNotifyHttpError");
        }
        this.P.a(i2, i3, iArr2, iArr, strArr);
        if (this.I == 0) {
            this.I = i3;
        }
        this.A.e(i2);
        if (i3 == 20506) {
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "] cid:" + i2 + "  chunked or gzip   ");
            }
            this.ak = true;
            if (this.ao == null) {
                this.ao = new com.qihoo.d.b.s();
            }
        } else if (i3 == 20103) {
            this.I = i3;
            this.R = v;
            this.J = j;
        }
        return true;
    }

    public boolean b(int i2, int i3, int i4) {
        if (this.R != t) {
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  Index:" + i2 + " result:" + i3 + " m_nFinishStatus:" + this.R);
            }
        } else if (i3 == 1) {
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "]   OnNotifyDiskCheckOps  Index:" + i2);
            }
            this.A.h(i2);
        } else {
            this.A.i(i2);
            this.I = i4;
            this.ay = true;
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  OnNotifyDiskCheckOps Index:" + i2 + "  校验数据错误!");
            }
        }
        return true;
    }

    public boolean b(int i2, int i3, int i4, int i5) {
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "] cid:" + i2 + "  OnNotifyP2PCancel  index:" + i3 + " begin:" + i4);
        }
        if (this.O) {
            return this.Q.b(i2, i3, i4, i4 + i5);
        }
        return false;
    }

    public boolean b(int i2, int i3, byte[] bArr) {
        if (!this.O) {
            return false;
        }
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "] cid:" + i2 + "  OnNotifyP2PMetaFile :");
        }
        if (this.ac == bl.TORRENT_STATUS_UNKNOWN.ordinal()) {
            if (i3 == 0 || i3 > u.f4334a || bArr == null) {
                return false;
            }
            this.ad = i3;
            if (this.ae != null) {
                this.ae = null;
            }
            this.ae = new byte[i3];
            System.arraycopy(bArr, 0, this.ae, 0, i3);
            if (this.A.a(this.ae, this.ad, i())) {
                this.ah = this.A.f();
                this.P.b(this.ah);
                this.Q.b(this.ah);
                this.ac = bl.TORRENT_STATUS_EXIST_P2P.ordinal();
            }
        }
        if (!f()) {
            return true;
        }
        a(i2);
        return true;
    }

    public boolean c() {
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "] StopTask ....");
        }
        if (!this.O) {
            return false;
        }
        if ((this.S & 1) > 0) {
            this.Q.b();
        }
        if ((this.S & 2) > 0) {
            this.P.b();
        }
        if (this.R != u) {
            this.A.d();
        }
        this.aa = y;
        this.W = System.currentTimeMillis();
        this.am = true;
        return true;
    }

    public boolean c(int i2) {
        if (!this.O) {
            return false;
        }
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "] cid:" + i2 + " OnNotifyHttpError");
        }
        this.P.f(i2);
        this.A.e(i2);
        return true;
    }

    public boolean c(int i2, int i3) {
        if (!this.O) {
            return false;
        }
        this.P.b(i2, i3);
        return true;
    }

    public void d() {
        if (this.O && this.R == t && f()) {
            int[] iArr = new int[1];
            if (this.P.a(iArr)) {
                for (int i2 = 0; i2 < iArr[0]; i2++) {
                    if (this.P.c(new int[1]) != 0) {
                        if (this.P.n() + this.P.m() == 0) {
                            j(this.P.f());
                            return;
                        }
                        return;
                    }
                }
            }
        }
    }

    public boolean d(int i2) {
        if (!this.O) {
            return false;
        }
        if (this.ac != bl.TORRENT_STATUS_UNKNOWN.ordinal()) {
            this.Q.b(0);
        }
        if (!this.Q.c(i2)) {
            return false;
        }
        if (this.ac != bl.TORRENT_STATUS_UNKNOWN.ordinal()) {
            byte[] m2 = this.A.m();
            int h2 = (this.A.h() + 7) / 8;
            if (m2 != null) {
                this.Q.b(i2, m2, h2);
            }
        }
        au a2 = this.Q.a(i2);
        if (a2 == null) {
            return false;
        }
        int i3 = a2.f.f4243b;
        if (a2.e == null) {
            return false;
        }
        return this.A.a(i2, com.qihoo.d.b.a.a(i3), a2.f.c, null, 0, a2.e.m, a2.e.c());
    }

    public boolean d(int i2, int i3) {
        if (!this.O) {
            return false;
        }
        if (!f()) {
            return true;
        }
        this.Q.c(i2, i3);
        this.A.a(i2, i3);
        a(i2);
        return true;
    }

    public void e() {
        if (this.O && this.R == t && f()) {
            int[] iArr = new int[1];
            if (this.P.b(iArr)) {
                for (int i2 = 0; i2 < iArr[0]; i2++) {
                    long[] jArr = new long[1];
                    long[] jArr2 = new long[1];
                    af k2 = this.P.k();
                    if (k2 == null) {
                        return;
                    }
                    if (this.A.f() == 0) {
                        this.ah = this.P.d();
                        if (this.ah > 0) {
                            this.A.a(this.ah);
                        }
                    }
                    if (!this.A.a(k2.f4206a, jArr, jArr2)) {
                        if (com.qihoo.d.b.a.c) {
                            com.qihoo.d.b.p.b("TaskID:[" + this.H + "] cid:" + k2.f4206a + " AllocRange fail ErrCode:" + this.A.c());
                            return;
                        }
                        return;
                    } else {
                        if (this.P.a(k2, jArr[0], jArr2[0]) != 0) {
                            if (this.P.n() + this.P.m() == 0) {
                                j(this.P.f());
                                return;
                            }
                            return;
                        }
                    }
                }
            }
        }
    }

    public boolean e(int i2) {
        if (!this.O) {
            return false;
        }
        if (this.ac != bl.TORRENT_STATUS_UNKNOWN.ordinal() && this.ad != 0 && this.ae != null) {
            this.Q.a(i2, this.ae, this.ad);
        }
        return true;
    }

    public boolean e(int i2, int i3) {
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "] cid:" + i2 + "  Reason " + i3 + "  OnNotifyP2PError ");
        }
        if (this.O) {
            return this.Q.b(i2, i3);
        }
        return false;
    }

    public boolean f() {
        if (!this.A.o()) {
            return true;
        }
        if (this.R != t || this.ag) {
            return false;
        }
        if (this.az == 1 && this.ac == bl.TORRENT_STATUS_EXIST_P2P.ordinal()) {
            if (com.qihoo.d.b.a.c) {
                com.qihoo.d.b.p.b("TaskID:[" + this.H + "]   CheckDataStatus ");
            }
            this.aI.a(this.H);
            return false;
        }
        if (this.ax && (this.S & 1) > 0 && this.ac == bl.TORRENT_STATUS_UNKNOWN.ordinal() && this.ah < 104857600) {
            o();
            this.ag = true;
            return false;
        }
        q();
        this.ag = true;
        if ((this.S & 1) > 0) {
            this.Q.b();
        }
        if ((this.S & 2) <= 0) {
            return false;
        }
        this.P.c();
        return false;
    }

    public boolean f(int i2) {
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "] cid:" + i2 + "  OnNotifyP2PInterested ");
        }
        if (this.O) {
            return this.Q.d(i2);
        }
        return false;
    }

    public boolean f(int i2, int i3) {
        if (i2 != 0) {
            return true;
        }
        this.I = i3;
        this.R = v;
        this.J = c;
        return true;
    }

    public String g() {
        return this.D;
    }

    public boolean g(int i2) {
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "] cid:" + i2 + "  OnNotifyP2PUnchoke ");
        }
        if (!this.O) {
            return false;
        }
        if (!f()) {
            return true;
        }
        a(i2);
        return true;
    }

    public boolean g(int i2, int i3) {
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.a("TaskID:[" + this.H + "] RenameMsg end..");
        }
        if (i2 == 1) {
            try {
                new File(this.F).delete();
            } catch (Exception e2) {
            }
            this.I = 0;
            this.R = u;
        } else {
            this.I = i3;
            this.R = v;
            this.J = f;
        }
        return true;
    }

    public int h() {
        return this.S;
    }

    public boolean h(int i2) {
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "] cid:" + i2 + "  OnNotifyP2PRelease ");
        }
        if (this.O) {
            return this.Q.e(i2);
        }
        return false;
    }

    public boolean h(int i2, int i3) {
        this.aB = System.currentTimeMillis() - this.aC;
        this.aA = 2;
        this.az = 2;
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.a("TaskID:[" + this.H + "] OnNotifyDiskFileHashOps end..");
        }
        if (i2 == 1) {
            q();
        } else {
            this.I = i3;
            this.R = v;
            this.J = h;
        }
        return true;
    }

    public String i() {
        return this.B.b();
    }

    public boolean i(int i2) {
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "]   OnNotifyDiskCheckStatusOps  result:" + i2);
        }
        this.az = i2 > 0 ? 2 : 1;
        return true;
    }

    public int j() {
        return this.H;
    }

    public int k() {
        return this.I;
    }

    public String l() {
        String m2 = m();
        int i2 = 0;
        while (i2 < this.aH.size() && i2 <= 20) {
            String str = m2 + ",LocationURL" + i2 + "|" + ((String) this.aH.get(i2));
            i2++;
            m2 = str;
        }
        return m2;
    }

    public String m() {
        long j2;
        long j3;
        long k2;
        long l2;
        long currentTimeMillis = System.currentTimeMillis() - this.V;
        if (this.ak) {
            j2 = this.an;
            j3 = this.an;
            k2 = this.an;
            l2 = 0;
        } else {
            j2 = this.A.j();
            j3 = this.A.j() + this.A.i();
            k2 = this.A.k();
            l2 = this.A.l();
        }
        this.K = "Status|" + this.aa + ",FStatus|" + this.R + ",ErrCode|" + this.I + ",ErrorType|" + this.J + ",FileLen|" + this.ah + ",TotalDownLen|" + j3 + ",DownLen|" + j2 + ",Tick|" + currentTimeMillis + ",P2SLen|" + k2 + ",P2PLen|" + l2 + ",Ver|1.1.0.180,S1|" + com.qihoo.d.b.a.f;
        if (this.P.g()) {
            this.K += ",S2|" + this.P.h();
            this.K += ",S3|" + this.P.i();
        }
        if (!this.ak) {
            this.K += ",Speed|" + this.P.c(System.currentTimeMillis());
            this.K += ",S4|" + com.qihoo.d.b.a.u;
        }
        this.K += ",S5|" + this.aF;
        this.K += ",S6|" + this.aG;
        this.K += ",S7|" + com.qihoo.d.b.a.v;
        this.K += ",S8|" + com.qihoo.d.b.a.w;
        this.K += ",S9|" + this.Y;
        this.K += ",S10|" + this.Z;
        this.K += ",S11|" + this.P.p();
        this.K += ",S12|" + com.qihoo.d.b.a.q;
        this.K += ",S13|" + com.qihoo.d.b.a.p;
        this.K += ",S14|" + com.qihoo.d.b.a.r;
        this.K += ",S15|" + this.N;
        this.K += ",S16|" + this.P.e();
        this.K += ",S17|" + this.aw;
        this.K += ",S18|" + this.Q.e();
        if (this.ay) {
            this.K += ",S19|1";
        } else {
            this.K += ",S20|0";
        }
        if (this.R == 2) {
            this.K += ",S21|" + com.qihoo.d.b.a.e;
            if (this.K.length() > 600) {
                this.K = this.K.substring(0, 600);
            }
        }
        return this.K;
    }

    public boolean n() {
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.b("TaskID:[" + this.H + "]  OnNotifyP2PRelogin ");
        }
        if (!this.O) {
            return false;
        }
        if (this.R == t) {
            return this.Q.f();
        }
        return true;
    }

    public boolean o() {
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.a("TaskID:[" + this.H + "] CheckFileMsg start..");
        }
        if (!r()) {
            return false;
        }
        this.aA = 1;
        this.aC = System.currentTimeMillis();
        return this.aI.b(this.H, i());
    }

    public void p() {
        if (com.qihoo.d.b.a.c) {
            com.qihoo.d.b.p.a("TaskID:[" + this.H + "]  ReStartTask");
        }
        try {
            a(true);
            a();
            File file = new File(this.D);
            File file2 = new File(this.D + ".temp");
            File file3 = new File(this.D + ".temp!");
            file.delete();
            file2.delete();
            file3.delete();
        } catch (Exception e2) {
        }
        a(this.H, this.C, this.D);
        b();
    }
}