package com.tencent.open.b; import a1.a; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.HandlerThread; import android.os.Message; import android.os.SystemClock; import android.text.TextUtils; import com.meizu.cloud.pushsdk.constants.PushConstants; import com.tencent.open.log.SLog; import com.tencent.open.utils.HttpUtils; import com.tencent.open.utils.g; import com.tencent.open.utils.i; import com.tencent.open.utils.l; import com.tencent.open.utils.m; import java.io.IOException; import java.io.Serializable; import java.net.SocketTimeoutException; import java.security.SecureRandom; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Random; import java.util.TimeZone; import java.util.concurrent.Executor; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import p4.d; import p4.f; /* compiled from: ProGuard */ public class h { /* renamed from: a reason: collision with root package name */ public static h f29369a; public Random b = new SecureRandom(); /* renamed from: c reason: collision with root package name */ public List<Serializable> f29370c = a.h(); public List<Serializable> d = a.h(); public HandlerThread e; public Handler f; /* renamed from: g reason: collision with root package name */ public Executor f29371g = l.b(); /* renamed from: h reason: collision with root package name */ public Executor f29372h = l.b(); private h() { if (this.e == null) { d dVar = new d("opensdk.report.handlerthread", 10, "com.tencent.open.b.h"); this.e = dVar; f.b(dVar, "com.tencent.open.b.h"); dVar.start(); } if (this.e.isAlive() && this.e.getLooper() != null) { this.f = new Handler(this.e.getLooper()) { /* class com.tencent.open.b.h.AnonymousClass1 */ public void handleMessage(Message message) { int i = message.what; if (i == 1000) { h.this.b(); } else if (i == 1001) { h.this.d(); } super.handleMessage(message); } }; } } public static synchronized h a() { h hVar; synchronized (h.class) { if (f29369a == null) { f29369a = new h(); } hVar = f29369a; } return hVar; } public void b() { } public Map<String, String> c() { List<Serializable> b2 = g.b("report_via"); if (b2 != null) { this.d.addAll(b2); } StringBuilder h12 = a.f.h("-->prepareViaData, mViaList size: "); h12.append(this.d.size()); SLog.d("openSDK_LOG.ReportManager", h12.toString()); if (this.d.size() == 0) { return null; } JSONArray jSONArray = new JSONArray(); Iterator<Serializable> it2 = this.d.iterator(); while (it2.hasNext()) { JSONObject jSONObject = new JSONObject(); c cVar = (c) it2.next(); for (String str : cVar.f29366a.keySet()) { try { String str2 = cVar.f29366a.get(str); if (str2 == null) { str2 = ""; } jSONObject.put(str, str2); } catch (JSONException e6) { SLog.e("openSDK_LOG.ReportManager", "-->prepareViaData, put bundle to json array exception", e6); } } jSONArray.put(jSONObject); } StringBuilder h13 = a.f.h("-->prepareViaData, JSONArray array: "); h13.append(jSONArray.toString()); SLog.v("openSDK_LOG.ReportManager", h13.toString()); JSONObject jSONObject2 = new JSONObject(); try { jSONObject2.put("data", jSONArray); HashMap hashMap = new HashMap(); hashMap.put("data", jSONObject2.toString()); return hashMap; } catch (JSONException e12) { SLog.e("openSDK_LOG.ReportManager", "-->prepareViaData, put bundle to json array exception", e12); return null; } } public void d() { if (m.b(g.a())) { this.f29371g.execute(new Runnable() { /* class com.tencent.open.b.h.AnonymousClass3 */ /* JADX WARNING: Code restructure failed: missing block: B:19:0x0082, code lost: r0 = -4; */ /* JADX WARNING: Code restructure failed: missing block: B:26:0x0096, code lost: r0 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:27:0x0098, code lost: r11 = 0; r8 = -6; r0 = r4; r9 = 0; */ /* JADX WARNING: Code restructure failed: missing block: B:57:0x00bd, code lost: continue; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Removed duplicated region for block: B:26:0x0096 A[ExcHandler: IOException (e java.io.IOException), Splitter:B:11:0x0068] */ /* JADX WARNING: Removed duplicated region for block: B:28:? A[ExcHandler: Exception (unused java.lang.Exception), SYNTHETIC, Splitter:B:8:0x0032] */ /* JADX WARNING: Removed duplicated region for block: B:39:? A[ExcHandler: SocketTimeoutException (unused java.net.SocketTimeoutException), SYNTHETIC, Splitter:B:11:0x0068] */ /* JADX WARNING: Removed duplicated region for block: B:55:0x00bf A[SYNTHETIC] */ public void run() { long j; long j12; long j13; boolean z; long j14; long j15; int i; try { Map<String, String> c5 = h.this.c(); if (c5 != null) { SLog.d("openSDK_LOG.ReportManager", "-->doReportVia, params: " + c5.toString()); int a5 = f.a(); long elapsedRealtime = SystemClock.elapsedRealtime(); int i3 = 0; int i12 = 0; while (true) { int i13 = i3 + 1; try { com.tencent.open.a.g b = com.tencent.open.a.f.a().b("https://appsupport.qq.com/cgi-bin/appstage/mstats_batch_report", c5); SLog.i("openSDK_LOG.ReportManager", "-->reportVia: statusCode " + b.d()); JSONObject d = m.d(b.a()); long c12 = (long) b.c(); i = i13; j15 = (long) b.b(); if (b.d() == 200) { int i14 = d.getInt("ret"); if (i14 != 0 && j15 == 0) { j14 = c12; i3 = i; continue; if (i3 >= a5) { j13 = elapsedRealtime; j = j15; j12 = j14; break; } } else { j13 = elapsedRealtime; j = j15; j12 = c12; z = true; } } else { i12 = b.d(); j13 = elapsedRealtime; j = j15; j12 = c12; break; } } catch (SocketTimeoutException unused) { i = i13; j14 = 0; elapsedRealtime = SystemClock.elapsedRealtime(); i12 = -8; j15 = j14; i3 = i; continue; if (i3 >= a5) { } } catch (JSONException unused2) { i = i13; j14 = 0; j15 = 0; i3 = i; i12 = -4; continue; if (i3 >= a5) { } } catch (IOException e) { IOException e6 = e; i = i13; j14 = 0; i12 = HttpUtils.getErrorCodeFromException(e6); j15 = j14; i3 = i; continue; if (i3 >= a5) { } } catch (Exception unused3) { } } z = false; h.this.a("mapp_apptrace_sdk", j13, j12, j, i12, null, false); if (z) { g.a("report_via"); } else { g.a("report_via", h.this.d); } h.this.d.clear(); SLog.i("openSDK_LOG.ReportManager", "-->doReportVia, uploadSuccess: " + z + " resultCode: " + i12); } } catch (Exception e12) { SLog.e("openSDK_LOG.ReportManager", "-->doReportVia, exception in serial executor.", e12); } } }); } } public void a(final Bundle bundle, String str, final boolean z) { if (bundle != null) { StringBuilder h12 = a.f.h("-->reportVia, bundle: "); h12.append(bundle.toString()); SLog.v("openSDK_LOG.ReportManager", h12.toString()); if (a("report_via", str) || z) { this.f29371g.execute(new Runnable() { /* class com.tencent.open.b.h.AnonymousClass2 */ public void run() { try { Bundle bundle = new Bundle(); bundle.putString("uin", "1000"); bundle.putString("platform", "1"); bundle.putString("os_ver", Build.VERSION.RELEASE); bundle.putString("position", ""); bundle.putString("network", a.a(g.a())); bundle.putString("language", d.a()); bundle.putString("resolution", d.a(g.a())); bundle.putString("apn", a.b(g.a())); bundle.putString("model_name", com.tencent.open.utils.f.a().c(g.a())); bundle.putString("timezone", TimeZone.getDefault().getID()); bundle.putString("sdk_ver", "3.5.13.lite"); bundle.putString("qz_ver", m.d(g.a(), "com.qzone")); bundle.putString("qq_ver", m.c(g.a(), "com.tencent.mobileqq")); bundle.putString("qua", m.e(g.a(), g.b())); bundle.putString("packagename", g.b()); bundle.putString("app_ver", m.d(g.a(), g.b())); Bundle bundle2 = bundle; if (bundle2 != null) { bundle.putAll(bundle2); } h.this.d.add(new c(bundle)); int size = h.this.d.size(); int a5 = i.a(g.a(), (String) null).a("Agent_ReportTimeInterval"); if (a5 == 0) { a5 = 10000; } if (!h.this.a("report_via", size)) { if (!z) { if (!h.this.f.hasMessages(PushConstants.PUSHSERVICE_INFO_SEND_MESSAGE_BY_BROADCAST)) { Message obtain = Message.obtain(); obtain.what = PushConstants.PUSHSERVICE_INFO_SEND_MESSAGE_BY_BROADCAST; h.this.f.sendMessageDelayed(obtain, (long) a5); return; } return; } } h.this.d(); h.this.f.removeMessages(PushConstants.PUSHSERVICE_INFO_SEND_MESSAGE_BY_BROADCAST); } catch (Exception e) { SLog.e("openSDK_LOG.ReportManager", "--> reporVia, exception in sub thread.", e); } } }); } } } public void a(String str, long j, long j12, long j13, int i) { a(str, j, j12, j13, i, "", false); } public void a(String str, long j, long j12, long j13, int i, String str2, boolean z) { StringBuilder sb2 = new StringBuilder(); sb2.append("-->reportCgi, command: "); sb2.append(str); sb2.append(" | startTime: "); sb2.append(j); h.a.v(sb2, " | reqSize:", j12, " | rspSize: "); sb2.append(j13); sb2.append(" | responseCode: "); sb2.append(i); sb2.append(" | detail: "); sb2.append(str2); SLog.v("openSDK_LOG.ReportManager", sb2.toString()); } public boolean a(String str, String str2) { int i; SLog.d("openSDK_LOG.ReportManager", "-->availableFrequency, report: " + str + " | ext: " + str2); boolean z = false; if (TextUtils.isEmpty(str)) { return false; } int i3 = 100; if (str.equals("report_cgi")) { try { i = a(Integer.parseInt(str2)); if (this.b.nextInt(100) < i) { z = true; } } catch (Exception unused) { return false; } } else { if (str.equals("report_via")) { i = f.a(str2); if (this.b.nextInt(100) < i) { i3 = i; z = true; } } SLog.d("openSDK_LOG.ReportManager", "-->availableFrequency, result: " + z + " | frequency: " + i3); return z; } i3 = i; SLog.d("openSDK_LOG.ReportManager", "-->availableFrequency, result: " + z + " | frequency: " + i3); return z; } /* JADX WARNING: Code restructure failed: missing block: B:3:0x0019, code lost: if (r0 == 0) goto L_0x0038; */ /* JADX WARNING: Code restructure failed: missing block: B:8:0x0034, code lost: if (r0 == 0) goto L_0x0038; */ /* JADX WARNING: Removed duplicated region for block: B:12:0x0060 A[RETURN] */ /* JADX WARNING: Removed duplicated region for block: B:13:0x0062 A[RETURN] */ public boolean a(String str, int i) { int a5; int i3 = 5; if (str.equals("report_cgi")) { a5 = i.a(g.a(), (String) null).a("Common_CGIReportMaxcount"); } else { if (str.equals("report_via")) { a5 = i.a(g.a(), (String) null).a("Agent_ReportBatchCount"); } else { i3 = 0; } SLog.d("openSDK_LOG.ReportManager", "-->availableCount, report: " + str + " | dataSize: " + i + " | maxcount: " + i3); if (i < i3) { return true; } return false; } i3 = a5; SLog.d("openSDK_LOG.ReportManager", "-->availableCount, report: " + str + " | dataSize: " + i + " | maxcount: " + i3); if (i < i3) { } } public int a(int i) { if (i == 0) { int a5 = i.a(g.a(), (String) null).a("Common_CGIReportFrequencySuccess"); if (a5 == 0) { return 10; } return a5; } int a12 = i.a(g.a(), (String) null).a("Common_CGIReportFrequencyFailed"); if (a12 == 0) { return 100; } return a12; } public void a(final String str, final Map<String, String> map) { if (m.b(g.a())) { l.b(new Runnable() { /* class com.tencent.open.b.h.AnonymousClass4 */ public void run() { int i = 0; try { int a5 = f.a(); if (a5 == 0) { a5 = 3; } SLog.d("openSDK_LOG.ReportManager", "-->httpRequest, retryCount: " + a5); do { i++; try { int d = com.tencent.open.a.f.a().a(str, map).d(); SLog.i("openSDK_LOG.ReportManager", "-->httpRequest, statusCode: " + d); return; } catch (SocketTimeoutException e) { SLog.e("openSDK_LOG.ReportManager", "-->ReportCenter httpRequest SocketTimeoutException:", e); if (i >= a5) { } } catch (Exception e6) { SLog.e("openSDK_LOG.ReportManager", "-->ReportCenter httpRequest Exception:", e6); return; } } while (i >= a5); } catch (Exception e12) { SLog.e("openSDK_LOG.ReportManager", "-->httpRequest, exception in serial executor:", e12); } } }); } } }