ChatOn v1.35.366360版本的 MD5 值为:cde28447b38d5467efa95e48e7076155

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


package s9;

import android.content.Context;
import android.location.Location;
import android.os.Build;
import android.util.Log;
import android.util.Pair;
import com.amplitude.api.AmplitudeServerZone;
import com.amplitude.api.CursorWindowAllocationException;
import com.itextpdf.text.Meta;
import com.itextpdf.text.pdf.PdfObject;
import com.itextpdf.text.xml.xmp.DublinCoreProperties;
import ec.k0;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import kotlin.jvm.internal.Intrinsics;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public final class l {
    public static final m S = m.f19374c;
    public final long A;
    public final long B;
    public boolean C;
    public int D;
    public boolean E;
    public boolean F;
    public boolean G;
    public boolean H;
    public final boolean I;
    public final String J;
    public final String K;
    public final AtomicBoolean L;
    public final AtomicBoolean M;
    public final String N;
    public final u O;
    public final u P;
    public final r9.a Q;
    public final n9.b R;
    public Context f19348a;
    public vk.i f19349b;
    public n f19350c;
    public String f19351d;
    public final String f19352e;
    public String f19353f;
    public String f19354g;
    public boolean f19355h = false;
    public boolean f19356i = false;
    public final s f19357j;
    public final JSONObject f19358k;
    public final boolean f19359l;
    public r f19360m;
    public String f19361n;
    public long f19362o;
    public long f19363p;
    public long f19364q;
    public long f19365r;
    public long f19366s;
    public long f19367t;
    public p f19368u;
    public final int f19369v;
    public final int f19370w;
    public final int f19371x;
    public final long f19372y;
    public final long f19373z;

    public l(String str) {
        r9.a aVar;
        s sVar = new s();
        s sVar2 = new s();
        Iterator it = sVar.f19413a.iterator();
        while (it.hasNext()) {
            sVar2.f19413a.add((String) it.next());
        }
        this.f19357j = sVar2;
        JSONObject jSONObject = new JSONObject();
        HashSet hashSet = sVar2.f19413a;
        if (!hashSet.isEmpty()) {
            String[] strArr = s.f19412b;
            for (int i10 = 0; i10 < 6; i10++) {
                String str2 = strArr[i10];
                if (hashSet.contains(str2)) {
                    try {
                        jSONObject.put(str2, false);
                    } catch (JSONException e10) {
                        m mVar = m.f19374c;
                        m.f19374c.a("s9.s", e10.toString());
                    }
                }
            }
        }
        this.f19358k = jSONObject;
        this.f19359l = true;
        AmplitudeServerZone amplitudeServerZone = AmplitudeServerZone.f5579d;
        this.f19362o = -1L;
        this.f19363p = 0L;
        this.f19364q = -1L;
        this.f19365r = -1L;
        this.f19366s = -1L;
        this.f19367t = -1L;
        this.f19369v = 30;
        this.f19370w = 50;
        this.f19371x = 1000;
        this.f19372y = 30000L;
        this.f19373z = 300000L;
        this.A = 30000L;
        this.B = 1800000L;
        this.C = false;
        this.D = 50;
        this.E = false;
        this.F = false;
        this.G = false;
        this.H = false;
        this.I = true;
        this.J = "amplitude-android";
        this.K = "2.39.7";
        this.L = new AtomicBoolean(false);
        this.M = new AtomicBoolean(false);
        this.N = "https://api2.amplitude.com/";
        u uVar = new u("logThread");
        this.O = uVar;
        u uVar2 = new u("httpThread");
        this.P = uVar2;
        this.R = new n9.b(10);
        String instanceName = t.d(str);
        this.f19352e = instanceName;
        uVar.start();
        uVar2.start();
        Object obj = r9.a.f18997c;
        Intrinsics.checkNotNullParameter(instanceName, "instanceName");
        synchronized (r9.a.f18997c) {
            try {
                LinkedHashMap linkedHashMap = r9.a.f18998d;
                Object obj2 = linkedHashMap.get(instanceName);
                if (obj2 == null) {
                    obj2 = new r9.a();
                    linkedHashMap.put(instanceName, obj2);
                }
                aVar = (r9.a) obj2;
            } catch (Throwable th2) {
                throw th2;
            }
        }
        this.Q = aVar;
    }

    public static Pair h(LinkedList linkedList, LinkedList linkedList2, long j10) {
        long j11;
        long j12;
        JSONArray jSONArray = new JSONArray();
        long j13 = -1;
        long j14 = -1;
        while (true) {
            if (jSONArray.length() >= j10) {
                break;
            }
            boolean isEmpty = linkedList.isEmpty();
            boolean isEmpty2 = linkedList2.isEmpty();
            if (isEmpty && isEmpty2) {
                S.c("s9.l", String.format("mergeEventsAndIdentifys: number of events and identifys less than expected by %d", Long.valueOf(j10 - jSONArray.length())));
                break;
            }
            if (isEmpty2) {
                JSONObject jSONObject = (JSONObject) linkedList.remove(0);
                j11 = jSONObject.getLong("event_id");
                jSONArray.put(jSONObject);
            } else {
                if (isEmpty) {
                    JSONObject jSONObject2 = (JSONObject) linkedList2.remove(0);
                    j12 = jSONObject2.getLong("event_id");
                    jSONArray.put(jSONObject2);
                } else if (!((JSONObject) linkedList.get(0)).has("sequence_number") || ((JSONObject) linkedList.get(0)).getLong("sequence_number") < ((JSONObject) linkedList2.get(0)).getLong("sequence_number")) {
                    JSONObject jSONObject3 = (JSONObject) linkedList.remove(0);
                    j11 = jSONObject3.getLong("event_id");
                    jSONArray.put(jSONObject3);
                } else {
                    JSONObject jSONObject4 = (JSONObject) linkedList2.remove(0);
                    j12 = jSONObject4.getLong("event_id");
                    jSONArray.put(jSONObject4);
                }
                j14 = j12;
            }
            j13 = j11;
        }
        return new Pair(new Pair(Long.valueOf(j13), Long.valueOf(j14)), jSONArray);
    }

    public static JSONArray p(JSONArray jSONArray) {
        for (int i10 = 0; i10 < jSONArray.length(); i10++) {
            Object obj = jSONArray.get(i10);
            if (obj.getClass().equals(String.class)) {
                String str = (String) obj;
                if (str.length() > 1024) {
                    str = str.substring(0, 1024);
                }
                jSONArray.put(i10, str);
            } else if (obj.getClass().equals(JSONObject.class)) {
                jSONArray.put(i10, q((JSONObject) obj));
            } else if (obj.getClass().equals(JSONArray.class)) {
                JSONArray jSONArray2 = (JSONArray) obj;
                p(jSONArray2);
                jSONArray.put(i10, jSONArray2);
            }
        }
        return jSONArray;
    }

    public static JSONObject q(JSONObject jSONObject) {
        Object obj;
        if (jSONObject == null) {
            return new JSONObject();
        }
        int length = jSONObject.length();
        m mVar = S;
        if (length > 1000) {
            mVar.c("s9.l", "Warning: too many properties (more than 1000), ignoring");
            return new JSONObject();
        }
        Iterator<String> keys = jSONObject.keys();
        while (keys.hasNext()) {
            String next = keys.next();
            try {
                obj = jSONObject.get(next);
            } catch (JSONException e10) {
                mVar.a("s9.l", e10.toString());
            }
            if (!next.equals("$receipt") && !next.equals("$receiptSig")) {
                if (obj.getClass().equals(String.class)) {
                    String str = (String) obj;
                    if (str.length() > 1024) {
                        str = str.substring(0, 1024);
                    }
                    jSONObject.put(next, str);
                } else if (obj.getClass().equals(JSONObject.class)) {
                    jSONObject.put(next, q((JSONObject) obj));
                } else if (obj.getClass().equals(JSONArray.class)) {
                    JSONArray jSONArray = (JSONArray) obj;
                    p(jSONArray);
                    jSONObject.put(next, jSONArray);
                }
            }
            jSONObject.put(next, obj);
        }
        return jSONObject;
    }

    public final synchronized boolean a(String str) {
        if (this.f19348a == null) {
            m mVar = S;
            mVar.a("s9.l", "context cannot be null, set context with initialize() before calling " + str);
            return false;
        } else if (t.c(this.f19351d)) {
            m mVar2 = S;
            mVar2.a("s9.l", "apiKey cannot be null or empty, set apiKey with initialize() before calling " + str);
            return false;
        } else {
            return true;
        }
    }

    public final long b(String str, long j10) {
        Long l10;
        n nVar = this.f19350c;
        synchronized (nVar) {
            l10 = (Long) nVar.h0("long_store", str);
        }
        return l10 == null ? j10 : l10.longValue();
    }

    public final String c() {
        String str;
        HashSet hashSet = new HashSet();
        hashSet.add(PdfObject.NOTHING);
        hashSet.add("9774d56d682e549c");
        hashSet.add(Meta.UNKNOWN);
        hashSet.add("000000000000000");
        hashSet.add("Android");
        hashSet.add("DEFACE");
        hashSet.add("00000000-0000-0000-0000-000000000000");
        n nVar = this.f19350c;
        synchronized (nVar) {
            str = (String) nVar.h0("store", "device_id");
        }
        if (t.c(str) || hashSet.contains(str) || str.endsWith("S")) {
            String str2 = UUID.randomUUID().toString() + "R";
            this.f19350c.l0("device_id", str2);
            return str2;
        }
        return str;
    }

    public final synchronized void d(Context context) {
        if (t.c("3bc305f2e3b1f3b368d18e6e36feccf3")) {
            S.a("s9.l", "Argument apiKey cannot be null or blank in initialize()");
            return;
        }
        Context applicationContext = context.getApplicationContext();
        this.f19348a = applicationContext;
        this.f19351d = "3bc305f2e3b1f3b368d18e6e36feccf3";
        this.f19350c = n.v(applicationContext, this.f19352e);
        this.f19361n = t.c(null) ? "Android" : null;
        j(new c(this, this));
    }

    public final long e(String str, JSONObject jSONObject, JSONObject jSONObject2, JSONObject jSONObject3, JSONObject jSONObject4, JSONObject jSONObject5, long j10, boolean z8, boolean z10) {
        Object obj;
        long j11;
        JSONException e10;
        Location c10;
        m mVar = S;
        String k10 = k0.k("Logged event to Amplitude: ", str);
        if (mVar.f19375a && mVar.f19376b <= 3) {
            Log.d("s9.l", k10);
        }
        if (this.f19356i) {
            return -1L;
        }
        if ((!this.F || (!str.equals("session_start") && !str.equals("session_end"))) && !z8) {
            if (!z10 || this.H) {
                this.H = false;
                o(j10);
            } else {
                i(j10);
            }
        }
        JSONObject jSONObject6 = new JSONObject();
        if (str == null) {
            try {
                obj = JSONObject.NULL;
            } catch (JSONException e11) {
                e10 = e11;
                j11 = -1;
                S.a("s9.l", String.format("JSON Serialization of event type %s failed, skipping: %s", str, e10.toString()));
                return j11;
            }
        } else {
            obj = str;
        }
        jSONObject6.put("event_type", obj);
        jSONObject6.put("timestamp", j10);
        Object obj2 = this.f19353f;
        if (obj2 == null) {
            obj2 = JSONObject.NULL;
        }
        jSONObject6.put("user_id", obj2);
        Object obj3 = this.f19354g;
        if (obj3 == null) {
            obj3 = JSONObject.NULL;
        }
        jSONObject6.put("device_id", obj3);
        jSONObject6.put("session_id", z8 ? -1L : this.f19362o);
        jSONObject6.put("uuid", UUID.randomUUID().toString());
        long j12 = this.f19363p + 1;
        this.f19363p = j12;
        this.f19350c.k0("sequence_number", Long.valueOf(j12));
        jSONObject6.put("sequence_number", this.f19363p);
        if (this.f19357j.a("version_name")) {
            Object obj4 = this.f19368u.a().f19384c;
            if (obj4 == null) {
                obj4 = JSONObject.NULL;
            }
            jSONObject6.put("version_name", obj4);
        }
        if (this.f19357j.a("os_name")) {
            Object obj5 = this.f19368u.a().f19385d;
            if (obj5 == null) {
                obj5 = JSONObject.NULL;
            }
            jSONObject6.put("os_name", obj5);
        }
        if (this.f19357j.a("os_version")) {
            Object obj6 = this.f19368u.a().f19386e;
            if (obj6 == null) {
                obj6 = JSONObject.NULL;
            }
            jSONObject6.put("os_version", obj6);
        }
        if (this.f19357j.a("api_level")) {
            Object valueOf = Integer.valueOf(Build.VERSION.SDK_INT);
            if (valueOf == null) {
                valueOf = JSONObject.NULL;
            }
            jSONObject6.put("api_level", valueOf);
        }
        if (this.f19357j.a("device_brand")) {
            Object obj7 = this.f19368u.a().f19387f;
            if (obj7 == null) {
                obj7 = JSONObject.NULL;
            }
            jSONObject6.put("device_brand", obj7);
        }
        if (this.f19357j.a("device_manufacturer")) {
            Object obj8 = this.f19368u.a().f19388g;
            if (obj8 == null) {
                obj8 = JSONObject.NULL;
            }
            jSONObject6.put("device_manufacturer", obj8);
        }
        if (this.f19357j.a("device_model")) {
            Object obj9 = this.f19368u.a().f19389h;
            if (obj9 == null) {
                obj9 = JSONObject.NULL;
            }
            jSONObject6.put("device_model", obj9);
        }
        if (this.f19357j.a("carrier")) {
            Object obj10 = this.f19368u.a().f19390i;
            if (obj10 == null) {
                obj10 = JSONObject.NULL;
            }
            jSONObject6.put("carrier", obj10);
        }
        if (this.f19357j.a("country")) {
            Object obj11 = this.f19368u.a().f19383b;
            if (obj11 == null) {
                obj11 = JSONObject.NULL;
            }
            jSONObject6.put("country", obj11);
        }
        if (this.f19357j.a(DublinCoreProperties.LANGUAGE)) {
            Object obj12 = this.f19368u.a().f19391j;
            if (obj12 == null) {
                obj12 = JSONObject.NULL;
            }
            jSONObject6.put(DublinCoreProperties.LANGUAGE, obj12);
        }
        if (this.f19357j.a("platform")) {
            jSONObject6.put("platform", this.f19361n);
        }
        JSONObject jSONObject7 = new JSONObject();
        String str2 = this.J;
        if (str2 == null) {
            str2 = "unknown-library";
        }
        jSONObject7.put("name", str2);
        String str3 = this.K;
        if (str3 == null) {
            str3 = "unknown-version";
        }
        jSONObject7.put("version", str3);
        jSONObject6.put("library", jSONObject7);
        JSONObject jSONObject8 = jSONObject2 == null ? new JSONObject() : jSONObject2;
        JSONObject jSONObject9 = this.f19358k;
        if (jSONObject9 != null && jSONObject9.length() > 0) {
            jSONObject8.put("tracking_options", this.f19358k);
        }
        if (this.f19357j.a("lat_lng") && (c10 = this.f19368u.c()) != null) {
            JSONObject jSONObject10 = new JSONObject();
            jSONObject10.put("lat", c10.getLatitude());
            jSONObject10.put("lng", c10.getLongitude());
            jSONObject8.put("location", jSONObject10);
        }
        if (this.f19357j.a("adid") && this.f19368u.a().f19382a != null) {
            jSONObject8.put("androidADID", this.f19368u.a().f19382a);
        }
        if (this.f19357j.a("app_set_id") && this.f19368u.a().f19394m != null) {
            jSONObject8.put("android_app_set_id", this.f19368u.a().f19394m);
        }
        jSONObject8.put("limit_ad_tracking", this.f19368u.a().f19392k);
        jSONObject8.put("gps_enabled", this.f19368u.a().f19393l);
        jSONObject6.put("api_properties", jSONObject8);
        jSONObject6.put("event_properties", jSONObject == null ? new JSONObject() : q(jSONObject));
        jSONObject6.put("user_properties", jSONObject3 == null ? new JSONObject() : q(jSONObject3));
        jSONObject6.put("groups", jSONObject4 == null ? new JSONObject() : q(jSONObject4));
        jSONObject6.put("group_properties", jSONObject5 == null ? new JSONObject() : q(jSONObject5));
        j11 = k(str, jSONObject6);
        try {
            if (str.equals("$identify") && jSONObject3 != null) {
                r9.e eVar = this.Q.f18999a;
                ReentrantReadWriteLock.ReadLock readLock = eVar.f19010a.readLock();
                readLock.lock();
                r9.c cVar = eVar.f19011b;
                readLock.unlock();
                r9.d dVar = new r9.d(cVar, eVar);
                dVar.a(com.bumptech.glide.d.j(jSONObject3));
                eVar.a(new r9.c(dVar.f19009c, dVar.f19007a, dVar.f19008b));
            }
        } catch (JSONException e12) {
            e10 = e12;
            S.a("s9.l", String.format("JSON Serialization of event type %s failed, skipping: %s", str, e10.toString()));
            return j11;
        }
        return j11;
    }

    public final void f(JSONObject jSONObject, String str) {
        long currentTimeMillis = System.currentTimeMillis();
        if (t.c(str)) {
            S.a("s9.l", "Argument eventType cannot be null or blank in logEvent()");
        } else if (a("logEvent()")) {
            g(str, jSONObject, null, currentTimeMillis);
        }
    }

    public final void g(String str, JSONObject jSONObject, JSONObject jSONObject2, long j10) {
        j(new i(this, str, jSONObject != null ? t.b(jSONObject) : jSONObject, null, jSONObject2 != null ? t.b(jSONObject2) : jSONObject2, null, null, j10, this.G));
    }

    public final void i(long j10) {
        if (this.f19362o >= 0) {
            this.f19366s = j10;
            this.f19350c.k0("last_event_time", Long.valueOf(j10));
        }
    }

    public final void j(Runnable runnable) {
        Thread currentThread = Thread.currentThread();
        u uVar = this.O;
        if (currentThread == uVar) {
            runnable.run();
            return;
        }
        uVar.a();
        uVar.f19415d.post(runnable);
    }

    public final long k(String str, JSONObject jSONObject) {
        r rVar;
        long b2;
        String str2;
        n9.b bVar = this.R;
        wf.a aVar = new wf.a(jSONObject, 13, (Object) null);
        bVar.getClass();
        boolean z8 = false;
        AtomicBoolean atomicBoolean = new AtomicBoolean(false);
        wf.a aVar2 = new wf.a(bVar, atomicBoolean, 14);
        ArrayList arrayList = new ArrayList((ConcurrentLinkedQueue) bVar.f16836e);
        if (arrayList.size() != 0) {
            androidx.activity.h.w(arrayList.get(0));
            throw null;
        }
        aVar2.B(aVar);
        if (!atomicBoolean.get()) {
            return -1L;
        }
        if (t.c(jSONObject.toString())) {
            S.a("s9.l", String.format("Detected empty event string for event type %s, skipping", str));
            return -1L;
        }
        rVar = this.f19360m;
        rVar.getClass();
        if (rVar.f19411i.getAndSet(true)) {
            String str3 = rVar.f19409g;
            String string = jSONObject.getString("user_id");
            if (str3 == null) {
                if (string == null) {
                    str2 = rVar.f19410h;
                    String string2 = jSONObject.getString("device_id");
                    if (str2 == null) {
                        if (string2 == null) {
                            if (z8) {
                            }
                            if (str.equals("$identify")) {
                                if (r.a(jSONObject, "$set")) {
                                }
                                if (r.a(jSONObject, "$clearAll")) {
                                    n nVar = rVar.f19403a;
                                    long j10 = rVar.f19407e;
                                    synchronized (nVar) {
                                        nVar.q0("identify_interceptor", j10);
                                    }
                                } else {
                                    rVar.c();
                                }
                            } else if (!str.equals("$groupidentify")) {
                                rVar.c();
                            }
                            if (jSONObject != null) {
                                return -1L;
                            }
                            return l(jSONObject, str);
                        }
                    }
                    if (str2 != null) {
                        if (string2 == null) {
                            if (!(!str2.equals(string2))) {
                            }
                            if (z8) {
                            }
                            if (str.equals("$identify")) {
                            }
                            if (jSONObject != null) {
                            }
                        }
                    }
                    rVar.f19410h = jSONObject.getString("device_id");
                }
            }
            if (str3 != null) {
                if (string == null) {
                }
            }
            rVar.f19409g = jSONObject.getString("user_id");
            z8 = true;
            str2 = rVar.f19410h;
            String string22 = jSONObject.getString("device_id");
            if (str2 == null) {
            }
            if (str2 != null) {
            }
            rVar.f19410h = jSONObject.getString("device_id");
        } else {
            rVar.f19409g = jSONObject.getString("user_id");
            rVar.f19410h = jSONObject.getString("device_id");
        }
        rVar.c();
        if (str.equals("$identify")) {
        }
        if (jSONObject != null) {
        }
        n nVar2 = rVar.f19403a;
        String jSONObject2 = jSONObject.toString();
        synchronized (nVar2) {
            b2 = nVar2.b("identify_interceptor", jSONObject2);
        }
        rVar.f19407e = b2;
        if (!rVar.f19406d.getAndSet(true)) {
            androidx.activity.n nVar3 = new androidx.activity.n(14, rVar);
            long j11 = rVar.f19405c;
            u uVar = rVar.f19404b;
            uVar.a();
            uVar.f19415d.postDelayed(nVar3, j11);
        }
        jSONObject = null;
        if (jSONObject != null) {
        }
    }

    public final long l(JSONObject jSONObject, String str) {
        long b2;
        long y10;
        long y11;
        long f02;
        long f03;
        long b10;
        String jSONObject2 = jSONObject.toString();
        if (str.equals("$identify") || str.equals("$groupidentify")) {
            n nVar = this.f19350c;
            synchronized (nVar) {
                b2 = nVar.b("identifys", jSONObject2);
            }
            this.f19365r = b2;
            this.f19350c.k0("last_identify_id", Long.valueOf(b2));
        } else {
            n nVar2 = this.f19350c;
            synchronized (nVar2) {
                b10 = nVar2.b("events", jSONObject2);
            }
            this.f19364q = b10;
            this.f19350c.k0("last_event_id", Long.valueOf(b10));
        }
        int min = Math.min(Math.max(1, this.f19371x / 10), 20);
        n nVar3 = this.f19350c;
        synchronized (nVar3) {
            y10 = nVar3.y("events");
        }
        if (y10 > this.f19371x) {
            n nVar4 = this.f19350c;
            long j10 = min;
            synchronized (nVar4) {
                synchronized (nVar4) {
                    f03 = nVar4.f0(j10, "events", "ASC");
                }
                synchronized (nVar4) {
                    nVar4.q0("events", f03);
                }
            }
            synchronized (nVar4) {
            }
        }
        n nVar5 = this.f19350c;
        synchronized (nVar5) {
            y11 = nVar5.y("identifys");
        }
        if (y11 > this.f19371x) {
            n nVar6 = this.f19350c;
            long j11 = min;
            synchronized (nVar6) {
                synchronized (nVar6) {
                    f02 = nVar6.f0(j11, "identifys", "ASC");
                }
                synchronized (nVar6) {
                    nVar6.q0("identifys", f02);
                }
            }
            synchronized (nVar6) {
            }
        }
        long g02 = this.f19350c.g0();
        long j12 = this.f19369v;
        if (g02 % j12 != 0 || g02 < j12) {
            long j13 = this.f19372y;
            if (!this.L.getAndSet(true)) {
                f fVar = new f(this, 0);
                u uVar = this.O;
                uVar.a();
                uVar.f19415d.postDelayed(fVar, j13);
            }
        } else {
            r(false);
        }
        return (str.equals("$identify") || str.equals("$groupidentify")) ? this.f19365r : this.f19364q;
    }

    public final void m(String str) {
        if (a(String.format("sendSessionEvent('%s')", str)) && this.f19362o >= 0) {
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.put("special", str);
                e(str, null, jSONObject, null, null, null, this.f19366s, false, false);
            } catch (JSONException unused) {
            }
        }
    }

    public final void n(long j10) {
        if (this.F) {
            m("session_end");
        }
        this.f19362o = j10;
        this.f19367t = j10;
        this.f19350c.k0("previous_session_id", Long.valueOf(j10));
        i(j10);
        if (this.F) {
            m("session_start");
        }
    }

    public final void o(long j10) {
        if (this.f19362o >= 0) {
            if (j10 - this.f19366s < (this.E ? this.f19373z : this.B)) {
                i(j10);
                return;
            } else {
                n(j10);
                return;
            }
        }
        if (j10 - this.f19366s >= (this.E ? this.f19373z : this.B)) {
            n(j10);
            return;
        }
        long j11 = this.f19367t;
        if (j11 == -1) {
            n(j10);
            return;
        }
        this.f19362o = j11;
        this.f19367t = j11;
        this.f19350c.k0("previous_session_id", Long.valueOf(j11));
        i(j10);
    }

    public final void r(boolean z8) {
        LinkedList d02;
        LinkedList d03;
        if (this.f19356i || this.M.getAndSet(true)) {
            return;
        }
        long min = Math.min(z8 ? this.D : this.f19370w, this.f19350c.g0());
        if (min <= 0) {
            this.M.set(false);
            return;
        }
        try {
            n nVar = this.f19350c;
            long j10 = this.f19364q;
            synchronized (nVar) {
                d02 = nVar.d0("events", j10, min);
            }
            n nVar2 = this.f19350c;
            long j11 = this.f19365r;
            synchronized (nVar2) {
                d03 = nVar2.d0("identifys", j11, min);
            }
            Pair h10 = h(d02, d03, min);
            if (((JSONArray) h10.second).length() == 0) {
                this.M.set(false);
                return;
            }
            long longValue = ((Long) ((Pair) h10.first).first).longValue();
            long longValue2 = ((Long) ((Pair) h10.first).second).longValue();
            String jSONArray = ((JSONArray) h10.second).toString();
            u uVar = this.P;
            g gVar = new g(this, jSONArray, longValue, longValue2);
            uVar.a();
            uVar.f19415d.post(gVar);
        } catch (CursorWindowAllocationException e10) {
            this.M.set(false);
            S.a("s9.l", String.format("Caught Cursor window exception during event upload, deferring upload: %s", e10.getMessage()));
        } catch (JSONException e11) {
            this.M.set(false);
            S.a("s9.l", e11.toString());
        }
    }
}