package e.w.c.e.f.c.b; import android.content.SharedPreferences; import android.os.Handler; import android.os.SystemClock; import android.text.TextUtils; import androidx.work.WorkRequest; import com.android.volley.toolbox.ImageRequest; import com.tencent.raft.codegenmeta.utils.Constants; import com.tencent.raft.measure.report.ATTAReporter; import e.w.c.e.b.l; import e.w.c.e.f.i; import e.w.c.e.f.j; import java.net.InetAddress; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public class d implements e.w.c.e.f.e, Runnable { /* renamed from: k reason: collision with root package name */ public static volatile d f11895k = null; /* renamed from: l reason: collision with root package name */ public static int f11896l = -1; public Map<String, e> b = new HashMap(); public e.w.c.e.f.d c; public boolean d = false; /* renamed from: e reason: collision with root package name */ public boolean f11897e = false; /* renamed from: f reason: collision with root package name */ public Handler f11898f; /* renamed from: g reason: collision with root package name */ public Map<String, c> f11899g = new ConcurrentHashMap(); /* renamed from: h reason: collision with root package name */ public Runnable f11900h = new a(); /* renamed from: i reason: collision with root package name */ public Runnable f11901i = new b(); /* renamed from: j reason: collision with root package name */ public Runnable f11902j = new c(); public class a implements Runnable { public a() { } public final void run() { int i2; Throwable th; d dVar = d.this; if (!dVar.d) { dVar.d = true; long elapsedRealtime = SystemClock.elapsedRealtime(); try { b bVar = new b(); for (c cVar : d.this.f11899g.values()) { cVar.c(bVar); } byte[] a2 = bVar.a(); if (e.w.c.e.h.d.g(a2)) { e c = d.c(d.this, e.w.c.e.b.e.f11747f); c.f11903a = SystemClock.elapsedRealtime(); c.b = 0; d.f(d.this); d.this.d = false; } new String(a2); e.w.c.e.d.a.c a3 = e.w.c.e.d.a.c.a("https://yun-hl.3g.qq.com/halleycloud", null, a2, 15000, e.w.c.e.h.d.k(), i.e().f()); a3.f11805s = Constants.Raft.PLATFORM; e.w.c.e.d.a.f c2 = a3.c(); i2 = c2.f11809a; try { int i3 = c2.c; if (i2 == 0 && i3 == 200) { i2 = d.a(d.this, c2); } a3.f11792j = SystemClock.elapsedRealtime() - elapsedRealtime; a3.b(false); } catch (Throwable th2) { th = th2; try { th.printStackTrace(); e c3 = d.c(d.this, e.w.c.e.b.e.f11747f); c3.f11903a = SystemClock.elapsedRealtime(); c3.b = i2; d.f(d.this); d.this.d = false; } catch (Throwable th3) { e c4 = d.c(d.this, e.w.c.e.b.e.f11747f); c4.f11903a = SystemClock.elapsedRealtime(); c4.b = i2; d.f(d.this); d.this.d = false; throw th3; } } e c32 = d.c(d.this, e.w.c.e.b.e.f11747f); c32.f11903a = SystemClock.elapsedRealtime(); c32.b = i2; d.f(d.this); d.this.d = false; } catch (Throwable th4) { th = th4; i2 = 0; th.printStackTrace(); e c322 = d.c(d.this, e.w.c.e.b.e.f11747f); c322.f11903a = SystemClock.elapsedRealtime(); c322.b = i2; d.f(d.this); d.this.d = false; } } } } public class b implements Runnable { public b() { } public final void run() { String str; int i2; try { e.w.c.e.b.e.d(); e c = d.c(d.this, e.w.c.e.b.e.f11747f); long elapsedRealtime = SystemClock.elapsedRealtime(); int i3 = c.b; if (i3 == 0) { str = "http_platform_update_interval_succ"; } else { if (i3 != -4) { if (i3 != -3) { str = "http_platform_update_interval_fail"; } } str = "http_platform_update_interval_nonet"; } if (i3 == 0) { i2 = 1800000; } else { if (i3 != -4) { if (i3 != -3) { i2 = ATTAReporter.TIMEOUT; } } i2 = 60000; } int c2 = e.v.a.c(str, 60000, 43200000, i2); long j2 = c.f11903a; if (elapsedRealtime - j2 > ((long) c2) || elapsedRealtime < j2) { d.f11896l = 2; if (!d.this.d) { e.w.c.e.b.f.a().f11754a.execute(d.this.f11900h); } } } catch (Throwable th) { th.printStackTrace(); } } } public class c implements Runnable { public c() { } public final void run() { d.this.g(); d.this.f11897e = false; } } /* renamed from: e.w.c.e.f.c.b.d$d reason: collision with other inner class name */ public class RunnableC0296d implements Runnable { public RunnableC0296d(d dVar) { } public final void run() { int c = e.v.a.c("detect_obtain_ip_type_interval", 0, ImageRequest.DEFAULT_IMAGE_TIMEOUT_MS, 24); "ready to obtain ip type report interval:".concat(String.valueOf(c)); if (c > 0) { SharedPreferences a2 = j.a(false); long j2 = a2 != null ? a2.getLong("next_detect_report_time", 0) : -1; long j3 = (long) (c * 60 * 60 * ImageRequest.DEFAULT_IMAGE_TIMEOUT_MS); if (j2 != 0 && System.currentTimeMillis() > j2) { j.d("next_detect_report_time", System.currentTimeMillis() + j3); HashMap hashMap = new HashMap(); StringBuilder sb = new StringBuilder(); sb.append((int) e.w.c.e.b.e.c); hashMap.put("D9", sb.toString()); hashMap.put("D40", e.w.c.e.c.f11780k); String c2 = e.w.c.e.b.e.c(); if (!TextUtils.isEmpty(c2)) { hashMap.put("D39", c2); } l.F("HLNotRealDetectEvent", true, hashMap, false); } else if (j2 == 0) { j.d("next_detect_report_time", System.currentTimeMillis() + j3); } } } } public class e { /* renamed from: a reason: collision with root package name */ public long f11903a; public int b; public e(d dVar, byte b2) { } } public final class f extends e.w.c.e.f.c.a.a { public f(String str) { super(str); } } public final class g implements Runnable { public final /* synthetic */ String b; public final /* synthetic */ byte[] c; public final /* synthetic */ h d; public g(h hVar, String str, byte[] bArr) { this.d = hVar; this.b = str; this.c = bArr; } public final void run() { String str = this.b; byte[] bArr = this.c; if (e.w.c.e.h.d.f(str) || e.w.c.e.h.d.g(bArr)) { e.w.c.e.b.e.d(); str = e.w.c.e.b.e.f11747f; bArr = this.d.b.b(str); } d.e().c.a(str, bArr, null); } } public final class h extends c { public f b = new f("HttpSchedulerHandler"); @Override // e.w.c.e.f.b, e.w.c.e.f.c.b.c public final void a() { e.w.c.e.c.f11783n.post(new g(this, null, null)); } /* JADX WARNING: Can't wrap try/catch for region: R(3:24|25|26) */ /* JADX WARNING: Code restructure failed: missing block: B:25:?, code lost: r1 = new org.json.JSONObject(); r2 = new java.lang.StringBuilder(); r2.append(e.w.c.e.c.f11777h); r1.put(r2.toString(), new org.json.JSONObject()); r12.f11894a.put("directScheduleCodes", r1); */ /* JADX WARNING: Code restructure failed: missing block: B:26:0x00ba, code lost: return; */ /* JADX WARNING: Code restructure failed: missing block: B:27:0x00bb, code lost: r12 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:28:0x00bc, code lost: r12.printStackTrace(); */ /* JADX WARNING: Code restructure failed: missing block: B:29:0x00bf, code lost: return; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:24:0x009a */ @Override // e.w.c.e.f.c.b.c public final void c(b bVar) { JSONObject jSONObject; String str; JSONObject jSONObject2 = new JSONObject(); f fVar = this.b; e.w.c.e.b.e.d(); byte[] b2 = fVar.b(e.w.c.e.b.e.f11747f); JSONObject jSONObject3 = !e.w.c.e.h.d.g(b2) ? new JSONObject(new String(b2)) : null; if (jSONObject3 != null) { JSONObject optJSONObject = jSONObject3.optJSONObject("resultMap"); if (optJSONObject != null) { Iterator<String> keys = optJSONObject.keys(); while (keys.hasNext()) { String next = keys.next(); JSONArray optJSONArray = optJSONObject.optJSONArray(next); if (optJSONArray != null) { JSONObject jSONObject4 = new JSONObject(); for (int i2 = 0; i2 < optJSONArray.length(); i2++) { JSONObject jSONObject5 = optJSONArray.getJSONObject(i2); jSONObject4.put(jSONObject5.optString("unit"), jSONObject5.optString("schedulecode")); } jSONObject2.put(next, jSONObject4); } } bVar.f11894a.put("directScheduleCodes", jSONObject2); } StringBuilder sb = new StringBuilder(); sb.append(e.w.c.e.c.f11777h); str = sb.toString(); jSONObject = new JSONObject(); } else { StringBuilder sb2 = new StringBuilder(); sb2.append(e.w.c.e.c.f11777h); str = sb2.toString(); jSONObject = new JSONObject(); } jSONObject2.put(str, jSONObject); bVar.f11894a.put("directScheduleCodes", jSONObject2); } @Override // e.w.c.e.f.c.b.c public final void d(JSONObject jSONObject) { try { JSONObject optJSONObject = jSONObject.optJSONObject("AccessScheduleRsp"); if (optJSONObject != null) { String jSONObject2 = optJSONObject.toString(); if (!e.w.c.e.h.d.f(jSONObject2)) { byte[] bytes = jSONObject2.getBytes(); if (!e.w.c.e.h.d.g(bytes)) { String str = e.w.c.e.b.e.f11747f; this.b.a(str, bytes); e.w.c.e.c.f11783n.post(new g(this, str, bytes)); } } } } catch (Throwable th) { th.printStackTrace(); } } } public static int a(d dVar, e.w.c.e.d.a.f fVar) { Throwable th; String str; Objects.requireNonNull(dVar); String str2 = ""; if (e.w.c.e.h.d.g(fVar.d)) { return -320; } try { str = new String(fVar.d); try { JSONObject jSONObject = new JSONObject(str); "HttpPlatform rspData:".concat(str); e.w.c.e.b.e.d(); for (c cVar : dVar.f11899g.values()) { cVar.d(jSONObject); } return 0; } catch (Throwable th2) { th = th2; th.printStackTrace(); try { str2 = InetAddress.getByName("yun-hl.3g.qq.com").getHostAddress(); } catch (Throwable th3) { th3.printStackTrace(); } StringBuilder d0 = e.d.a.a.a.d0(str2, "/"); d0.append(str.substring(0, Math.min(str.length(), 20))); fVar.b = d0.toString(); return -321; } } catch (Throwable th4) { th = th4; str = str2; th.printStackTrace(); str2 = InetAddress.getByName("yun-hl.3g.qq.com").getHostAddress(); StringBuilder d02 = e.d.a.a.a.d0(str2, "/"); d02.append(str.substring(0, Math.min(str.length(), 20))); fVar.b = d02.toString(); return -321; } } public static e c(d dVar, String str) { JSONObject optJSONObject; if (dVar.b.isEmpty()) { try { String f2 = j.f("apnrecords", "", true); if (!f2.isEmpty()) { JSONObject jSONObject = new JSONObject(f2); Iterator<String> keys = jSONObject.keys(); while (keys.hasNext()) { String next = keys.next(); if (!TextUtils.isEmpty(next) && (optJSONObject = jSONObject.optJSONObject(next)) != null) { e eVar = new e(dVar, (byte) 0); eVar.b = optJSONObject.optInt("lastCode"); eVar.f11903a = optJSONObject.optLong("lastReqTime"); dVar.b.put(next, eVar); } } } } catch (Exception e2) { e2.printStackTrace(); } } e eVar2 = dVar.b.get(str); if (eVar2 != null) { return eVar2; } e eVar3 = new e(dVar, (byte) 0); dVar.b.put(str, eVar3); return eVar3; } public static d e() { if (f11895k == null) { synchronized (d.class) { if (f11895k == null) { f11895k = new d(); } } } return f11895k; } public static /* synthetic */ void f(d dVar) { if (!dVar.b.isEmpty()) { JSONObject jSONObject = new JSONObject(); for (Map.Entry<String, e> entry : dVar.b.entrySet()) { e value = entry.getValue(); JSONObject jSONObject2 = new JSONObject(); try { jSONObject2.put("lastCode", value.b); jSONObject2.put("lastReqTime", value.f11903a); jSONObject.put(entry.getKey(), jSONObject2); } catch (JSONException e2) { e2.printStackTrace(); } } j.e("apnrecords", jSONObject.toString(), true); } } @Override // e.w.c.e.f.b public final void a() { this.f11899g.get("accessscheduler").a(); } @Override // e.w.c.e.f.b public final void b() { this.f11899g.get("settings").b(); } @Override // e.w.c.e.f.e public final void b(e.w.c.e.f.d dVar) { this.c = dVar; this.f11899g.put("state", new e.w.c.e.f.c.b.f.a()); this.f11899g.put("accessscheduler", new h()); this.f11899g.put("settings", new e.w.c.e.f.c.b.e.a()); this.f11899g.put("detector", new e.w.c.e.f.c.b.a.a()); } @Override // e.w.c.e.f.e public final void d() { Handler handler = e.w.c.e.c.f11783n; this.f11898f = handler; handler.post(this); this.f11898f.postDelayed(new RunnableC0296d(this), WorkRequest.MIN_BACKOFF_MILLIS); this.c.c(); } public final void g() { this.f11898f.removeCallbacks(this.f11901i); this.f11898f.post(this.f11901i); } public void run() { if (e.v.a.c("http_platform_start_update_on", 0, 1, 1) == 1) { f11896l = 1; g(); } } }