同程有借 v1.0.0版本的 MD5 值为:e33397cdbab33543d0c134ec96d77fb8

以下内容为反编译后的 b.java 源代码,内容仅作参考


package com.bonree.sdk.ax;

import android.os.Message;
import android.text.TextUtils;
import com.bonree.sdk.agent.business.entity.BaseEventInfo;
import com.bonree.sdk.agent.business.entity.EventBean;
import com.bonree.sdk.agent.business.entity.NetworkEventInfoBean;
import com.bonree.sdk.aj.c;
import com.bonree.sdk.ax.e;
import com.bonree.sdk.bl.f;
import com.bonree.sdk.bz.af;
import com.bonree.sdk.bz.k;
import com.bonree.sdk.bz.x;
import com.bonree.sdk.o.j;
import com.moture.lib.core.utils.date.DateTimeUtils;
import com.plugin.location.request.MoLocationOption;
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.concurrent.atomic.AtomicInteger;
public final class b {
    private static int f3907a = 0;
    private static int f3908b = 1;
    private static int f3909c = 2;
    private static int f3910d = 3;
    private static int f3911e = 4;
    private static int f3912f = 6;
    private static int f3913g = 7;
    private static int f3914h = 8;
    private static int f3915i = 9;
    private static int f3916j = 10;
    private static int f3917k = 11;
    private static final int f3918l = 200;
    private static final int f3919m = 1000;
    private static int f3920n = 30000;
    private static final int f3921o = 3600000;
    private static final int f3922p = 1500;
    private static f f3923q = com.bonree.sdk.bl.a.a();
    private final List<String> A;
    private final List<String> B;
    private final c C;
    private final List<com.bonree.sdk.ah.b> D;
    private String[] E;
    private boolean F;
    private boolean G;
    private int H;
    private final AtomicInteger I;
    private final List<EventBean> f3924r;
    private final Map<String, j> f3925s;
    private final Map<String, com.bonree.sdk.m.b> f3926t;
    private final Map<String, Object> f3927u;
    private final Map<String, NetworkEventInfoBean> f3928v;
    private final Map<String, List> f3929w;
    private final List<String> f3930x;
    private final List<String> f3931y;
    private final List<String> f3932z;

    public static class a {
        private static final b f3933a = new b((byte) 0);
    }

    b(byte b9) {
        this();
    }

    public static b a() {
        return a.f3933a;
    }

    private void b(long j9) {
        synchronized (this.f3925s) {
            if (this.f3925s.size() < 30) {
                return;
            }
            Iterator<Map.Entry<String, j>> it = this.f3925s.entrySet().iterator();
            while (it.hasNext()) {
                if (j9 - (it.next().getValue().g() / 1000) > DateTimeUtils.HOUR_UNIT) {
                    it.remove();
                }
            }
        }
    }

    private void c(long j9) {
        if (this.G) {
            synchronized (this.D) {
                ArrayList arrayList = new ArrayList();
                for (int i9 = 0; i9 < this.D.size(); i9++) {
                    com.bonree.sdk.ah.b bVar = this.D.get(i9);
                    if (j9 - bVar.b() > 10000) {
                        a(bVar.a(), true);
                    } else {
                        arrayList.add(bVar);
                    }
                }
                this.D.clear();
                this.D.addAll(arrayList);
            }
        }
    }

    private void d(long j9) {
        synchronized (this.f3927u) {
            Iterator<Map.Entry<String, Object>> it = this.f3927u.entrySet().iterator();
            while (it.hasNext()) {
                Object value = it.next().getValue();
                if (value instanceof com.bonree.sdk.o.e) {
                    if (j9 - ((com.bonree.sdk.o.e) value).h() > 180000) {
                        f3923q.a("eventlistener cache timeout  %s", value);
                        it.remove();
                    }
                } else if (value instanceof HashMap) {
                    for (Map.Entry entry : ((HashMap) value).entrySet()) {
                        entry.getValue();
                        if (j9 - ((com.bonree.sdk.o.e) value).h() > 180000) {
                            f3923q.a("eventlistener cache timeout  %s", value);
                            it.remove();
                        }
                    }
                    if (((HashMap) value).size() == 0) {
                        it.remove();
                    }
                }
            }
        }
    }

