导航菜单

页面标题

页面副标题

Crafto v9.3.3 - h.java 源代码

正在查看: Crafto v9.3.3 应用的 h.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package z5;

import android.content.Context;
import android.location.Location;
import android.os.Build;
import android.util.Log;
import android.util.Pair;
import com.amplitude.api.CursorWindowAllocationException;
import com.android.volley.toolbox.ImageRequest;
import com.appsflyer.AdRevenueScheme;
import com.cashfree.pg.core.api.ui.CashfreeCoreNativeVerificationActivity;
import com.crafto.android.CraftoApp;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import kotlin.jvm.internal.Intrinsics;
import okhttp3.Call;
import okhttp3.Request;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import x5.C2802a;
import x5.C2805d;
import x5.C2806e;
import x5.C2807f;
import y5.C2844a;

public final class h {

    public static final r f28252S = r.f28327a;

    public final long f28253A;

    public final long f28254B;

    public boolean f28255C;

    public int f28256D;

    public boolean f28257E;

    public boolean f28258F;

    public boolean f28259G;

    public boolean f28260H;

    public final boolean f28261I;

    public final String f28262J;

    public final String f28263K;

    public final AtomicBoolean f28264L;

    public final AtomicBoolean f28265M;

    public final String f28266N;

    public final E f28267O;

    public final E f28268P;

    public final C2802a f28269Q;

    public final q9.h f28270R;

    public Context f28271a;

    public Call.Factory f28272b;

    public t f28273c;
    public String d;

    public final String f28274e;

    public String f28275f;

    public String f28276g;

    public boolean f28277h;

    public boolean f28278i;

    public final C f28279j;

    public final JSONObject f28280k;

    public final boolean f28281l;

    public z f28282m;

    public String f28283n;

    public long f28284o;

    public long f28285p;

    public long f28286q;

    public long f28287r;

    public long f28288s;

    public long f28289t;

    public w f28290u;

    public final int f28291v;

    public final int f28292w;

    public final int f28293x;

    public final long f28294y;

    public final long f28295z;

    public class a implements Runnable {

        public final String f28296a;

        public final long f28297b;

        public final long f28298c;

        public a(String str, long j7, long j8) {
            this.f28296a = str;
            this.f28297b = j7;
            this.f28298c = j8;
        }

        @Override
        public final void run() {
            throw new UnsupportedOperationException("Method not decompiled: z5.h.a.run():void");
        }
    }

    public h() {
        this(null);
    }

    public static HashSet b() {
        HashSet hashSet = new HashSet();
        hashSet.add("");
        hashSet.add("9774d56d682e549c");
        hashSet.add("unknown");
        hashSet.add("000000000000000");
        hashSet.add(CashfreeCoreNativeVerificationActivity.WB_INTENT_BRIDGE);
        hashSet.add("DEFACE");
        hashSet.add("00000000-0000-0000-0000-000000000000");
        return hashSet;
    }

