抖阴.apk(点击下载) / l.java


package com.tencent.smtt.sdk;

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import com.alipay.sdk.util.g;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.lzy.okgo.model.HttpHeaders;
import com.tencent.smtt.sdk.TbsDownloadConfig;
import com.tencent.smtt.sdk.TbsLogReport;
import com.tencent.smtt.utils.Apn;
import com.tencent.smtt.utils.FileUtil;
import com.tencent.smtt.utils.TbsLog;
import com.tencent.smtt.utils.a;
import com.tencent.smtt.utils.b;
import com.tencent.smtt.utils.p;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
import java.util.zip.Inflater;
import java.util.zip.InflaterInputStream;
import javax.net.ssl.SSLHandshakeException;

/* access modifiers changed from: package-private */
public class l {

    /* renamed from: e  reason: collision with root package name */
    private static int f6818e = 5;

    /* renamed from: f  reason: collision with root package name */
    private static int f6819f = 1;
    private static final String[] g = {"tbs_downloading_com.tencent.mtt", "tbs_downloading_com.tencent.mm", "tbs_downloading_com.tencent.mobileqq", "tbs_downloading_com.tencent.tbs", "tbs_downloading_com.qzone"};
    private Handler A;
    private Set<String> B;
    private int C = f6818e;
    private boolean D;
    String a;

    /* renamed from: b  reason: collision with root package name */
    String[] f6820b = null;

    /* renamed from: c  reason: collision with root package name */
    int f6821c = 0;

    /* renamed from: d  reason: collision with root package name */
    private boolean f6822d = false;
    private Context h;
    private String i;
    private String j;
    private String k;
    private File l;
    private long m;
    private int n = 30000;
    private int o = 20000;
    private boolean p;
    private int q;
    private int r;
    private boolean s;
    private boolean t;
    private HttpURLConnection u;
    private String v;
    private TbsLogReport.TbsLogInfo w;
    private String x;
    private int y;
    private boolean z;

    public l(Context context) throws NullPointerException {
        this.h = context.getApplicationContext();
        this.w = TbsLogReport.getInstance(this.h).tbsLogInfo();
        this.B = new HashSet();
        this.v = "tbs_downloading_" + this.h.getPackageName();
        o.a();
        this.l = o.s(this.h);
        if (this.l != null) {
            g();
            this.x = null;
            this.y = -1;
            return;
        }
        throw new NullPointerException("TbsCorePrivateDir is null!");
    }

    private long a(long j2, long j3) {
        long currentTimeMillis = System.currentTimeMillis();
        this.w.setDownConsumeTime(currentTimeMillis - j2);
        this.w.setDownloadSize(j3);
        return currentTimeMillis;
    }

    @TargetApi(8)
    static File a(Context context) {
        try {
            File file = Build.VERSION.SDK_INT >= 8 ? new File(FileUtil.a(context, 4)) : null;
            if (file != null && !file.exists() && !file.isDirectory()) {
                file.mkdirs();
            }
            return file;
        } catch (Exception e2) {
            e2.printStackTrace();
            TbsLog.e(TbsDownloader.LOGTAG, "[TbsApkDownloader.backupApkPath] Exception is " + e2.getMessage());
            return null;
        }
    }

    private static File a(Context context, int i2) {
        File file = new File(FileUtil.a(context, i2));
        if (file.exists() && file.isDirectory()) {
            if (new File(file, TbsDownloader.getOverSea(context) ? "x5.oversea.tbs.org" : TbsDownloader.getBackupFileName(false)).exists()) {
                return file;
            }
        }
        return null;
    }

    private String a(Throwable th) {
        String stackTraceString = Log.getStackTraceString(th);
        return stackTraceString.length() > 1024 ? stackTraceString.substring(0, 1024) : stackTraceString;
    }

    private String a(URL url) {
        try {
            return InetAddress.getByName(url.getHost()).getHostAddress();
        } catch (Exception e2) {
            e2.printStackTrace();
        } catch (Error e3) {
            e3.printStackTrace();
        }
        return "";
    }

    private void a(int i2, String str, boolean z2) {
        if (z2 || this.q > this.C) {
            this.w.setErrorCode(i2);
            this.w.setFailDetail(str);
        }
    }

    private void a(long j2) {
        this.q++;
        if (j2 <= 0) {
            try {
                j2 = n();
            } catch (Exception unused) {
                return;
            }
        }
        Thread.sleep(j2);
    }