    private void e(long j9) {
        synchronized (this.f3928v) {
            Iterator<Map.Entry<String, NetworkEventInfoBean>> it = this.f3928v.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, NetworkEventInfoBean> next = it.next();
                if (j9 - Long.parseLong(next.getKey().substring(next.getKey().indexOf("_") + 1)) <= 600000 && this.f3928v.size() <= 50) {
                    if (a(next.getKey(), next.getValue().mRequestUrl)) {
                        it.remove();
                    }
                }
                a(next.getValue(), true);
                it.remove();
            }
        }
    }

    private void f() {
        a(this.f3924r);
    }

    private void g() {
        a(this.f3925s);
        a(this.f3926t);
        a(this.f3927u);
        a(this.f3928v);
        a(this.f3929w);
        a(this.D);
        this.C.d();
    }

    private void h() {
        try {
            e.a.f3940a.b(8);
            long b9 = com.bonree.sdk.c.a.b();
            a(b9);
            b(b9);
            e(b9);
            d(b9);
            c(b9);
            e.a.f3940a.a(8, MoLocationOption.LOC_DELAY_TIME);
        } catch (Throwable th) {
            f3923q.c("timer exception:", th);
        }
    }

    private void i() {
        long b9 = com.bonree.sdk.c.a.b();
        a(b9);
        b(b9);
        e(b9);
        d(b9);
        c(b9);
    }

    private void j() {
        synchronized (this.f3924r) {
            for (EventBean eventBean : this.f3924r) {
                long j9 = eventBean.mEventTime;
                if (j9 < 0) {
                    eventBean.correctEventTime(com.bonree.sdk.c.a.c(j9));
                    this.I.getAndDecrement();
                    if (this.I.get() <= 0) {
                        break;
                    }
                }
            }
        }
    }

    private b() {
        this.H = 1;
        this.I = new AtomicInteger(0);
        this.f3924r = Collections.synchronizedList(new ArrayList());
        this.f3925s = new k();
        this.f3926t = new k();
        this.f3927u = new k();
        this.f3928v = new k();
        this.f3929w = new k();
        this.f3930x = Collections.synchronizedList(new ArrayList());
        this.f3931y = Collections.synchronizedList(new ArrayList());
        this.f3932z = Collections.synchronizedList(new ArrayList());
        this.A = Collections.synchronizedList(new ArrayList());
        this.B = Collections.synchronizedList(new ArrayList());
        this.C = new c();
        this.D = Collections.synchronizedList(new ArrayList());
        this.F = false;
        this.G = false;
    }

    private static void a(List list) {
        synchronized (list) {
            if (list.size() > 0) {
                list.clear();
            }
        }
    }

    private static long f(long j9) {
        return com.bonree.sdk.c.a.c(j9);
    }

    private static void a(Map map) {
        synchronized (map) {
            if (!map.isEmpty()) {
                map.clear();
            }
        }
    }

    private void a(long j9) {
        synchronized (this.f3926t) {
            Iterator<Map.Entry<String, com.bonree.sdk.m.b>> it = this.f3926t.entrySet().iterator();
            f fVar = f3923q;
            fVar.a("mSocketSdMap size():  " + this.f3926t.size(), new Object[0]);
            while (it.hasNext()) {
                Map.Entry<String, com.bonree.sdk.m.b> next = it.next();
                com.bonree.sdk.m.b value = next.getValue();
                Map<Long, j> b9 = value.b();
                if (b9 != null) {
                    Iterator<Map.Entry<Long, j>> it2 = b9.entrySet().iterator();
                    f fVar2 = f3923q;
                    fVar2.a(next.getKey() + "   serializeDataMap size() :  " + b9.size(), new Object[0]);
                    while (it2.hasNext()) {
                        j value2 = it2.next().getValue();
                        if (value2 != null && j9 - value2.g() > 90000) {
                            if (!value.a()) {
                                if (b(value2)) {
                                    it2.remove();
                                }
                            } else {
                                a(value2);
                            }
                        }
                    }
                    if (b9.isEmpty()) {
                        it.remove();
                    }
                }
            }
        }
    }

    private boolean b(j jVar) {
        if (jVar.o() > 0) {
            a(jVar, (com.bonree.sdk.agent.engine.network.cronet.b) null);
            return true;
        }
        List<com.bonree.sdk.agent.engine.network.cronet.b> a9 = jVar.a();
        if (a9 == null) {
            return true;
        }
        Iterator<com.bonree.sdk.agent.engine.network.cronet.b> it = a9.iterator();
        while (it.hasNext()) {
            com.bonree.sdk.agent.engine.network.cronet.b next = it.next();
            if (com.bonree.sdk.c.a.b() - next.c() > DateTimeUtils.MINUTE_UNIT) {
                a(jVar, next);
                it.remove();
            }
        }
        return a9.isEmpty();
    }

    public final List<EventBean> c() {
        ArrayList arrayList;
        synchronized (this.f3924r) {
            if (this.I.get() > 0) {
                j();
            }
            arrayList = new ArrayList(this.f3924r);
            a(this.f3924r);
        }
        return arrayList;
    }

    public final void e(String[] strArr) {
        synchronized (this.B) {
            this.B.clear();
            if (strArr != null && strArr.length != 0) {
                Collections.addAll(this.B, strArr);
            }
        }
    }

    public final void c(String[] strArr) {
        synchronized (this.f3932z) {
            this.f3932z.clear();
            if (strArr != null && strArr.length != 0) {
                Collections.addAll(this.f3932z, strArr);
            }
        }
    }

    private void b(com.bonree.sdk.o.b bVar) {
        if (bVar != null) {
            try {
                if (bVar.f() == null) {
                    return;
                }
                f fVar = f3923q;
                fVar.c("FrameData = " + bVar, new Object[0]);
                f fVar2 = f3923q;
                fVar2.c("FrameData requestId = " + bVar.s(), new Object[0]);
                com.bonree.sdk.o.e b9 = b(bVar.s(), bVar.f());
                f fVar3 = f3923q;
                fVar3.c("ok3EventData = " + b9, new Object[0]);
                if (b9 != null && (TextUtils.isEmpty(bVar.j()) || !TextUtils.isEmpty(b9.a()))) {
                    if (!b9.b() && !bVar.P()) {
                        NetworkEventInfoBean a9 = g.a(b9, this.H, this.f3930x, this.B, this.A);
                        if (a9 == null) {
                            return;
                        }
                        if (!TextUtils.isEmpty(bVar.j()) && !TextUtils.isEmpty(b9.a())) {
                            if (!TextUtils.isEmpty(bVar.f()) && !TextUtils.equals(bVar.f(), b9.c())) {
                                a9.mRequestUrl = bVar.f();
                            }
                            if (a9.mRequestDataSize == 0 && bVar.T() != 0) {
                                a9.mRequestDataSize = bVar.T();
                            }
                        }
                        a9.mIdentifier = bVar.X();
                        a9.mCustomBusinessBody = g.a((Object) bVar.S(), this.f3931y);
                        g.a(a9, b9.s(), this.C);
                        g.a(bVar, a9);
                        a(a9);
                        synchronized (this.f3927u) {
                            Object obj = this.f3927u.get(b9.x());
                            if (obj != null && (obj instanceof com.bonree.sdk.o.e)) {
                                this.f3927u.remove(b9.x());
                            }
                        }
                        return;
                    }
                    bVar.a(true);
                    synchronized (this.f3927u) {
                        Object obj2 = this.f3927u.get(b9.x());
                        if (obj2 != null && (obj2 instanceof com.bonree.sdk.o.e)) {
                            this.f3927u.remove(b9.x());
                        }
                    }
                }
                NetworkEventInfoBean a10 = g.a(bVar, this.H);
                g.a(a10, bVar, this.G, this.E);
                if (bVar.w() != null && bVar.w().size() > 0) {
                    a10.mCustomBusinessHeader = g.a(bVar.w(), this.f3930x);
                    a10.mResponseTraceInfo = g.b(bVar.O(), this.A);
                    a10.mRequestTraceInfo = g.c(bVar.x(), this.B);
                    g.a(a10, bVar.w(), this.C);
                } else {
                    g.a(a10, bVar.v(), this.f3930x);
                    a10.mResponseTraceInfo = g.b(bVar.O(), this.A);
                    g.a(a10, bVar.v(), this.C);
                }
                a10.mCustomBusinessBody = g.a((Object) bVar.S(), this.f3931y);
                if (g.a(bVar, a10, d.a(bVar, this.f3926t), this.F && !TextUtils.isEmpty(bVar.s()))) {
                    d.a(a10, x.c(bVar.f()), bVar, this.f3926t);
                    if (this.F && !TextUtils.isEmpty(bVar.s()) && a10.mErrorCode.intValue() == 0) {
                        f3923q.c("可能是okhttp3Event 缓存在发送", new Object[0]);
                        synchronized (this.f3928v) {
                            this.f3928v.put(bVar.s(), a10);
                        }
                        return;
                    }
                    g.a(bVar, a10);
                    if (bVar.V()) {
                        return;
                    }
                    f3923q.a("frame data:%s", a10);
                    a(a10);
                }
            } catch (Throwable th) {
                f3923q.a("frame error:", th);
            }
        }
    }

    private void e() {
        a(this.f3924r);
        g();
    }

    public final void d(String[] strArr) {
        synchronized (this.A) {
            this.A.clear();
            if (strArr != null && strArr.length != 0) {
                Collections.addAll(this.A, strArr);
            }
        }
    }

    public final boolean d() {
        List<String> list = this.f3931y;
        return list != null && list.size() > 0;
    }

    private static void a(j jVar) {
        List<com.bonree.sdk.agent.engine.network.cronet.b> a9 = jVar.a();
        if (a9 != null) {
            Iterator<com.bonree.sdk.agent.engine.network.cronet.b> it = a9.iterator();
            while (it.hasNext()) {
                if (com.bonree.sdk.c.a.b() - it.next().c() > 90000) {
                    it.remove();
                }
            }
        }
        List<com.bonree.sdk.agent.business.util.c> b9 = jVar.b();
        if (b9 != null) {
            Iterator<com.bonree.sdk.agent.business.util.c> it2 = b9.iterator();
            while (it2.hasNext()) {
                if (com.bonree.sdk.c.a.b() - it2.next().c() > 90000) {
                    it2.remove();
                }
            }
        }
    }

    private void a(j jVar, com.bonree.sdk.agent.engine.network.cronet.b bVar) {
        NetworkEventInfoBean a9;
        try {
            synchronized (this.f3925s) {
                a9 = g.a(jVar, bVar, this.f3925s);
            }
            if (a9 == null) {
                return;
            }
            f3923q.a("原生socket :%s", a9);
            a(a9);
        } catch (Throwable th) {
            f3923q.a("socket error:", th);
        }
    }

    private void a(com.bonree.sdk.o.e eVar) {
        if (eVar != null) {
            try {
                if (!TextUtils.isEmpty(eVar.c()) && !TextUtils.isEmpty(eVar.x())) {
                    f3923q.c("okhttp3Event:%s", eVar);
                    this.F = true;
                    synchronized (this.f3927u) {
                        String x8 = eVar.x();
                        if (!this.f3927u.containsKey(x8)) {
                            this.f3927u.put(x8, eVar);
                        } else {
                            Object obj = this.f3927u.get(x8);
                            if (obj instanceof com.bonree.sdk.o.e) {
                                if (eVar.c() != null) {
                                    HashMap hashMap = new HashMap();
                                    hashMap.put(((com.bonree.sdk.o.e) obj).c(), obj);
                                    if (TextUtils.equals(eVar.c(), ((com.bonree.sdk.o.e) obj).c())) {
                                        hashMap.put(eVar.v(), eVar);
                                    } else {
                                        hashMap.put(eVar.c(), eVar);
                                    }
                                    this.f3927u.put(x8, hashMap);
                                }
                            } else if (obj instanceof HashMap) {
                                if (((com.bonree.sdk.o.e) ((HashMap) obj).get(eVar.c())) == null) {
                                    ((HashMap) obj).put(eVar.c(), eVar);
                                } else {
                                    ((HashMap) obj).put(eVar.v(), eVar);
                                }
                            }
                        }
                    }
                    return;
                }
            } catch (Throwable th) {
                f3923q.a("okhttp3Event error:", th);
                return;
            }
        }
        f3923q.e("okhttp3Event is invalid :%s", eVar);
    }

    private boolean a(String str, String str2) {
        f fVar = f3923q;
        fVar.c("okhttp3Event mathch start:" + str, new Object[0]);
        com.bonree.sdk.o.e b9 = b(str, str2);
        if (b9 == null) {
            return false;
        }
        f fVar2 = f3923q;
        fVar2.c("okhttp3Event mathch end: " + str, new Object[0]);
        a(g.a(b9, this.H, this.f3930x, this.B, this.A), true);
        synchronized (this.f3927u) {
            this.f3927u.remove(b9.x());
        }
        return true;
    }

    private com.bonree.sdk.o.e b(String str, String str2) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        synchronized (this.f3927u) {
            Object obj = this.f3927u.get(str);
            if (obj != null) {
                if (obj instanceof com.bonree.sdk.o.e) {
                    return (com.bonree.sdk.o.e) obj;
                } else if (obj instanceof Map) {
                    Object obj2 = ((Map) obj).get(str2);
                    if (obj2 == null) {
                        obj2 = ((Map) obj).get(x.c(str2));
                    }
                    return (com.bonree.sdk.o.e) obj2;
                }
            }
            return null;
        }
    }

    private void a(com.bonree.sdk.o.b bVar) {
        if (bVar != null) {
            try {
                if (bVar.f() == null) {
                    return;
                }
                NetworkEventInfoBean a9 = g.a(bVar, this.f3929w, this.H);
                a9.mCustomBusinessHeader = g.a(bVar.w(), this.f3930x);
                a9.mCustomBusinessQuery = g.a(a9.mRequestUrl, this.f3932z);
                a9.mResponseTraceInfo = g.b(bVar.O(), this.A);
                a9.mRequestTraceInfo = g.c(bVar.w(), this.B);
                String d9 = x.d(bVar.d());
                if (!TextUtils.isEmpty(d9)) {
                    a9.mTraceId = d9;
                }
                String e9 = x.e(bVar.d());
                if (!TextUtils.isEmpty(e9)) {
                    a9.xBrResponse = e9;
                }
                String f9 = x.f(bVar.d());
                if (!TextUtils.isEmpty(f9)) {
                    a9.traceResponse = f9;
                }
                EventBean eventBean = new EventBean();
                eventBean.mEventType = BaseEventInfo.EVENT_TYPE_NETWORK;
                long R = bVar.R() * 1000;
                eventBean.mEventTime = R;
                if (R < 0) {
                    this.I.getAndIncrement();
                } else if (this.I.get() > 0) {
                    j();
                }
                eventBean.mStateIndex = eventBean.getStateIndex();
                eventBean.mEventInfo = a9;
                g.a(eventBean, a9);
                synchronized (this.f3924r) {
                    if (this.f3924r.size() >= f3922p) {
                        this.f3924r.remove(0);
                    }
                    eventBean.uploadStateKey();
                    this.f3924r.add(eventBean);
                }
                f3923q.c("network flutter eventBean :%s", eventBean);
            } catch (Exception e10) {
                f3923q.a("constructFlutterNetworkData error:", e10);
            }
        }
    }

    public final void b(String[] strArr) {
        synchronized (this.f3931y) {
            this.f3931y.clear();
            if (strArr != null && strArr.length != 0) {
                Collections.addAll(this.f3931y, strArr);
            }
        }
    }

    private void b(NetworkEventInfoBean networkEventInfoBean) {
        networkEventInfoBean.isCustom = true;
        networkEventInfoBean.mAppRequestType = 10;
        EventBean eventBean = new EventBean();
        eventBean.mEventType = BaseEventInfo.EVENT_TYPE_NETWORK;
        long g9 = com.bonree.sdk.c.a.g();
        eventBean.mEventTime = g9;
        if (g9 < 0) {
            this.I.getAndIncrement();
        } else if (this.I.get() > 0) {
            j();
        }
        eventBean.mStateIndex = eventBean.getStateIndex();
        eventBean.mEventInfo = networkEventInfoBean;
        g.a(eventBean, networkEventInfoBean);
        synchronized (this.f3924r) {
            if (this.f3924r.size() >= f3922p) {
                this.f3924r.remove(0);
            }
            eventBean.uploadStateKey();
            this.f3924r.add(eventBean);
        }
        f3923q.c("eventBean :%s", eventBean);
    }

    public final void b() {
        a(this.f3924r);
        a(this.f3925s);
        a(this.f3926t);
        a(this.f3927u);
        a(this.f3928v);
        a(this.f3929w);
        a(this.D);
        this.C.d();
    }

    private void a(com.bonree.sdk.o.a aVar) {
        if (aVar == null) {
            return;
        }
        NetworkEventInfoBean a9 = g.a(aVar, this.H);
        a9.mCustomBusinessHeader = g.a(aVar.n(), this.f3930x);
        a9.mResponseTraceInfo = g.b(aVar.o(), this.A);
        a9.mRequestTraceInfo = g.c(aVar.n(), this.B);
        g.a(a9, aVar.n(), this.C);
        if (aVar.o() != null && aVar.o().size() > 0) {
            String a10 = x.a(aVar.o());
            if (!TextUtils.isEmpty(a10)) {
                a9.mTraceId = a10;
            }
            String b9 = x.b(aVar.o());
            if (!TextUtils.isEmpty(b9)) {
                a9.xBrResponse = b9;
            }
            String c9 = x.c(aVar.o());
            if (!TextUtils.isEmpty(c9)) {
                a9.traceResponse = c9;
            }
        }
        g.a(aVar, a9);
        a(a9, true);
    }

    private void a(com.bonree.sdk.o.f fVar) {
        if (fVar != null) {
            try {
                if (fVar.b() == null) {
                    return;
                }
                synchronized (this.f3926t) {
                    String b9 = fVar.b();
                    Long valueOf = Long.valueOf(fVar.c() + fVar.l());
                    if (b9 != null && this.f3926t.containsKey(b9) && this.f3926t.get(b9) != null) {
                        com.bonree.sdk.m.b bVar = this.f3926t.get(b9);
                        if (bVar == null) {
                            return;
                        }
                        Map<Long, j> b10 = bVar.b();
                        if (b10 == null) {
                            a(null, bVar, null, fVar, valueOf, b9);
                            return;
                        } else {
                            a(b10, bVar, b10.get(valueOf), fVar, valueOf, b9);
                            return;
                        }
                    }
                    a(null, null, null, fVar, valueOf, b9);
                }
            } catch (Throwable th) {
                f3923q.a("socket save error:", th);
            }
        }
    }

    private void a(Map<Long, j> map, com.bonree.sdk.m.b bVar, j jVar, com.bonree.sdk.o.f fVar, Long l9, String str) {
        if (jVar == null) {
            jVar = new j(fVar);
        }
        jVar.a(fVar);
        if (map == null) {
            map = new k<>();
        }
        map.put(l9, jVar);
        if (bVar == null) {
            bVar = new com.bonree.sdk.m.b(map);
        } else {
            bVar.a(map);
        }
        this.f3926t.put(str, bVar);
    }

    private void a(com.bonree.sdk.ah.k kVar) {
        Integer num;
        List<String> a9;
        Integer num2;
        int f9 = kVar.f();
        for (EventBean eventBean : com.bonree.sdk.bi.i.a(kVar.a(), BaseEventInfo.EVENT_TYPE_NETWORK)) {
            NetworkEventInfoBean networkEventInfoBean = (NetworkEventInfoBean) eventBean.mEventInfo;
            if (!networkEventInfoBean.isCustom) {
                String l9 = af.l(networkEventInfoBean.mRequestUrl);
                if ((TextUtils.isEmpty(networkEventInfoBean.mTargetIp) || "0".equals(networkEventInfoBean.mTargetIp)) && (num = networkEventInfoBean.mErrorCode) != null && !h.a(num.intValue())) {
                    String[] b9 = h.b(networkEventInfoBean.mRequestUrl, l9);
                    if (!TextUtils.isEmpty(b9[0])) {
                        networkEventInfoBean.mTargetIp = b9[0];
                    }
                    networkEventInfoBean.mTargetPort = Integer.parseInt(b9[1]);
                }
                if (!TextUtils.isEmpty(networkEventInfoBean.mRequestUrl) && !TextUtils.isEmpty(networkEventInfoBean.mTargetIp) && networkEventInfoBean.mRequestUrl.contains(networkEventInfoBean.mTargetIp)) {
                    networkEventInfoBean.mDnsTimeUs = 0;
                } else if (!af.b(l9) && (a9 = h.a(l9, this.f3929w)) != null && !a9.isEmpty()) {
                    networkEventInfoBean.mCNameArray = a9;
                }
                if (networkEventInfoBean.mErrorCode.intValue() >= 400 || (((num2 = networkEventInfoBean.mErrorOccurrentProcess) != null && num2.intValue() > 0) || (!TextUtils.isEmpty(networkEventInfoBean.mErrorMsg) && !networkEventInfoBean.mErrorMsg.equals("null")))) {
                    eventBean.mTraceInfoList = com.bonree.sdk.be.c.h().f();
                }
                if (f9 == 1) {
                    networkEventInfoBean.mCustomBusinessHeader = g.a(kVar.c(), this.f3930x);
                    networkEventInfoBean.mCustomBusinessBody = g.a((Object) kVar.d(), this.f3931y);
                    networkEventInfoBean.mCustomBusinessQuery = g.a(networkEventInfoBean.mRequestUrl, this.f3932z);
                }
                if (this.G && (f9 == 1 || f9 == 2)) {
                    networkEventInfoBean.startTime = -eventBean.mEventTime;
                    a(networkEventInfoBean, 0);
                    f3923q.c("addCacheResultList=network : %s", eventBean);
                    return;
                }
            }
            eventBean.mEventTime = -eventBean.mEventTime;
            this.I.getAndIncrement();
            eventBean.mEventInfo = networkEventInfoBean;
            eventBean.mStateIndex = eventBean.getStateIndex();
            synchronized (this.f3924r) {
                if (this.f3924r.size() >= f3922p) {
                    this.f3924r.remove(0);
                }
                eventBean.uploadStateKey();
                this.f3924r.add(eventBean);
                f3923q.c("eventBean=network : %s", eventBean);
            }
        }
    }

    private void a(NetworkEventInfoBean networkEventInfoBean) {
        a(networkEventInfoBean, true);
    }

    private void a(NetworkEventInfoBean networkEventInfoBean, boolean z8) {
        if (networkEventInfoBean == null) {
            return;
        }
        networkEventInfoBean.mCustomBusinessQuery = g.a(networkEventInfoBean.mRequestUrl, this.f3932z);
        g.a(networkEventInfoBean, this.f3929w);
        if (networkEventInfoBean.mRequestTimeUs <= 0 && networkEventInfoBean.mResponseTimeUs <= 0 && networkEventInfoBean.mDownloadTimeUs <= 0 && networkEventInfoBean.mErrorCode.intValue() == 0 && networkEventInfoBean.mAppRequestType == 10 && af.b(networkEventInfoBean.mErrorMsg)) {
            f3923q.c("network data is exception", new Object[0]);
        } else if (networkEventInfoBean.mAppRequestType == 10 && ((TextUtils.isEmpty(networkEventInfoBean.mTargetIp) || networkEventInfoBean.mTargetIp.equals("0")) && !h.a(networkEventInfoBean.mErrorCode.intValue()))) {
            f3923q.c("network address ip is null", new Object[0]);
        } else {
            EventBean eventBean = new EventBean();
            eventBean.mEventType = BaseEventInfo.EVENT_TYPE_NETWORK;
            long j9 = networkEventInfoBean.startTime;
            eventBean.mEventTime = j9;
            if (j9 < 0) {
                this.I.getAndIncrement();
            } else if (this.I.get() > 0) {
                j();
            }
            eventBean.mStateIndex = eventBean.getStateIndex();
            eventBean.mEventInfo = networkEventInfoBean;
            g.a(eventBean, networkEventInfoBean);
            synchronized (this.f3924r) {
                if (this.f3924r.size() >= f3922p) {
                    this.f3924r.remove(0);
                }
                eventBean.uploadStateKey();
                e unused = e.a.f3940a;
                com.bonree.sdk.aj.c.b(c.b.NETWORK, eventBean);
                this.f3924r.add(eventBean);
            }
            f3923q.c("eventBean :%s", eventBean);
        }
    }

    private void a(com.bonree.sdk.ah.f fVar) {
        try {
            if (!this.G) {
                synchronized (this.f3924r) {
                    if (g.a(fVar, this.f3924r, this.H)) {
                        NetworkEventInfoBean a9 = g.a(fVar, this.f3930x, this.B, this.A, this.H);
                        f3923q.a("WebviewError:%s", a9);
                        a(a9);
                        return;
                    }
                    return;
                }
            }
            NetworkEventInfoBean a10 = g.a(fVar, this.f3930x, this.B, this.A, this.H);
            f3923q.a("WebviewError:%s", a10);
            a(a10, 1);
        } catch (Throwable th) {
            f3923q.e("WebviewError throwable:%s", th.toString());
        }
    }

    public final void a(String[] strArr) {
        synchronized (this.f3930x) {
            this.f3930x.clear();
            if (strArr != null && strArr.length != 0) {
                Collections.addAll(this.f3930x, strArr);
            }
        }
    }

    public final void a(String str, String str2, String str3) {
        if (!TextUtils.isEmpty(str3)) {
            if (this.C.c() >= 200) {
                this.C.b();
            }
            this.C.a(str, str2, str3);
            return;
        }
        this.C.b(str, str2);
    }

    public final void a(boolean z8) {
        if (z8) {
            this.G = true;
            if (this.E == null) {
                this.E = new String[]{"Result-Status", "Tips", "x-mgw-http-code", "Result-tips"};
            }
        }
    }

    public final void a(int i9) {
        if (i9 < 0 || i9 > 2) {
            return;
        }
        this.H = i9;
    }

    private void a(NetworkEventInfoBean networkEventInfoBean, int i9) {
        if (networkEventInfoBean == null) {
            return;
        }
        try {
            synchronized (this.D) {
                NetworkEventInfoBean networkEventInfoBean2 = null;
                com.bonree.sdk.ah.b bVar = null;
                int i10 = 0;
                while (true) {
                    if (i10 >= this.D.size()) {
                        break;
                    }
                    bVar = this.D.get(i10);
                    if (bVar == null || bVar.c() == i9 || !h.c(networkEventInfoBean.mRequestUrl, bVar.a().mRequestUrl)) {
                        i10++;
                    } else {
                        f3923q.c("type %d ,WebviewError:%s", Integer.valueOf(i9), networkEventInfoBean.mRequestUrl);
                        if (i9 == 0) {
                            networkEventInfoBean2 = g.a(networkEventInfoBean, bVar.a());
                        } else {
                            networkEventInfoBean2 = g.a(bVar.a(), networkEventInfoBean);
                        }
                    }
                }
                if (networkEventInfoBean2 != null) {
                    a(networkEventInfoBean2, true);
                    this.D.remove(bVar);
                } else {
                    if (this.D.size() > 200) {
                        a(this.D.get(0).a(), true);
                        this.D.remove(0);
                    }
                    this.D.add(new com.bonree.sdk.ah.b(networkEventInfoBean, i9));
                }
            }
        } catch (Throwable th) {
            f3923q.a("cacheWebviewList error:", th);
        }
    }

    public final void a(Message message) {
        Integer num;
        List<String> a9;
        Integer num2;
        Object obj = message.obj;
        if (obj != null || message.what == 8) {
            switch (message.what) {
                case 2:
                    com.bonree.sdk.ah.f fVar = (com.bonree.sdk.ah.f) obj;
                    try {
                        if (!this.G) {
                            synchronized (this.f3924r) {
                                if (g.a(fVar, this.f3924r, this.H)) {
                                    NetworkEventInfoBean a10 = g.a(fVar, this.f3930x, this.B, this.A, this.H);
                                    f3923q.a("WebviewError:%s", a10);
                                    a(a10);
                                }
                            }
                        } else {
                            NetworkEventInfoBean a11 = g.a(fVar, this.f3930x, this.B, this.A, this.H);
                            f3923q.a("WebviewError:%s", a11);
                            a(a11, 1);
                        }
                        return;
                    } catch (Throwable th) {
                        f3923q.e("WebviewError throwable:%s", th.toString());
                        return;
                    }
                case 3:
                    com.bonree.sdk.o.b bVar = (com.bonree.sdk.o.b) obj;
                    if (bVar != null) {
                        try {
                            if (bVar.f() == null) {
                                return;
                            }
                            f fVar2 = f3923q;
                            fVar2.c("FrameData = " + bVar, new Object[0]);
                            f fVar3 = f3923q;
                            fVar3.c("FrameData requestId = " + bVar.s(), new Object[0]);
                            com.bonree.sdk.o.e b9 = b(bVar.s(), bVar.f());
                            f fVar4 = f3923q;
                            fVar4.c("ok3EventData = " + b9, new Object[0]);
                            if (b9 != null && (TextUtils.isEmpty(bVar.j()) || !TextUtils.isEmpty(b9.a()))) {
                                if (!b9.b() && !bVar.P()) {
                                    NetworkEventInfoBean a12 = g.a(b9, this.H, this.f3930x, this.B, this.A);
                                    if (a12 == null) {
                                        return;
                                    }
                                    if (!TextUtils.isEmpty(bVar.j()) && !TextUtils.isEmpty(b9.a())) {
                                        if (!TextUtils.isEmpty(bVar.f()) && !TextUtils.equals(bVar.f(), b9.c())) {
                                            a12.mRequestUrl = bVar.f();
                                        }
                                        if (a12.mRequestDataSize == 0 && bVar.T() != 0) {
                                            a12.mRequestDataSize = bVar.T();
                                        }
                                    }
                                    a12.mIdentifier = bVar.X();
                                    a12.mCustomBusinessBody = g.a((Object) bVar.S(), this.f3931y);
                                    g.a(a12, b9.s(), this.C);
                                    g.a(bVar, a12);
                                    a(a12);
                                    synchronized (this.f3927u) {
                                        Object obj2 = this.f3927u.get(b9.x());
                                        if (obj2 != null && (obj2 instanceof com.bonree.sdk.o.e)) {
                                            this.f3927u.remove(b9.x());
                                        }
                                    }
                                    return;
                                }
                                bVar.a(true);
                                synchronized (this.f3927u) {
                                    Object obj3 = this.f3927u.get(b9.x());
                                    if (obj3 != null && (obj3 instanceof com.bonree.sdk.o.e)) {
                                        this.f3927u.remove(b9.x());
                                    }
                                }
                            }
                            NetworkEventInfoBean a13 = g.a(bVar, this.H);
                            g.a(a13, bVar, this.G, this.E);
                            if (bVar.w() != null && bVar.w().size() > 0) {
                                a13.mCustomBusinessHeader = g.a(bVar.w(), this.f3930x);
                                a13.mResponseTraceInfo = g.b(bVar.O(), this.A);
                                a13.mRequestTraceInfo = g.c(bVar.x(), this.B);
                                g.a(a13, bVar.w(), this.C);
                            } else {
                                g.a(a13, bVar.v(), this.f3930x);
                                a13.mResponseTraceInfo = g.b(bVar.O(), this.A);
                                g.a(a13, bVar.v(), this.C);
                            }
                            a13.mCustomBusinessBody = g.a((Object) bVar.S(), this.f3931y);
                            if (g.a(bVar, a13, d.a(bVar, this.f3926t), this.F && !TextUtils.isEmpty(bVar.s()))) {
                                d.a(a13, x.c(bVar.f()), bVar, this.f3926t);
                                if (this.F && !TextUtils.isEmpty(bVar.s()) && a13.mErrorCode.intValue() == 0) {
                                    f3923q.c("可能是okhttp3Event 缓存在发送", new Object[0]);
                                    synchronized (this.f3928v) {
                                        this.f3928v.put(bVar.s(), a13);
                                    }
                                    return;
                                }
                                g.a(bVar, a13);
                                if (bVar.V()) {
                                    return;
                                }
                                f3923q.a("frame data:%s", a13);
                                a(a13);
                                return;
                            }
                            return;
                        } catch (Throwable th2) {
                            f3923q.a("frame error:", th2);
                            return;
                        }
                    }
                    return;
                case 4:
                    com.bonree.sdk.o.f fVar5 = (com.bonree.sdk.o.f) obj;
                    if (fVar5 != null) {
                        try {
                            if (fVar5.b() == null) {
                                return;
                            }
                            synchronized (this.f3926t) {
                                String b10 = fVar5.b();
                                Long valueOf = Long.valueOf(fVar5.c() + fVar5.l());
                                if (b10 != null && this.f3926t.containsKey(b10) && this.f3926t.get(b10) != null) {
                                    com.bonree.sdk.m.b bVar2 = this.f3926t.get(b10);
                                    if (bVar2 == null) {
                                        return;
                                    }
                                    Map<Long, j> b11 = bVar2.b();
                                    if (b11 == null) {
                                        a(null, bVar2, null, fVar5, valueOf, b10);
                                        return;
                                    } else {
                                        a(b11, bVar2, b11.get(valueOf), fVar5, valueOf, b10);
                                        return;
                                    }
                                }
                                a(null, null, null, fVar5, valueOf, b10);
                                return;
                            }
                        } catch (Throwable th3) {
                            f3923q.a("socket save error:", th3);
                            return;
                        }
                    }
                    return;
                case 5:
                default:
                    return;
                case 6:
                    com.bonree.sdk.o.e eVar = (com.bonree.sdk.o.e) obj;
                    if (eVar != null) {
                        try {
                            if (!TextUtils.isEmpty(eVar.c()) && !TextUtils.isEmpty(eVar.x())) {
                                f3923q.c("okhttp3Event:%s", eVar);
                                this.F = true;
                                synchronized (this.f3927u) {
                                    String x8 = eVar.x();
                                    if (!this.f3927u.containsKey(x8)) {
                                        this.f3927u.put(x8, eVar);
                                    } else {
                                        Object obj4 = this.f3927u.get(x8);
                                        if (obj4 instanceof com.bonree.sdk.o.e) {
                                            if (eVar.c() != null) {
                                                HashMap hashMap = new HashMap();
                                                hashMap.put(((com.bonree.sdk.o.e) obj4).c(), obj4);
                                                if (TextUtils.equals(eVar.c(), ((com.bonree.sdk.o.e) obj4).c())) {
                                                    hashMap.put(eVar.v(), eVar);
                                                } else {
                                                    hashMap.put(eVar.c(), eVar);
                                                }
                                                this.f3927u.put(x8, hashMap);
                                            }
                                        } else if (obj4 instanceof HashMap) {
                                            if (((com.bonree.sdk.o.e) ((HashMap) obj4).get(eVar.c())) == null) {
                                                ((HashMap) obj4).put(eVar.c(), eVar);
                                            } else {
                                                ((HashMap) obj4).put(eVar.v(), eVar);
                                            }
                                        }
                                    }
                                }
                                return;
                            }
                        } catch (Throwable th4) {
                            f3923q.a("okhttp3Event error:", th4);
                            return;
                        }
                    }
                    f3923q.e("okhttp3Event is invalid :%s", eVar);
                    return;
                case 7:
                    com.bonree.sdk.o.a aVar = (com.bonree.sdk.o.a) obj;
                    if (aVar != null) {
                        NetworkEventInfoBean a14 = g.a(aVar, this.H);
                        a14.mCustomBusinessHeader = g.a(aVar.n(), this.f3930x);
                        a14.mResponseTraceInfo = g.b(aVar.o(), this.A);
                        a14.mRequestTraceInfo = g.c(aVar.n(), this.B);
                        g.a(a14, aVar.n(), this.C);
                        if (aVar.o() != null && aVar.o().size() > 0) {
                            String a15 = x.a(aVar.o());
                            if (!TextUtils.isEmpty(a15)) {
                                a14.mTraceId = a15;
                            }
                            String b12 = x.b(aVar.o());
                            if (!TextUtils.isEmpty(b12)) {
                                a14.xBrResponse = b12;
                            }
                            String c9 = x.c(aVar.o());
                            if (!TextUtils.isEmpty(c9)) {
                                a14.traceResponse = c9;
                            }
                        }
                        g.a(aVar, a14);
                        a(a14);
                        return;
                    }
                    return;
                case 8:
                    try {
                        e.a.f3940a.b(8);
                        long b13 = com.bonree.sdk.c.a.b();
                        a(b13);
                        b(b13);
                        e(b13);
                        d(b13);
                        c(b13);
                        e.a.f3940a.a(8, MoLocationOption.LOC_DELAY_TIME);
                        return;
                    } catch (Throwable th5) {
                        f3923q.c("timer exception:", th5);
                        return;
                    }
                case 9:
                    b((NetworkEventInfoBean) obj);
                    return;
                case 10:
                    com.bonree.sdk.o.b bVar3 = (com.bonree.sdk.o.b) obj;
                    if (bVar3 != null) {
                        try {
                            if (bVar3.f() == null) {
                                return;
                            }
                            NetworkEventInfoBean a16 = g.a(bVar3, this.f3929w, this.H);
                            a16.mCustomBusinessHeader = g.a(bVar3.w(), this.f3930x);
                            a16.mCustomBusinessQuery = g.a(a16.mRequestUrl, this.f3932z);
                            a16.mResponseTraceInfo = g.b(bVar3.O(), this.A);
                            a16.mRequestTraceInfo = g.c(bVar3.w(), this.B);
                            String d9 = x.d(bVar3.d());
                            if (!TextUtils.isEmpty(d9)) {
                                a16.mTraceId = d9;
                            }
                            String e9 = x.e(bVar3.d());
                            if (!TextUtils.isEmpty(e9)) {
                                a16.xBrResponse = e9;
                            }
                            String f9 = x.f(bVar3.d());
                            if (!TextUtils.isEmpty(f9)) {
                                a16.traceResponse = f9;
                            }
                            EventBean eventBean = new EventBean();
                            eventBean.mEventType = BaseEventInfo.EVENT_TYPE_NETWORK;
                            long R = bVar3.R() * 1000;
                            eventBean.mEventTime = R;
                            if (R < 0) {
                                this.I.getAndIncrement();
                            } else if (this.I.get() > 0) {
                                j();
                            }
                            eventBean.mStateIndex = eventBean.getStateIndex();
                            eventBean.mEventInfo = a16;
                            g.a(eventBean, a16);
                            synchronized (this.f3924r) {
                                if (this.f3924r.size() >= f3922p) {
                                    this.f3924r.remove(0);
                                }
                                eventBean.uploadStateKey();
                                this.f3924r.add(eventBean);
                            }
                            f3923q.c("network flutter eventBean :%s", eventBean);
                            return;
                        } catch (Exception e10) {
                            f3923q.a("constructFlutterNetworkData error:", e10);
                            return;
                        }
                    }
                    return;
                case 11:
                    com.bonree.sdk.ah.k kVar = (com.bonree.sdk.ah.k) obj;
                    int f10 = kVar.f();
                    for (EventBean eventBean2 : com.bonree.sdk.bi.i.a(kVar.a(), BaseEventInfo.EVENT_TYPE_NETWORK)) {
                        NetworkEventInfoBean networkEventInfoBean = (NetworkEventInfoBean) eventBean2.mEventInfo;
                        if (!networkEventInfoBean.isCustom) {
                            String l9 = af.l(networkEventInfoBean.mRequestUrl);
                            if ((TextUtils.isEmpty(networkEventInfoBean.mTargetIp) || "0".equals(networkEventInfoBean.mTargetIp)) && (num = networkEventInfoBean.mErrorCode) != null && !h.a(num.intValue())) {
                                String[] b14 = h.b(networkEventInfoBean.mRequestUrl, l9);
                                if (!TextUtils.isEmpty(b14[0])) {
                                    networkEventInfoBean.mTargetIp = b14[0];
                                }
                                networkEventInfoBean.mTargetPort = Integer.parseInt(b14[1]);
                            }
                            if (!TextUtils.isEmpty(networkEventInfoBean.mRequestUrl) && !TextUtils.isEmpty(networkEventInfoBean.mTargetIp) && networkEventInfoBean.mRequestUrl.contains(networkEventInfoBean.mTargetIp)) {
                                networkEventInfoBean.mDnsTimeUs = 0;
                            } else if (!af.b(l9) && (a9 = h.a(l9, this.f3929w)) != null && !a9.isEmpty()) {
                                networkEventInfoBean.mCNameArray = a9;
                            }
                            if (networkEventInfoBean.mErrorCode.intValue() >= 400 || (((num2 = networkEventInfoBean.mErrorOccurrentProcess) != null && num2.intValue() > 0) || (!TextUtils.isEmpty(networkEventInfoBean.mErrorMsg) && !networkEventInfoBean.mErrorMsg.equals("null")))) {
                                eventBean2.mTraceInfoList = com.bonree.sdk.be.c.h().f();
                            }
                            if (f10 == 1) {
                                networkEventInfoBean.mCustomBusinessHeader = g.a(kVar.c(), this.f3930x);
                                networkEventInfoBean.mCustomBusinessBody = g.a((Object) kVar.d(), this.f3931y);
                                networkEventInfoBean.mCustomBusinessQuery = g.a(networkEventInfoBean.mRequestUrl, this.f3932z);
                            }
                            if (this.G && (f10 == 1 || f10 == 2)) {
                                networkEventInfoBean.startTime = -eventBean2.mEventTime;
                                a(networkEventInfoBean, 0);
                                f3923q.c("addCacheResultList=network : %s", eventBean2);
                                return;
                            }
                        }
                        eventBean2.mEventTime = -eventBean2.mEventTime;
                        this.I.getAndIncrement();
                        eventBean2.mEventInfo = networkEventInfoBean;
                        eventBean2.mStateIndex = eventBean2.getStateIndex();
                        synchronized (this.f3924r) {
                            if (this.f3924r.size() >= f3922p) {
                                this.f3924r.remove(0);
                            }
                            eventBean2.uploadStateKey();
                            this.f3924r.add(eventBean2);
                            f3923q.c("eventBean=network : %s", eventBean2);
                        }
                    }
                    return;
            }
        }
    }
}