package com.tencent.open.b; 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.alibaba.sdk.android.oss.common.RequestParameters; import com.iflytek.cloud.SpeechUtility; import com.tencent.connect.common.Constants; import com.tencent.open.a.f; 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 com.umeng.analytics.pro.ak; import java.io.IOException; import java.io.Serializable; import java.net.SocketTimeoutException; import java.security.SecureRandom; import java.util.ArrayList; import java.util.Collections; 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; public class h { /* renamed from: a reason: collision with root package name */ public static h f23608a; /* renamed from: b reason: collision with root package name */ public Random f23609b = new SecureRandom(); public List<Serializable> c = Collections.synchronizedList(new ArrayList()); public List<Serializable> d = Collections.synchronizedList(new ArrayList()); public HandlerThread e = null; public Handler f; public Executor g = l.b(); public Executor h = l.b(); private h() { if (this.e == null) { c03 c03 = new c03("opensdk.report.handlerthread", 10, "com.tencent.open.b.h"); this.e = c03; d03.d(c03, "com.tencent.open.b.h"); c03.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 (f23608a == null) { f23608a = new h(); } hVar = f23608a; } return hVar; } public void b() { } public Map<String, String> c() { List<Serializable> b2 = g.b("report_via"); if (b2 != null) { this.d.addAll(b2); } SLog.d("openSDK_LOG.ReportManager", "-->prepareViaData, mViaList size: " + this.d.size()); 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.f23604a.keySet()) { try { String str2 = cVar.f23604a.get(str); if (str2 == null) { str2 = ""; } jSONObject.put(str, str2); } catch (JSONException e2) { SLog.e("openSDK_LOG.ReportManager", "-->prepareViaData, put bundle to json array exception", e2); } } jSONArray.put(jSONObject); } SLog.v("openSDK_LOG.ReportManager", "-->prepareViaData, JSONArray array: " + jSONArray.toString()); JSONObject jSONObject2 = new JSONObject(); try { jSONObject2.put("data", jSONArray); HashMap hashMap = new HashMap(); hashMap.put("data", jSONObject2.toString()); return hashMap; } catch (JSONException e3) { SLog.e("openSDK_LOG.ReportManager", "-->prepareViaData, put bundle to json array exception", e3); return null; } } public void d() { if (m.b(g.a())) { this.g.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 j2; long j3; boolean z; long j4; long j5; int i; try { Map<String, String> c = h.this.c(); if (c != null) { SLog.d("openSDK_LOG.ReportManager", "-->doReportVia, params: " + c.toString()); int a2 = f.a(); long elapsedRealtime = SystemClock.elapsedRealtime(); int i2 = 0; int i3 = 0; while (true) { int i4 = i2 + 1; try { com.tencent.open.a.g b2 = f.a().b("https://appsupport.qq.com/cgi-bin/appstage/mstats_batch_report", c); SLog.i("openSDK_LOG.ReportManager", "-->reportVia: statusCode " + b2.d()); JSONObject d = m.d(b2.a()); long c2 = (long) b2.c(); i = i4; j5 = (long) b2.b(); if (b2.d() == 200) { int i5 = d.getInt(SpeechUtility.TAG_RESOURCE_RET); if (i5 != 0 && j5 == 0) { j4 = c2; i2 = i; continue; if (i2 >= a2) { j3 = elapsedRealtime; j = j5; j2 = j4; break; } } else { j3 = elapsedRealtime; j = j5; j2 = c2; z = true; } } else { i3 = b2.d(); j3 = elapsedRealtime; j = j5; j2 = c2; break; } } catch (SocketTimeoutException unused) { i = i4; j4 = 0; elapsedRealtime = SystemClock.elapsedRealtime(); i3 = -8; j5 = j4; i2 = i; continue; if (i2 >= a2) { } } catch (JSONException unused2) { i = i4; j4 = 0; j5 = 0; i2 = i; i3 = -4; continue; if (i2 >= a2) { } } catch (IOException e) { IOException e2 = e; i = i4; j4 = 0; i3 = HttpUtils.getErrorCodeFromException(e2); j5 = j4; i2 = i; continue; if (i2 >= a2) { } } catch (Exception unused3) { } } z = false; h.this.a("mapp_apptrace_sdk", j3, j2, j, i3, 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: " + i3); } } catch (Exception e3) { SLog.e("openSDK_LOG.ReportManager", "-->doReportVia, exception in serial executor.", e3); } } }); } } public void a(final Bundle bundle, String str, final boolean z) { if (bundle != null) { SLog.v("openSDK_LOG.ReportManager", "-->reportVia, bundle: " + bundle.toString()); if (a("report_via", str) || z) { this.g.execute(new Runnable() { /* class com.tencent.open.b.h.AnonymousClass2 */ public void run() { try { String k = m.k(d.b(g.a())); String k2 = m.k(d.c(g.a())); String k3 = m.k(d.a()); String k4 = m.k(d.d(g.a())); Bundle bundle = new Bundle(); bundle.putString("uin", Constants.DEFAULT_UIN); bundle.putString("imei", k); bundle.putString("imsi", k2); bundle.putString("android_id", k4); bundle.putString("mac", k3); bundle.putString("platform", "1"); bundle.putString("os_ver", Build.VERSION.RELEASE); bundle.putString(RequestParameters.POSITION, ""); bundle.putString("network", a.a(g.a())); bundle.putString("language", d.b()); bundle.putString("resolution", d.a(g.a())); bundle.putString("apn", a.b(g.a())); bundle.putString(Constants.PARAM_MODEL_NAME, com.tencent.open.utils.f.a().c(g.a())); bundle.putString(ak.M, TimeZone.getDefault().getID()); bundle.putString("sdk_ver", Constants.SDK_VERSION); bundle.putString("qz_ver", m.d(g.a(), "com.qzone")); bundle.putString(Constants.PARAM_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(Constants.PARAM_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 a2 = i.a(g.a(), (String) null).a("Agent_ReportTimeInterval"); if (a2 == 0) { a2 = 10000; } if (!h.this.a("report_via", size)) { if (!z) { if (!h.this.f.hasMessages(1001)) { Message obtain = Message.obtain(); obtain.what = 1001; h.this.f.sendMessageDelayed(obtain, (long) a2); return; } return; } } h.this.d(); h.this.f.removeMessages(1001); } catch (Exception e) { SLog.e("openSDK_LOG.ReportManager", "--> reporVia, exception in sub thread.", e); } } }); } } } public void a(String str, long j, long j2, long j3, int i) { a(str, j, j2, j3, i, "", false); } public void a(String str, long j, long j2, long j3, int i, String str2, boolean z) { SLog.v("openSDK_LOG.ReportManager", "-->reportCgi, command: " + str + " | startTime: " + j + " | reqSize:" + j2 + " | rspSize: " + j3 + " | responseCode: " + i + " | detail: " + str2); } 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 i2 = 100; if (str.equals("report_cgi")) { try { i = a(Integer.parseInt(str2)); if (this.f23609b.nextInt(100) < i) { z = true; } } catch (Exception unused) { return false; } } else { if (str.equals("report_via")) { i = f.a(str2); if (this.f23609b.nextInt(100) < i) { i2 = i; z = true; } } SLog.d("openSDK_LOG.ReportManager", "-->availableFrequency, result: " + z + " | frequency: " + i2); return z; } i2 = i; SLog.d("openSDK_LOG.ReportManager", "-->availableFrequency, result: " + z + " | frequency: " + i2); 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 a2; int i2 = 5; if (str.equals("report_cgi")) { a2 = i.a(g.a(), (String) null).a("Common_CGIReportMaxcount"); } else { if (str.equals("report_via")) { a2 = i.a(g.a(), (String) null).a("Agent_ReportBatchCount"); } else { i2 = 0; } SLog.d("openSDK_LOG.ReportManager", "-->availableCount, report: " + str + " | dataSize: " + i + " | maxcount: " + i2); if (i < i2) { return true; } return false; } i2 = a2; SLog.d("openSDK_LOG.ReportManager", "-->availableCount, report: " + str + " | dataSize: " + i + " | maxcount: " + i2); if (i < i2) { } } public int a(int i) { if (i == 0) { int a2 = i.a(g.a(), (String) null).a("Common_CGIReportFrequencySuccess"); if (a2 == 0) { return 10; } return a2; } int a3 = i.a(g.a(), (String) null).a("Common_CGIReportFrequencyFailed"); if (a3 == 0) { return 100; } return a3; } 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 a2 = f.a(); if (a2 == 0) { a2 = 3; } SLog.d("openSDK_LOG.ReportManager", "-->httpRequest, retryCount: " + a2); do { i++; try { int d = 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 >= a2) { } } catch (Exception e2) { SLog.e("openSDK_LOG.ReportManager", "-->ReportCenter httpRequest Exception:", e2); return; } } while (i >= a2); } catch (Exception e3) { SLog.e("openSDK_LOG.ReportManager", "-->httpRequest, exception in serial executor:", e3); } } }); } } }