得物.apk(点击下载) / cz.java


package c.t.m.g;

import a.f;
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 cz {
    private static cz j;

    /* renamed from: a  reason: collision with root package name */
    private final LinkedBlockingQueue<a> f2094a = new LinkedBlockingQueue<>(3);
    private final ce b;

    /* renamed from: c  reason: collision with root package name */
    private long f2095c;
    private long d;
    private long e;
    private long f;

    /* renamed from: g  reason: collision with root package name */
    private volatile boolean f2096g;

    /* renamed from: h  reason: collision with root package name */
    private boolean f2097h;
    private volatile Handler i;

    private cz(ce ceVar) {
        this.b = ceVar;
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    /* JADX WARNING: Code restructure failed: missing block: B:32:0x00bb, code lost:
        r0 = th;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:33:0x00bc, code lost:
        r5 = r8;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:34:0x00be, code lost:
        r0 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:35:0x00bf, code lost:
        r9 = 0;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:37:0x00c2, code lost:
        r0 = e;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:38:0x00c3, code lost:
        r5 = r8;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:42:0x00ca, code lost:
        c.t.m.g.ee.a("TxRequestSender", "run: other exception.", r0);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:47:0x00dc, code lost:
        c.t.m.g.ee.a("TxRequestSender", a40.f.f("cost:", r11, ",run: io error"), r0);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:50:0x00ec, code lost:
        c.t.m.g.ee.b("TxRequestSender", "Send timeout");
     */
    /* JADX WARNING: Code restructure failed: missing block: B:53:0x00f5, code lost:
        r8 = null;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:54:0x00f7, code lost:
        r8 = r0.getLooper();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:62:0x0113, code lost:
        c.t.m.g.ee.a("TxRequestSender", "run: thread is interrupted", r0);
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Removed duplicated region for block: B:32:0x00bb A[ExcHandler: all (th java.lang.Throwable), Splitter:B:6:0x0017] */
    /* JADX WARNING: Removed duplicated region for block: B:37:0x00c2 A[ExcHandler: InterruptedException (e java.lang.InterruptedException), Splitter:B:6:0x0017] */
    /* JADX WARNING: Removed duplicated region for block: B:42:0x00ca  */
    /* JADX WARNING: Removed duplicated region for block: B:47:0x00dc  */
    /* JADX WARNING: Removed duplicated region for block: B:50:0x00ec  */
    /* JADX WARNING: Removed duplicated region for block: B:53:0x00f5  */
    /* JADX WARNING: Removed duplicated region for block: B:54:0x00f7  */
    /* JADX WARNING: Removed duplicated region for block: B:62:0x0113  */
    /* JADX WARNING: Removed duplicated region for block: B:68:0x000a A[SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:73:0x000a A[SYNTHETIC] */
    private void c() {
        long j12;
        IOException e6;
        Handler handler;
        LinkedBlockingQueue<a> linkedBlockingQueue = this.f2094a;
        a aVar = null;
        while (this.f2096g) {
            try {
                a take = linkedBlockingQueue.take();
                try {
                    if (a.d != take) {
                        j12 = System.currentTimeMillis();
                        Bundle a5 = this.b.a(take.f2101g, take.f, true);
                        String string = a5.getString("result");
                        long currentTimeMillis = System.currentTimeMillis() - j12;
                        ee.a("cost:" + currentTimeMillis + ",result:" + string);
                        if (string == null) {
                            string = "";
                        }
                        a(take, string);
                        Handler handler2 = this.i;
                        take.f2100c = j12;
                        if (!this.f2097h && this.f2096g && handler2 != null && handler2.getLooper().getThread().isAlive()) {
                            Message obtainMessage = handler2.obtainMessage();
                            obtainMessage.arg1 = (int) currentTimeMillis;
                            a(string, take, obtainMessage);
                        }
                        if (take.e == 1 && this.b.h().m() == 0) {
                            this.b.h().c(currentTimeMillis);
                            this.b.h().i(a5.getString("req_key"));
                        }
                        aVar = take;
                    } else if (ee.f2193a) {
                        ee.a("TxRequestSender", "run: state=[shutdown]");
                        return;
                    } else {
                        return;
                    }
                } catch (InterruptedException e12) {
                } catch (IOException e13) {
                    e6 = e13;
                    aVar = take;
                    long currentTimeMillis2 = System.currentTimeMillis() - j12;
                    if (ee.f2193a) {
                    }
                    b(aVar);
                    if (ee.f2193a) {
                    }
                    handler = this.i;
                    if (handler == null) {
                    }
                    handler.sendEmptyMessageDelayed(4998, 0);
                } catch (Throwable th2) {
                }
            } catch (InterruptedException e14) {
                InterruptedException e15 = e14;
                if (!ee.f2193a) {
                }
            } catch (IOException e16) {
                e6 = e16;
                j12 = 0;
                long currentTimeMillis22 = System.currentTimeMillis() - j12;
                if (ee.f2193a) {
                }
                b(aVar);
                if (ee.f2193a) {
                }
                handler = this.i;
                if (handler == null) {
                }
                handler.sendEmptyMessageDelayed(4998, 0);
            } catch (Throwable th3) {
                Throwable th4 = th3;
                if (!ee.f2193a) {
                }
            }
        }
    }

    /* compiled from: TML */
    public static class a {
        public static final a d = new a();

        /* renamed from: a  reason: collision with root package name */
        public final Object f2099a;
        public String b;

        /* renamed from: c  reason: collision with root package name */
        public long f2100c;
        private final int e;
        private final byte[] f;

        /* renamed from: g  reason: collision with root package name */
        private final String f2101g;

        /* renamed from: h  reason: collision with root package name */
        private int f2102h = 1;

        private a() {
        }

        public static /* synthetic */ int d(a aVar) {
            int i = aVar.f2102h;
            aVar.f2102h = i - 1;
            return i;
        }

        public a(int i, byte[] bArr, String str, Object obj) {
            this.e = i;
            this.f = bArr;
            this.f2101g = str;
            this.f2099a = obj;
        }
    }

    public static cz a(ce ceVar) {
        if (j == null) {
            synchronized (cz.class) {
                if (j == null) {
                    j = new cz(ceVar);
                }
            }
        }
        return j;
    }

    private void b() {
        this.f2095c = 0;
        this.d = 0;
        this.e = 0;
        this.f = 0;
    }

    private void b(a aVar) {
        boolean z;
        a.d(aVar);
        Iterator<a> it2 = this.f2094a.iterator();
        while (true) {
            if (it2.hasNext()) {
                if (it2.next().e == aVar.e) {
                    z = true;
                    break;
                }
            } else {
                z = false;
                break;
            }
        }
        if (aVar.f2102h > 0 && !z) {
            if (ee.f2193a) {
                StringBuilder h12 = f.h("retryIfNeed: times=");
                h12.append(aVar.f2102h);
                ee.a("TxRequestSender", h12.toString());
            }
            this.f2094a.offer(aVar);
        }
    }

    public void a(String str) {
        try {
            if (!TextUtils.isEmpty(str)) {
                byte[] b2 = ek.b(str.getBytes("UTF-8"));
                if (ee.f2193a) {
                    ee.a("hh", "postWifisRequest fun_o");
                }
                SoUtils.fun_o(b2, 2);
                if (ee.f2193a) {
                    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 th2) {
            if (ee.f2193a) {
                ee.a("TxRequestSender", "", th2);
            }
        }
    }

    public void a(String str, dh dhVar, int i3) {
        try {
            if (ee.f2193a) {
                ee.b("TxRequestSender", str);
            }
            byte[] a5 = el.a(str.getBytes("GBK"));
            String a12 = a(a5, i3);
            if (ee.f2193a) {
                ee.b("TxRequestSender", "postLocationRequest url = " + a12);
            }
            a aVar = new a(1, a5, a12, dhVar);
            aVar.b = str;
            a(aVar);
        } catch (Throwable th2) {
            if (ee.f2193a) {
                ee.a("TxRequestSender", "", th2);
            }
        }
    }

    private boolean a(a aVar) {
        String str;
        boolean offer = aVar.f != null ? this.f2094a.offer(aVar) : false;
        if (!offer) {
            this.f2094a.clear();
            this.f2094a.offer(aVar);
            if (aVar.e == 2) {
                str = "List";
            } else {
                str = aVar.e == 3 ? "Wifis" : "Location";
            }
            if (ee.f2193a) {
                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.f2096g) {
            this.f2096g = true;
            this.i = handler;
            this.f2097h = z;
            this.b.i().execute(new Runnable() {
                /* class c.t.m.g.cz.AnonymousClass1 */

                public void run() {
                    cz.this.f2094a.clear();
                    cz.this.c();
                }
            });
            this.f = SystemClock.elapsedRealtime();
        }
    }

    public void a() {
        if (this.f2096g) {
            this.f2096g = false;
            this.f2094a.clear();
            this.f2094a.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.f2095c));
                if (ee.f2193a) {
                    ee.a("TxRequestSender", format);
                }
            }
            b();
        }
    }

    private void a(a aVar, String str) throws FileNotFoundException, IOException {
        this.f2095c++;
        this.d += (long) aVar.f.length;
        byte[] a5 = el.a(str.getBytes("UTF-8"));
        this.e += (long) (a5 != null ? a5.length : 0);
    }

    private void a(String str, a aVar, Message message) {
        if (ee.f2193a) {
            ee.b("TxRequestSender", "handleResponse");
        }
        if (1 == aVar.e) {
            if (ee.f2193a) {
                ee.b("TxRequestSender", "handleResponse result: " + str);
            }
            message.obj = Pair.create(str, aVar);
            message.what = 4999;
            message.sendToTarget();
        }
    }

    private String a(byte[] bArr, int i3) {
        boolean a5 = dn.a();
        try {
            if (ee.f2193a) {
                ee.a("hh", "obfuscate fun_o");
            }
            if (!a5 && bArr != null) {
                if (SoUtils.fun_o(bArr, 1) >= 0) {
                    return cs.a(1, i3, 1);
                }
            }
            return cs.a(1, i3, 0);
        } catch (UnsatisfiedLinkError unused) {
            return null;
        }
    }
}