package c.t.m.sapp.c; import android.content.Context; import androidx.camera.core.FocusMeteringAction; import com.tencent.tinker.loader.shareutil.ShareConstants; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; public class c implements Runnable { /* renamed from: a reason: collision with root package name */ public static int f45649a; /* renamed from: b reason: collision with root package name */ public final int f45650b = 30000; /* renamed from: c reason: collision with root package name */ public final int f45651c = 20000; /* renamed from: d reason: collision with root package name */ public Context f45652d; /* renamed from: e reason: collision with root package name */ public List<a> f45653e = null; /* renamed from: f reason: collision with root package name */ public String f45654f = null; /* renamed from: g reason: collision with root package name */ public boolean f45655g = false; public c(Context context) { this.f45652d = context; this.f45654f = this.f45652d.getFilesDir().getAbsolutePath() + File.separator + "TencentLocation_sapp/UpCp"; File file = new File(this.f45652d.getFilesDir().getAbsolutePath(), "TencentLocation_sapp/UpCp"); if (!file.exists()) { file.mkdirs(); } } public final synchronized void a() { List<a> list = this.f45653e; if (list != null && list.size() > 0) { f45649a = 1; r.i(this.f45652d); if (r.d() < 10485760) { f45649a = 2; return; } ArrayList arrayList = new ArrayList(); boolean z15 = false; boolean z16 = true; for (a aVar : this.f45653e) { if (!a(aVar)) { z16 = false; } else { arrayList.add(aVar); } } if (!z16) { f45649a = 2; a(arrayList); } else if (arrayList.size() == this.f45653e.size()) { r.c(this.f45652d, "__SP_UPDATE_TencentLoc_COMP_INFO__sapp_", ""); if (r.a(this.f45652d, this.f45653e)) { r.d(this.f45652d, "__SP_UPDATE_TencentLoc_COMP_SDK_VER__sapp_", h.f45674a); Iterator it = arrayList.iterator(); while (it.hasNext()) { a aVar2 = (a) it.next(); if (!aVar2.f45641c.contains(ShareConstants.DEX_SUFFIX)) { aVar2.f45641c += ShareConstants.DEX_SUFFIX; } File file = new File(this.f45654f, aVar2.f45641c); boolean delete = file.exists() ? file.delete() : true; File file2 = new File(this.f45654f, aVar2.f45641c); boolean renameTo = new File(this.f45654f, "tmp__sapp" + aVar2.f45641c).renameTo(file2); boolean a15 = a(aVar2, file2); if (delete && renameTo && a15) { z15 = true; } } if (!z15) { r.d(this.f45652d, "__SP_UPDATE_TencentLoc_COMP_INFO__sapp_", ""); r.a(this.f45654f); f45649a = 2; return; } f45649a = 1; e.a(this.f45652d).a("CPU", "down suc"); } else { a(arrayList); f45649a = 2; } } else { j.a("down load failed"); e.a(this.f45652d).a("CPU", "down failed"); a(arrayList); f45649a = 2; } } } public void b(List<a> list) { this.f45653e = list; if (f45649a != 1) { new Thread(this).start(); } } public void run() { d.a(this.f45652d).b("updatelock_sapp"); a(); e.a(this.f45652d).d(); d.a(this.f45652d).c("updatelock_sapp"); } public final void a(List<a> list) { Iterator<a> it = list.iterator(); while (it.hasNext()) { String str = this.f45654f; File file = new File(str, "tmp__sapp" + it.next().f45641c); if (file.exists() && file.isFile()) { file.delete(); } } } public final boolean a(a aVar) { byte[] b15; Throwable th5; BufferedOutputStream bufferedOutputStream; Exception e15; try { StringBuilder sb5 = new StringBuilder(); sb5.append("https://maplbs-40171.sh.gfp.tencent-cloud.com/Index/"); sb5.append(aVar.f45643e); String sb6 = sb5.toString(); j.a("start down load:" + aVar.f45643e); BufferedOutputStream bufferedOutputStream2 = null; int i15 = 0; while (true) { int i16 = i15 + 1; if (i15 >= 3) { break; } byte[] a15 = p.a(sb6); if (!(a15 == null || (b15 = r.b(m.a(a15, "sE0zy%DVqLnXA$hmNZ8NBwcg7FDrvi!q"))) == null)) { String str = this.f45654f; File file = new File(str, "tmp__sapp" + aVar.f45641c); try { bufferedOutputStream = new BufferedOutputStream(new FileOutputStream(file, false), 1024); try { bufferedOutputStream.write(b15); if (a(aVar, file)) { StringBuilder sb7 = new StringBuilder(); sb7.append("down load available:"); sb7.append(aVar.f45643e); j.a(sb7.toString()); e a16 = e.a(this.f45652d); a16.a("CPU", "sud:" + aVar.f45643e); try { bufferedOutputStream.close(); return true; } catch (Exception unused) { return true; } } else { j.a("down load unavailable:" + aVar.f45643e); e a17 = e.a(this.f45652d); a17.a("CPU", "failed:" + aVar.f45643e); if (file.exists() && file.isFile()) { file.delete(); } try { bufferedOutputStream.close(); } catch (Exception unused2) { } bufferedOutputStream2 = bufferedOutputStream; } } catch (Exception e16) { e15 = e16; try { if (file.exists() && file.isFile()) { file.delete(); } e a18 = e.a(this.f45652d); a18.a("CPU", "failed:" + e15.toString()); bufferedOutputStream.close(); bufferedOutputStream2 = bufferedOutputStream; r.a((long) FocusMeteringAction.DEFAULT_AUTOCANCEL_DURATION); i15 = i16; } catch (Throwable th6) { th5 = th6; bufferedOutputStream2 = bufferedOutputStream; try { bufferedOutputStream2.close(); } catch (Exception unused3) { } throw th5; } } } catch (Exception e17) { bufferedOutputStream = bufferedOutputStream2; e15 = e17; file.delete(); e a182 = e.a(this.f45652d); a182.a("CPU", "failed:" + e15.toString()); bufferedOutputStream.close(); bufferedOutputStream2 = bufferedOutputStream; r.a((long) FocusMeteringAction.DEFAULT_AUTOCANCEL_DURATION); i15 = i16; } catch (Throwable th7) { th5 = th7; bufferedOutputStream2.close(); throw th5; } } r.a((long) FocusMeteringAction.DEFAULT_AUTOCANCEL_DURATION); i15 = i16; } } catch (Throwable unused4) { } return false; } public final boolean a(a aVar, File file) { if (file != null && file.exists()) { return aVar.f45642d == ((int) file.length()) && aVar.f45643e.equals(r.a(file)); } } }