    private void a(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (IOException unused) {
            }
        }
    }

    public static void a(File file, Context context) {
        synchronized (a.class) {
            if (file != null) {
                if (file.exists()) {
                    if (!TbsShareManager.isThirdPartyApp(context)) {
                        try {
                            File a2 = a(context);
                            if (a2 != null) {
                                File file2 = TbsDownloadConfig.getInstance(context).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V_TYPE, 0) == 1 ? new File(a2, TbsDownloader.getBackupFileName(true)) : new File(a2, TbsDownloader.getOverSea(context) ? "x5.oversea.tbs.org" : TbsDownloader.getBackupFileName(false));
                                file2.delete();
                                FileUtil.b(file, file2);
                                boolean contains = file2.getName().contains("tbs.org");
                                boolean contains2 = file2.getName().contains("x5.tbs.decouple");
                                if (contains2 || contains) {
                                    File[] listFiles = a2.listFiles();
                                    Pattern compile = Pattern.compile(a.a(contains2) + "(.*)");
                                    for (File file3 : listFiles) {
                                        if (compile.matcher(file3.getName()).find() && file3.isFile() && file3.exists()) {
                                            file3.delete();
                                        }
                                    }
                                    File file4 = new File(a2, a.a(contains2) + "." + TbsDownloadConfig.getInstance(context).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V, 0));
                                    if (file4.exists()) {
                                        TbsLog.e(TbsDownloader.LOGTAG, "[TbsApkDownloader.backupTbsApk]delete bacup config file error ");
                                        return;
                                    }
                                    file4.createNewFile();
                                }
                                if (TbsDownloadConfig.getInstance(context).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V_TYPE, 0) != 1 && TbsDownloadConfig.getInstance(context).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DECOUPLECOREVERSION, 0) == a.a(context, file)) {
                                    int i2 = TbsDownloadConfig.getInstance(context).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_RESPONSECODE, 0);
                                    if (i2 == 5 || i2 == 3) {
                                        TbsLog.i("TbsApkDownloader", "response code=" + i2 + "return backup decouple apk");
                                    }
                                    File file5 = new File(a2, TbsDownloader.getBackupFileName(true));
                                    if (a.a(context, file) != a.a(context, file5)) {
                                        file5.delete();
                                        FileUtil.b(file, file5);
                                    }
                                }
                            }
                        } catch (Exception unused) {
                        }
                    }
                }
            }
        }
    }

    private void a(String str) throws Exception {
        URL url = new URL(str);
        HttpURLConnection httpURLConnection = this.u;
        if (httpURLConnection != null) {
            try {
                httpURLConnection.disconnect();
            } catch (Throwable th) {
                TbsLog.e(TbsDownloader.LOGTAG, "[initHttpRequest] mHttpRequest.disconnect() Throwable:" + th.toString());
            }
        }
        this.u = (HttpURLConnection) url.openConnection();
        this.u.setRequestProperty(HttpHeaders.HEAD_KEY_USER_AGENT, TbsDownloader.b(this.h));
        this.u.setRequestProperty(HttpHeaders.HEAD_KEY_ACCEPT_ENCODING, "identity");
        this.u.setRequestMethod("GET");
        this.u.setInstanceFollowRedirects(false);
        this.u.setConnectTimeout(this.o);
        this.u.setReadTimeout(this.n);
    }

    private boolean a(File file) {
        int i2 = TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_USE_BACKUP_VERSION, 0);
        if (i2 == 0) {
            i2 = TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V, 0);
        }
        return a.a(this.h, file, 0, i2);
    }

    @TargetApi(8)
    static File b(Context context) {
        try {
            if (Build.VERSION.SDK_INT < 8) {
                return null;
            }
            File a2 = a(context, 4);
            if (a2 == null) {
                a2 = a(context, 3);
            }
            if (a2 == null) {
                a2 = a(context, 2);
            }
            return a2 == null ? a(context, 1) : a2;
        } catch (Exception e2) {
            e2.printStackTrace();
            TbsLog.e(TbsDownloader.LOGTAG, "[TbsApkDownloader.backupApkPath] Exception is " + e2.getMessage());
            return null;
        }
    }

    private boolean b(int i2) {
        try {
            File file = new File(this.l, "x5.tbs");
            File a2 = a(this.h);
            if (a2 == null) {
                return false;
            }
            File file2 = new File(a2, TbsDownloader.getOverSea(this.h) ? "x5.oversea.tbs.org" : TbsDownloader.getBackupFileName(false));
            file.delete();
            FileUtil.b(file2, file);
            if (a.a(this.h, file, 0, i2)) {
                return true;
            }
            TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.copyTbsApkFromBackupToInstall] verifyTbsApk error!!");
            return false;
        } catch (Exception e2) {
            e2.printStackTrace();
            TbsLog.e(TbsDownloader.LOGTAG, "[TbsApkDownloader.copyTbsApkFromBackupToInstall] Exception is " + e2.getMessage());
            return false;
        }
    }

    public static void c(Context context) {
        try {
            o.a();
            File s2 = o.s(context);
            new File(s2, "x5.tbs").delete();
            new File(s2, "x5.tbs.temp").delete();
            File a2 = a(context);
            if (a2 != null) {
                new File(a2, TbsDownloader.getBackupFileName(false)).delete();
                new File(a2, "x5.oversea.tbs.org").delete();
                File[] listFiles = a2.listFiles();
                Pattern compile = Pattern.compile(a.a(true) + "(.*)");
                for (File file : listFiles) {
                    if (compile.matcher(file.getName()).find() && file.isFile() && file.exists()) {
                        file.delete();
                    }
                }
                Pattern compile2 = Pattern.compile(a.a(false) + "(.*)");
                for (File file2 : listFiles) {
                    if (compile2.matcher(file2.getName()).find() && file2.isFile() && file2.exists()) {
                        file2.delete();
                    }
                }
            }
        } catch (Exception unused) {
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:18:0x0085, code lost:
        if (r10 != r8) goto L_0x0087;
     */
    private boolean c(boolean z2, boolean z3) {
        boolean z4;
        int i2;
        TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] isTempFile=" + z2);
        File file = new File(this.l, !z2 ? "x5.tbs" : "x5.tbs.temp");
        if (!file.exists()) {
            return false;
        }
        Exception exc = null;
        String string = TbsDownloadConfig.getInstance(this.h).mPreferences.getString(TbsDownloadConfig.TbsConfigKey.KEY_TBSAPK_MD5, null);
        String a2 = a.a(file);
        if (string == null || !string.equals(a2)) {
            TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] isTempFile=" + z2 + " md5 failed");
            if (z2) {
                this.w.setCheckErrorDetail("fileMd5 not match");
            }
            return false;
        }
        TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] md5(" + a2 + ") successful!");
        long j2 = 0;
        if (z2) {
            long j3 = TbsDownloadConfig.getInstance(this.h).mPreferences.getLong(TbsDownloadConfig.TbsConfigKey.KEY_TBSAPKFILESIZE, 0);
            if (file.exists()) {
                if (j3 > 0) {
                    j2 = file.length();
                }
            }
            TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] isTempFile=" + z2 + " filelength failed");
            TbsLogReport.TbsLogInfo tbsLogInfo = this.w;
            tbsLogInfo.setCheckErrorDetail("fileLength:" + j2 + ",contentLength:" + j3);
            return false;
        }
        TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] length(" + j2 + ") successful!");
        int i3 = -1;
        if (!z3 || z2 || (i2 = TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V, 0)) == (i3 = a.a(this.h, file))) {
            TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] tbsApkVersionCode(" + i3 + ") successful!");
            if (z3 && !z2) {
                String a3 = b.a(this.h, false, file);
                if (!"3082023f308201a8a00302010202044c46914a300d06092a864886f70d01010505003064310b30090603550406130238363110300e060355040813074265696a696e673110300e060355040713074265696a696e673110300e060355040a130754656e63656e74310c300a060355040b13035753443111300f0603550403130873616d75656c6d6f301e170d3130303732313036313835305a170d3430303731333036313835305a3064310b30090603550406130238363110300e060355040813074265696a696e673110300e060355040713074265696a696e673110300e060355040a130754656e63656e74310c300a060355040b13035753443111300f0603550403130873616d75656c6d6f30819f300d06092a864886f70d010101050003818d0030818902818100c209077044bd0d63ea00ede5b839914cabcc912a87f0f8b390877e0f7a2583f0d5933443c40431c35a4433bc4c965800141961adc44c9625b1d321385221fd097e5bdc2f44a1840d643ab59dc070cf6c4b4b4d98bed5cbb8046e0a7078ae134da107cdf2bfc9b440fe5cb2f7549b44b73202cc6f7c2c55b8cfb0d333a021f01f0203010001300d06092a864886f70d010105050003818100b007db9922774ef4ccfee81ba514a8d57c410257e7a2eba64bfa17c9e690da08106d32f637ac41fbc9f205176c71bde238c872c3ee2f8313502bee44c80288ea4ef377a6f2cdfe4d3653c145c4acfedbfbadea23b559d41980cc3cdd35d79a68240693739aabf5c5ed26148756cf88264226de394c8a24ac35b712b120d4d23a".equals(a3)) {
                    TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] isTempFile=" + z2 + " signature failed");
                    if (z2) {
                        TbsLogReport.TbsLogInfo tbsLogInfo2 = this.w;
                        StringBuilder sb = new StringBuilder();
                        sb.append("signature:");
                        sb.append(a3 == null ? "null" : Integer.valueOf(a3.length()));
                        tbsLogInfo2.setCheckErrorDetail(sb.toString());
                    }
                    return false;
                }
            }
            TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] signature successful!");
            if (z2) {
                try {
                    z4 = file.renameTo(new File(this.l, "x5.tbs"));
                } catch (Exception e2) {
                    exc = e2;
                    z4 = false;
                }
                if (!z4) {
                    a(109, a(exc), true);
                    return false;
                }
            } else {
                z4 = false;
            }
            TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] rename(" + z4 + ") successful!");
            return true;
        }
        TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] isTempFile=" + z2 + " versionCode failed");
        if (z2) {
            TbsLogReport.TbsLogInfo tbsLogInfo3 = this.w;
            tbsLogInfo3.setCheckErrorDetail("fileVersion:" + i3 + ",configVersion:" + i2);
        }
        return false;
    }

    private void d(boolean z2) {
        Bundle a2;
        p.a(this.h);
        TbsDownloadConfig instance = TbsDownloadConfig.getInstance(this.h);
        instance.mSyncMap.put(TbsDownloadConfig.TbsConfigKey.KEY_FULL_PACKAGE, false);
        instance.mSyncMap.put(TbsDownloadConfig.TbsConfigKey.KEY_NEEDDOWNLOAD, false);
        instance.mSyncMap.put(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOAD_INTERRUPT_CODE_REASON, -123);
        instance.commit();
        QbSdk.m.onDownloadFinish(z2 ? 100 : 120);
        int i2 = instance.mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_RESPONSECODE, 0);
        boolean a3 = TbsDownloader.a(this.h);
        if (i2 == 5) {
            a2 = a(i2, a3);
            if (a2 == null) {
                return;
            }
        } else if (i2 == 3 || i2 > 10000) {
            File a4 = a(this.h);
            if (a4 != null) {
                a2 = a(i2, a4, a3);
            } else {
                c();
                instance.mSyncMap.put(TbsDownloadConfig.TbsConfigKey.KEY_NEEDDOWNLOAD, true);
                instance.commit();
                return;
            }
        } else {
            o.a().a(this.h, new File(this.l, "x5.tbs").getAbsolutePath(), instance.mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V, 0));
            a(new File(this.l, "x5.tbs"), this.h);
            return;
        }
        o.a().b(this.h, a2);
    }

    private boolean e(boolean z2) {
        TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.deleteFile] isApk=" + z2);
        File file = z2 ? new File(this.l, "x5.tbs") : new File(this.l, "x5.tbs.temp");
        if (file.exists()) {
            FileUtil.b(file);
        }
        return true;
    }

    private void g() {
        this.q = 0;
        this.r = 0;
        this.m = -1;
        this.k = null;
        this.p = false;
        this.s = false;
        this.t = false;
        this.z = false;
    }

    private void h() {
        TbsLogReport.EventType eventType;
        TbsLogReport tbsLogReport;
        TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.closeHttpRequest]");
        HttpURLConnection httpURLConnection = this.u;
        if (httpURLConnection != null) {
            if (!this.s) {
                this.w.setResolveIp(a(httpURLConnection.getURL()));
            }
            try {
                this.u.disconnect();
            } catch (Throwable th) {
                TbsLog.e(TbsDownloader.LOGTAG, "[closeHttpRequest] mHttpRequest.disconnect() Throwable:" + th.toString());
            }
            this.u = null;
        }
        TbsLogReport.TbsLogInfo tbsLogInfo = this.w;
        int i2 = tbsLogInfo.a;
        if (!this.s && this.z) {
            tbsLogInfo.setEventTime(System.currentTimeMillis());
            String apnInfo = Apn.getApnInfo(this.h);
            if (apnInfo == null) {
                apnInfo = "";
            }
            int apnType = Apn.getApnType(this.h);
            this.w.setApn(apnInfo);
            this.w.setNetworkType(apnType);
            if (apnType != this.y || !apnInfo.equals(this.x)) {
                this.w.setNetworkChange(0);
            }
            int i3 = this.w.a;
            if ((i3 == 0 || i3 == 107) && this.w.getDownFinalFlag() == 0 && (!Apn.isNetworkAvailable(this.h) || !m())) {
                a(101, (String) null, true);
            }
            if (TbsDownloader.a(this.h)) {
                tbsLogReport = TbsLogReport.getInstance(this.h);
                eventType = TbsLogReport.EventType.TYPE_DOWNLOAD_DECOUPLE;
            } else {
                tbsLogReport = TbsLogReport.getInstance(this.h);
                eventType = TbsLogReport.EventType.TYPE_DOWNLOAD;
            }
            tbsLogReport.eventReport(eventType, this.w);
            this.w.resetArgs();
            if (i2 != 100) {
                QbSdk.m.onDownloadFinish(i2);
            }
        } else if (!this.f6822d) {
            TbsDownloader.a = false;
        }
    }

    private File i() {
        return TbsDownloader.a(this.h) ? new File(FileUtil.a(this.h, 4), TbsDownloader.getBackupFileName(true)) : new File(FileUtil.a(this.h, 4), TbsDownloader.getOverSea(this.h) ? "x5.oversea.tbs.org" : TbsDownloader.getBackupFileName(false));
    }

    private void j() {
        try {
            File i2 = i();
            if (i2 != null && i2.exists()) {
                FileUtil.b(i2);
                File[] listFiles = i2.getParentFile().listFiles();
                Pattern compile = Pattern.compile(a.a(TbsDownloader.a(this.h)) + "(.*)");
                for (File file : listFiles) {
                    if (compile.matcher(file.getName()).find() && file.isFile() && file.exists()) {
                        FileUtil.b(file);
                    }
                }
            }
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    private boolean k() {
        return new File(this.l, "x5.tbs.temp").exists();
    }

    private long l() {
        File file = new File(this.l, "x5.tbs.temp");
        if (file.exists()) {
            return file.length();
        }
        return 0;
    }

    private boolean m() {
        BufferedReader bufferedReader;
        InputStreamReader inputStreamReader;
        InputStream inputStream;
        Throwable th;
        boolean z2 = false;
        try {
            inputStream = Runtime.getRuntime().exec("ping " + "www.qq.com").getInputStream();
            try {
                inputStreamReader = new InputStreamReader(inputStream);
                try {
                    bufferedReader = new BufferedReader(inputStreamReader);
                    int i2 = 0;
                    while (true) {
                        try {
                            String readLine = bufferedReader.readLine();
                            if (readLine != null) {
                                if (!readLine.contains("TTL") && !readLine.contains("ttl")) {
                                    i2++;
                                    if (i2 >= 5) {
                                        break;
                                    }
                                } else {
                                    z2 = true;
                                }
                            } else {
                                break;
                            }
                        } catch (Throwable th2) {
                            th = th2;
                            try {
                                th.printStackTrace();
                                a(inputStream);
                                a(inputStreamReader);
                                a(bufferedReader);
                                return z2;
                            } catch (Throwable th3) {
                                a(inputStream);
                                a(inputStreamReader);
                                a(bufferedReader);
                                throw th3;
                            }
                        }
                    }
                    z2 = true;
                } catch (Throwable th4) {
                    th = th4;
                    bufferedReader = null;
                    th.printStackTrace();
                    a(inputStream);
                    a(inputStreamReader);
                    a(bufferedReader);
                    return z2;
                }
            } catch (Throwable th5) {
                th = th5;
                inputStreamReader = null;
                bufferedReader = null;
                th.printStackTrace();
                a(inputStream);
                a(inputStreamReader);
                a(bufferedReader);
                return z2;
            }
        } catch (Throwable th6) {
            th = th6;
            inputStream = null;
            inputStreamReader = null;
            bufferedReader = null;
            th.printStackTrace();
            a(inputStream);
            a(inputStreamReader);
            a(bufferedReader);
            return z2;
        }
        a(inputStream);
        a(inputStreamReader);
        a(bufferedReader);
        return z2;
    }

    private long n() {
        int i2 = this.q;
        return (i2 == 1 || i2 == 2) ? ((long) i2) * 20000 : (i2 == 3 || i2 == 4) ? 100000 : 200000;
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    /* JADX WARNING: Code restructure failed: missing block: B:14:0x007c, code lost:
        if (r5 != null) goto L_0x0088;
     */
    private boolean o() {
        String str;
        HttpURLConnection httpURLConnection;
        Throwable th;
        boolean z2 = false;
        boolean z3 = Apn.getApnType(this.h) == 3;
        TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDwonloader.detectWifiNetworkAvailable] isWifi=" + z3);
        if (z3) {
            str = Apn.getWifiSSID(this.h);
            TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDwonloader.detectWifiNetworkAvailable] localBSSID=" + str);
            try {
                httpURLConnection = (HttpURLConnection) new URL("https://pms.mb.qq.com/rsp204").openConnection();
                try {
                    httpURLConnection.setInstanceFollowRedirects(false);
                    httpURLConnection.setConnectTimeout(10000);
                    httpURLConnection.setReadTimeout(10000);
                    httpURLConnection.setUseCaches(false);
                    httpURLConnection.getInputStream();
                    int responseCode = httpURLConnection.getResponseCode();
                    TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDwonloader.detectWifiNetworkAvailable] responseCode=" + responseCode);
                    if (responseCode == 204) {
                        z2 = true;
                    }
                } catch (Throwable th2) {
                    th = th2;
                    try {
                        th.printStackTrace();
                    } finally {
                        if (httpURLConnection != null) {
                            try {
                                httpURLConnection.disconnect();
                            } catch (Exception unused) {
                            }
                        }
                    }
                }
            } catch (Throwable th3) {
                th = th3;
                httpURLConnection = null;
                th.printStackTrace();
            }
        } else {
            str = null;
        }
        if (!z2 && !TextUtils.isEmpty(str) && !this.B.contains(str)) {
            this.B.add(str);
            p();
            this.A.sendMessageDelayed(this.A.obtainMessage(150, str), 120000);
        }
        if (z2 && this.B.contains(str)) {
            this.B.remove(str);
        }
        return z2;
    }

    private void p() {
        if (this.A == null) {
            this.A = new Handler(n.a().getLooper()) {
                /* class com.tencent.smtt.sdk.l.AnonymousClass1 */

                public void handleMessage(Message message) {
                    if (message.what == 150) {
                        l.this.o();
                    }
                }
            };
        }
    }

    public Bundle a(int i2, File file, boolean z2) {
        File file2;
        if (z2) {
            file2 = new File(file, TbsDownloader.getBackupFileName(true));
        } else {
            file2 = new File(file, TbsDownloader.getOverSea(this.h) ? "x5.oversea.tbs.org" : TbsDownloader.getBackupFileName(false));
        }
        int a2 = a.a(this.h, file2);
        File file3 = new File(this.l, "x5.tbs");
        String absolutePath = file3.exists() ? file3.getAbsolutePath() : null;
        int i3 = TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V, 0);
        Bundle bundle = new Bundle();
        bundle.putInt("operation", i2);
        bundle.putInt("old_core_ver", a2);
        bundle.putInt("new_core_ver", i3);
        bundle.putString("old_apk_location", file2.getAbsolutePath());
        bundle.putString("new_apk_location", absolutePath);
        bundle.putString("diff_file_location", absolutePath);
        return bundle;
    }

    public Bundle a(int i2, boolean z2) {
        int i3;
        File file;
        o oVar;
        int i4;
        Context context;
        o a2 = o.a();
        Context context2 = this.h;
        if (z2) {
            file = a2.p(context2);
            i3 = o.a().h(this.h);
        } else {
            file = a2.q(context2);
            i3 = o.a().i(this.h);
        }
        File file2 = new File(this.l, "x5.tbs");
        String absolutePath = file2.exists() ? file2.getAbsolutePath() : null;
        if (absolutePath == null) {
            return null;
        }
        int i5 = TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V, 0);
        if (z2) {
            oVar = o.a();
            context = this.h;
            i4 = 6;
        } else {
            oVar = o.a();
            context = this.h;
            i4 = 5;
        }
        File f2 = oVar.f(context, i4);
        Bundle bundle = new Bundle();
        bundle.putInt("operation", i2);
        bundle.putInt("old_core_ver", i3);
        bundle.putInt("new_core_ver", i5);
        bundle.putString("old_apk_location", file.getAbsolutePath());
        bundle.putString("new_apk_location", f2.getAbsolutePath());
        bundle.putString("diff_file_location", absolutePath);
        String a3 = FileUtil.a(this.h, 7);
        File file3 = new File(a3);
        if (!file3.exists()) {
            file3.mkdirs();
        }
        bundle.putString("backup_apk", new File(a3, i5 + ".tbs").getAbsolutePath());
        return bundle;
    }

    public void a(int i2) {
        if (o.a().t(this.h)) {
            o.a().b();
            try {
                File file = new File(this.l, "x5.tbs");
                int a2 = a.a(this.h, file);
                if (-1 == a2 || (i2 > 0 && i2 == a2)) {
                    FileUtil.b(file);
                }
            } catch (Exception unused) {
            }
        }
    }

    public void a(boolean z2) {
        b(z2, false);
    }

    public boolean a() {
        TbsLog.i("TbsApkDownloader", "verifyAndInstallDecoupleCoreFromBackup #1");
        try {
            File file = new File(FileUtil.a(this.h, 4), TbsDownloader.getBackupFileName(true));
            if (file.exists()) {
                TbsLog.i("TbsApkDownloader", "verifyAndInstallDecoupleCoreFromBackup #2");
            } else {
                File b2 = TbsDownloader.b(TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DECOUPLECOREVERSION, -1));
                if (b2 != null && b2.exists()) {
                    FileUtil.b(b2, file);
                }
            }
            if (!a.a(this.h, file, 0, TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DECOUPLECOREVERSION, -1))) {
                return false;
            }
            TbsLog.i("TbsApkDownloader", "verifyAndInstallDecoupleCoreFromBackup #3");
            return o.a().e(this.h);
        } catch (Exception unused) {
            return false;
        }
    }

    public boolean a(boolean z2, boolean z3) {
        String str;
        boolean z4;
        File i2;
        TbsLogReport.EventType eventType;
        TbsLogReport tbsLogReport;
        if (Build.VERSION.SDK_INT == 23) {
            return false;
        }
        int i3 = TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_USE_BACKUP_VERSION, 0);
        int i4 = o.a().i(this.h);
        if (i3 == 0) {
            i3 = TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V, 0);
            str = "by default key";
        } else {
            str = "by new key";
        }
        this.a = str;
        if (!(i3 == 0 || i3 == i4)) {
            if (z3) {
                File a2 = TbsDownloader.a(i3);
                if (a2 != null && a2.exists()) {
                    File file = new File(FileUtil.a(this.h, 4), TbsDownloader.getOverSea(this.h) ? "x5.oversea.tbs.org" : TbsDownloader.getBackupFileName(false));
                    try {
                        if (TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V_TYPE, 0) != 1) {
                            FileUtil.b(a2, file);
                            z4 = true;
                            i2 = i();
                            if (i2 != null || !i2.exists() || !a(i2)) {
                                j();
                                if (a2 != null && a2.exists() && !a.a(this.h, a2, 0, i3) && a2 != null && a2.exists()) {
                                    FileUtil.b(a2);
                                }
                            } else if (b(i3)) {
                                TbsDownloadConfig.getInstance(this.h).mSyncMap.put(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOAD_INTERRUPT_CODE_REASON, -214);
                                TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-214);
                                d(false);
                                if (z4) {
                                    a(100, "use local backup apk in startDownload" + this.a, true);
                                    if (TbsDownloader.a(this.h)) {
                                        tbsLogReport = TbsLogReport.getInstance(this.h);
                                        eventType = TbsLogReport.EventType.TYPE_DOWNLOAD_DECOUPLE;
                                    } else {
                                        tbsLogReport = TbsLogReport.getInstance(this.h);
                                        eventType = TbsLogReport.EventType.TYPE_DOWNLOAD;
                                    }
                                    tbsLogReport.eventReport(eventType, this.w);
                                    this.w.resetArgs();
                                }
                                return true;
                            }
                        }
                    } catch (Exception e2) {
                        e2.printStackTrace();
                    }
                }
                z4 = false;
                i2 = i();
                if (i2 != null) {
                }
                j();
                FileUtil.b(a2);
            }
            if (c(false, z3)) {
                TbsDownloadConfig.getInstance(this.h).mSyncMap.put(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOAD_INTERRUPT_CODE_REASON, -214);
                TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-214);
                d(false);
                return true;
            } else if (!e(true) && !e(true)) {
                TbsLog.e(TbsDownloader.LOGTAG, "[TbsApkDownloader] delete file failed!");
                TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-301);
            }
        }
        return false;
    }

    public void b() {
        TbsLogReport.EventType eventType;
        TbsLogReport tbsLogReport;
        this.s = true;
        if (TbsShareManager.isThirdPartyApp(this.h)) {
            TbsLogReport.TbsLogInfo tbsLogInfo = TbsLogReport.getInstance(this.h).tbsLogInfo();
            tbsLogInfo.setErrorCode(-309);
            tbsLogInfo.setFailDetail(new Exception());
            if (TbsDownloader.a(this.h)) {
                tbsLogReport = TbsLogReport.getInstance(this.h);
                eventType = TbsLogReport.EventType.TYPE_DOWNLOAD_DECOUPLE;
            } else {
                tbsLogReport = TbsLogReport.getInstance(this.h);
                eventType = TbsLogReport.EventType.TYPE_DOWNLOAD;
            }
            tbsLogReport.eventReport(eventType, tbsLogInfo);
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:151:0x03e1, code lost:
        if (r39 == false) goto L_0x0605;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:163:0x040d, code lost:
        if (r39 == false) goto L_0x05a9;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:165:0x0423, code lost:
        if (r39 == false) goto L_0x0605;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:179:0x046e, code lost:
        if (r39 == false) goto L_0x0605;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:187:0x048d, code lost:
        if (r39 == false) goto L_0x0605;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:190:0x0495, code lost:
        if (r39 == false) goto L_0x05a9;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:198:0x04c1, code lost:
        if (r39 == false) goto L_0x0605;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:199:0x04c5, code lost:
        if (r39 == false) goto L_0x05a9;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:213:0x04f3, code lost:
        if (r39 == false) goto L_0x0605;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:214:0x04f7, code lost:
        if (r39 == false) goto L_0x05a9;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:222:0x0510, code lost:
        if (r39 == false) goto L_0x05a9;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:224:0x051f, code lost:
        if (r39 != false) goto L_0x0609;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:241:0x05a7, code lost:
        if (r39 == false) goto L_0x05a9;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:243:0x05b8, code lost:
        r11 = r8;
        r10 = r26;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:247:0x0603, code lost:
        if (r39 == false) goto L_0x0605;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:248:0x0605, code lost:
        r29 = r4;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:249:0x0609, code lost:
        r29 = r4;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:273:0x0676, code lost:
        r34 = r3;
        r29 = r4;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:274:0x067a, code lost:
        r27 = r12;
        r10 = false;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:298:?, code lost:
        com.tencent.smtt.utils.TbsLog.i(r8, "STEP 1/2 begin downloading...failed because you exceeded max flow!", true);
        a(112, "downloadFlow=" + r3 + " downloadMaxflow=" + r12, true);
        com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r38.h).setDownloadInterruptCode(-307);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:302:0x0754, code lost:
        r18 = r3;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:304:0x075b, code lost:
        r0 = th;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:306:0x0760, code lost:
        r0 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:307:0x0761, code lost:
        r18 = r3;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:335:0x07e8, code lost:
        b();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:336:0x07ed, code lost:
        if (com.tencent.smtt.sdk.QbSdk.m == null) goto L_0x07f6;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:337:0x07ef, code lost:
        com.tencent.smtt.sdk.QbSdk.m.onDownloadFinish(111);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:338:0x07f6, code lost:
        com.tencent.smtt.utils.TbsLog.i(r8, "Download is paused due to NOT_WIFI error!", false);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:340:?, code lost:
        com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r38.h).setDownloadInterruptCode(-304);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:341:0x0807, code lost:
        r10 = false;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:347:0x0817, code lost:
        r0 = th;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:349:0x0819, code lost:
        r0 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:384:0x088d, code lost:
        a(r7);
        a(r5);
        a(r9);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:385:0x0898, code lost:
        if (r38.t != false) goto L_0x08a5;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:386:0x089a, code lost:
        com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r38.h).setDownloadInterruptCode(-319);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:387:0x08a5, code lost:
        if (r39 != false) goto L_0x0a1f;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:407:0x091e, code lost:
        if (r39 == false) goto L_0x0a03;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:414:0x0944, code lost:
        if (r39 == false) goto L_0x0966;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:416:0x0964, code lost:
        if (r39 == false) goto L_0x0966;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:423:0x0989, code lost:
        r0 = th;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:444:0x0a01, code lost:
        if (r39 == false) goto L_0x0a03;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:445:0x0a03, code lost:
        r7 = r26;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:446:0x0a05, code lost:
        com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r38.h).mSyncMap.put(com.tencent.smtt.sdk.TbsDownloadConfig.TbsConfigKey.KEY_TBSDOWNLOAD_FLOW, java.lang.Long.valueOf(r18));
        com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r38.h).commit();
        r26 = r7;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:48:0x016a, code lost:
        r26 = r10;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:68:0x0202, code lost:
        r7 = r10;
     */
    /* JADX WARNING: Removed duplicated region for block: B:133:0x0375  */
    /* JADX WARNING: Removed duplicated region for block: B:146:0x03c5  */
    /* JADX WARNING: Removed duplicated region for block: B:152:0x03e5  */
    /* JADX WARNING: Removed duplicated region for block: B:399:0x08cd A[Catch:{ all -> 0x097b }] */
    /* JADX WARNING: Removed duplicated region for block: B:435:0x09a2 A[ADDED_TO_REGION, Catch:{ all -> 0x0af8 }] */
    /* JADX WARNING: Removed duplicated region for block: B:476:0x0ac0  */
    /* JADX WARNING: Removed duplicated region for block: B:490:0x020f A[SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:507:0x03d6 A[SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:509:0x09f6 A[SYNTHETIC] */
    public void b(boolean z2, boolean z3) {
        boolean z4;
        boolean z5;
        int i2;
        boolean z6;
        boolean z7;
        String str;
        long j2;
        String str2;
        boolean z8;
        String str3;
        Throwable th;
        long j3;
        InputStream inputStream;
        FileOutputStream fileOutputStream;
        InputStream inputStream2;
        Throwable th2;
        FileOutputStream fileOutputStream2;
        Closeable closeable;
        IOException iOException;
        IOException e2;
        Throwable th3;
        boolean z9;
        String str4;
        String str5;
        HttpURLConnection httpURLConnection;
        String str6 = TbsDownloadConfig.TbsConfigKey.KEY_TBSDOWNLOAD_STARTTIME;
        if (!o.a().c(this.h) || z2) {
            int i3 = TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_RESPONSECODE, 0);
            boolean z10 = true;
            boolean z11 = i3 == 1 || i3 == 2 || i3 == 4;
            if (z3 || !a(z2, z11)) {
                this.D = z2;
                String str7 = null;
                this.i = TbsDownloadConfig.getInstance(this.h).mPreferences.getString(TbsDownloadConfig.TbsConfigKey.KEY_TBSDOWNLOADURL, null);
                String string = TbsDownloadConfig.getInstance(this.h).mPreferences.getString(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOADURL_LIST, null);
                String str8 = TbsDownloader.LOGTAG;
                TbsLog.i(str8, "backupUrlStrings:" + string, true);
                this.f6820b = null;
                this.f6821c = 0;
                if (!z2 && string != null && !"".equals(string.trim())) {
                    this.f6820b = string.trim().split(g.f556b);
                }
                TbsLog.i(str8, "[TbsApkDownloader.startDownload] mDownloadUrl=" + this.i + " backupUrlStrings=" + string + " mLocation=" + this.k + " mCanceled=" + this.s + " mHttpRequest=" + this.u);
                if (this.i == null && this.k == null) {
                    QbSdk.m.onDownloadFinish(110);
                    TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-302);
                } else if (this.u != null && !this.s) {
                    QbSdk.m.onDownloadFinish(110);
                    TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-303);
                } else if (z2 || !this.B.contains(Apn.getWifiSSID(this.h))) {
                    g();
                    TbsLog.i(str8, "STEP 1/2 begin downloading...", true);
                    long downloadMaxflow = TbsDownloadConfig.getInstance(this.h).getDownloadMaxflow();
                    long j4 = 0;
                    long j5 = TbsDownloadConfig.getInstance(this.h).mPreferences.getLong(TbsDownloadConfig.TbsConfigKey.KEY_TBSDOWNLOAD_FLOW, 0);
                    this.C = z2 ? f6819f : f6818e;
                    long j6 = j5;
                    boolean z12 = false;
                    while (true) {
                        if (this.q > this.C) {
                            break;
                        } else if (this.r > 8) {
                            a(123, str7, z10);
                            TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-306);
                            break;
                        } else {
                            long currentTimeMillis = System.currentTimeMillis();
                            if (!z2) {
                                try {
                                    if (currentTimeMillis - TbsDownloadConfig.getInstance(this.h).mPreferences.getLong(str6, j4) > 86400000) {
                                        try {
                                            TbsLog.i(str8, "[TbsApkDownloader.startDownload] OVER DOWNLOAD_PERIOD");
                                            TbsDownloadConfig.getInstance(this.h).mSyncMap.put(str6, Long.valueOf(currentTimeMillis));
                                            TbsDownloadConfig.getInstance(this.h).mSyncMap.put(TbsDownloadConfig.TbsConfigKey.KEY_TBSDOWNLOAD_FLOW, Long.valueOf(j4));
                                            TbsDownloadConfig.getInstance(this.h).commit();
                                            j6 = j4;
                                            if (!FileUtil.b(this.h)) {
                                                TbsLog.i(str8, "DownloadBegin FreeSpace too small", z10);
                                                a(105, str7, z10);
                                                TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-308);
                                                if (!z2) {
                                                    z4 = z11;
                                                }
                                            }
                                        } catch (Throwable th4) {
                                            th = th4;
                                        }
                                    } else {
                                        StringBuilder sb = new StringBuilder();
                                        sb.append("[TbsApkDownloader.startDownload] downloadFlow=");
                                        j4 = j6;
                                        try {
                                            sb.append(j4);
                                            TbsLog.i(str8, sb.toString());
                                            if (j4 >= downloadMaxflow) {
                                                TbsLog.i(str8, "STEP 1/2 begin downloading...failed because you exceeded max flow!", z10);
                                                a(112, str7, z10);
                                                TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-307);
                                                if (!z2) {
                                                    z4 = z11;
                                                    j6 = j4;
                                                }
                                            }
                                            j6 = j4;
                                            if (!FileUtil.b(this.h)) {
                                            }
                                        } catch (Throwable th5) {
                                            th = th5;
                                            str = str6;
                                            z4 = z11;
                                            j6 = j4;
                                            z5 = z12;
                                            str2 = str8;
                                            j2 = downloadMaxflow;
                                            try {
                                                if (th instanceof SSLHandshakeException) {
                                                }
                                                str3 = null;
                                                th.printStackTrace();
                                                j4 = 0;
                                                a(0L);
                                                a(107, a(th), false);
                                                if (!this.s) {
                                                }
                                            } finally {
                                                if (!z2) {
                                                    TbsDownloadConfig.getInstance(this.h).mSyncMap.put(TbsDownloadConfig.TbsConfigKey.KEY_TBSDOWNLOAD_FLOW, Long.valueOf(j6));
                                                    TbsDownloadConfig.getInstance(this.h).commit();
                                                }
                                            }
                                        }
                                    }
                                } catch (Throwable th6) {
                                    th = th6;
                                    str = str6;
                                    z4 = z11;
                                    z5 = z12;
                                    str2 = str8;
                                    j2 = downloadMaxflow;
                                    if (th instanceof SSLHandshakeException) {
                                    }
                                    str3 = null;
                                    th.printStackTrace();
                                    j4 = 0;
                                    a(0L);
                                    a(107, a(th), false);
                                    if (!this.s) {
                                    }
                                }
                            }
                            this.z = z10;
                            String str9 = this.k != null ? this.k : this.i;
                            TbsLog.i(str8, "try url:" + str9 + ",mRetryTimes:" + this.q, z10);
                            if (!str9.equals(this.j)) {
                                this.w.setDownloadUrl(str9);
                            }
                            this.j = str9;
                            a(str9);
                            if (!this.p) {
                                try {
                                    j3 = l();
                                    TbsLog.i(str8, "[TbsApkDownloader.startDownload] range=" + j3);
                                } catch (Throwable th7) {
                                    th = th7;
                                    z5 = z12;
                                    str2 = str8;
                                    str = str6;
                                    z4 = z11;
                                    j2 = downloadMaxflow;
                                    if ((th instanceof SSLHandshakeException) || z2 || this.f6820b == null || !b(false)) {
                                        str3 = null;
                                        th.printStackTrace();
                                        j4 = 0;
                                        a(0L);
                                        a(107, a(th), false);
                                        if (!this.s) {
                                            TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-309);
                                        } else {
                                            z8 = z4;
                                        }
                                    } else {
                                        TbsLog.e(str2, "[startdownload]url:" + this.k + " download exception:" + th.toString());
                                        str3 = null;
                                        a(125, (String) null, true);
                                        z8 = z4;
                                        j4 = 0;
                                    }
                                    TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-316);
                                }
                                try {
                                    if (this.m <= 0) {
                                        try {
                                            TbsLog.i(str8, "STEP 1/2 begin downloading...current" + j3, z10);
                                            httpURLConnection = this.u;
                                            str5 = "bytes=" + j3 + "-";
                                            str4 = HttpHeaders.HEAD_KEY_RANGE;
                                            z5 = z12;
                                            str2 = str8;
                                        } catch (Throwable th8) {
                                            th = th8;
                                            str = str6;
                                            z4 = z11;
                                            z5 = z12;
                                            str2 = str8;
                                            j2 = downloadMaxflow;
                                            if (th instanceof SSLHandshakeException) {
                                            }
                                            str3 = null;
                                            th.printStackTrace();
                                            j4 = 0;
                                            a(0L);
                                            a(107, a(th), false);
                                            if (!this.s) {
                                            }
                                        }
                                    } else {
                                        StringBuilder sb2 = new StringBuilder();
                                        sb2.append("#1 STEP 1/2 begin downloading...current/total=");
                                        sb2.append(j3);
                                        sb2.append("/");
                                        z5 = z12;
                                        try {
                                            sb2.append(this.m);
                                            TbsLog.i(str8, sb2.toString(), true);
                                            httpURLConnection = this.u;
                                            StringBuilder sb3 = new StringBuilder();
                                            sb3.append("bytes=");
                                            sb3.append(j3);
                                            sb3.append("-");
                                            str2 = str8;
                                            try {
                                                sb3.append(this.m);
                                                str5 = sb3.toString();
                                                str4 = HttpHeaders.HEAD_KEY_RANGE;
                                            } catch (Throwable th9) {
                                                th = th9;
                                                str = str6;
                                                z4 = z11;
                                                j2 = downloadMaxflow;
                                                if (th instanceof SSLHandshakeException) {
                                                }
                                                str3 = null;
                                                th.printStackTrace();
                                                j4 = 0;
                                                a(0L);
                                                a(107, a(th), false);
                                                if (!this.s) {
                                                }
                                            }
                                        } catch (Throwable th10) {
                                            th = th10;
                                            str2 = str8;
                                            str = str6;
                                            z4 = z11;
                                            j2 = downloadMaxflow;
                                            if (th instanceof SSLHandshakeException) {
                                            }
                                            str3 = null;
                                            th.printStackTrace();
                                            j4 = 0;
                                            a(0L);
                                            a(107, a(th), false);
                                            if (!this.s) {
                                            }
                                        }
                                    }
                                    httpURLConnection.setRequestProperty(str4, str5);
                                } catch (Throwable th11) {
                                    th = th11;
                                    z5 = z12;
                                    str2 = str8;
                                    str = str6;
                                    z4 = z11;
                                    j2 = downloadMaxflow;
                                    if (th instanceof SSLHandshakeException) {
                                    }
                                    str3 = null;
                                    th.printStackTrace();
                                    j4 = 0;
                                    a(0L);
                                    a(107, a(th), false);
                                    if (!this.s) {
                                    }
                                }
                            } else {
                                z5 = z12;
                                str2 = str8;
                                j3 = 0;
                            }
                            this.w.setDownloadCancel(j3 == 0 ? 0 : 1);
                            int apnType = Apn.getApnType(this.h);
                            String apnInfo = Apn.getApnInfo(this.h);
                            if (this.x == null && this.y == -1) {
                                this.x = apnInfo;
                            } else if (apnType != this.y || !apnInfo.equals(this.x)) {
                                this.w.setNetworkChange(0);
                                this.x = apnInfo;
                            } else {
                                if (this.q >= 1) {
                                    this.u.addRequestProperty("Referer", this.i);
                                }
                                int responseCode = this.u.getResponseCode();
                                TbsLog.i(str2, "[TbsApkDownloader.startDownload] responseCode=" + responseCode);
                                this.w.setHttpCode(responseCode);
                                if (!z2 && !TbsDownloader.getOverSea(this.h) && ((Apn.getApnType(this.h) != 3 || Apn.getApnType(this.h) == 0) && !QbSdk.getDownloadWithoutWifi())) {
                                    b();
                                    if (QbSdk.m != null) {
                                        QbSdk.m.onDownloadFinish(111);
                                    }
                                    TbsLog.i(str2, "Download is canceled due to NOT_WIFI error!", false);
                                }
                                if (!this.s) {
                                    TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-309);
                                } else {
                                    if (responseCode == 200 || responseCode == 206) {
                                        this.m = ((long) this.u.getContentLength()) + j3;
                                        TbsLog.i(str2, "[TbsApkDownloader.startDownload] mContentLength=" + this.m);
                                        this.w.setPkgSize(this.m);
                                        j2 = j3;
                                        long j7 = TbsDownloadConfig.getInstance(this.h).mPreferences.getLong(TbsDownloadConfig.TbsConfigKey.KEY_TBSAPKFILESIZE, 0);
                                        if (j7 == 0 || this.m == j7) {
                                            TbsLog.i(str2, "[TbsApkDownloader.startDownload] begin readResponse");
                                            try {
                                                inputStream = this.u.getInputStream();
                                                if (inputStream == null) {
                                                    z4 = z11;
                                                    inputStream2 = null;
                                                    fileOutputStream = null;
                                                    break;
                                                }
                                                try {
                                                    String contentEncoding = this.u.getContentEncoding();
                                                    inputStream2 = (contentEncoding == null || !contentEncoding.contains("gzip")) ? (contentEncoding == null || !contentEncoding.contains("deflate")) ? inputStream : new InflaterInputStream(inputStream, new Inflater(true)) : new GZIPInputStream(inputStream);
                                                } catch (IOException e3) {
                                                    str = str6;
                                                    z4 = z11;
                                                    j2 = downloadMaxflow;
                                                    iOException = e3;
                                                    closeable = inputStream;
                                                    inputStream2 = null;
                                                    fileOutputStream2 = null;
                                                    try {
                                                        iOException.printStackTrace();
                                                        if (!(iOException instanceof SocketTimeoutException)) {
                                                            if (!(iOException instanceof SocketException)) {
                                                                if (z2 || FileUtil.b(this.h)) {
                                                                    a(0L);
                                                                    a(!k() ? 106 : 104, a(iOException), false);
                                                                    a(fileOutputStream2);
                                                                    a(inputStream2);
                                                                    a(closeable);
                                                                } else {
                                                                    a(105, "freespace=" + p.a() + ",and minFreeSpace=" + TbsDownloadConfig.getInstance(this.h).getDownloadMinFreeSpace(), true);
                                                                    TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-308);
                                                                    a(fileOutputStream2);
                                                                    a(inputStream2);
                                                                    a(closeable);
                                                                }
                                                            }
                                                        }
                                                        this.n = com.google.android.exoplayer2.e0.q.a.q;
                                                        a(0L);
                                                        a(103, a(iOException), false);
                                                        a(fileOutputStream2);
                                                        a(inputStream2);
                                                        a(closeable);
                                                    } catch (Throwable th12) {
                                                        th2 = th12;
                                                        fileOutputStream = fileOutputStream2;
                                                        inputStream = closeable;
                                                        a(fileOutputStream);
                                                        a(inputStream2);
                                                        a(inputStream);
                                                        throw th2;
                                                    }
                                                } catch (Throwable th13) {
                                                    th2 = th13;
                                                    inputStream2 = null;
                                                    fileOutputStream = null;
                                                    a(fileOutputStream);
                                                    a(inputStream2);
                                                    a(inputStream);
                                                    throw th2;
                                                }
                                                try {
                                                    byte[] bArr = new byte[8192];
                                                    boolean z13 = true;
                                                    fileOutputStream = new FileOutputStream(new File(this.l, "x5.tbs.temp"), true);
                                                    try {
                                                        long currentTimeMillis2 = System.currentTimeMillis();
                                                        long j8 = currentTimeMillis;
                                                        long j9 = j2;
                                                        while (true) {
                                                            if (this.s) {
                                                                TbsLog.i(str2, "STEP 1/2 begin downloading...Canceled!", z13);
                                                                TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-309);
                                                                break;
                                                            }
                                                            int read = inputStream2.read(bArr, 0, 8192);
                                                            if (read > 0) {
                                                                fileOutputStream.write(bArr, 0, read);
                                                                fileOutputStream.flush();
                                                                str = str6;
                                                                z4 = z11;
                                                                if (!z2) {
                                                                    long j10 = j6 + ((long) read);
                                                                    if (j10 >= downloadMaxflow) {
                                                                        break;
                                                                    } else if (!FileUtil.b(this.h)) {
                                                                        TbsLog.i(str2, "DownloadEnd FreeSpace too small ", true);
                                                                        a(105, "freespace=" + p.a() + ",and minFreeSpace=" + TbsDownloadConfig.getInstance(this.h).getDownloadMinFreeSpace(), true);
                                                                        TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-308);
                                                                        break;
                                                                    } else {
                                                                        j6 = j10;
                                                                    }
                                                                }
                                                                long j11 = (long) read;
                                                                try {
                                                                    j8 = a(j8, j11);
                                                                    long currentTimeMillis3 = System.currentTimeMillis();
                                                                    long j12 = j2 + j11;
                                                                    if (currentTimeMillis3 - currentTimeMillis2 > 1000) {
                                                                        StringBuilder sb4 = new StringBuilder();
                                                                        sb4.append("#2 STEP 1/2 begin downloading...current/total=");
                                                                        sb4.append(j12);
                                                                        sb4.append("/");
                                                                        j2 = downloadMaxflow;
                                                                        try {
                                                                            sb4.append(this.m);
                                                                            TbsLog.i(str2, sb4.toString(), true);
                                                                            if (QbSdk.m != null) {
                                                                                try {
                                                                                    QbSdk.m.onDownloadProgress((int) ((((double) j12) / ((double) this.m)) * 100.0d));
                                                                                } catch (IOException e4) {
                                                                                    iOException = e4;
                                                                                } catch (Throwable th14) {
                                                                                    th2 = th14;
                                                                                    a(fileOutputStream);
                                                                                    a(inputStream2);
                                                                                    a(inputStream);
                                                                                    throw th2;
                                                                                }
                                                                            }
                                                                            if (!z2 && j12 - j9 > 1048576) {
                                                                                if (!TbsDownloader.getOverSea(this.h) && ((Apn.getApnType(this.h) != 3 || Apn.getApnType(this.h) == 0) && !QbSdk.getDownloadWithoutWifi())) {
                                                                                    break;
                                                                                }
                                                                                j9 = j12;
                                                                            }
                                                                            currentTimeMillis2 = currentTimeMillis3;
                                                                        } catch (IOException e5) {
                                                                            e2 = e5;
                                                                            iOException = e2;
                                                                            closeable = inputStream;
                                                                            fileOutputStream2 = fileOutputStream;
                                                                            iOException.printStackTrace();
                                                                            if (!(iOException instanceof SocketTimeoutException)) {
                                                                            }
                                                                            this.n = com.google.android.exoplayer2.e0.q.a.q;
                                                                            a(0L);
                                                                            a(103, a(iOException), false);
                                                                            a(fileOutputStream2);
                                                                            a(inputStream2);
                                                                            a(closeable);
                                                                        } catch (Throwable th15) {
                                                                            th3 = th15;
                                                                            th2 = th3;
                                                                            a(fileOutputStream);
                                                                            a(inputStream2);
                                                                            a(inputStream);
                                                                            throw th2;
                                                                        }
                                                                    } else {
                                                                        j2 = downloadMaxflow;
                                                                    }
                                                                    downloadMaxflow = j2;
                                                                    z13 = true;
                                                                    j2 = j12;
                                                                    z11 = z4;
                                                                    str6 = str;
                                                                } catch (IOException e6) {
                                                                    e2 = e6;
                                                                    j2 = downloadMaxflow;
                                                                    iOException = e2;
                                                                    closeable = inputStream;
                                                                    fileOutputStream2 = fileOutputStream;
                                                                    iOException.printStackTrace();
                                                                    if (!(iOException instanceof SocketTimeoutException)) {
                                                                    }
                                                                    this.n = com.google.android.exoplayer2.e0.q.a.q;
                                                                    a(0L);
                                                                    a(103, a(iOException), false);
                                                                    a(fileOutputStream2);
                                                                    a(inputStream2);
                                                                    a(closeable);
                                                                } catch (Throwable th16) {
                                                                    th3 = th16;
                                                                    th2 = th3;
                                                                    a(fileOutputStream);
                                                                    a(inputStream2);
                                                                    a(inputStream);
                                                                    throw th2;
                                                                }
                                                            } else if (this.f6820b == null || c(true, z11)) {
                                                                this.t = true;
                                                                if (this.f6820b != null) {
                                                                    z5 = true;
                                                                }
                                                                TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-311);
                                                            } else if (z2 || !b(false)) {
                                                                this.t = true;
                                                                str = str6;
                                                                z4 = z11;
                                                                j2 = downloadMaxflow;
                                                                z9 = false;
                                                                z5 = false;
                                                            } else {
                                                                str = str6;
                                                                z4 = z11;
                                                                j2 = downloadMaxflow;
                                                                z9 = true;
                                                            }
                                                        }
                                                        if (!z9) {
                                                            break;
                                                        }
                                                        a(fileOutputStream);
                                                        a(inputStream2);
                                                        a(inputStream);
                                                        if (!z2) {
                                                            z8 = z4;
                                                            str3 = null;
                                                            j4 = 0;
                                                            str7 = str3;
                                                            z11 = z8;
                                                            str8 = str2;
                                                            z12 = z5;
                                                            downloadMaxflow = j2;
                                                            str6 = str;
                                                            z10 = true;
                                                        }
                                                        str8 = str2;
                                                        z12 = z5;
                                                        downloadMaxflow = j2;
                                                        z11 = z4;
                                                        str6 = str;
                                                        j4 = 0;
                                                        z10 = true;
                                                        str7 = null;
                                                    } catch (IOException e7) {
                                                        e2 = e7;
                                                        str = str6;
                                                        z4 = z11;
                                                        j2 = downloadMaxflow;
                                                        iOException = e2;
                                                        closeable = inputStream;
                                                        fileOutputStream2 = fileOutputStream;
                                                        iOException.printStackTrace();
                                                        if (!(iOException instanceof SocketTimeoutException)) {
                                                        }
                                                        this.n = com.google.android.exoplayer2.e0.q.a.q;
                                                        a(0L);
                                                        a(103, a(iOException), false);
                                                        a(fileOutputStream2);
                                                        a(inputStream2);
                                                        a(closeable);
                                                    } catch (Throwable th17) {
                                                        th3 = th17;
                                                        th2 = th3;
                                                        a(fileOutputStream);
                                                        a(inputStream2);
                                                        a(inputStream);
                                                        throw th2;
                                                    }
                                                } catch (IOException e8) {
                                                    str = str6;
                                                    z4 = z11;
                                                    j2 = downloadMaxflow;
                                                    iOException = e8;
                                                    closeable = inputStream;
                                                    fileOutputStream2 = null;
                                                    iOException.printStackTrace();
                                                    if (!(iOException instanceof SocketTimeoutException)) {
                                                    }
                                                    this.n = com.google.android.exoplayer2.e0.q.a.q;
                                                    a(0L);
                                                    a(103, a(iOException), false);
                                                    a(fileOutputStream2);
                                                    a(inputStream2);
                                                    a(closeable);
                                                } catch (Throwable th18) {
                                                    th2 = th18;
                                                    fileOutputStream = null;
                                                    a(fileOutputStream);
                                                    a(inputStream2);
                                                    a(inputStream);
                                                    throw th2;
                                                }
                                            } catch (IOException e9) {
                                                str = str6;
                                                z4 = z11;
                                                j2 = downloadMaxflow;
                                                iOException = e9;
                                                inputStream = null;
                                                closeable = inputStream;
                                                inputStream2 = null;
                                                fileOutputStream2 = null;
                                                iOException.printStackTrace();
                                                if (!(iOException instanceof SocketTimeoutException)) {
                                                }
                                                this.n = com.google.android.exoplayer2.e0.q.a.q;
                                                a(0L);
                                                a(103, a(iOException), false);
                                                a(fileOutputStream2);
                                                a(inputStream2);
                                                a(closeable);
                                            } catch (Throwable th19) {
                                                th2 = th19;
                                                inputStream = null;
                                                inputStream2 = null;
                                                fileOutputStream = null;
                                                a(fileOutputStream);
                                                a(inputStream2);
                                                a(inputStream);
                                                throw th2;
                                            }
                                        } else {
                                            TbsLog.i(str2, "DownloadBegin tbsApkFileSize=" + j7 + "  but contentLength=" + this.m, true);
                                            if (z2 || (!o() && (!QbSdk.getDownloadWithoutWifi() || !Apn.isNetworkAvailable(this.h)))) {
                                                a(101, "WifiNetworkUnAvailable", true);
                                                TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-304);
                                            } else if (this.f6820b == null || !b(false)) {
                                                a(113, "tbsApkFileSize=" + j7 + "  but contentLength=" + this.m, true);
                                                TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-310);
                                            }
                                        }
                                    } else if (responseCode < 300 || responseCode > 307) {
                                        a(102, String.valueOf(responseCode), false);
                                        if (responseCode == 416) {
                                            if (c(true, z11)) {
                                                try {
                                                    TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-214);
                                                    z4 = z11;
                                                    if (!z2) {
                                                        boolean z14 = true;
                                                    } else {
                                                        z5 = true;
                                                    }
                                                } catch (Throwable th20) {
                                                    th = th20;
                                                    str = str6;
                                                    z4 = z11;
                                                    j2 = downloadMaxflow;
                                                    z5 = true;
                                                }
                                            } else {
                                                e(false);
                                                TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-313);
                                            }
                                        } else if ((responseCode == 403 || responseCode == 406) && this.m == -1) {
                                            TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-314);
                                        } else if (responseCode != 202) {
                                            if (this.q < this.C && responseCode == 503) {
                                                a(Long.parseLong(this.u.getHeaderField("Retry-After")));
                                                if (this.s) {
                                                    TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-309);
                                                }
                                            } else if (this.q < this.C && (responseCode == 408 || responseCode == 504 || responseCode == 502 || responseCode == 408)) {
                                                a(0L);
                                                if (this.s) {
                                                    TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-309);
                                                }
                                            } else if (l() > 0 || this.p || responseCode == 410) {
                                                TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-315);
                                            } else {
                                                this.p = true;
                                            }
                                        }
                                    } else {
                                        String headerField = this.u.getHeaderField(HttpHeaders.HEAD_KEY_LOCATION);
                                        if (!TextUtils.isEmpty(headerField)) {
                                            this.k = headerField;
                                            this.r++;
                                        } else {
                                            a(124, (String) null, true);
                                            TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-312);
                                        }
                                    }
                                    str = str6;
                                    z8 = z11;
                                    j2 = downloadMaxflow;
                                    str3 = null;
                                    j4 = 0;
                                    str7 = str3;
                                    z11 = z8;
                                    str8 = str2;
                                    z12 = z5;
                                    downloadMaxflow = j2;
                                    str6 = str;
                                    z10 = true;
                                }
                            }
                            this.y = apnType;
                            if (this.q >= 1) {
                            }
                            int responseCode2 = this.u.getResponseCode();
                            TbsLog.i(str2, "[TbsApkDownloader.startDownload] responseCode=" + responseCode2);
                            this.w.setHttpCode(responseCode2);
                            b();
                            if (QbSdk.m != null) {
                            }
                            TbsLog.i(str2, "Download is canceled due to NOT_WIFI error!", false);
                            if (!this.s) {
                            }
                        }
                    }
                    if (!this.s) {
                        if (this.t) {
                            if (this.f6820b != null || z5) {
                                z7 = z4;
                            } else {
                                z7 = z4;
                                z5 = c(true, z7);
                            }
                            z6 = z5;
                            this.w.setUnpkgFlag(z6 ? 1 : 0);
                            this.w.setPatchUpdateFlag(!z7 ? z6 ? 1 : 2 : 0);
                            if (z6) {
                                d(true);
                                TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-317);
                                a(100, FirebaseAnalytics.b.F, true);
                                i2 = 0;
                            } else {
                                TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-318);
                                i2 = 0;
                                e(false);
                            }
                        } else {
                            i2 = 0;
                            z6 = z5;
                        }
                        TbsDownloadConfig instance = TbsDownloadConfig.getInstance(this.h);
                        if (z6) {
                            instance.mSyncMap.put(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOAD_SUCCESS_RETRYTIMES, Integer.valueOf(instance.mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOAD_SUCCESS_RETRYTIMES, i2) + 1));
                        } else {
                            int i4 = instance.mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOAD_FAILED_RETRYTIMES, i2) + 1;
                            instance.mSyncMap.put(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOAD_FAILED_RETRYTIMES, Integer.valueOf(i4));
                            if (i4 == instance.getDownloadFailedMaxRetrytimes()) {
                                this.w.setDownloadCancel(2);
                            }
                        }
                        instance.commit();
                        TbsLogReport.TbsLogInfo tbsLogInfo = this.w;
                        int i5 = z6 ? 1 : 0;
                        int i6 = z6 ? 1 : 0;
                        tbsLogInfo.setDownFinalFlag(i5);
                    }
                    h();
                } else {
                    TbsLog.i(str8, "[TbsApkDownloader.startDownload] WIFI Unavailable");
                    QbSdk.m.onDownloadFinish(110);
                    TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-304);
                }
            } else {
                TbsDownloader.a = false;
            }
        } else {
            TbsDownloader.a = false;
            TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-322);
        }
    }

    public boolean b(boolean z2) {
        String[] strArr;
        int i2;
        if ((z2 && !o() && (!QbSdk.getDownloadWithoutWifi() || !Apn.isNetworkAvailable(this.h))) || (strArr = this.f6820b) == null || (i2 = this.f6821c) < 0 || i2 >= strArr.length) {
            return false;
        }
        this.f6821c = i2 + 1;
        this.k = strArr[i2];
        this.q = 0;
        this.r = 0;
        this.m = -1;
        this.p = false;
        this.s = false;
        this.t = false;
        this.z = false;
        return true;
    }

    public int c(boolean z2) {
        File a2 = a(this.h);
        if (z2) {
            if (a2 == null) {
                return 0;
            }
            return a.a(this.h, new File(a2, TbsDownloader.getBackupFileName(true)));
        } else if (a2 == null) {
            return 0;
        } else {
            Context context = this.h;
            return a.a(context, new File(a2, TbsDownloader.getOverSea(context) ? "x5.oversea.tbs.org" : TbsDownloader.getBackupFileName(false)));
        }
    }

    public void c() {
        b();
        e(false);
        e(true);
    }

    public boolean d() {
        TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.isDownloadForeground] mIsDownloadForeground=" + this.D);
        return this.D;
    }

    /* access modifiers changed from: package-private */
    public void e() {
        TbsLog.i(TbsDownloader.LOGTAG, "pauseDownload,isPause=" + this.f6822d + "isDownloading=" + TbsDownloader.isDownloading());
        if (!this.f6822d && TbsDownloader.isDownloading()) {
            b();
            this.f6822d = true;
            this.z = false;
        }
    }

    /* access modifiers changed from: package-private */
    public void f() {
        TbsLog.i(TbsDownloader.LOGTAG, "resumeDownload,isPause=" + this.f6822d + "isDownloading=" + TbsDownloader.isDownloading());
        if (this.f6822d && TbsDownloader.isDownloading()) {
            this.f6822d = false;
            a(false);
        }
    }
}