package cn.jiguang.au; import android.content.Context; import android.os.Bundle; import android.os.SystemClock; import android.text.TextUtils; import cn.jiguang.aq.c; import cn.jiguang.aw.e; import cn.jiguang.aw.f; import cn.jiguang.f.g; import cn.jiguang.f.h; import cn.jiguang.g.a; import cn.jiguang.g.b; import cn.jiguang.internal.JConstants; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.util.Iterator; import java.util.LinkedList; import java.util.Set; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import org.json.JSONArray; public class k { private static k c; Context a; public final LinkedList<m> b; private int d = 0; private byte[] e; private int f; public k(Context context) { this.a = context; this.b = m.a((String) b.a(context, a.G())); } public static k a(Context context) { if (c == null) { synchronized (k.class) { if (c == null) { c = new k(context); } } } return c; } private n a(int i) { long j; double d2; double d3; String e2 = cn.jiguang.d.a.e(this.a); long f2 = cn.jiguang.d.a.f(this.a); String b2 = g.b(this.a); long currentTimeMillis = System.currentTimeMillis(); Object a2 = e.a(this.a, "get_loc_info", null); double d4 = 200.0d; if (a2 instanceof Bundle) { try { Bundle bundle = (Bundle) a2; d3 = bundle.getDouble("lat"); try { d4 = bundle.getDouble("lot"); currentTimeMillis = bundle.getLong("time"); } catch (Throwable unused) { } } catch (Throwable unused2) { d3 = 200.0d; } j = currentTimeMillis; d4 = d3; d2 = d4; } else { j = currentTimeMillis; d2 = 200.0d; } return new n(i, e2, cn.jiguang.a.a.b, f2, b2, d4, d2, j); } private synchronized void a(m mVar) { this.b.add(mVar); c.c("SisConnContext", "addSisReportInfo:" + mVar.a().toString()); while (this.b.size() > 30) { this.b.removeFirst(); } JSONArray jSONArray = new JSONArray(); Iterator<m> it = this.b.iterator(); while (it.hasNext()) { jSONArray.put(it.next().a()); } b.a(this.a, a.G().a(jSONArray.toString())); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private boolean a(InetAddress inetAddress, int i, DatagramSocket datagramSocket, byte[] bArr) { try { return h.c(c.a(c.a(datagramSocket, new DatagramPacket(bArr, bArr.length, inetAddress, i)))) == 0; } catch (Throwable th) { c.i("SisConnContext", "report failed : " + th); return false; } } public l a(long j) { FutureTask futureTask = new FutureTask(new i(this)); this.d = 0; cn.jiguang.as.b.d(futureTask, new int[0]); if (j < 10) { j = 10; } try { return (l) futureTask.get(j, TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException unused) { return null; } } public void a(int i, String str, int i2, long j, long j2, int i3) { if (g.a(str, i2)) { m mVar = new m(); mVar.a = cn.jiguang.d.a.e(this.a); mVar.b = i; mVar.c = new g(str, i2); mVar.e = j; mVar.f = j2; mVar.k = i3; mVar.g = g.a(this.a); mVar.d = cn.jiguang.d.a.f(this.a); mVar.h = 200.0d; mVar.i = 200.0d; mVar.j = System.currentTimeMillis(); Object a2 = e.a(this.a, "get_loc_info", null); if (a2 instanceof Bundle) { try { Bundle bundle = (Bundle) a2; mVar.h = bundle.getDouble("lat"); mVar.i = bundle.getDouble("lot"); mVar.j = bundle.getLong("time"); } catch (Throwable unused) { } } a(mVar); } } public void a(final g gVar) { if (((Boolean) b.a(this.a, a.L())).booleanValue()) { if (h.a(((Long) b.a(this.a, a.N())).longValue(), JConstants.HOUR)) { cn.jiguang.as.b.b(new cn.jiguang.bd.b("SisConnContext#asyncSisReportIfNeed") { /* class cn.jiguang.au.k.AnonymousClass1 */ /* JADX WARNING: Removed duplicated region for block: B:28:0x0113 A[SYNTHETIC, Splitter:B:28:0x0113] */ /* JADX WARNING: Removed duplicated region for block: B:35:0x0136 A[SYNTHETIC, Splitter:B:35:0x0136] */ /* JADX WARNING: Removed duplicated region for block: B:43:? A[RETURN, SYNTHETIC] */ @Override // cn.jiguang.bd.b public void a() { DatagramSocket datagramSocket; Throwable th; StringBuilder sb; String str; Throwable th2; Throwable th3; try { datagramSocket = new DatagramSocket(); try { String str2 = (String) b.a(k.this.a, a.G()); if (TextUtils.isEmpty(str2)) { c.c("SisConnContext", "reportInfo is Empty, quit report"); try { datagramSocket.close(); return; } catch (Throwable th4) { c.g("SisConnContext", "sisReport ,close udpsocket error:" + th4.getMessage()); return; } } else { byte[] a2 = c.a("DG", str2); c.c("SisConnContext", "sis report data(" + a2.length + ") at " + gVar.c + ":" + gVar.b); if (k.this.a(gVar.c, gVar.b, datagramSocket, a2)) { c.c("SisConnContext", "report succeed : " + str2); b.a(k.this.a, a.N().a(Long.valueOf(SystemClock.elapsedRealtime()))); b.a(k.this.a, a.G().a((String) null)); } else { c.g("SisConnContext", "report failed" + str2); } try { datagramSocket.close(); return; } catch (Throwable th5) { th2 = th5; str = "SisConnContext"; sb = new StringBuilder(); } } } catch (Throwable th6) { th3 = th6; try { c.g("SisConnContext", "sisReport failed, error:" + th3); if (datagramSocket == null) { } } catch (Throwable th7) { th = th7; if (datagramSocket != null) { } throw th; } } sb.append("sisReport ,close udpsocket error:"); sb.append(th2.getMessage()); c.g(str, sb.toString()); } catch (Throwable th8) { datagramSocket = null; th = th8; if (datagramSocket != null) { try { datagramSocket.close(); } catch (Throwable th9) { c.g("SisConnContext", "sisReport ,close udpsocket error:" + th9.getMessage()); } } throw th; } } }, new int[0]); } else { c.c("SisConnContext", "sis report: not yet"); } } } public void a(boolean z) { this.d = (z ? 1 : 2) | this.d; cn.jiguang.ax.b.a().a(this.a, this.d); } public boolean a() { return false; } public byte[] a(Set<String> set) { int a2 = g.a(this.a); if (this.e == null || a2 != this.f) { this.f = a2; try { this.e = c.a("UG", a(a2).a(set).toString()); } catch (Exception e2) { throw new f(2, "Failed to package data - " + e2); } } return this.e; } public int b() { if (this.d == 0) { this.d = cn.jiguang.ax.b.a().a(this.a); } int b2 = cn.jiguang.ax.b.a().b(this.d); c.c("SisConnContext", "ipvsupport=" + this.d + ", prefer=" + b2); return b2; } }