package c.t.m.g; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.os.SystemClock; import android.text.TextUtils; import android.util.Pair; import com.tencent.map.geolocation.util.SoUtils; import java.io.FileNotFoundException; import java.io.IOException; import java.util.Iterator; import java.util.Locale; import java.util.concurrent.LinkedBlockingQueue; /* compiled from: TML */ public class da { private static da j; private final LinkedBlockingQueue<a> a = new LinkedBlockingQueue<>(3); private final cf b; /* renamed from: c reason: collision with root package name */ private long f119c; private long d; private long e; private long f; private volatile boolean g; private boolean h; private volatile Handler i; public static da a(cf cfVar) { if (j == null) { synchronized (da.class) { if (j == null) { j = new da(cfVar); } } } return j; } private da(cf cfVar) { this.b = cfVar; } public void a(String str) { try { if (!TextUtils.isEmpty(str)) { byte[] b2 = ek.b(str.getBytes("UTF-8")); if (ee.a) { ee.a("hh", "postWifisRequest fun_o"); } SoUtils.fun_o(b2, 2); if (ee.a) { ee.a("hh", "postWifisRequest fun_d"); } a aVar = new a(3, b2, "https://ue.indoorloc.map.qq.com/?wl", null); aVar.b = str; a(aVar); } } catch (Throwable th) { if (ee.a) { ee.a("TxRequestSender", "", th); } } } public void a(String str, di diVar, int i2) { try { if (ee.a) { ee.b("TxRequestSender", str); } byte[] a2 = el.a(str.getBytes("GBK")); String a3 = a(a2, i2); if (ee.a) { ee.b("TxRequestSender", "postLocationRequest url = " + a3); } a aVar = new a(1, a2, a3, diVar); aVar.b = str; a(aVar); } catch (Throwable th) { if (ee.a) { ee.a("TxRequestSender", "", th); } } } private boolean a(a aVar) { boolean offer = aVar.f != null ? this.a.offer(aVar) : false; if (!offer) { this.a.clear(); this.a.offer(aVar); String str = "Location"; if (aVar.e == 2) { str = "List"; } else if (aVar.e == 3) { str = "Wifis"; } if (ee.a) { ee.b("TxRequestSender", "post" + str + "Request: failed to add request,because the queue has full,so we delete the first"); } } return offer; } public void a(Handler handler, boolean z) { if (!this.g) { this.g = true; this.i = handler; this.h = z; this.b.i().execute(new Runnable() { /* class c.t.m.g.da.AnonymousClass1 */ public void run() { da.this.a.clear(); da.this.c(); } }); this.f = SystemClock.elapsedRealtime(); } } public void a() { if (this.g) { this.g = false; this.a.clear(); this.a.offer(a.d); this.i = null; if (this.f != 0) { long elapsedRealtime = SystemClock.elapsedRealtime() - this.f; String format = String.format(Locale.ENGLISH, "shutdown: duration=%ds, sent=%dB, recv=%dB, reqCount=%d", Long.valueOf(elapsedRealtime / 1000), Long.valueOf(this.d), Long.valueOf(this.e), Long.valueOf(this.f119c)); if (ee.a) { ee.a("TxRequestSender", format); } } b(); } } private void b() { this.f119c = 0; this.d = 0; this.e = 0; this.f = 0; } /* access modifiers changed from: private */ /* access modifiers changed from: public */ /* JADX WARNING: Code restructure failed: missing block: B:30:0x00b5, code lost: r2 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:31:0x00b7, code lost: r2 = th; */ /* JADX WARNING: Code restructure failed: missing block: B:34:0x00bc, code lost: r2 = e; */ /* JADX WARNING: Code restructure failed: missing block: B:39:0x00c6, code lost: c.t.m.g.ee.a("TxRequestSender", "run: other exception.", r2); */ /* JADX WARNING: Code restructure failed: missing block: B:45:0x00de, code lost: c.t.m.g.ee.a("TxRequestSender", "cost:" + r8 + ",run: io error", r2); */ /* JADX WARNING: Code restructure failed: missing block: B:48:0x0100, code lost: c.t.m.g.ee.b("TxRequestSender", "Send timeout"); */ /* JADX WARNING: Code restructure failed: missing block: B:51:0x010b, code lost: r6 = null; */ /* JADX WARNING: Code restructure failed: missing block: B:52:0x010d, code lost: r6 = r2.getLooper(); */ /* JADX WARNING: Code restructure failed: missing block: B:61:0x012a, code lost: c.t.m.g.ee.a("TxRequestSender", "run: thread is interrupted", r2); */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Removed duplicated region for block: B:31:0x00b7 A[ExcHandler: Throwable (th java.lang.Throwable), Splitter:B:6:0x0010] */ /* JADX WARNING: Removed duplicated region for block: B:34:0x00bc A[ExcHandler: InterruptedException (e java.lang.InterruptedException), Splitter:B:6:0x0010] */ /* JADX WARNING: Removed duplicated region for block: B:39:0x00c6 */ /* JADX WARNING: Removed duplicated region for block: B:45:0x00de */ /* JADX WARNING: Removed duplicated region for block: B:48:0x0100 */ /* JADX WARNING: Removed duplicated region for block: B:51:0x010b */ /* JADX WARNING: Removed duplicated region for block: B:52:0x010d */ /* JADX WARNING: Removed duplicated region for block: B:61:0x012a */ private void c() { a aVar; long j2; IOException e2; Handler handler; LinkedBlockingQueue<a> linkedBlockingQueue = this.a; a aVar2 = null; while (this.g) { try { aVar = linkedBlockingQueue.take(); try { if (a.d != aVar) { j2 = System.currentTimeMillis(); Bundle a2 = this.b.a(aVar.g, aVar.f, true); String string = a2.getString("result"); long currentTimeMillis = System.currentTimeMillis() - j2; ee.a("cost:" + currentTimeMillis + ",result:" + string); if (string == null) { string = ""; } a(aVar, string); Handler handler2 = this.i; aVar.f120c = j2; if (!this.h && this.g && handler2 != null && handler2.getLooper().getThread().isAlive()) { Message obtainMessage = handler2.obtainMessage(); obtainMessage.arg1 = (int) currentTimeMillis; a(string, aVar, obtainMessage); } if (aVar.e == 1 && this.b.h().m() == 0) { this.b.h().c(currentTimeMillis); this.b.h().i(a2.getString("req_key")); } aVar2 = aVar; } else if (ee.a) { ee.a("TxRequestSender", "run: state=[shutdown]"); return; } else { return; } } catch (InterruptedException e3) { } catch (IOException e4) { e2 = e4; j2 = 0; long currentTimeMillis2 = System.currentTimeMillis() - j2; if (ee.a) { } b(aVar); if (ee.a) { } handler = this.i; if (handler == null) { } handler.sendEmptyMessageDelayed(4998, 0); aVar2 = aVar; } catch (Throwable th) { } } catch (InterruptedException e5) { aVar = aVar2; InterruptedException e6 = e5; if (ee.a) { } aVar2 = aVar; } catch (IOException e7) { j2 = 0; aVar = aVar2; e2 = e7; long currentTimeMillis22 = System.currentTimeMillis() - j2; if (ee.a) { } b(aVar); if (ee.a) { } handler = this.i; if (handler == null) { } handler.sendEmptyMessageDelayed(4998, 0); aVar2 = aVar; } catch (Throwable th2) { aVar = aVar2; Throwable th3 = th2; if (ee.a) { } aVar2 = aVar; } } } private void a(a aVar, String str) throws FileNotFoundException, IOException { this.f119c++; this.d += (long) aVar.f.length; byte[] a2 = el.a(str.getBytes("UTF-8")); this.e += (long) (a2 != null ? a2.length : 0); } private void b(a aVar) { boolean z; a.d(aVar); Iterator<a> it = this.a.iterator(); while (true) { if (it.hasNext()) { if (it.next().e == aVar.e) { z = true; break; } } else { z = false; break; } } if (aVar.h > 0 && !z) { if (ee.a) { ee.a("TxRequestSender", "retryIfNeed: times=" + aVar.h); } this.a.offer(aVar); } } private void a(String str, a aVar, Message message) { if (ee.a) { ee.b("TxRequestSender", "handleResponse"); } if (1 == aVar.e) { if (ee.a) { ee.b("TxRequestSender", "handleResponse result: " + str); } message.obj = Pair.create(str, aVar); message.what = 4999; message.sendToTarget(); } } private String a(byte[] bArr, int i2) { boolean a2 = Cdo.a(); try { if (ee.a) { ee.a("hh", "obfuscate fun_o"); } if (!a2 && bArr != null) { if (SoUtils.fun_o(bArr, 1) >= 0) { return ct.a(1, i2, 1); } } return ct.a(1, i2, 0); } catch (UnsatisfiedLinkError unused) { return null; } } /* access modifiers changed from: package-private */ /* compiled from: TML */ public static class a { public static final a d = new a(); final Object a; public String b; /* renamed from: c reason: collision with root package name */ public long f120c; private final int e; private final byte[] f; private final String g; private int h; static /* synthetic */ int d(a aVar) { int i = aVar.h; aVar.h = i - 1; return i; } private a() { this.h = 1; this.e = 0; this.f = null; this.g = null; this.a = null; } a(int i, byte[] bArr, String str, Object obj) { this.h = 1; this.e = i; this.f = bArr; this.g = str; this.a = obj; } } }