package com.tencent.smtt.sdk; import aegon.chrome.net.NetError; import android.content.Context; import android.content.SharedPreferences; import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.text.TextUtils; import android.util.Log; import com.baidu.mobads.sdk.internal.bf; import com.kwai.video.player.PlayerProps; import com.mbridge.msdk.foundation.download.Command; import com.mbridge.msdk.playercommon.exoplayer2.extractor.ogg.DefaultOggSeeker; 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.r; 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.SocketException; import java.net.SocketTimeoutException; import java.net.URL; import java.util.Objects; 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 m { private static int e = 5; private static int f = 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 boolean A; private Handler B; private boolean C = false; private int D = e; private boolean E; String a; String[] b = null; int c = 0; private boolean d = false; private Context h; private String i; private String j; private String k; private File l; private File m; private long n; private int o = PlayerProps.FFP_PROP_FLOAT_MAX_AVDIFF_REALTIME; private int p = 20000; private boolean q; private int r; private int s; private boolean t; private boolean u; private HttpURLConnection v; private String w; private final TbsLogReport.TbsLogInfo x; private String y; private int z; public m(Context context) throws NullPointerException { Context applicationContext = context.getApplicationContext(); this.h = applicationContext; this.x = TbsLogReport.getInstance(applicationContext).tbsLogInfo(); this.w = "tbs_downloading_" + this.h.getPackageName(); p.a(); File t2 = p.t(this.h); this.l = t2; Objects.requireNonNull(t2, "TbsCorePrivateDir is null!"); try { Context packageContext = TbsShareManager.getPackageContext(context, TbsConfig.APP_WX, false); if (packageContext == null) { this.m = new File(FileUtil.a(context, TbsConfig.APP_WX, 4, true)); } else { this.m = new File(FileUtil.a(packageContext, 4)); } } catch (Throwable unused) { } g(); this.y = null; this.z = -1; } private long a(long j2, long j3) { long currentTimeMillis = System.currentTimeMillis(); this.x.setDownConsumeTime(currentTimeMillis - j2); this.x.setDownloadSize(j3); return currentTimeMillis; } 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 void a(int i2, String str, boolean z2) { if (z2 || this.r > this.D) { this.x.setErrorCode(i2); this.x.setFailDetail(str); } } private void a(long j2) { this.r++; if (j2 <= 0) { try { j2 = p(); } catch (Exception unused) { return; } } Thread.sleep(j2); } public static void a(Context context) { try { TbsLog.i(TbsDownloader.LOGTAG, "clearDecoupleDirOld #00"); File a2 = p.a().a(context, context.getDir("tbs_64", 0)); FileUtil.b(a2); if (a2 != null) { TbsLog.i(TbsDownloader.LOGTAG, "clearDecoupleDirOld dir is " + a2.getAbsolutePath()); } File a3 = p.a().a(context, context.getDir("tbs", 0)); FileUtil.b(a3); if (a3 != null) { TbsLog.i(TbsDownloader.LOGTAG, "clearDecoupleDirOld dir is " + a3.getAbsolutePath()); } } catch (Throwable th) { TbsLog.i(TbsDownloader.LOGTAG, "clearDecoupleDirOld stack is " + Log.getStackTraceString(th)); } } 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 c2 = c(context); if (c2 != null) { File file2 = new File(c2, TbsDownloader.getOverSea(context) ? "x5.oversea.tbs.org" : TbsDownloader.getBackupFileName(false)); file2.delete(); FileUtil.b(file, file2); TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.backupTbsApk]tbsApk is " + file.getAbsolutePath()); TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.backupTbsApk]backUpApk is " + file2.getAbsolutePath()); boolean contains = file2.getName().contains("tbs.org"); boolean contains2 = file2.getName().contains("x5.tbs.decouple"); if (contains2 || contains) { File[] listFiles = c2.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(c2, 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(); } } } catch (Exception unused) { } } } } } } private void a(String str) throws Exception { URL url = new URL(str); HttpURLConnection httpURLConnection = this.v; if (httpURLConnection != null) { try { httpURLConnection.disconnect(); } catch (Throwable th) { TbsLog.e(TbsDownloader.LOGTAG, "[initHttpRequest] mHttpRequest.disconnect() Throwable:" + th.toString()); } } HttpURLConnection httpURLConnection2 = (HttpURLConnection) url.openConnection(); this.v = httpURLConnection2; httpURLConnection2.setRequestProperty("User-Agent", TbsDownloader.b(this.h)); this.v.setRequestProperty("Accept-Encoding", "identity"); this.v.setRequestMethod("GET"); this.v.setInstanceFollowRedirects(false); this.v.setConnectTimeout(this.p); this.v.setReadTimeout(this.o); } 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); } /* JADX WARNING: Code restructure failed: missing block: B:26:0x00a4, code lost: if (r10 != r8) goto L_0x00a6; */ private boolean a(boolean z2, boolean z3, File file) { boolean z4; int i2; TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] isTempFile=" + z2); if (file != null) { TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] verifyFile is " + file.getAbsolutePath()); } File file2 = new File(this.l, !z2 ? "x5.tbs" : "x5.tbs.temp"); if (file != null) { file2 = file; } boolean z5 = false; if (!file2.exists()) { return false; } Exception exc = null; String string = TbsDownloadConfig.getInstance(this.h).mPreferences.getString(TbsDownloadConfig.TbsConfigKey.KEY_TBSAPK_MD5, null); String a2 = a.a(file2); if (string == null || !string.equals(a2)) { TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] isTempFile=" + z2 + " md5 failed"); if (z2) { this.x.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 (file2 != null && file2.exists()) { if (j3 > 0) { j2 = file2.length(); } } TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] isTempFile=" + z2 + " filelength failed"); TbsLogReport.TbsLogInfo tbsLogInfo = this.x; 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, file2))) { TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] tbsApkVersionCode(" + i3 + ") successful!"); if (z3 && !z2) { String a3 = b.a(this.h, false, file2); if (!"3082023f308201a8a00302010202044c46914a300d06092a864886f70d01010505003064310b30090603550406130238363110300e060355040813074265696a696e673110300e060355040713074265696a696e673110300e060355040a130754656e63656e74310c300a060355040b13035753443111300f0603550403130873616d75656c6d6f301e170d3130303732313036313835305a170d3430303731333036313835305a3064310b30090603550406130238363110300e060355040813074265696a696e673110300e060355040713074265696a696e673110300e060355040a130754656e63656e74310c300a060355040b13035753443111300f0603550403130873616d75656c6d6f30819f300d06092a864886f70d010101050003818d0030818902818100c209077044bd0d63ea00ede5b839914cabcc912a87f0f8b390877e0f7a2583f0d5933443c40431c35a4433bc4c965800141961adc44c9625b1d321385221fd097e5bdc2f44a1840d643ab59dc070cf6c4b4b4d98bed5cbb8046e0a7078ae134da107cdf2bfc9b440fe5cb2f7549b44b73202cc6f7c2c55b8cfb0d333a021f01f0203010001300d06092a864886f70d010105050003818100b007db9922774ef4ccfee81ba514a8d57c410257e7a2eba64bfa17c9e690da08106d32f637ac41fbc9f205176c71bde238c872c3ee2f8313502bee44c80288ea4ef377a6f2cdfe4d3653c145c4acfedbfbadea23b559d41980cc3cdd35d79a68240693739aabf5c5ed26148756cf88264226de394c8a24ac35b712b120d4d23a".equals(a3)) { TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] isTempFile=" + z2 + " signature failed"); if (z2) { TbsLogReport.TbsLogInfo tbsLogInfo2 = this.x; 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 && file == null) { try { z4 = file2.renameTo(new File(this.l, "x5.tbs")); } catch (Exception e2) { exc = e2; z4 = false; } if (!z4) { a(109, a(exc), true); return false; } z5 = z4; } TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] rename(" + z5 + ") successful!"); return true; } TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.verifyTbsApk] isTempFile=" + z2 + " versionCode failed"); if (z2) { TbsLogReport.TbsLogInfo tbsLogInfo3 = this.x; tbsLogInfo3.setCheckErrorDetail("fileVersion:" + i3 + ",configVersion:" + i2); } return false; } public static void b(Context context) { try { if (!TbsShareManager.isThirdPartyApp(context)) { if (!r.g(context)) { return; } } TbsLog.i(TbsDownloader.LOGTAG, "clearOldBackup #00"); String str = Environment.getExternalStorageDirectory() + File.separator; if (!str.equals("")) { str = str + "tencent" + File.separator + "tbs" + File.separator + "backup" + File.separator + context.getApplicationInfo().packageName; } File file = new File(str); FileUtil.b(file); TbsLog.i(TbsDownloader.LOGTAG, "clearOldBackup dir is " + file.getAbsolutePath()); } catch (Throwable th) { TbsLog.i(TbsDownloader.LOGTAG, "clearOldBackup stack is " + Log.getStackTraceString(th)); } } private boolean b(int i2) { try { File file = new File(this.l, "x5.tbs"); File c2 = c(this.h); if (c2 == null) { return false; } File file2 = new File(c2, 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; } } static File c(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 boolean c(boolean z2, boolean z3) { return a(z2, z3, (File) null); } static File d(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; } } /* JADX WARNING: Code restructure failed: missing block: B:30:0x0133, code lost: if (com.tencent.smtt.utils.b.c() != false) goto L_0x0140; */ /* JADX WARNING: Code restructure failed: missing block: B:35:0x013e, code lost: if (r11 == 64) goto L_0x0140; */ /* JADX WARNING: Code restructure failed: missing block: B:36:0x0140, code lost: r10 = "stable_64_tpatch_fail"; */ private void d(boolean z2) { Bundle bundle; String str; File file; r.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, Integer.valueOf((int) NetError.ERR_SSL_NO_RENEGOTIATION)); instance.commit(); QbSdk.n.onDownloadFinish(z2 ? 100 : 120); int i2 = instance.mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_RESPONSECODE, 0); boolean a2 = TbsDownloader.a(this.h); try { int i3 = instance.mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_CPUTYPE_OTHER_STABLE_CORE, 0); TbsLog.i(TbsDownloader.LOGTAG, "downloadSuccess #1 cpuTypeForOtherStableCore is " + i3 + " isDownloadDecoupleCore is " + a2); StringBuilder sb = new StringBuilder(); sb.append("downloadSuccess #1 responseCode is "); sb.append(i2); TbsLog.i(TbsDownloader.LOGTAG, sb.toString()); if (a2 && r.b(this.h) && i2 != 3) { File[] listFiles = this.m.listFiles(); Pattern compile = Pattern.compile(a.a(false, i3)); for (File file2 : listFiles) { if (compile.matcher(file2.getName()).find() && file2.isFile() && file2.exists()) { file2.delete(); } } File file3 = new File(this.m, a.a(false, i3) + "." + instance.mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V, 0)); if (!file3.exists()) { file3.createNewFile(); } try { boolean renameTo = new File(this.m, TbsDownloader.getBackupFileName(false) + "." + "tmp").renameTo(new File(this.m, TbsDownloader.getBackupFileName(false, i3))); String str2 = "none"; if (i3 != 0) { if (i3 != 32) { } } str2 = "stable_32_tpatch_fail"; n.a(this.h).a(str2, 0); TbsLog.i(TbsDownloader.LOGTAG, "downloadSuccess setStatus " + str2 + " is 0"); StringBuilder sb2 = new StringBuilder(); sb2.append("downloadSuccess renameResult is "); sb2.append(renameTo); TbsLog.i(TbsDownloader.LOGTAG, sb2.toString()); } catch (Throwable th) { TbsLog.i(TbsDownloader.LOGTAG, "downloadSuccess stack is " + Log.getStackTraceString(th)); } TbsLog.i(TbsDownloader.LOGTAG, "downloadSuccess getTbsStableCoreVersion is " + TbsShareManager.getTbsStableCoreVersion(this.h, i3)); } } catch (Throwable th2) { TbsLog.i(TbsDownloader.LOGTAG, "downloadSuccess stack is " + Log.getStackTraceString(th2)); } if (i2 == 5 || i2 == 3) { bundle = a(i2, a2); if (bundle == null) { str = "downloadSuccess RESPONSECODE_TPATCH bundle is null "; } else { TbsLog.i(TbsDownloader.LOGTAG, "downloadSuccess RESPONSECODE_TPATCH bundle is " + bundle); p.a().b(this.h, bundle); a(this.h); b(this.h); } } else if (i2 == 3 || i2 > 10000) { File c2 = c(this.h); if (c2 != null) { bundle = a(i2, c2, a2); p.a().b(this.h, bundle); a(this.h); b(this.h); } c(); instance.mSyncMap.put(TbsDownloadConfig.TbsConfigKey.KEY_NEEDDOWNLOAD, true); instance.commit(); a(this.h); b(this.h); } else { int i4 = instance.mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V, 0); p.a().a(this.h, new File(this.l, "x5.tbs").getAbsolutePath(), i4); if (!r.b(this.h)) { file = new File(this.l, "x5.tbs"); } else { int i5 = TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DECOUPLECOREVERSION, 0); TbsLog.i(TbsDownloader.LOGTAG, "downloadSuccess tbsCorVer is " + i4 + " stableCoreVersionServer is " + i5); if (i4 == i5) { TbsLog.i(TbsDownloader.LOGTAG, "downloadSuccess backup"); file = new File(this.l, "x5.tbs"); } else { str = "downloadSuccess not backup"; } } a(file, this.h); a(this.h); b(this.h); } TbsLog.i(TbsDownloader.LOGTAG, str); a(this.h); b(this.h); } public static void e(Context context) { try { p.a(); File t2 = p.t(context); new File(t2, "x5.tbs").delete(); new File(t2, "x5.tbs.temp").delete(); File c2 = c(context); if (c2 != null) { new File(c2, TbsDownloader.getBackupFileName(false)).delete(); new File(c2, "x5.oversea.tbs.org").delete(); File[] listFiles = c2.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) { } } 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.r = 0; this.s = 0; this.n = -1; this.k = null; this.q = false; this.t = false; this.u = false; this.A = false; } private void h() { TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.closeHttpRequest]"); HttpURLConnection httpURLConnection = this.v; if (httpURLConnection != null) { try { httpURLConnection.disconnect(); } catch (Throwable th) { TbsLog.e(TbsDownloader.LOGTAG, "[closeHttpRequest] mHttpRequest.disconnect() Throwable:" + th.toString()); } this.v = null; TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.closeHttpRequest] mHttpRequest set null"); } if (!this.t && this.A) { i(); int i2 = this.x.a; if (i2 != 100) { QbSdk.n.onDownloadFinish(i2); } } else if (!this.d) { TbsDownloader.a = false; } } private void i() { this.x.setEventTime(System.currentTimeMillis()); String apnInfo = Apn.getApnInfo(this.h); if (apnInfo == null) { apnInfo = ""; } int apnType = Apn.getApnType(this.h); this.x.setApn(apnInfo); this.x.setNetworkType(apnType); if (apnType != this.z || !apnInfo.equals(this.y)) { this.x.setNetworkChange(0); } if ((this.x.a == 0 || this.x.a == 107) && this.x.getDownFinalFlag() == 0 && (!Apn.isNetworkAvailable(this.h) || !o())) { a(101, (String) null, true); } TbsLogReport.getInstance(this.h).eventReport(TbsLogReport.EventType.TYPE_CDN_DOWNLOAD_STAT, this.x); this.x.resetArgs(); } private void j() { int apnType = Apn.getApnType(this.h); String apnInfo = Apn.getApnInfo(this.h); String str = this.y; if (!(str == null && this.z == -1)) { if (apnType != this.z || !apnInfo.equals(str)) { this.x.setNetworkChange(0); } else { return; } } this.y = apnInfo; this.z = apnType; } private File k() { 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 l() { try { File k2 = k(); if (k2 != null && k2.exists()) { FileUtil.b(k2); File[] listFiles = k2.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 m() { return new File(this.l, "x5.tbs.temp").exists(); } private long n() { File file = new File(this.l, "x5.tbs.temp"); if (file.exists()) { return file.length(); } return 0; } private boolean o() { 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) { bufferedReader = null; th = th4; th.printStackTrace(); a(inputStream); a(inputStreamReader); a(bufferedReader); return z2; } } catch (Throwable th5) { bufferedReader = null; th = th5; inputStreamReader = null; th.printStackTrace(); a(inputStream); a(inputStreamReader); a(bufferedReader); return z2; } } catch (Throwable th6) { inputStreamReader = null; bufferedReader = null; th = th6; inputStream = null; th.printStackTrace(); a(inputStream); a(inputStreamReader); a(bufferedReader); return z2; } a(inputStream); a(inputStreamReader); a(bufferedReader); return z2; } private long p() { int i2 = this.r; return (i2 == 1 || i2 == 2) ? ((long) i2) * 20000 : (i2 == 3 || i2 == 4) ? 100000 : 200000; } /* JADX WARNING: Removed duplicated region for block: B:24:0x0075 A[SYNTHETIC, Splitter:B:24:0x0075] */ /* JADX WARNING: Removed duplicated region for block: B:35:0x0083 */ /* JADX WARNING: Removed duplicated region for block: B:36:0x0086 */ private boolean q() { boolean z2; Throwable th; HttpURLConnection httpURLConnection; boolean z3 = Apn.getApnType(this.h) == 3; TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDwonloader.detectWifiNetworkAvailable] isWifi=" + z3); if (z3) { try { httpURLConnection = (HttpURLConnection) new URL("https://pms.mb.qq.com/rsp204").openConnection(); } catch (Throwable th2) { th = th2; httpURLConnection = null; try { th.printStackTrace(); z2 = false; if (!z2) { } return z2; } finally { if (httpURLConnection != null) { try { httpURLConnection.disconnect(); } catch (Exception unused) { } } } } 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); z2 = responseCode == 204; if (httpURLConnection != null) { try { httpURLConnection.disconnect(); } catch (Exception unused2) { } } } catch (Throwable th3) { th = th3; th.printStackTrace(); z2 = false; if (!z2) { } return z2; } if (!z2) { this.C = true; } else { this.C = false; this.B.sendMessageDelayed(this.B.obtainMessage(150, null), 120000); } return z2; } z2 = false; if (!z2) { } return z2; } 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; } /* JADX WARNING: Removed duplicated region for block: B:32:0x0164 */ /* JADX WARNING: Removed duplicated region for block: B:39:0x0198 */ public Bundle a(int i2, boolean z2) { int i3; File file; File file2; Bundle bundle; File file3; int i4; Context context; p pVar; String str = "not_stable"; if (!z2) { file = p.a().r(this.h); i3 = p.a().j(this.h); } else if (r.b(this.h)) { int i5 = TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_CPUTYPE_OTHER_STABLE_CORE, 0); file = new File(this.m, TbsDownloader.getBackupFileName(false, i5)); i3 = TbsShareManager.getTbsStableCoreVersion(this.h, i5); str = "stable_core_" + i5; } else { file = p.a().q(this.h); i3 = p.a().i(this.h); } File file4 = new File(this.l, "x5.tbs"); String absolutePath = file4.exists() ? file4.getAbsolutePath() : null; if (z2 && r.b(this.h)) { file4 = new File(this.m, TbsDownloader.getBackupFileName(false) + "." + "tmp"); absolutePath = file4.exists() ? file4.getAbsolutePath() : null; } if (absolutePath == null) { TbsLog.i(TbsDownloader.LOGTAG, "gettpatchBundle tbsApkFile is " + file4.getAbsolutePath()); return null; } int i6 = TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_TBS_DOWNLOAD_V, 0); if (!z2) { pVar = p.a(); context = this.h; i4 = 5; } else if (r.b(this.h)) { file2 = new File(this.m, TbsDownloader.getBackupFileName(false) + "." + "tpatch" + "." + "tmp"); bundle = new Bundle(); bundle.putInt("operation", i2); bundle.putInt("old_core_ver", i3); bundle.putInt("new_core_ver", i6); bundle.putString("old_apk_location", file.getAbsolutePath()); bundle.putString("new_apk_location", file2.getAbsolutePath()); bundle.putString("diff_file_location", absolutePath); bundle.putString("core_type_tpatch", str); String a2 = FileUtil.a(this.h, 7); file3 = new File(a2); if (!file3.exists()) { file3.mkdirs(); } bundle.putString("backup_apk", new File(a2, i6 + ".tbs").getAbsolutePath()); if (z2 && r.b(this.h)) { bundle.putInt("for_stable_core", 1); } if (!z2) { bundle.putInt("for_self_core", 1); } return bundle; } else { pVar = p.a(); context = this.h; i4 = 6; } file2 = pVar.f(context, i4); bundle = new Bundle(); bundle.putInt("operation", i2); bundle.putInt("old_core_ver", i3); bundle.putInt("new_core_ver", i6); bundle.putString("old_apk_location", file.getAbsolutePath()); bundle.putString("new_apk_location", file2.getAbsolutePath()); bundle.putString("diff_file_location", absolutePath); bundle.putString("core_type_tpatch", str); String a22 = FileUtil.a(this.h, 7); file3 = new File(a22); if (!file3.exists()) { } bundle.putString("backup_apk", new File(a22, i6 + ".tbs").getAbsolutePath()); bundle.putInt("for_stable_core", 1); if (!z2) { } return bundle; } public void a(int i2) { if (p.a().u(this.h)) { p.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); } /* JADX WARNING: Removed duplicated region for block: B:43:0x0197 */ public boolean a() { Context context; String str; String str2; TbsLog.i("TbsApkDownloader", "verifyAndInstallDecoupleCoreFromBackup #1"); try { File file = r.b(this.h) ? new File(FileUtil.a(this.h, TbsConfig.APP_WX, 4, true), TbsDownloader.getBackupFileName(false)) : new File(FileUtil.a(this.h, 4), TbsDownloader.getBackupFileName(true)); TbsLog.i("TbsApkDownloader", "verifyAndInstallDecoupleCoreFromBackup backupFile is " + file.getAbsolutePath()); if (file.exists()) { str = "verifyAndInstallDecoupleCoreFromBackup #2"; } else { File b2 = TbsDownloader.b(TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DECOUPLECOREVERSION, -1)); if (b2 != null) { TbsLog.i("TbsApkDownloader", "verifyAndInstallDecoupleCoreFromBackup getExistBackupCoreForDecouple is " + b2.getAbsolutePath()); } if (b2 != null && b2.exists()) { FileUtil.b(b2, file); } try { String name = b2.getName(); TbsLog.i("TbsApkDownloader", "verifyAndInstallDecoupleCoreFromBackup fileNameSource is " + name); int i2 = 32; if (name.contains("64")) { i2 = 64; } if (r.b(this.h)) { File[] listFiles = this.m.listFiles(); Pattern compile = Pattern.compile(a.a(false, i2)); for (File file2 : listFiles) { if (compile.matcher(file2.getName()).find() && file2.isFile() && file2.exists()) { file2.delete(); TbsLog.i("TbsApkDownloader", "verifyAndInstallDecoupleCoreFromBackup delete file " + file2.getAbsolutePath()); } } File file3 = new File(this.m, a.a(false, i2) + "." + TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DECOUPLECOREVERSION, -1)); if (file3.exists()) { str2 = "verifyAndInstallDecoupleCoreFromBackup file already exist " + file3.getAbsolutePath(); } else { file3.createNewFile(); str2 = "verifyAndInstallDecoupleCoreFromBackup create file " + file3.getAbsolutePath(); } TbsLog.i("TbsApkDownloader", str2); } } catch (Throwable th) { str = "stack is " + Log.getStackTraceString(th); } context = this.h; if (a.a(context, file, 0, TbsDownloadConfig.getInstance(context).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DECOUPLECOREVERSION, -1))) { TbsLog.i("TbsApkDownloader", "verifyAndInstallDecoupleCoreFromBackup #3"); if (r.b(this.h)) { TbsLog.i("TbsApkDownloader", "verifyAndInstallDecoupleCoreFromBackup isStableCoreForHostEnable and return true"); return true; } TbsLog.i("TbsApkDownloader", "verifyAndInstallDecoupleCoreFromBackup goto installDecoupleCoreFromBackup"); return p.a().f(this.h); } return false; } TbsLog.i("TbsApkDownloader", str); context = this.h; if (a.a(context, file, 0, TbsDownloadConfig.getInstance(context).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DECOUPLECOREVERSION, -1))) { } } catch (Exception e2) { TbsLog.i("TbsApkDownloader", "stack is " + Log.getStackTraceString(e2)); } return false; } /* JADX WARNING: Removed duplicated region for block: B:43:0x00ed */ public boolean a(boolean z2, boolean z3) { String str; boolean z4; File k2; if (Build.VERSION.SDK_INT == 23) { return false; } int i2 = TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_USE_BACKUP_VERSION, 0); int j2 = p.a().j(this.h); if (i2 == 0) { i2 = 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 (!(i2 == 0 || i2 == j2)) { if (z3) { File a2 = TbsDownloader.a(i2); 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; k2 = k(); if (k2 != null || !k2.exists() || !a(k2)) { if (!r.b(this.h)) { l(); } if (a2 != null && a2.exists() && !a.a(this.h, a2, 0, i2) && a2 != null && a2.exists()) { FileUtil.b(a2); } } else if (b(i2)) { TbsDownloadConfig.getInstance(this.h).mSyncMap.put(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOAD_INTERRUPT_CODE_REASON, Integer.valueOf((int) NetError.ERR_CERTIFICATE_TRANSPARENCY_REQUIRED)); TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(NetError.ERR_CERTIFICATE_TRANSPARENCY_REQUIRED); d(false); if (z4) { a(100, "use local backup apk in startDownload" + this.a, true); TbsLogReport.getInstance(this.h).eventReport(TbsLogReport.EventType.TYPE_DOWNLOAD, this.x); this.x.resetArgs(); } return true; } } } catch (Exception e2) { e2.printStackTrace(); } } z4 = false; k2 = k(); if (k2 != null) { } if (!r.b(this.h)) { } FileUtil.b(a2); } if (c(false, z3)) { TbsDownloadConfig.getInstance(this.h).mSyncMap.put(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOAD_INTERRUPT_CODE_REASON, Integer.valueOf((int) NetError.ERR_CERTIFICATE_TRANSPARENCY_REQUIRED)); TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(NetError.ERR_CERTIFICATE_TRANSPARENCY_REQUIRED); d(false); return true; } else if (!e(true) && !e(true)) { TbsLog.e(TbsDownloader.LOGTAG, "[TbsApkDownloader] delete file failed!"); TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(NetError.ERR_DISALLOWED_URL_SCHEME); } } return false; } public void b() { this.t = true; if (TbsShareManager.isThirdPartyApp(this.h)) { TbsLogReport.TbsLogInfo tbsLogInfo = TbsLogReport.getInstance(this.h).tbsLogInfo(); tbsLogInfo.setErrorCode(-309); tbsLogInfo.setFailDetail(new Exception()); TbsLogReport.getInstance(this.h).eventReport(TbsLogReport.EventType.TYPE_DOWNLOAD, tbsLogInfo); } } /* JADX WARNING: Code restructure failed: missing block: B:146:0x0484, code lost: if (r41 == false) goto L_0x021a; */ /* JADX WARNING: Code restructure failed: missing block: B:154:0x04a3, code lost: if (r41 == false) goto L_0x021a; */ /* JADX WARNING: Code restructure failed: missing block: B:157:0x04ab, code lost: if (r41 == false) goto L_0x04ad; */ /* JADX WARNING: Code restructure failed: missing block: B:167:0x04f2, code lost: if (r41 == false) goto L_0x021a; */ /* JADX WARNING: Code restructure failed: missing block: B:168:0x04f6, code lost: if (r41 == false) goto L_0x04ad; */ /* JADX WARNING: Code restructure failed: missing block: B:179:0x051b, code lost: if (r41 == false) goto L_0x021a; */ /* JADX WARNING: Code restructure failed: missing block: B:180:0x051f, code lost: if (r41 == false) goto L_0x04ad; */ /* JADX WARNING: Code restructure failed: missing block: B:188:0x0537, code lost: if (r41 == false) goto L_0x04ad; */ /* JADX WARNING: Code restructure failed: missing block: B:190:0x0546, code lost: if (r41 != false) goto L_0x0647; */ /* JADX WARNING: Code restructure failed: missing block: B:285:0x0762, code lost: r26 = r27; */ /* JADX WARNING: Code restructure failed: missing block: B:287:0x0766, code lost: r15 = false; */ /* JADX WARNING: Code restructure failed: missing block: B:294:0x0776, code lost: if (r40.b == null) goto L_0x07a0; */ /* JADX WARNING: Code restructure failed: missing block: B:296:0x077d, code lost: if (c(true, r4) != false) goto L_0x07a0; */ /* JADX WARNING: Code restructure failed: missing block: B:297:0x077f, code lost: if (r41 != false) goto L_0x0791; */ /* JADX WARNING: Code restructure failed: missing block: B:299:0x0785, code lost: if (b(false) == false) goto L_0x0791; */ /* JADX WARNING: Code restructure failed: missing block: B:300:0x0787, code lost: r25 = r4; r5 = r13; r26 = r27; r15 = true; */ /* JADX WARNING: Code restructure failed: missing block: B:301:0x0791, code lost: r40.u = true; r25 = r4; r5 = r13; r26 = r27; r15 = false; r17 = false; */ /* JADX WARNING: Code restructure failed: missing block: B:302:0x07a0, code lost: r40.u = true; */ /* JADX WARNING: Code restructure failed: missing block: B:303:0x07a5, code lost: if (r40.b == null) goto L_0x07a9; */ /* JADX WARNING: Code restructure failed: missing block: B:304:0x07a7, code lost: r15 = true; */ /* JADX WARNING: Code restructure failed: missing block: B:305:0x07a9, code lost: r15 = r17; */ /* JADX WARNING: Code restructure failed: missing block: B:307:?, code lost: com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r40.h).setDownloadInterruptCode(aegon.chrome.net.NetError.ERR_UNSAFE_REDIRECT); */ /* JADX WARNING: Code restructure failed: missing block: B:308:0x07b6, code lost: r25 = r4; r5 = r13; r17 = r15; */ /* JADX WARNING: Code restructure failed: missing block: B:309:0x07bc, code lost: r0 = th; */ /* JADX WARNING: Code restructure failed: missing block: B:310:0x07bd, code lost: r5 = r13; */ /* JADX WARNING: Code restructure failed: missing block: B:311:0x07c4, code lost: r0 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:312:0x07c5, code lost: r3 = r0; r25 = r4; r5 = r13; r17 = r15; */ /* JADX WARNING: Code restructure failed: missing block: B:323:?, code lost: com.tencent.smtt.utils.TbsLog.i(com.tencent.smtt.sdk.TbsDownloader.LOGTAG, r5, true); r5 = new java.lang.StringBuilder(); r5.append("downloadFlow="); r5.append(r3); r5.append(" downloadMaxflow="); */ /* JADX WARNING: Code restructure failed: missing block: B:326:?, code lost: r5.append(r27); a(112, r5.toString(), true); com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r40.h).setDownloadInterruptCode(-307); */ /* JADX WARNING: Code restructure failed: missing block: B:327:0x0818, code lost: r31 = r3; r26 = r27; */ /* JADX WARNING: Code restructure failed: missing block: B:328:0x081d, code lost: r0 = th; */ /* JADX WARNING: Code restructure failed: missing block: B:329:0x081e, code lost: r5 = r13; */ /* JADX WARNING: Code restructure failed: missing block: B:330:0x0825, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:331:0x0826, code lost: r31 = r3; r5 = r13; r26 = r27; */ /* JADX WARNING: Code restructure failed: missing block: B:332:0x082d, code lost: r0 = th; */ /* JADX WARNING: Code restructure failed: missing block: B:334:0x0832, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:335:0x0833, code lost: r31 = r3; */ /* JADX WARNING: Code restructure failed: missing block: B:341:0x0885, code lost: r5 = r13; */ /* JADX WARNING: Code restructure failed: missing block: B:375:0x0916, code lost: b(); */ /* JADX WARNING: Code restructure failed: missing block: B:376:0x091b, code lost: if (com.tencent.smtt.sdk.QbSdk.n == null) goto L_0x0924; */ /* JADX WARNING: Code restructure failed: missing block: B:377:0x091d, code lost: com.tencent.smtt.sdk.QbSdk.n.onDownloadFinish(111); */ /* JADX WARNING: Code restructure failed: missing block: B:378:0x0924, code lost: com.tencent.smtt.utils.TbsLog.i(com.tencent.smtt.sdk.TbsDownloader.LOGTAG, "Download is paused due to NOT_WIFI error!", false); a(111, (java.lang.String) null, true); */ /* JADX WARNING: Code restructure failed: missing block: B:380:?, code lost: com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r40.h).setDownloadInterruptCode(-304); */ /* JADX WARNING: Code restructure failed: missing block: B:386:0x095c, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:398:0x0993, code lost: r0 = th; */ /* JADX WARNING: Code restructure failed: missing block: B:399:0x0995, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:429:0x0a1b, code lost: a(r5); a(r7); a(r6); */ /* JADX WARNING: Code restructure failed: missing block: B:430:0x0a26, code lost: if (r40.u != false) goto L_0x0a33; */ /* JADX WARNING: Code restructure failed: missing block: B:431:0x0a28, code lost: com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r40.h).setDownloadInterruptCode(-319); */ /* JADX WARNING: Code restructure failed: missing block: B:432:0x0a33, code lost: if (r41 != false) goto L_0x0bef; */ /* JADX WARNING: Code restructure failed: missing block: B:433:0x0a35, code lost: com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r40.h).mSyncMap.put(r9, java.lang.Long.valueOf(r31)); */ /* JADX WARNING: Code restructure failed: missing block: B:451:0x0abe, code lost: if (r41 == false) goto L_0x0a35; */ /* JADX WARNING: Code restructure failed: missing block: B:49:0x0179, code lost: r2.setDownloadInterruptCode(r3); r24 = "tmp"; r25 = "."; */ /* JADX WARNING: Code restructure failed: missing block: B:65:0x0218, code lost: if (r41 == false) goto L_0x021a; */ /* JADX WARNING: Code restructure failed: missing block: B:66:0x021a, code lost: com.tencent.smtt.sdk.TbsDownloadConfig.getInstance(r40.h).mSyncMap.put(r14, java.lang.Long.valueOf(r8)); */ /* JADX WARNING: Code restructure failed: missing block: B:71:0x0253, code lost: if (r41 == false) goto L_0x021a; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Removed duplicated region for block: B:117:0x03e4 A[Catch:{ all -> 0x0b58 }] */ /* JADX WARNING: Removed duplicated region for block: B:244:0x06ae A[SYNTHETIC, Splitter:B:244:0x06ae] */ /* JADX WARNING: Removed duplicated region for block: B:288:0x0769 */ /* JADX WARNING: Removed duplicated region for block: B:382:0x0940 A[SYNTHETIC, Splitter:B:382:0x0940] */ /* JADX WARNING: Removed duplicated region for block: B:398:0x0993 A[ExcHandler: all (th java.lang.Throwable), Splitter:B:289:0x076e] */ /* JADX WARNING: Removed duplicated region for block: B:443:0x0a6d A[Catch:{ all -> 0x0b46 }] */ /* JADX WARNING: Removed duplicated region for block: B:463:0x0b23 */ /* JADX WARNING: Removed duplicated region for block: B:483:0x0b76 A[ADDED_TO_REGION, Catch:{ all -> 0x0d23 }] */ /* JADX WARNING: Removed duplicated region for block: B:498:0x0bf5 */ /* JADX WARNING: Removed duplicated region for block: B:523:0x0cae */ /* JADX WARNING: Removed duplicated region for block: B:524:0x0cc2 */ /* JADX WARNING: Removed duplicated region for block: B:530:0x0ced */ /* JADX WARNING: Removed duplicated region for block: B:554:0x0a1b A[EDGE_INSN: B:554:0x0a1b->B:429:0x0a1b ?: BREAK , SYNTHETIC] */ /* JADX WARNING: Removed duplicated region for block: B:561:0x0bca A[SYNTHETIC] */ /* JADX WARNING: Removed duplicated region for block: B:563:0x03d5 A[SYNTHETIC] */ /* JADX WARNING: Removed duplicated region for block: B:567:0x074c A[SYNTHETIC] */ /* JADX WARNING: Removed duplicated region for block: B:77:0x0273 */ /* JADX WARNING: Removed duplicated region for block: B:80:0x029c */ /* JADX WARNING: Removed duplicated region for block: B:83:0x02aa */ /* JADX WARNING: Removed duplicated region for block: B:89:0x0345 A[Catch:{ all -> 0x0b58 }] */ /* JADX WARNING: Removed duplicated region for block: B:92:0x0351 A[Catch:{ all -> 0x0b58 }] */ /* JADX WARNING: Removed duplicated region for block: B:93:0x0353 A[Catch:{ all -> 0x0b58 }] */ /* JADX WARNING: Removed duplicated region for block: B:96:0x035f A[Catch:{ all -> 0x0b58 }] */ public void b(boolean z2, boolean z3) { TbsDownloadConfig instance; int i2; boolean z4; String str; String str2; boolean z5; int i3; boolean z6; String str3; String str4; long j2; long j3; String str5; Throwable th; long j4; String str6; String str7; long j5; long j6; InputStream inputStream; InputStream inputStream2; Closeable closeable; Throwable th2; Throwable th3; IOException iOException; boolean z7; int i4; String a2; IOException e2; Throwable th4; String str8; File file; FileOutputStream fileOutputStream; IOException e3; long j7; boolean z8; long j8; String str9; String str10 = TbsDownloadConfig.TbsConfigKey.KEY_TBSDOWNLOAD_STARTTIME; if (!p.a().d(this.h) || z2) { int i5 = TbsDownloadConfig.getInstance(this.h).mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_RESPONSECODE, 0); boolean z9 = i5 == 1 || i5 == 2 || i5 == 4; if (z3 || !a(z2, z9)) { this.E = z2; String str11 = 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); TbsLog.i(TbsDownloader.LOGTAG, "backupUrlStrings:" + string, true); this.b = null; this.c = 0; if (!z2 && string != null && !"".equals(string.trim())) { this.b = string.trim().split(";"); } TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.startDownload] mDownloadUrl=" + this.i + " backupUrlStrings=" + string + " mLocation=" + this.k + " mCanceled=" + this.t + " mHttpRequest=" + this.v); if (this.i == null && this.k == null) { TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(NetError.ERR_UNKNOWN_URL_SCHEME); QbSdk.n.onDownloadFinish(110); } else if (this.v != null && !this.t) { TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(NetError.ERR_INVALID_REDIRECT); QbSdk.n.onDownloadFinish(110); } else if (z2 || !this.C) { g(); TbsLog.i(TbsDownloader.LOGTAG, "STEP 1/2 begin downloading...", true); long downloadMaxflow = TbsDownloadConfig.getInstance(this.h).getDownloadMaxflow(); SharedPreferences sharedPreferences = TbsDownloadConfig.getInstance(this.h).mPreferences; String str12 = TbsDownloadConfig.TbsConfigKey.KEY_TBSDOWNLOAD_FLOW; long j9 = sharedPreferences.getLong(str12, 0); this.D = z2 ? f : e; long j10 = j9; boolean z10 = false; while (true) { if (this.r > this.D) { instance = TbsDownloadConfig.getInstance(this.h); i2 = -305; break; } else if (this.s > 8) { a(123, str11, true); instance = TbsDownloadConfig.getInstance(this.h); i2 = -306; break; } else { long currentTimeMillis = System.currentTimeMillis(); String str13 = "STEP 1/2 begin downloading...failed because you exceeded max flow!"; if (!z2) { try { str = "tmp"; str3 = "."; try { if (currentTimeMillis - TbsDownloadConfig.getInstance(this.h).mPreferences.getLong(str10, 0) > 86400000) { TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.startDownload] OVER DOWNLOAD_PERIOD"); TbsDownloadConfig.getInstance(this.h).mSyncMap.put(str10, Long.valueOf(currentTimeMillis)); TbsDownloadConfig.getInstance(this.h).mSyncMap.put(str12, 0L); TbsDownloadConfig.getInstance(this.h).commit(); j10 = 0; } else { TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.startDownload] downloadFlow=" + j10); if (j10 >= downloadMaxflow) { TbsLog.i(TbsDownloader.LOGTAG, str13, true); a(112, (String) null, true); TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-307); } } if (!FileUtil.b(this.h)) { TbsLog.i(TbsDownloader.LOGTAG, "DownloadBegin FreeSpace too small", true); a(105, (String) null, true); TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-308); } this.A = true; str7 = this.k; if (str7 == null) { str7 = this.i; } TbsLog.i(TbsDownloader.LOGTAG, "try url:" + str7 + ",mRetryTimes:" + this.r, true); if (!str7.equals(this.j)) { this.x.setDownloadUrl(str7); } this.j = str7; a(str7); if (this.q) { long n2 = n(); TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.startDownload] range=" + n2); j5 = downloadMaxflow; try { if (this.n <= 0) { TbsLog.i(TbsDownloader.LOGTAG, "STEP 1/2 begin downloading...current" + n2, true); this.v.setRequestProperty(Command.HTTP_HEADER_RANGE, "bytes=" + n2 + "-"); j6 = n2; } else { TbsLog.i(TbsDownloader.LOGTAG, "#1 STEP 1/2 begin downloading...current/total=" + n2 + "/" + this.n, true); HttpURLConnection httpURLConnection = this.v; StringBuilder sb = new StringBuilder(); sb.append("bytes="); sb.append(n2); sb.append("-"); j6 = n2; sb.append(this.n); httpURLConnection.setRequestProperty(Command.HTTP_HEADER_RANGE, sb.toString()); } } catch (Throwable th5) { th = th5; str4 = str10; j2 = j10; str5 = str12; str2 = str3; j3 = j5; z4 = z9; try { if (th instanceof SSLHandshakeException) { } str6 = null; th.printStackTrace(); j4 = 0; a(0L); a(107, a(th), false); if (this.t) { } } finally { if (!z2) { TbsDownloadConfig.getInstance(this.h).mSyncMap.put(str5, Long.valueOf(j2)); TbsDownloadConfig.getInstance(this.h).commit(); } } } } else { j5 = downloadMaxflow; j6 = 0; } this.x.setDownloadCancel(j6 != 0 ? 0 : 1); j(); if (this.r >= 1) { this.v.addRequestProperty("Referer", this.i); } int responseCode = this.v.getResponseCode(); TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.startDownload] responseCode=" + responseCode); this.x.setHttpCode(responseCode); if (z2 && !TbsDownloader.getOverSea(this.h) && ((Apn.getApnType(this.h) != 3 || Apn.getApnType(this.h) == 0) && !QbSdk.getDownloadWithoutWifi())) { b(); a(111, (String) null, true); TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(NetError.ERR_EMPTY_RESPONSE); if (QbSdk.n != null) { QbSdk.n.onDownloadFinish(111); } TbsLog.i(TbsDownloader.LOGTAG, "Download is canceled due to NOT_WIFI error!", false); } if (!this.t) { TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-309); if (!z2) { } } else { if (responseCode != 200) { if (responseCode != 206) { if (responseCode < 300 || responseCode > 307) { a(102, String.valueOf(responseCode), false); if (responseCode == 416) { if (c(true, z9)) { try { TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(NetError.ERR_UNEXPECTED_PROXY_AUTH); if (!z2) { TbsDownloadConfig.getInstance(this.h).mSyncMap.put(str12, Long.valueOf(j10)); TbsDownloadConfig.getInstance(this.h).commit(); } str2 = str3; z5 = true; } catch (Throwable th6) { th = th6; str4 = str10; j2 = j10; str5 = str12; str2 = str3; j3 = j5; z10 = true; } } else { e(false); TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-313); } } else if ((responseCode == 403 || responseCode == 406) && this.n == -1) { TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-314); } else if (responseCode != 202) { int i6 = this.r; int i7 = this.D; if (i6 < i7 && responseCode == 503) { a(Long.parseLong(this.v.getHeaderField("Retry-After"))); if (this.t) { TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-309); } } else if (i6 < i7 && (responseCode == 408 || responseCode == 504 || responseCode == 502)) { a(0L); if (this.t) { TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-309); } } else if (n() > 0 || this.q || responseCode == 410) { TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-315); } else { this.q = true; } } } else { String headerField = this.v.getHeaderField("Location"); if (!TextUtils.isEmpty(headerField)) { this.k = headerField; this.s++; if (!z2) { } j2 = j10; str5 = str12; str12 = str5; downloadMaxflow = j5; j10 = j2; str11 = null; } else { a(124, (String) null, true); TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(NetError.ERR_UNSAFE_PORT); if (!z2) { } } } TbsDownloadConfig.getInstance(this.h).mSyncMap.put(str12, Long.valueOf(j10)); TbsDownloadConfig.getInstance(this.h).commit(); j2 = j10; str5 = str12; str12 = str5; downloadMaxflow = j5; j10 = j2; str11 = null; } } this.n = ((long) this.v.getContentLength()) + j6; TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.startDownload] mContentLength=" + this.n); this.x.setPkgSize(this.n); j2 = j10; str5 = str12; try { long j11 = TbsDownloadConfig.getInstance(this.h).mPreferences.getLong(TbsDownloadConfig.TbsConfigKey.KEY_TBSAPKFILESIZE, 0); if (j11 == 0 || this.n == j11) { TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.startDownload] begin readResponse"); try { inputStream2 = this.v.getInputStream(); if (inputStream2 == null) { str2 = str3; z4 = z9; closeable = null; inputStream = null; break; } try { String contentEncoding = this.v.getContentEncoding(); if (contentEncoding != null) { try { if (contentEncoding.contains("gzip")) { inputStream = new GZIPInputStream(inputStream2); byte[] bArr = new byte[8192]; if (z3) { try { if (r.b(this.h)) { File file2 = this.m; StringBuilder sb2 = new StringBuilder(); sb2.append(TbsDownloader.getBackupFileName(false)); str2 = str3; try { sb2.append(str2); str8 = str; try { sb2.append(str8); file = new File(file2, sb2.toString()); if (file.exists()) { file.delete(); } TbsLog.i(TbsDownloader.LOGTAG, "fileDownloadApk is " + file.getAbsolutePath(), true); fileOutputStream = new FileOutputStream(file, true); long currentTimeMillis2 = System.currentTimeMillis(); str = str8; j7 = currentTimeMillis; long j12 = j6; while (true) { try { if (this.t) { TbsLog.i(TbsDownloader.LOGTAG, "STEP 1/2 begin downloading...Canceled!", true); TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-309); str4 = str10; z4 = z9; closeable = fileOutputStream; break; } str4 = str10; try { int read = inputStream.read(bArr, 0, 8192); if (read <= 0) { break; } fileOutputStream.write(bArr, 0, read); fileOutputStream.flush(); z4 = z9; if (!z2) { long j13 = j2 + ((long) read); if (j13 >= j5) { break; } j2 = j13; j3 = j5; try { if (!FileUtil.b(this.h)) { TbsLog.i(TbsDownloader.LOGTAG, "DownloadEnd FreeSpace too small ", true); a(105, "freespace=" + r.a() + ",and minFreeSpace=" + TbsDownloadConfig.getInstance(this.h).getDownloadMinFreeSpace(), true); TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-308); break; } } catch (IOException e4) { iOException = e4; closeable = fileOutputStream; try { iOException.printStackTrace(); if (!(iOException instanceof SocketTimeoutException)) { if (!(iOException instanceof SocketException)) { if (z2 || FileUtil.b(this.h)) { a(0L); if (!m()) { i4 = 106; a2 = a(iOException); z7 = false; } else { z7 = false; i4 = 104; a2 = a(iOException); } a(i4, a2, z7); a(closeable); a(inputStream); a(inputStream2); if (!z2) { TbsDownloadConfig.getInstance(this.h).mSyncMap.put(str5, Long.valueOf(j2)); TbsDownloadConfig.getInstance(this.h).commit(); } str12 = str5; z9 = z4; downloadMaxflow = j3; j10 = j2; str10 = str4; str11 = null; } else { a(105, "freespace=" + r.a() + ",and minFreeSpace=" + TbsDownloadConfig.getInstance(this.h).getDownloadMinFreeSpace(), true); TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-308); a(closeable); a(inputStream); a(inputStream2); } } } this.o = DefaultOggSeeker.MATCH_BYTE_RANGE; a(0L); a(103, a(iOException), false); a(closeable); a(inputStream); a(inputStream2); if (!z2) { TbsDownloadConfig.getInstance(this.h).mSyncMap.put(str5, Long.valueOf(j2)); TbsDownloadConfig.getInstance(this.h).commit(); } str12 = str5; z9 = z4; downloadMaxflow = j3; j10 = j2; str10 = str4; str11 = null; } catch (Throwable th7) { th3 = th7; th2 = th3; a(closeable); a(inputStream); a(inputStream2); throw th2; } } catch (Throwable th8) { th2 = th8; closeable = fileOutputStream; a(closeable); a(inputStream); a(inputStream2); throw th2; } } else { j3 = j5; } long j14 = (long) read; try { long a3 = a(j7, j14); long currentTimeMillis3 = System.currentTimeMillis(); long j15 = j6 + j14; if (currentTimeMillis3 - currentTimeMillis2 > 1000) { StringBuilder sb3 = new StringBuilder(); str9 = str13; sb3.append("#2 STEP 1/2 begin downloading...current/total="); sb3.append(j15); sb3.append("/"); closeable = fileOutputStream; j8 = a3; try { sb3.append(this.n); TbsLog.i(TbsDownloader.LOGTAG, sb3.toString(), true); if (QbSdk.n != null) { try { QbSdk.n.onDownloadProgress((int) ((((double) j15) / ((double) this.n)) * 100.0d)); } catch (IOException e5) { iOException = e5; } catch (Throwable th9) { th2 = th9; a(closeable); a(inputStream); a(inputStream2); throw th2; } } if (!z2 && j15 - j12 > 1048576) { if (!TbsDownloader.getOverSea(this.h) && ((Apn.getApnType(this.h) != 3 || Apn.getApnType(this.h) == 0) && !QbSdk.getDownloadWithoutWifi())) { break; } j12 = j15; } currentTimeMillis2 = currentTimeMillis3; } catch (IOException e6) { e3 = e6; iOException = e3; iOException.printStackTrace(); if (!(iOException instanceof SocketTimeoutException)) { } this.o = DefaultOggSeeker.MATCH_BYTE_RANGE; a(0L); a(103, a(iOException), false); a(closeable); a(inputStream); a(inputStream2); if (!z2) { } str12 = str5; z9 = z4; downloadMaxflow = j3; j10 = j2; str10 = str4; str11 = null; } catch (Throwable th10) { th3 = th10; th2 = th3; a(closeable); a(inputStream); a(inputStream2); throw th2; } } else { str9 = str13; closeable = fileOutputStream; j8 = a3; } fileOutputStream = closeable; j5 = j3; str13 = str9; j7 = j8; j6 = j15; z9 = z4; str10 = str4; } catch (IOException e7) { e3 = e7; closeable = fileOutputStream; iOException = e3; iOException.printStackTrace(); if (!(iOException instanceof SocketTimeoutException)) { } this.o = DefaultOggSeeker.MATCH_BYTE_RANGE; a(0L); a(103, a(iOException), false); a(closeable); a(inputStream); a(inputStream2); if (!z2) { } str12 = str5; z9 = z4; downloadMaxflow = j3; j10 = j2; str10 = str4; str11 = null; } catch (Throwable th11) { th3 = th11; closeable = fileOutputStream; th2 = th3; a(closeable); a(inputStream); a(inputStream2); throw th2; } } catch (IOException e8) { iOException = e8; z4 = z9; closeable = fileOutputStream; j3 = j5; iOException.printStackTrace(); if (!(iOException instanceof SocketTimeoutException)) { } this.o = DefaultOggSeeker.MATCH_BYTE_RANGE; a(0L); a(103, a(iOException), false); a(closeable); a(inputStream); a(inputStream2); if (!z2) { } str12 = str5; z9 = z4; downloadMaxflow = j3; j10 = j2; str10 = str4; str11 = null; } catch (Throwable th12) { } } catch (IOException e9) { e3 = e9; str4 = str10; z4 = z9; closeable = fileOutputStream; j3 = j5; iOException = e3; iOException.printStackTrace(); if (!(iOException instanceof SocketTimeoutException)) { } this.o = DefaultOggSeeker.MATCH_BYTE_RANGE; a(0L); a(103, a(iOException), false); a(closeable); a(inputStream); a(inputStream2); if (!z2) { } str12 = str5; z9 = z4; downloadMaxflow = j3; j10 = j2; str10 = str4; str11 = null; } catch (Throwable th13) { th3 = th13; closeable = fileOutputStream; th2 = th3; a(closeable); a(inputStream); a(inputStream2); throw th2; } } if (!z8) { break; } try { a(closeable); a(inputStream); a(inputStream2); if (!z2) { TbsDownloadConfig.getInstance(this.h).mSyncMap.put(str5, Long.valueOf(j2)); TbsDownloadConfig.getInstance(this.h).commit(); } str12 = str5; z9 = z4; downloadMaxflow = j3; j10 = j2; str10 = str4; str11 = null; } catch (Throwable th14) { th = th14; if (th instanceof SSLHandshakeException) { } str6 = null; th.printStackTrace(); j4 = 0; a(0L); a(107, a(th), false); if (this.t) { } } } catch (IOException e10) { e3 = e10; str4 = str10; z4 = z9; str = str8; j3 = j5; closeable = null; iOException = e3; iOException.printStackTrace(); if (!(iOException instanceof SocketTimeoutException)) { } this.o = DefaultOggSeeker.MATCH_BYTE_RANGE; a(0L); a(103, a(iOException), false); a(closeable); a(inputStream); a(inputStream2); if (!z2) { } str12 = str5; z9 = z4; downloadMaxflow = j3; j10 = j2; str10 = str4; str11 = null; } catch (Throwable th15) { th3 = th15; closeable = null; th2 = th3; a(closeable); a(inputStream); a(inputStream2); throw th2; } } catch (IOException e11) { e3 = e11; str4 = str10; z4 = z9; j3 = j5; closeable = null; iOException = e3; iOException.printStackTrace(); if (!(iOException instanceof SocketTimeoutException)) { } this.o = DefaultOggSeeker.MATCH_BYTE_RANGE; a(0L); a(103, a(iOException), false); a(closeable); a(inputStream); a(inputStream2); if (!z2) { } str12 = str5; z9 = z4; downloadMaxflow = j3; j10 = j2; str10 = str4; str11 = null; } catch (Throwable th16) { th3 = th16; closeable = null; th2 = th3; a(closeable); a(inputStream); a(inputStream2); throw th2; } } } catch (IOException e12) { e3 = e12; str2 = str3; str4 = str10; z4 = z9; j3 = j5; closeable = null; iOException = e3; iOException.printStackTrace(); if (!(iOException instanceof SocketTimeoutException)) { } this.o = DefaultOggSeeker.MATCH_BYTE_RANGE; a(0L); a(103, a(iOException), false); a(closeable); a(inputStream); a(inputStream2); if (!z2) { } str12 = str5; z9 = z4; downloadMaxflow = j3; j10 = j2; str10 = str4; str11 = null; } catch (Throwable th17) { th3 = th17; closeable = null; th2 = th3; a(closeable); a(inputStream); a(inputStream2); throw th2; } } str8 = str; str2 = str3; file = new File(this.l, "x5.tbs.temp"); TbsLog.i(TbsDownloader.LOGTAG, "fileDownloadApk is " + file.getAbsolutePath(), true); fileOutputStream = new FileOutputStream(file, true); try { long currentTimeMillis22 = System.currentTimeMillis(); str = str8; j7 = currentTimeMillis; long j122 = j6; while (true) { if (this.t) { } fileOutputStream = closeable; j5 = j3; str13 = str9; j7 = j8; j6 = j15; z9 = z4; str10 = str4; } if (!z8) { } } catch (IOException e13) { e3 = e13; str4 = str10; z4 = z9; closeable = fileOutputStream; str = str8; j3 = j5; iOException = e3; iOException.printStackTrace(); if (!(iOException instanceof SocketTimeoutException)) { } this.o = DefaultOggSeeker.MATCH_BYTE_RANGE; a(0L); a(103, a(iOException), false); a(closeable); a(inputStream); a(inputStream2); if (!z2) { } str12 = str5; z9 = z4; downloadMaxflow = j3; j10 = j2; str10 = str4; str11 = null; } catch (Throwable th18) { th3 = th18; closeable = fileOutputStream; th2 = th3; a(closeable); a(inputStream); a(inputStream2); throw th2; } } } catch (IOException e14) { str4 = str10; str2 = str3; j3 = j5; closeable = null; inputStream = null; iOException = e14; z4 = z9; iOException.printStackTrace(); if (!(iOException instanceof SocketTimeoutException)) { } this.o = DefaultOggSeeker.MATCH_BYTE_RANGE; a(0L); a(103, a(iOException), false); a(closeable); a(inputStream); a(inputStream2); if (!z2) { } str12 = str5; z9 = z4; downloadMaxflow = j3; j10 = j2; str10 = str4; str11 = null; } catch (Throwable th19) { th3 = th19; closeable = null; inputStream = null; th2 = th3; a(closeable); a(inputStream); a(inputStream2); throw th2; } } inputStream = (contentEncoding == null || !contentEncoding.contains("deflate")) ? inputStream2 : new InflaterInputStream(inputStream2, new Inflater(true)); try { byte[] bArr2 = new byte[8192]; if (z3) { } str8 = str; str2 = str3; } catch (IOException e15) { e2 = e15; str4 = str10; str2 = str3; j3 = j5; z4 = z9; iOException = e2; closeable = null; iOException.printStackTrace(); if (!(iOException instanceof SocketTimeoutException)) { } this.o = DefaultOggSeeker.MATCH_BYTE_RANGE; a(0L); a(103, a(iOException), false); a(closeable); a(inputStream); a(inputStream2); if (!z2) { } str12 = str5; z9 = z4; downloadMaxflow = j3; j10 = j2; str10 = str4; str11 = null; } catch (Throwable th20) { th4 = th20; th2 = th4; closeable = null; a(closeable); a(inputStream); a(inputStream2); throw th2; } } catch (IOException e16) { str4 = str10; str2 = str3; j3 = j5; z4 = z9; iOException = e16; closeable = null; inputStream = null; iOException.printStackTrace(); if (!(iOException instanceof SocketTimeoutException)) { } this.o = DefaultOggSeeker.MATCH_BYTE_RANGE; a(0L); a(103, a(iOException), false); a(closeable); a(inputStream); a(inputStream2); if (!z2) { } str12 = str5; z9 = z4; downloadMaxflow = j3; j10 = j2; str10 = str4; str11 = null; } catch (Throwable th21) { th2 = th21; closeable = null; inputStream = null; a(closeable); a(inputStream); a(inputStream2); throw th2; } try { file = new File(this.l, "x5.tbs.temp"); TbsLog.i(TbsDownloader.LOGTAG, "fileDownloadApk is " + file.getAbsolutePath(), true); fileOutputStream = new FileOutputStream(file, true); long currentTimeMillis222 = System.currentTimeMillis(); str = str8; j7 = currentTimeMillis; long j1222 = j6; while (true) { if (this.t) { } fileOutputStream = closeable; j5 = j3; str13 = str9; j7 = j8; j6 = j15; z9 = z4; str10 = str4; } if (!z8) { } } catch (IOException e17) { e2 = e17; str4 = str10; z4 = z9; str = str8; j3 = j5; iOException = e2; closeable = null; iOException.printStackTrace(); if (!(iOException instanceof SocketTimeoutException)) { } this.o = DefaultOggSeeker.MATCH_BYTE_RANGE; a(0L); a(103, a(iOException), false); a(closeable); a(inputStream); a(inputStream2); if (!z2) { } str12 = str5; z9 = z4; downloadMaxflow = j3; j10 = j2; str10 = str4; str11 = null; } catch (Throwable th22) { th4 = th22; th2 = th4; closeable = null; a(closeable); a(inputStream); a(inputStream2); throw th2; } } catch (IOException e18) { str4 = str10; str2 = str3; j3 = j5; z4 = z9; iOException = e18; closeable = null; inputStream2 = null; inputStream = null; iOException.printStackTrace(); if (!(iOException instanceof SocketTimeoutException)) { } this.o = DefaultOggSeeker.MATCH_BYTE_RANGE; a(0L); a(103, a(iOException), false); a(closeable); a(inputStream); a(inputStream2); if (!z2) { } str12 = str5; z9 = z4; downloadMaxflow = j3; j10 = j2; str10 = str4; str11 = null; } catch (Throwable th23) { th2 = th23; closeable = null; inputStream2 = null; inputStream = null; a(closeable); a(inputStream); a(inputStream2); throw th2; } } else { TbsLog.i(TbsDownloader.LOGTAG, "DownloadBegin tbsApkFileSize=" + j11 + " but contentLength=" + this.n, true); if (z2 || (!q() && (!QbSdk.getDownloadWithoutWifi() || !Apn.isNetworkAvailable(this.h)))) { a(101, "WifiNetworkUnAvailable", true); TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-304); } else if (this.b == null || !b(false)) { a(113, "tbsApkFileSize=" + j11 + " but contentLength=" + this.n, true); TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(NetError.ERR_TOO_MANY_REDIRECTS); } else { if (!z2) { TbsDownloadConfig.getInstance(this.h).mSyncMap.put(str5, Long.valueOf(j2)); TbsDownloadConfig.getInstance(this.h).commit(); } str12 = str5; downloadMaxflow = j5; j10 = j2; str11 = null; } if (!z2) { TbsDownloadConfig.getInstance(this.h).mSyncMap.put(str5, Long.valueOf(j2)); TbsDownloadConfig.getInstance(this.h).commit(); } } } catch (Throwable th24) { th = th24; str4 = str10; str2 = str3; j3 = j5; z4 = z9; if (th instanceof SSLHandshakeException) { } str6 = null; th.printStackTrace(); j4 = 0; a(0L); a(107, a(th), false); if (this.t) { } } } } catch (Throwable th25) { th = th25; str4 = str10; j2 = j10; j3 = downloadMaxflow; str5 = str12; str2 = str3; z4 = z9; if ((th instanceof SSLHandshakeException) || z2 || this.b == null || !b(false)) { str6 = null; th.printStackTrace(); j4 = 0; a(0L); a(107, a(th), false); if (this.t) { TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-309); if (!z2) { TbsDownloadConfig.getInstance(this.h).mSyncMap.put(str5, Long.valueOf(j2)); TbsDownloadConfig.getInstance(this.h).commit(); } z5 = z10; if (!this.t) { } h(); } z9 = z4; } else { TbsLog.e(TbsDownloader.LOGTAG, "[startdownload]url:" + this.k + " download exception:" + th.toString()); str6 = null; a(125, (String) null, true); z9 = z4; j4 = 0; } TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-316); str11 = str6; str12 = str5; downloadMaxflow = j3; j10 = j2; str10 = str4; } } catch (Throwable th26) { th = th26; str4 = str10; z4 = z9; str = "tmp"; str2 = "."; j2 = j10; j3 = downloadMaxflow; str5 = str12; if (th instanceof SSLHandshakeException) { } str6 = null; th.printStackTrace(); j4 = 0; a(0L); a(107, a(th), false); if (this.t) { } } } else { str = "tmp"; str3 = "."; this.A = true; str7 = this.k; if (str7 == null) { } TbsLog.i(TbsDownloader.LOGTAG, "try url:" + str7 + ",mRetryTimes:" + this.r, true); if (!str7.equals(this.j)) { } this.j = str7; a(str7); if (this.q) { } this.x.setDownloadCancel(j6 != 0 ? 0 : 1); j(); if (this.r >= 1) { } int responseCode2 = this.v.getResponseCode(); TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.startDownload] responseCode=" + responseCode2); this.x.setHttpCode(responseCode2); if (z2) { } if (!this.t) { } } } } z5 = z10; str2 = str3; z4 = z9; if (!this.t) { if (this.u) { if (this.b != null || z5) { z6 = z4; } else if (!z3 || !r.b(this.h)) { z6 = z4; z5 = c(true, z6); } else { File file3 = new File(this.m, TbsDownloader.getBackupFileName(false) + str2 + str); z6 = z4; z5 = a(true, z6, file3); } TbsLogReport.TbsLogInfo tbsLogInfo = this.x; int i8 = z5 ? 1 : 0; int i9 = z5 ? 1 : 0; int i10 = z5 ? 1 : 0; int i11 = z5 ? 1 : 0; int i12 = z5 ? 1 : 0; int i13 = z5 ? 1 : 0; int i14 = z5 ? 1 : 0; int i15 = z5 ? 1 : 0; tbsLogInfo.setUnpkgFlag(i8); r.a("10is" + z5); TbsLogReport.TbsLogInfo tbsLogInfo2 = this.x; if (!z6) { tbsLogInfo2.setPatchUpdateFlag(z5 ? 1 : 2); } else { tbsLogInfo2.setPatchUpdateFlag(0); } TbsLog.i(TbsDownloader.LOGTAG, "downloadSuccess is " + z5); if (z5) { h(); d(true); TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-317); a(100, bf.o, true); } else { TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-318); i3 = 0; e(false); TbsDownloadConfig instance2 = TbsDownloadConfig.getInstance(this.h); if (!z5) { instance2.mSyncMap.put(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOAD_SUCCESS_RETRYTIMES, Integer.valueOf(instance2.mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOAD_SUCCESS_RETRYTIMES, i3) + 1)); } else { int i16 = instance2.mPreferences.getInt(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOAD_FAILED_RETRYTIMES, i3) + 1; instance2.mSyncMap.put(TbsDownloadConfig.TbsConfigKey.KEY_DOWNLOAD_FAILED_RETRYTIMES, Integer.valueOf(i16)); if (i16 == instance2.getDownloadFailedMaxRetrytimes()) { this.x.setDownloadCancel(2); } } instance2.commit(); TbsLogReport.TbsLogInfo tbsLogInfo3 = this.x; int i17 = z5 ? 1 : 0; int i18 = z5 ? 1 : 0; tbsLogInfo3.setDownFinalFlag(i17); } } i3 = 0; TbsDownloadConfig instance22 = TbsDownloadConfig.getInstance(this.h); if (!z5) { } instance22.commit(); TbsLogReport.TbsLogInfo tbsLogInfo32 = this.x; int i172 = z5 ? 1 : 0; int i182 = z5 ? 1 : 0; tbsLogInfo32.setDownFinalFlag(i172); } h(); } else { TbsLog.i(TbsDownloader.LOGTAG, "[TbsApkDownloader.startDownload] WIFI Unavailable"); TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(-304); QbSdk.n.onDownloadFinish(110); } } else { TbsDownloader.a = false; QbSdk.n.onDownloadFinish(130); } } else { TbsDownloader.a = false; TbsDownloadConfig.getInstance(this.h).setDownloadInterruptCode(NetError.ERR_METHOD_NOT_SUPPORTED); QbSdk.n.onDownloadFinish(NetError.ERR_METHOD_NOT_SUPPORTED); } } public boolean b(boolean z2) { String[] strArr; int i2; if ((z2 && !q() && (!QbSdk.getDownloadWithoutWifi() || !Apn.isNetworkAvailable(this.h))) || (strArr = this.b) == null || (i2 = this.c) < 0 || i2 >= strArr.length) { return false; } this.c = i2 + 1; this.k = strArr[i2]; this.r = 0; this.s = 0; this.n = -1; this.q = false; this.t = false; this.u = false; this.A = false; return true; } public int c(boolean z2) { File c2 = c(this.h); if (z2) { if (c2 == null) { return 0; } return a.a(this.h, new File(c2, TbsDownloader.getBackupFileName(true))); } else if (c2 == null) { return 0; } else { return a.a(this.h, new File(c2, TbsDownloader.getOverSea(this.h) ? "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.E); return this.E; } /* access modifiers changed from: package-private */ public void e() { TbsLog.i(TbsDownloader.LOGTAG, "pauseDownload,isPause=" + this.d + "isDownloading=" + TbsDownloader.isDownloading()); if (!this.d && TbsDownloader.isDownloading()) { b(); this.d = true; this.A = false; } } /* access modifiers changed from: package-private */ public void f() { TbsLog.i(TbsDownloader.LOGTAG, "resumeDownload,isPause=" + this.d + "isDownloading=" + TbsDownloader.isDownloading()); if (this.d && TbsDownloader.isDownloading()) { this.d = false; a(false); } } }