    public static Pair l(LinkedList linkedList, LinkedList linkedList2, long j7) throws JSONException {
        long j8;
        long j9;
        JSONArray jSONArray = new JSONArray();
        long j10 = -1;
        long j11 = -1;
        while (true) {
            if (jSONArray.length() >= j7) {
                break;
            }
            boolean isEmpty = linkedList.isEmpty();
            boolean isEmpty2 = linkedList2.isEmpty();
            if (isEmpty && isEmpty2) {
                String format = String.format("mergeEventsAndIdentifys: number of events and identifys less than expected by %d", Long.valueOf(j7 - jSONArray.length()));
                f28252S.getClass();
                Log.w("z5.h", format);
                break;
            }
            if (isEmpty2) {
                JSONObject jSONObject = (JSONObject) linkedList.remove(0);
                j8 = jSONObject.getLong("event_id");
                jSONArray.put(jSONObject);
            } else {
                if (isEmpty) {
                    JSONObject jSONObject2 = (JSONObject) linkedList2.remove(0);
                    j9 = 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);
                    j8 = jSONObject3.getLong("event_id");
                    jSONArray.put(jSONObject3);
                } else {
                    JSONObject jSONObject4 = (JSONObject) linkedList2.remove(0);
                    j9 = jSONObject4.getLong("event_id");
                    jSONArray.put(jSONObject4);
                }
                j11 = j9;
            }
            j10 = j8;
        }
        return new Pair(new Pair(Long.valueOf(j10), Long.valueOf(j11)), jSONArray);
    }

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

    public static JSONObject w(JSONObject jSONObject) {
        Object obj;
        if (jSONObject == null) {
            return new JSONObject();
        }
        int length = jSONObject.length();
        r rVar = f28252S;
        if (length > 1000) {
            rVar.getClass();
            Log.w("z5.h", "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 e8) {
                String obj2 = e8.toString();
                rVar.getClass();
                Log.e("z5.h", obj2);
            }
            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, w((JSONObject) obj));
                } else if (obj.getClass().equals(JSONArray.class)) {
                    JSONArray jSONArray = (JSONArray) obj;
                    v(jSONArray);
                    jSONObject.put(next, jSONArray);
                }
            }
            jSONObject.put(next, obj);
        }
        return jSONObject;
    }

    public final synchronized boolean a(String str) {
        if (this.f28271a == null) {
            r rVar = f28252S;
            String concat = "context cannot be null, set context with initialize() before calling ".concat(str);
            rVar.getClass();
            Log.e("z5.h", concat);
            return false;
        }
        if (!D.d(this.d)) {
            return true;
        }
        r rVar2 = f28252S;
        String concat2 = "apiKey cannot be null or empty, set apiKey with initialize() before calling ".concat(str);
        rVar2.getClass();
        Log.e("z5.h", concat2);
        return false;
    }

    public final long c(long j7, String str) {
        Long l7;
        t tVar = this.f28273c;
        synchronized (tVar) {
            l7 = (Long) tVar.B0("long_store", str);
        }
        return l7 == null ? j7 : l7.longValue();
    }

    public final void d(x xVar) {
        JSONObject jSONObject = xVar.f28349a;
        if (jSONObject.length() == 0 || !a("identify()")) {
            return;
        }
        j("$identify", null, jSONObject, System.currentTimeMillis(), false);
    }

    public final void e(CraftoApp craftoApp, String str) {
        synchronized (this) {
            g(craftoApp, str);
        }
    }

    public final String f() {
        String str;
        HashSet b8 = b();
        t tVar = this.f28273c;
        synchronized (tVar) {
            str = (String) tVar.B0("store", "device_id");
        }
        if (!D.d(str) && !b8.contains(str) && !str.endsWith("S")) {
            return str;
        }
        String str2 = UUID.randomUUID().toString() + "R";
        this.f28273c.j1("device_id", str2);
        return str2;
    }

    public final synchronized void g(CraftoApp craftoApp, final String str) {
        if (craftoApp == null) {
            f28252S.getClass();
            Log.e("z5.h", "Argument context cannot be null in initialize()");
        } else {
            if (D.d("427d12d0417d24af0396fcb5cf7b56cb")) {
                f28252S.getClass();
                Log.e("z5.h", "Argument apiKey cannot be null or blank in initialize()");
                return;
            }
            Context applicationContext = craftoApp.getApplicationContext();
            this.f28271a = applicationContext;
            this.d = "427d12d0417d24af0396fcb5cf7b56cb";
            this.f28273c = t.M(applicationContext, this.f28274e);
            this.f28283n = D.d(null) ? CashfreeCoreNativeVerificationActivity.WB_INTENT_BRIDGE : null;
            n(new Runnable() {

                public final Call.Factory f28248b = null;

                @Override
                public final void run() {
                    String str2;
                    h hVar = this;
                    Call.Factory factory = this.f28248b;
                    String str3 = str;
                    h hVar2 = this;
                    if (hVar.f28277h) {
                        return;
                    }
                    try {
                        if (factory == null) {
                            final C2887d c2887d = new C2887d();
                            if (!(c2887d instanceof A5.a)) {
                                A5.a aVar = new A5.a();
                                aVar.f76b = A5.a.f74c;
                                aVar.f75a = c2887d;
                                c2887d = aVar;
                            }
                            hVar.f28272b = new Call.Factory() {
                                public final Call newCall(Request request) {
                                    return ((Call.Factory) A5.b.this.get()).newCall(request);
                                }
                            };
                        } else {
                            hVar.f28272b = factory;
                        }
                        Context context = hVar.f28271a;
                        boolean a8 = hVar.f28279j.a("adid");
                        w wVar = new w();
                        wVar.f28335c = context;
                        wVar.f28333a = hVar.f28281l;
                        wVar.f28334b = a8;
                        hVar.f28290u = wVar;
                        hVar.f28276g = hVar.f();
                        if (str3 != null) {
                            hVar2.f28275f = str3;
                            hVar.f28273c.j1("user_id", str3);
                        } else {
                            t tVar = hVar.f28273c;
                            synchronized (tVar) {
                                str2 = (String) tVar.B0("store", "user_id");
                            }
                            hVar2.f28275f = str2;
                        }
                        hVar.f28269Q.f27701b.a(new Ya.h(hVar, 3));
                        hVar.f28269Q.f27700a.a(new C2805d(str3, hVar.f28276g, new HashMap()));
                        hVar.f28290u.a();
                        Long j02 = hVar.f28273c.j0("opt_out");
                        hVar.f28278i = j02 != null && j02.longValue() == 1;
                        long c8 = hVar.c(-1L, "previous_session_id");
                        hVar.f28289t = c8;
                        if (c8 >= 0) {
                            hVar.f28284o = c8;
                        }
                        hVar.f28285p = hVar.c(0L, "sequence_number");
                        hVar.f28286q = hVar.c(-1L, "last_event_id");
                        hVar.f28287r = hVar.c(-1L, "last_identify_id");
                        hVar.f28288s = hVar.c(-1L, "last_event_time");
                        hVar.f28273c.f28331c = new k(hVar, hVar2);
                        hVar.f28282m = new z(hVar.f28273c, hVar.f28267O, hVar.f28253A, hVar);
                        hVar.f28277h = true;
                    } catch (CursorWindowAllocationException e8) {
                        r rVar = h.f28252S;
                        String str4 = "Failed to initialize Amplitude SDK due to: " + e8.getMessage();
                        rVar.getClass();
                        Log.e("z5.h", str4);
                        hVar2.d = null;
                    }
                }
            });
        }
    }

    public final long h(String str, JSONObject jSONObject, JSONObject jSONObject2, JSONObject jSONObject3, JSONObject jSONObject4, JSONObject jSONObject5, long j7, boolean z7, boolean z8) {
        JSONException e8;
        Location c8;
        String str2 = str;
        C c9 = this.f28279j;
        f28252S.getClass();
        long j8 = -1;
        if (this.f28278i) {
            return -1L;
        }
        if ((!this.f28258F || (!str2.equals("session_start") && !str2.equals("session_end"))) && !z7) {
            if (!z8 || this.f28260H) {
                this.f28260H = false;
                u(j7);
            } else {
                m(j7);
            }
        }
        JSONObject jSONObject6 = new JSONObject();
        if (str2 == null) {
            try {
                str2 = JSONObject.NULL;
            } catch (JSONException e9) {
                e8 = e9;
                Log.e("z5.h", "JSON Serialization of event type " + str2 + " failed, skipping: " + e8.toString());
                return j8;
            }
        }
        try {
            jSONObject6.put("event_type", str2);
            jSONObject6.put("timestamp", j7);
            Object obj = this.f28275f;
            if (obj == null) {
                obj = JSONObject.NULL;
            }
            jSONObject6.put("user_id", obj);
            Object obj2 = this.f28276g;
            if (obj2 == null) {
                obj2 = JSONObject.NULL;
            }
            jSONObject6.put("device_id", obj2);
            jSONObject6.put("session_id", z7 ? -1L : this.f28284o);
            jSONObject6.put("uuid", UUID.randomUUID().toString());
            long j9 = this.f28285p + 1;
            this.f28285p = j9;
            this.f28273c.e1("sequence_number", Long.valueOf(j9));
            jSONObject6.put("sequence_number", this.f28285p);
            if (c9.a("version_name")) {
                Object obj3 = this.f28290u.a().f28338c;
                if (obj3 == null) {
                    obj3 = JSONObject.NULL;
                }
                jSONObject6.put("version_name", obj3);
            }
            if (c9.a("os_name")) {
                Object obj4 = this.f28290u.a().d;
                if (obj4 == null) {
                    obj4 = JSONObject.NULL;
                }
                jSONObject6.put("os_name", obj4);
            }
            if (c9.a("os_version")) {
                Object obj5 = this.f28290u.a().f28339e;
                if (obj5 == null) {
                    obj5 = JSONObject.NULL;
                }
                jSONObject6.put("os_version", obj5);
            }
            if (c9.a("api_level")) {
                jSONObject6.put("api_level", Integer.valueOf(Build.VERSION.SDK_INT));
            }
            if (c9.a("device_brand")) {
                Object obj6 = this.f28290u.a().f28340f;
                if (obj6 == null) {
                    obj6 = JSONObject.NULL;
                }
                jSONObject6.put("device_brand", obj6);
            }
            if (c9.a("device_manufacturer")) {
                Object obj7 = this.f28290u.a().f28341g;
                if (obj7 == null) {
                    obj7 = JSONObject.NULL;
                }
                jSONObject6.put("device_manufacturer", obj7);
            }
            if (c9.a("device_model")) {
                Object obj8 = this.f28290u.a().f28342h;
                if (obj8 == null) {
                    obj8 = JSONObject.NULL;
                }
                jSONObject6.put("device_model", obj8);
            }
            if (c9.a("carrier")) {
                Object obj9 = this.f28290u.a().f28343i;
                if (obj9 == null) {
                    obj9 = JSONObject.NULL;
                }
                jSONObject6.put("carrier", obj9);
            }
            if (c9.a(AdRevenueScheme.COUNTRY)) {
                Object obj10 = this.f28290u.a().f28337b;
                if (obj10 == null) {
                    obj10 = JSONObject.NULL;
                }
                jSONObject6.put(AdRevenueScheme.COUNTRY, obj10);
            }
            if (c9.a("language")) {
                Object obj11 = this.f28290u.a().f28344j;
                if (obj11 == null) {
                    obj11 = JSONObject.NULL;
                }
                jSONObject6.put("language", obj11);
            }
            if (c9.a("platform")) {
                jSONObject6.put("platform", this.f28283n);
            }
            JSONObject jSONObject7 = new JSONObject();
            String str3 = this.f28262J;
            if (str3 == null) {
                str3 = "unknown-library";
            }
            jSONObject7.put("name", str3);
            String str4 = this.f28263K;
            if (str4 == null) {
                str4 = "unknown-version";
            }
            jSONObject7.put("version", str4);
            jSONObject6.put("library", jSONObject7);
            JSONObject jSONObject8 = jSONObject2 == null ? new JSONObject() : jSONObject2;
            JSONObject jSONObject9 = this.f28280k;
            if (jSONObject9 != null && jSONObject9.length() > 0) {
                jSONObject8.put("tracking_options", jSONObject9);
            }
            if (c9.a("lat_lng") && (c8 = this.f28290u.c()) != null) {
                JSONObject jSONObject10 = new JSONObject();
                jSONObject10.put("lat", c8.getLatitude());
                jSONObject10.put("lng", c8.getLongitude());
                jSONObject8.put("location", jSONObject10);
            }
            if (c9.a("adid") && this.f28290u.a().f28336a != null) {
                jSONObject8.put("androidADID", this.f28290u.a().f28336a);
            }
            if (c9.a("app_set_id") && this.f28290u.a().f28347m != null) {
                jSONObject8.put("android_app_set_id", this.f28290u.a().f28347m);
            }
            jSONObject8.put("limit_ad_tracking", this.f28290u.a().f28345k);
            jSONObject8.put("gps_enabled", this.f28290u.a().f28346l);
            jSONObject6.put("api_properties", jSONObject8);
            jSONObject6.put("event_properties", jSONObject == null ? new JSONObject() : w(jSONObject));
            jSONObject6.put("user_properties", jSONObject3 == null ? new JSONObject() : w(jSONObject3));
            jSONObject6.put("groups", jSONObject4 == null ? new JSONObject() : w(jSONObject4));
            jSONObject6.put("group_properties", jSONObject5 == null ? new JSONObject() : w(jSONObject5));
            str2 = str;
            j8 = o(str2, jSONObject6);
            if (str2.equals("$identify") && jSONObject3 != null) {
                C2807f c2807f = this.f28269Q.f27700a;
                ReentrantReadWriteLock.ReadLock readLock = c2807f.f27711a.readLock();
                readLock.lock();
                try {
                    C2805d c2805d = c2807f.f27712b;
                    readLock.unlock();
                    C2806e c2806e = new C2806e(c2805d, c2807f);
                    c2806e.b(C2844a.e(jSONObject3));
                    c2806e.a();
                } catch (Throwable th) {
                    readLock.unlock();
                    throw th;
                }
            }
        } catch (JSONException e10) {
            e8 = e10;
            str2 = str;
            Log.e("z5.h", "JSON Serialization of event type " + str2 + " failed, skipping: " + e8.toString());
            return j8;
        }
        return j8;
    }

    public final void i(JSONObject jSONObject, String str, boolean z7) {
        long currentTimeMillis = System.currentTimeMillis();
        if (D.d(str)) {
            f28252S.getClass();
            Log.e("z5.h", "Argument eventType cannot be null or blank in logEvent()");
        } else if (a("logEvent()")) {
            j(str, jSONObject, null, currentTimeMillis, z7);
        }
    }

    public final void j(String str, JSONObject jSONObject, JSONObject jSONObject2, long j7, boolean z7) {
        n(new l(this, str, jSONObject != null ? D.b(jSONObject) : jSONObject, null, jSONObject2 != null ? D.b(jSONObject2) : jSONObject2, null, null, j7, z7, this.f28259G));
    }

    public final void k(B b8) {
        if (a("logRevenueV2()")) {
            if (b8.f28237c == null) {
                B.f28234g.getClass();
                Log.w("z5.B", "Invalid revenue, need to set price");
                return;
            }
            JSONObject jSONObject = b8.f28239f;
            if (jSONObject == null) {
                jSONObject = new JSONObject();
            }
            JSONObject jSONObject2 = jSONObject;
            try {
                jSONObject2.put("$productId", b8.f28235a);
                jSONObject2.put("$quantity", b8.f28236b);
                jSONObject2.put("$price", b8.f28237c);
                jSONObject2.put("$revenueType", (Object) null);
                jSONObject2.put("$receipt", b8.d);
                jSONObject2.put("$receiptSig", b8.f28238e);
            } catch (JSONException e8) {
                String a8 = C1.e.a("Failed to convert revenue object to JSON: ", e8.toString());
                B.f28234g.getClass();
                Log.e("z5.B", a8);
            }
            h("revenue_amount", jSONObject2, null, null, null, null, System.currentTimeMillis(), false, this.f28259G);
        }
    }

    public final void m(long j7) {
        if (this.f28284o >= 0) {
            this.f28288s = j7;
            this.f28273c.e1("last_event_time", Long.valueOf(j7));
        }
    }

    public final void n(Runnable runnable) {
        Thread currentThread = Thread.currentThread();
        E e8 = this.f28267O;
        if (currentThread == e8) {
            runnable.run();
        } else {
            e8.a();
            e8.f28243a.post(runnable);
        }
    }

    public final long o(java.lang.String r10, org.json.JSONObject r11) {
        throw new UnsupportedOperationException("Method not decompiled: z5.h.o(java.lang.String, org.json.JSONObject):long");
    }

    public final long p(String str, JSONObject jSONObject) {
        long a8;
        String jSONObject2 = jSONObject.toString();
        if (str.equals("$identify") || str.equals("$groupidentify")) {
            long k7 = this.f28273c.k(jSONObject2);
            this.f28287r = k7;
            this.f28273c.e1("last_identify_id", Long.valueOf(k7));
        } else {
            t tVar = this.f28273c;
            synchronized (tVar) {
                a8 = tVar.a("events", jSONObject2);
            }
            this.f28286q = a8;
            this.f28273c.e1("last_event_id", Long.valueOf(a8));
        }
        int min = Math.min(Math.max(1, this.f28293x / 10), 20);
        if (this.f28273c.P() > this.f28293x) {
            t tVar2 = this.f28273c;
            tVar2.q1(tVar2.m0(min));
        }
        if (this.f28273c.e0() > this.f28293x) {
            t tVar3 = this.f28273c;
            tVar3.u1(tVar3.s0(min));
        }
        long t02 = this.f28273c.t0();
        long j7 = this.f28291v;
        if (t02 % j7 != 0 || t02 < j7) {
            long j8 = this.f28294y;
            if (!this.f28264L.getAndSet(true)) {
                f fVar = new f(this);
                E e8 = this.f28267O;
                e8.a();
                e8.f28243a.postDelayed(fVar, j8);
            }
        } else {
            x(false);
        }
        return (str.equals("$identify") || str.equals("$groupidentify")) ? this.f28287r : this.f28286q;
    }

    public final void q(String str) {
        if (a("sendSessionEvent('" + str + "')") && this.f28284o >= 0) {
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.put("special", str);
                h(str, null, jSONObject, null, null, null, this.f28288s, false, false);
            } catch (JSONException unused) {
            }
        }
    }

    public final void r(String str) {
        if (a("setUserId()")) {
            n(new o(str, this, this));
        }
    }

    public final void s(JSONObject jSONObject) {
        x xVar;
        if (jSONObject.length() == 0 || !a("setUserProperties")) {
            return;
        }
        JSONObject w7 = w(jSONObject);
        if (w7.length() == 0) {
            xVar = null;
        } else {
            x xVar2 = new x();
            Iterator<String> keys = w7.keys();
            while (keys.hasNext()) {
                String next = keys.next();
                try {
                    xVar2.a(w7.get(next), next);
                } catch (JSONException e8) {
                    String obj = e8.toString();
                    f28252S.getClass();
                    Log.e("z5.h", obj);
                }
            }
            xVar = xVar2;
        }
        if (xVar != null) {
            d(xVar);
        }
    }

    public final void t(long j7) {
        if (this.f28258F) {
            q("session_end");
        }
        this.f28284o = j7;
        this.f28289t = j7;
        this.f28273c.e1("previous_session_id", Long.valueOf(j7));
        m(j7);
        if (this.f28258F) {
            q("session_start");
        }
    }

    public final void u(long j7) {
        if (this.f28284o >= 0) {
            if (j7 - this.f28288s < (this.f28257E ? this.f28295z : this.f28254B)) {
                m(j7);
                return;
            } else {
                t(j7);
                return;
            }
        }
        if (j7 - this.f28288s >= (this.f28257E ? this.f28295z : this.f28254B)) {
            t(j7);
            return;
        }
        long j8 = this.f28289t;
        if (j8 == -1) {
            t(j7);
            return;
        }
        this.f28284o = j8;
        this.f28289t = j8;
        this.f28273c.e1("previous_session_id", Long.valueOf(j8));
        m(j7);
    }

    public final void x(boolean z7) {
        LinkedList c02;
        if (this.f28278i || this.f28265M.getAndSet(true)) {
            return;
        }
        long min = Math.min(z7 ? this.f28256D : this.f28292w, this.f28273c.t0());
        if (min <= 0) {
            this.f28265M.set(false);
            return;
        }
        try {
            t tVar = this.f28273c;
            long j7 = this.f28286q;
            synchronized (tVar) {
                c02 = tVar.c0(j7, min, "events");
            }
            Pair l7 = l(c02, this.f28273c.f0(this.f28287r, min), min);
            if (((JSONArray) l7.second).length() == 0) {
                this.f28265M.set(false);
                return;
            }
            long longValue = ((Long) ((Pair) l7.first).first).longValue();
            long longValue2 = ((Long) ((Pair) l7.first).second).longValue();
            String jSONArray = ((JSONArray) l7.second).toString();
            E e8 = this.f28268P;
            a aVar = new a(jSONArray, longValue, longValue2);
            e8.a();
            e8.f28243a.post(aVar);
        } catch (CursorWindowAllocationException e9) {
            this.f28265M.set(false);
            r rVar = f28252S;
            String str = "Caught Cursor window exception during event upload, deferring upload: " + e9.getMessage();
            rVar.getClass();
            Log.e("z5.h", str);
        } catch (JSONException e10) {
            this.f28265M.set(false);
            r rVar2 = f28252S;
            String obj = e10.toString();
            rVar2.getClass();
            Log.e("z5.h", obj);
        }
    }

    public h(String str) {
        C2802a c2802a;
        this.f28277h = false;
        this.f28278i = false;
        C c8 = new C();
        C c9 = new C();
        Iterator it = c8.f28241a.iterator();
        while (it.hasNext()) {
            c9.f28241a.add((String) it.next());
        }
        this.f28279j = c9;
        JSONObject jSONObject = new JSONObject();
        HashSet hashSet = c9.f28241a;
        if (!hashSet.isEmpty()) {
            String[] strArr = C.f28240b;
            for (int i7 = 0; i7 < 6; i7++) {
                String str2 = strArr[i7];
                if (hashSet.contains(str2)) {
                    try {
                        jSONObject.put(str2, false);
                    } catch (JSONException e8) {
                        Log.e("z5.C", e8.toString());
                    }
                }
            }
        }
        this.f28280k = jSONObject;
        this.f28281l = true;
        s sVar = s.US;
        this.f28284o = -1L;
        this.f28285p = 0L;
        this.f28286q = -1L;
        this.f28287r = -1L;
        this.f28288s = -1L;
        this.f28289t = -1L;
        this.f28291v = 30;
        this.f28292w = 50;
        this.f28293x = ImageRequest.DEFAULT_IMAGE_TIMEOUT_MS;
        this.f28294y = 30000L;
        this.f28295z = 300000L;
        this.f28253A = 30000L;
        this.f28254B = 1800000L;
        this.f28255C = false;
        this.f28256D = 50;
        this.f28257E = false;
        this.f28258F = false;
        this.f28259G = false;
        this.f28260H = false;
        this.f28261I = true;
        this.f28262J = "amplitude-android";
        this.f28263K = "2.39.7";
        this.f28264L = new AtomicBoolean(false);
        this.f28265M = new AtomicBoolean(false);
        this.f28266N = "https://api2.amplitude.com/";
        E e9 = new E("logThread");
        this.f28267O = e9;
        E e10 = new E("httpThread");
        this.f28268P = e10;
        this.f28270R = new q9.h();
        String e11 = D.e(str);
        this.f28274e = e11;
        e9.start();
        e10.start();
        Object obj = C2802a.f27699c;
        Intrinsics.checkNotNullParameter(e11, "instanceName");
        synchronized (C2802a.f27699c) {
            try {
                LinkedHashMap linkedHashMap = C2802a.d;
                Object obj2 = linkedHashMap.get(e11);
                if (obj2 == null) {
                    obj2 = new C2802a();
                    linkedHashMap.put(e11, obj2);
                }
                c2802a = (C2802a) obj2;
            } catch (Throwable th) {
                throw th;
            }
        }
        this.f28269Q = c2802a;
    }
}