package L1;

import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ServiceInfo;
import android.content.pm.Signature;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.Log;
import androidx.fragment.app.C0284p;
import java.io.ByteArrayInputStream;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Random;
import java.util.TreeSet;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import javax.security.auth.x500.X500Principal;
import o0.C0922a;
import p1.AbstractC0935g;
import p1.C0934f;
import r0.C0971b;
import r4.AbstractC0983h;
import y1.C1112b;

/* JADX INFO: loaded from: classes.dex */
public final class c2 extends G0 {

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public static final String[] f1744s = {"firebase_", "google_", "ga_"};

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public static final String[] f1745t = {"_err"};

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public SecureRandom f1746m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final AtomicLong f1747n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public int f1748o;
    public q0.d p;
    public Boolean q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public Integer f1749r;

    public c2(C0146w0 c0146w0) {
        super(c0146w0);
        this.f1749r = null;
        this.f1747n = new AtomicLong(0L);
    }

    public static void A(b2 b2Var, String str, int i, String str2, String str3, int i5) {
        Bundle bundle = new Bundle();
        d0(i, bundle);
        if (!TextUtils.isEmpty(str2) && !TextUtils.isEmpty(str3)) {
            bundle.putString(str2, str3);
        }
        if (i == 6 || i == 7 || i == 2) {
            bundle.putLong("_el", i5);
        }
        b2Var.a(str, "_err", bundle);
    }

    public static MessageDigest B() {
        MessageDigest messageDigest;
        for (int i = 0; i < 2; i++) {
            try {
                messageDigest = MessageDigest.getInstance("MD5");
            } catch (NoSuchAlgorithmException unused) {
            }
            if (messageDigest != null) {
                return messageDigest;
            }
        }
        return null;
    }

    public static long C(byte[] bArr) {
        s1.z.g(bArr);
        int length = bArr.length;
        if (length <= 0) {
            throw new IllegalStateException();
        }
        int i = 0;
        long j5 = 0;
        for (int i5 = length - 1; i5 >= 0 && i5 >= bArr.length - 8; i5--) {
            j5 += (((long) bArr[i5]) & 255) << i;
            i += 8;
        }
        return j5;
    }

    public static boolean D(Context context) {
        ServiceInfo serviceInfo;
        try {
            PackageManager packageManager = context.getPackageManager();
            if (packageManager != null && (serviceInfo = packageManager.getServiceInfo(new ComponentName(context, "com.google.android.gms.measurement.AppMeasurementJobService"), 0)) != null) {
                if (serviceInfo.enabled) {
                    return true;
                }
            }
        } catch (PackageManager.NameNotFoundException unused) {
        }
        return false;
    }

    public static boolean G(String str) {
        String str2 = (String) F.f1434r0.a(null);
        return str2.equals("*") || Arrays.asList(str2.split(",")).contains(str);
    }

    public static boolean I(String str) {
        return !TextUtils.isEmpty(str) && str.startsWith("_");
    }

    public static boolean J(String str, String[] strArr) {
        s1.z.g(strArr);
        for (String str2 : strArr) {
            if (Objects.equals(str, str2)) {
                return true;
            }
        }
        return false;
    }

    public static byte[] O(Parcelable parcelable) {
        if (parcelable == null) {
            return null;
        }
        Parcel parcelObtain = Parcel.obtain();
        try {
            parcelable.writeToParcel(parcelObtain, 0);
            return parcelObtain.marshall();
        } finally {
            parcelObtain.recycle();
        }
    }

    public static ArrayList Z(List list) {
        if (list == null) {
            return new ArrayList(0);
        }
        ArrayList arrayList = new ArrayList(list.size());
        Iterator it = list.iterator();
        while (it.hasNext()) {
            C0092e c0092e = (C0092e) it.next();
            Bundle bundle = new Bundle();
            bundle.putString("app_id", c0092e.f1757k);
            bundle.putString("origin", c0092e.f1758l);
            bundle.putLong("creation_timestamp", c0092e.f1760n);
            bundle.putString("name", c0092e.f1759m.f1654l);
            Object objA = c0092e.f1759m.a();
            s1.z.g(objA);
            M0.d(bundle, objA);
            bundle.putBoolean("active", c0092e.f1761o);
            String str = c0092e.p;
            if (str != null) {
                bundle.putString("trigger_event_name", str);
            }
            C0142v c0142v = c0092e.q;
            if (c0142v != null) {
                bundle.putString("timed_out_event_name", c0142v.f2013k);
                C0139u c0139u = c0142v.f2014l;
                if (c0139u != null) {
                    bundle.putBundle("timed_out_event_params", c0139u.d());
                }
            }
            bundle.putLong("trigger_timeout", c0092e.f1762r);
            C0142v c0142v2 = c0092e.f1763s;
            if (c0142v2 != null) {
                bundle.putString("triggered_event_name", c0142v2.f2013k);
                C0139u c0139u2 = c0142v2.f2014l;
                if (c0139u2 != null) {
                    bundle.putBundle("triggered_event_params", c0139u2.d());
                }
            }
            bundle.putLong("triggered_timestamp", c0092e.f1759m.f1655m);
            bundle.putLong("time_to_live", c0092e.f1764t);
            C0142v c0142v3 = c0092e.f1765u;
            if (c0142v3 != null) {
                bundle.putString("expired_event_name", c0142v3.f2013k);
                C0139u c0139u3 = c0142v3.f2014l;
                if (c0139u3 != null) {
                    bundle.putBundle("expired_event_params", c0139u3.d());
                }
            }
            arrayList.add(bundle);
        }
        return arrayList;
    }

    public static boolean a0(Context context) {
        ActivityInfo receiverInfo;
        s1.z.g(context);
        try {
            PackageManager packageManager = context.getPackageManager();
            if (packageManager != null && (receiverInfo = packageManager.getReceiverInfo(new ComponentName(context, "com.google.android.gms.measurement.AppMeasurementReceiver"), 0)) != null) {
                if (receiverInfo.enabled) {
                    return true;
                }
            }
        } catch (PackageManager.NameNotFoundException unused) {
        }
        return false;
    }

    public static void b0(C0112k1 c0112k1, Bundle bundle, boolean z5) {
        if (bundle != null && c0112k1 != null) {
            if (!bundle.containsKey("_sc") || z5) {
                String str = c0112k1.f1887a;
                if (str != null) {
                    bundle.putString("_sn", str);
                } else {
                    bundle.remove("_sn");
                }
                String str2 = c0112k1.f1888b;
                if (str2 != null) {
                    bundle.putString("_sc", str2);
                } else {
                    bundle.remove("_sc");
                }
                bundle.putLong("_si", c0112k1.f1889c);
                return;
            }
            z5 = false;
        }
        if (bundle != null && c0112k1 == null && z5) {
            bundle.remove("_sn");
            bundle.remove("_sc");
            bundle.remove("_si");
        }
    }

    public static final boolean d0(int i, Bundle bundle) {
        if (bundle == null || bundle.getLong("_err") != 0) {
            return false;
        }
        bundle.putLong("_err", i);
        return true;
    }

    public static boolean i0(String str) {
        s1.z.d(str);
        return str.charAt(0) != '_' || str.equals("_ep");
    }

    public static String p(int i, String str, boolean z5) {
        if (str == null) {
            return null;
        }
        if (str.codePointCount(0, str.length()) <= i) {
            return str;
        }
        if (z5) {
            return String.valueOf(str.substring(0, str.offsetByCodePoints(0, i))).concat("...");
        }
        return null;
    }

    public static boolean s0(Object obj) {
        return (obj instanceof Parcelable[]) || (obj instanceof ArrayList) || (obj instanceof Bundle);
    }

    public final q0.d E() {
        r0.e c0971b;
        Object objInvoke;
        if (this.p == null) {
            Context context = ((C0146w0) this.f29k).f2032k;
            AbstractC0983h.e("context", context);
            StringBuilder sb = new StringBuilder("AdServicesInfo.version=");
            int i = Build.VERSION.SDK_INT;
            o0.c cVar = o0.c.f9378a;
            sb.append(i >= 33 ? cVar.a() : 0);
            Log.d("MeasurementManager", sb.toString());
            if ((i >= 33 ? cVar.a() : 0) >= 5) {
                Object systemService = context.getSystemService((Class<Object>) AbstractC0143v0.i());
                AbstractC0983h.d("context.getSystemService…ementManager::class.java)", systemService);
                c0971b = new C0971b(AbstractC0143v0.e(systemService));
            } else {
                C0922a c0922a = C0922a.f9377a;
                if (((i == 31 || i == 32) ? c0922a.a() : 0) >= 9) {
                    try {
                        objInvoke = new C0284p(3, context).invoke(context);
                    } catch (NoClassDefFoundError unused) {
                        StringBuilder sb2 = new StringBuilder("Unable to find adservices code, check manifest for uses-library tag, versionS=");
                        int i5 = Build.VERSION.SDK_INT;
                        sb2.append((i5 == 31 || i5 == 32) ? c0922a.a() : 0);
                        Log.d("MeasurementManager", sb2.toString());
                        objInvoke = null;
                    }
                    c0971b = (r0.e) objInvoke;
                } else {
                    c0971b = null;
                }
            }
            this.p = c0971b != null ? new q0.d(c0971b) : null;
        }
        return this.p;
    }

    /* JADX WARN: Removed duplicated region for block: B:59:0x00be  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final long F() {
        /*
            r11 = this;
            r11.k()
            java.lang.Object r0 = r11.f29k
            L1.w0 r0 = (L1.C0146w0) r0
            L1.N r1 = r0.q()
            L1.X r0 = r0.p
            java.lang.String r1 = r1.q()
            boolean r1 = G(r1)
            r2 = 0
            if (r1 != 0) goto L1a
            return r2
        L1a:
            int r1 = android.os.Build.VERSION.SDK_INT
            r4 = 0
            r5 = 30
            r6 = 0
            if (r1 >= r5) goto L25
            r7 = 4
            goto L50
        L25:
            int r7 = P.v0.a()
            r8 = 4
            if (r7 >= r8) goto L2f
            r7 = 8
            goto L50
        L2f:
            if (r1 < r5) goto L3d
            int r1 = P.v0.a()
            r5 = 3
            if (r1 <= r5) goto L3d
            int r1 = o0.AbstractC0923b.a()
            goto L3e
        L3d:
            r1 = r4
        L3e:
            L1.E r5 = L1.F.l0
            java.lang.Object r5 = r5.a(r6)
            java.lang.Integer r5 = (java.lang.Integer) r5
            int r5 = r5.intValue()
            if (r1 >= r5) goto L4f
            r7 = 16
            goto L50
        L4f:
            r7 = r2
        L50:
            java.lang.String r1 = "android.permission.ACCESS_ADSERVICES_ATTRIBUTION"
            boolean r1 = r11.H(r1)
            if (r1 != 0) goto L5b
            r9 = 2
            long r7 = r7 | r9
        L5b:
            int r1 = (r7 > r2 ? 1 : (r7 == r2 ? 0 : -1))
            if (r1 != 0) goto Lc0
            java.lang.Boolean r1 = r11.q
            if (r1 != 0) goto Lb6
            q0.d r1 = r11.E()
            if (r1 != 0) goto L6a
            goto Lbc
        L6a:
            s2.b r1 = r1.b()
            java.util.concurrent.TimeUnit r5 = java.util.concurrent.TimeUnit.MILLISECONDS     // Catch: java.util.concurrent.TimeoutException -> L94 java.lang.InterruptedException -> L97 java.util.concurrent.ExecutionException -> L99 java.util.concurrent.CancellationException -> L9b
            r9 = 10000(0x2710, double:4.9407E-320)
            java.lang.Object r1 = r1.get(r9, r5)     // Catch: java.util.concurrent.TimeoutException -> L94 java.lang.InterruptedException -> L97 java.util.concurrent.ExecutionException -> L99 java.util.concurrent.CancellationException -> L9b
            java.lang.Integer r1 = (java.lang.Integer) r1     // Catch: java.util.concurrent.TimeoutException -> L94 java.lang.InterruptedException -> L97 java.util.concurrent.ExecutionException -> L99 java.util.concurrent.CancellationException -> L9b
            if (r1 == 0) goto L8b
            int r5 = r1.intValue()     // Catch: java.util.concurrent.TimeoutException -> L83 java.lang.InterruptedException -> L85 java.util.concurrent.ExecutionException -> L87 java.util.concurrent.CancellationException -> L89
            r6 = 1
            if (r5 != r6) goto L8b
            r4 = r6
            goto L8b
        L83:
            r4 = move-exception
            goto L92
        L85:
            r4 = move-exception
            goto L92
        L87:
            r4 = move-exception
            goto L92
        L89:
            r4 = move-exception
            goto L92
        L8b:
            java.lang.Boolean r4 = java.lang.Boolean.valueOf(r4)     // Catch: java.util.concurrent.TimeoutException -> L83 java.lang.InterruptedException -> L85 java.util.concurrent.ExecutionException -> L87 java.util.concurrent.CancellationException -> L89
            r11.q = r4     // Catch: java.util.concurrent.TimeoutException -> L83 java.lang.InterruptedException -> L85 java.util.concurrent.ExecutionException -> L87 java.util.concurrent.CancellationException -> L89
            goto Lac
        L92:
            r6 = r1
            goto L9d
        L94:
            r1 = move-exception
        L95:
            r4 = r1
            goto L9d
        L97:
            r1 = move-exception
            goto L95
        L99:
            r1 = move-exception
            goto L95
        L9b:
            r1 = move-exception
            goto L95
        L9d:
            L1.C0146w0.l(r0)
            java.lang.String r1 = "Measurement manager api exception"
            L1.V r5 = r0.f1626s
            r5.c(r1, r4)
            java.lang.Boolean r1 = java.lang.Boolean.FALSE
            r11.q = r1
            r1 = r6
        Lac:
            L1.C0146w0.l(r0)
            java.lang.String r4 = "Measurement manager api status result"
            L1.V r0 = r0.f1631x
            r0.c(r4, r1)
        Lb6:
            java.lang.Boolean r0 = r11.q
            boolean r4 = r0.booleanValue()
        Lbc:
            if (r4 != 0) goto Lc0
            r7 = 64
        Lc0:
            int r0 = (r7 > r2 ? 1 : (r7 == r2 ? 0 : -1))
            if (r0 != 0) goto Lc7
            r0 = 1
            return r0
        Lc7:
            return r7
        */
        throw new UnsupportedOperationException("Method not decompiled: L1.c2.F():long");
    }

    public final boolean H(String str) {
        k();
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        if (C1112b.a(c0146w0.f2032k).f1637k.checkCallingOrSelfPermission(str) == 0) {
            return true;
        }
        X x5 = c0146w0.p;
        C0146w0.l(x5);
        x5.f1630w.c("Permission not granted", str);
        return false;
    }

    public final boolean K(String str, String str2) {
        if (!TextUtils.isEmpty(str2)) {
            return true;
        }
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        return ((C0146w0) this.f29k).f2035n.o("debug.firebase.analytics.app").equals(str);
    }

    public final Bundle L(Bundle bundle) {
        Bundle bundle2 = new Bundle();
        if (bundle != null) {
            for (String str : bundle.keySet()) {
                Object objR = r(str, bundle.get(str));
                if (objR == null) {
                    C0146w0 c0146w0 = (C0146w0) this.f29k;
                    X x5 = c0146w0.p;
                    C0146w0.l(x5);
                    x5.f1628u.c("Param value can't be null", c0146w0.f2039t.b(str));
                } else {
                    z(bundle2, str, objR);
                }
            }
        }
        return bundle2;
    }

    public final C0142v M(String str, Bundle bundle, String str2, long j5, boolean z5) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        if (o0(str) != 0) {
            C0146w0 c0146w0 = (C0146w0) this.f29k;
            X x5 = c0146w0.p;
            C0146w0.l(x5);
            x5.p.c("Invalid conditional property event name", c0146w0.f2039t.c(str));
            throw new IllegalArgumentException();
        }
        Bundle bundle2 = bundle != null ? new Bundle(bundle) : new Bundle();
        bundle2.putString("_o", str2);
        Bundle bundleS = s(str, bundle2, Collections.singletonList("_o"), true);
        if (z5) {
            bundleS = L(bundleS);
        }
        s1.z.g(bundleS);
        return new C0142v(str, new C0139u(bundleS), str2, j5);
    }

    public final boolean N(Context context, String str) {
        Signature[] signatureArr;
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        X500Principal x500Principal = new X500Principal("CN=Android Debug,O=Android,C=US");
        try {
            PackageInfo packageInfoE = C1112b.a(context).e(64, str);
            if (packageInfoE == null || (signatureArr = packageInfoE.signatures) == null || signatureArr.length <= 0) {
                return true;
            }
            return ((X509Certificate) CertificateFactory.getInstance("X.509").generateCertificate(new ByteArrayInputStream(signatureArr[0].toByteArray()))).getSubjectX500Principal().equals(x500Principal);
        } catch (PackageManager.NameNotFoundException e2) {
            X x5 = c0146w0.p;
            C0146w0.l(x5);
            x5.p.c("Package name not found", e2);
            return true;
        } catch (CertificateException e6) {
            X x6 = c0146w0.p;
            C0146w0.l(x6);
            x6.p.c("Error obtaining certificate", e6);
            return true;
        }
    }

    public final boolean P(int i) {
        Boolean bool = ((C0146w0) this.f29k).o().f2065o;
        if (Q() < i / 1000) {
            return (bool == null || bool.booleanValue()) ? false : true;
        }
        return true;
    }

    public final int Q() {
        if (this.f1749r == null) {
            C0934f c0934f = C0934f.f9460b;
            Context context = ((C0146w0) this.f29k).f2032k;
            c0934f.getClass();
            AtomicBoolean atomicBoolean = AbstractC0935g.f9461a;
            int i = 0;
            try {
                i = context.getPackageManager().getPackageInfo("com.google.android.gms", 0).versionCode;
            } catch (PackageManager.NameNotFoundException unused) {
                Log.w("GooglePlayServicesUtil", "Google Play services is missing.");
            }
            this.f1749r = Integer.valueOf(i / 1000);
        }
        return this.f1749r.intValue();
    }

    public final void R(Bundle bundle, long j5) {
        long j6 = bundle.getLong("_et");
        if (j6 != 0) {
            X x5 = ((C0146w0) this.f29k).p;
            C0146w0.l(x5);
            x5.f1626s.c("Params already contained engagement", Long.valueOf(j6));
        } else {
            j6 = 0;
        }
        bundle.putLong("_et", j5 + j6);
    }

    public final void S(String str, com.google.android.gms.internal.measurement.L l5) {
        Bundle bundle = new Bundle();
        bundle.putString("r", str);
        try {
            l5.n(bundle);
        } catch (RemoteException e2) {
            X x5 = ((C0146w0) this.f29k).p;
            C0146w0.l(x5);
            x5.f1626s.c("Error returning string value to wrapper", e2);
        }
    }

    public final void T(com.google.android.gms.internal.measurement.L l5, long j5) {
        Bundle bundle = new Bundle();
        bundle.putLong("r", j5);
        try {
            l5.n(bundle);
        } catch (RemoteException e2) {
            X x5 = ((C0146w0) this.f29k).p;
            C0146w0.l(x5);
            x5.f1626s.c("Error returning long value to wrapper", e2);
        }
    }

    public final void U(com.google.android.gms.internal.measurement.L l5, int i) {
        Bundle bundle = new Bundle();
        bundle.putInt("r", i);
        try {
            l5.n(bundle);
        } catch (RemoteException e2) {
            X x5 = ((C0146w0) this.f29k).p;
            C0146w0.l(x5);
            x5.f1626s.c("Error returning int value to wrapper", e2);
        }
    }

    public final void V(com.google.android.gms.internal.measurement.L l5, byte[] bArr) {
        Bundle bundle = new Bundle();
        bundle.putByteArray("r", bArr);
        try {
            l5.n(bundle);
        } catch (RemoteException e2) {
            X x5 = ((C0146w0) this.f29k).p;
            C0146w0.l(x5);
            x5.f1626s.c("Error returning byte array to wrapper", e2);
        }
    }

    public final void W(com.google.android.gms.internal.measurement.L l5, boolean z5) {
        Bundle bundle = new Bundle();
        bundle.putBoolean("r", z5);
        try {
            l5.n(bundle);
        } catch (RemoteException e2) {
            X x5 = ((C0146w0) this.f29k).p;
            C0146w0.l(x5);
            x5.f1626s.c("Error returning boolean value to wrapper", e2);
        }
    }

    public final void X(com.google.android.gms.internal.measurement.L l5, Bundle bundle) {
        try {
            l5.n(bundle);
        } catch (RemoteException e2) {
            X x5 = ((C0146w0) this.f29k).p;
            C0146w0.l(x5);
            x5.f1626s.c("Error returning bundle value to wrapper", e2);
        }
    }

    public final void Y(com.google.android.gms.internal.measurement.L l5, ArrayList arrayList) {
        Bundle bundle = new Bundle();
        bundle.putParcelableArrayList("r", arrayList);
        try {
            l5.n(bundle);
        } catch (RemoteException e2) {
            X x5 = ((C0146w0) this.f29k).p;
            C0146w0.l(x5);
            x5.f1626s.c("Error returning bundle list to wrapper", e2);
        }
    }

    public final String c0() {
        byte[] bArr = new byte[16];
        h0().nextBytes(bArr);
        return String.format(Locale.US, "%032x", new BigInteger(1, bArr));
    }

    public final Object e0(int i, Object obj, boolean z5, boolean z6) {
        if (obj == null) {
            return null;
        }
        if ((obj instanceof Long) || (obj instanceof Double)) {
            return obj;
        }
        if (obj instanceof Integer) {
            return Long.valueOf(((Integer) obj).intValue());
        }
        if (obj instanceof Byte) {
            return Long.valueOf(((Byte) obj).byteValue());
        }
        if (obj instanceof Short) {
            return Long.valueOf(((Short) obj).shortValue());
        }
        if (obj instanceof Boolean) {
            return Long.valueOf(true != ((Boolean) obj).booleanValue() ? 0L : 1L);
        }
        if (obj instanceof Float) {
            return Double.valueOf(((Float) obj).doubleValue());
        }
        if ((obj instanceof String) || (obj instanceof Character) || (obj instanceof CharSequence)) {
            return p(i, obj.toString(), z5);
        }
        if (!z6) {
            return null;
        }
        if (!(obj instanceof Bundle[]) && !(obj instanceof Parcelable[])) {
            return null;
        }
        ArrayList arrayList = new ArrayList();
        for (Parcelable parcelable : (Parcelable[]) obj) {
            if (parcelable instanceof Bundle) {
                Bundle bundleL = L((Bundle) parcelable);
                if (!bundleL.isEmpty()) {
                    arrayList.add(bundleL);
                }
            }
        }
        return arrayList.toArray(new Bundle[arrayList.size()]);
    }

    public final int f0(String str) {
        boolean zEquals = "_ldl".equals(str);
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        if (zEquals) {
            c0146w0.getClass();
            return 2048;
        }
        if ("_id".equals(str)) {
            c0146w0.getClass();
            return 256;
        }
        if ("_lgclid".equals(str)) {
            c0146w0.getClass();
            return 100;
        }
        c0146w0.getClass();
        return 36;
    }

    public final long g0() {
        long andIncrement;
        long j5;
        AtomicLong atomicLong = this.f1747n;
        if (atomicLong.get() != 0) {
            AtomicLong atomicLong2 = this.f1747n;
            synchronized (atomicLong2) {
                atomicLong2.compareAndSet(-1L, 1L);
                andIncrement = atomicLong2.getAndIncrement();
            }
            return andIncrement;
        }
        synchronized (atomicLong) {
            long jNanoTime = System.nanoTime();
            ((C0146w0) this.f29k).f2040u.getClass();
            long jNextLong = new Random(jNanoTime ^ System.currentTimeMillis()).nextLong();
            int i = this.f1748o + 1;
            this.f1748o = i;
            j5 = jNextLong + ((long) i);
        }
        return j5;
    }

    public final SecureRandom h0() {
        k();
        if (this.f1746m == null) {
            this.f1746m = new SecureRandom();
        }
        return this.f1746m;
    }

    public final Bundle j0(Uri uri) {
        String queryParameter;
        String queryParameter2;
        String queryParameter3;
        String queryParameter4;
        String queryParameter5;
        String queryParameter6;
        String queryParameter7;
        String queryParameter8;
        String queryParameter9;
        String str;
        if (uri == null) {
            return null;
        }
        try {
            if (uri.isHierarchical()) {
                queryParameter = uri.getQueryParameter("utm_campaign");
                queryParameter2 = uri.getQueryParameter("utm_source");
                queryParameter3 = uri.getQueryParameter("utm_medium");
                queryParameter4 = uri.getQueryParameter("gclid");
                queryParameter5 = uri.getQueryParameter("gbraid");
                queryParameter6 = uri.getQueryParameter("utm_id");
                queryParameter7 = uri.getQueryParameter("dclid");
                queryParameter8 = uri.getQueryParameter("srsltid");
                queryParameter9 = uri.getQueryParameter("sfmc_id");
            } else {
                queryParameter = null;
                queryParameter2 = null;
                queryParameter3 = null;
                queryParameter4 = null;
                queryParameter5 = null;
                queryParameter6 = null;
                queryParameter7 = null;
                queryParameter8 = null;
                queryParameter9 = null;
            }
            if (TextUtils.isEmpty(queryParameter) && TextUtils.isEmpty(queryParameter2) && TextUtils.isEmpty(queryParameter3) && TextUtils.isEmpty(queryParameter4) && TextUtils.isEmpty(queryParameter5) && TextUtils.isEmpty(queryParameter6) && TextUtils.isEmpty(queryParameter7) && TextUtils.isEmpty(queryParameter8) && TextUtils.isEmpty(queryParameter9)) {
                return null;
            }
            Bundle bundle = new Bundle();
            if (TextUtils.isEmpty(queryParameter)) {
                str = "sfmc_id";
            } else {
                str = "sfmc_id";
                bundle.putString("campaign", queryParameter);
            }
            if (!TextUtils.isEmpty(queryParameter2)) {
                bundle.putString("source", queryParameter2);
            }
            if (!TextUtils.isEmpty(queryParameter3)) {
                bundle.putString("medium", queryParameter3);
            }
            if (!TextUtils.isEmpty(queryParameter4)) {
                bundle.putString("gclid", queryParameter4);
            }
            if (!TextUtils.isEmpty(queryParameter5)) {
                bundle.putString("gbraid", queryParameter5);
            }
            String queryParameter10 = uri.getQueryParameter("gad_source");
            if (!TextUtils.isEmpty(queryParameter10)) {
                bundle.putString("gad_source", queryParameter10);
            }
            String queryParameter11 = uri.getQueryParameter("utm_term");
            if (!TextUtils.isEmpty(queryParameter11)) {
                bundle.putString("term", queryParameter11);
            }
            String queryParameter12 = uri.getQueryParameter("utm_content");
            if (!TextUtils.isEmpty(queryParameter12)) {
                bundle.putString("content", queryParameter12);
            }
            String queryParameter13 = uri.getQueryParameter("aclid");
            if (!TextUtils.isEmpty(queryParameter13)) {
                bundle.putString("aclid", queryParameter13);
            }
            String queryParameter14 = uri.getQueryParameter("cp1");
            if (!TextUtils.isEmpty(queryParameter14)) {
                bundle.putString("cp1", queryParameter14);
            }
            String queryParameter15 = uri.getQueryParameter("anid");
            if (!TextUtils.isEmpty(queryParameter15)) {
                bundle.putString("anid", queryParameter15);
            }
            if (!TextUtils.isEmpty(queryParameter6)) {
                bundle.putString("campaign_id", queryParameter6);
            }
            if (!TextUtils.isEmpty(queryParameter7)) {
                bundle.putString("dclid", queryParameter7);
            }
            String queryParameter16 = uri.getQueryParameter("utm_source_platform");
            if (!TextUtils.isEmpty(queryParameter16)) {
                bundle.putString("source_platform", queryParameter16);
            }
            String queryParameter17 = uri.getQueryParameter("utm_creative_format");
            if (!TextUtils.isEmpty(queryParameter17)) {
                bundle.putString("creative_format", queryParameter17);
            }
            String queryParameter18 = uri.getQueryParameter("utm_marketing_tactic");
            if (!TextUtils.isEmpty(queryParameter18)) {
                bundle.putString("marketing_tactic", queryParameter18);
            }
            if (!TextUtils.isEmpty(queryParameter8)) {
                bundle.putString("srsltid", queryParameter8);
            }
            if (!TextUtils.isEmpty(queryParameter9)) {
                bundle.putString(str, queryParameter9);
            }
            for (String str2 : uri.getQueryParameterNames()) {
                if (str2.startsWith("gad_")) {
                    String queryParameter19 = uri.getQueryParameter(str2);
                    if (!TextUtils.isEmpty(queryParameter19)) {
                        bundle.putString(str2, queryParameter19);
                    }
                }
            }
            return bundle;
        } catch (UnsupportedOperationException e2) {
            X x5 = ((C0146w0) this.f29k).p;
            C0146w0.l(x5);
            x5.f1626s.c("Install referrer url isn't a hierarchical URI", e2);
            return null;
        }
    }

    public final boolean k0(String str, String str2) {
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        if (str2 == null) {
            X x5 = c0146w0.p;
            C0146w0.l(x5);
            x5.f1625r.c("Name is required and can't be null. Type", str);
            return false;
        }
        if (str2.length() == 0) {
            X x6 = c0146w0.p;
            C0146w0.l(x6);
            x6.f1625r.c("Name is required and can't be empty. Type", str);
            return false;
        }
        int iCodePointAt = str2.codePointAt(0);
        if (!Character.isLetter(iCodePointAt)) {
            X x7 = c0146w0.p;
            C0146w0.l(x7);
            x7.f1625r.d(str, str2, "Name must start with a letter. Type, name");
            return false;
        }
        int length = str2.length();
        int iCharCount = Character.charCount(iCodePointAt);
        while (iCharCount < length) {
            int iCodePointAt2 = str2.codePointAt(iCharCount);
            if (iCodePointAt2 != 95 && !Character.isLetterOrDigit(iCodePointAt2)) {
                X x8 = c0146w0.p;
                C0146w0.l(x8);
                x8.f1625r.d(str, str2, "Name must consist of letters, digits or _ (underscores). Type, name");
                return false;
            }
            iCharCount += Character.charCount(iCodePointAt2);
        }
        return true;
    }

    @Override // L1.G0
    public final boolean l() {
        return true;
    }

    public final boolean l0(String str, String str2) {
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        if (str2 == null) {
            X x5 = c0146w0.p;
            C0146w0.l(x5);
            x5.f1625r.c("Name is required and can't be null. Type", str);
            return false;
        }
        if (str2.length() == 0) {
            X x6 = c0146w0.p;
            C0146w0.l(x6);
            x6.f1625r.c("Name is required and can't be empty. Type", str);
            return false;
        }
        int iCodePointAt = str2.codePointAt(0);
        if (!Character.isLetter(iCodePointAt)) {
            if (iCodePointAt != 95) {
                X x7 = c0146w0.p;
                C0146w0.l(x7);
                x7.f1625r.d(str, str2, "Name must start with a letter or _ (underscore). Type, name");
                return false;
            }
            iCodePointAt = 95;
        }
        int length = str2.length();
        int iCharCount = Character.charCount(iCodePointAt);
        while (iCharCount < length) {
            int iCodePointAt2 = str2.codePointAt(iCharCount);
            if (iCodePointAt2 != 95 && !Character.isLetterOrDigit(iCodePointAt2)) {
                X x8 = c0146w0.p;
                C0146w0.l(x8);
                x8.f1625r.d(str, str2, "Name must consist of letters, digits or _ (underscores). Type, name");
                return false;
            }
            iCharCount += Character.charCount(iCodePointAt2);
        }
        return true;
    }

    public final boolean m0(String str, String[] strArr, String[] strArr2, String str2) {
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        if (str2 == null) {
            X x5 = c0146w0.p;
            C0146w0.l(x5);
            x5.f1625r.c("Name is required and can't be null. Type", str);
            return false;
        }
        String[] strArr3 = f1744s;
        for (int i = 0; i < 3; i++) {
            if (str2.startsWith(strArr3[i])) {
                X x6 = c0146w0.p;
                C0146w0.l(x6);
                x6.f1625r.d(str, str2, "Name starts with reserved prefix. Type, name");
                return false;
            }
        }
        if (strArr == null || !J(str2, strArr)) {
            return true;
        }
        if (strArr2 != null && J(str2, strArr2)) {
            return true;
        }
        X x7 = c0146w0.p;
        C0146w0.l(x7);
        x7.f1625r.d(str, str2, "Name is reserved. Type, name");
        return false;
    }

    public final boolean n0(int i, String str, String str2) {
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        if (str2 == null) {
            X x5 = c0146w0.p;
            C0146w0.l(x5);
            x5.f1625r.c("Name is required and can't be null. Type", str);
            return false;
        }
        if (str2.codePointCount(0, str2.length()) <= i) {
            return true;
        }
        X x6 = c0146w0.p;
        C0146w0.l(x6);
        x6.f1625r.e("Name is too long. Type, maximum supported length, name", str, Integer.valueOf(i), str2);
        return false;
    }

    public final boolean o(String str) {
        boolean zIsEmpty = TextUtils.isEmpty(str);
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        if (zIsEmpty) {
            X x5 = c0146w0.p;
            C0146w0.l(x5);
            x5.f1625r.b("Missing google_app_id. Firebase Analytics disabled. See https://goo.gl/NAOOOI");
            return false;
        }
        s1.z.g(str);
        if (str.matches("^1:\\d+:android:[a-f0-9]+$")) {
            return true;
        }
        X x6 = c0146w0.p;
        C0146w0.l(x6);
        x6.f1625r.c("Invalid google_app_id. Firebase Analytics disabled. See https://goo.gl/NAOOOI. provided id", X.s(str));
        return false;
    }

    public final int o0(String str) {
        if (!l0("event", str)) {
            return 2;
        }
        if (!m0("event", M0.f1490a, M0.f1491b, str)) {
            return 13;
        }
        ((C0146w0) this.f29k).getClass();
        return !n0(40, "event", str) ? 2 : 0;
    }

    public final int p0(String str) {
        if (!l0("user property", str)) {
            return 6;
        }
        if (!m0("user property", M0.i, null, str)) {
            return 15;
        }
        ((C0146w0) this.f29k).getClass();
        return !n0(24, "user property", str) ? 6 : 0;
    }

    /* JADX WARN: Removed duplicated region for block: B:34:0x009b  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final int q(java.lang.String r13, java.lang.String r14, java.lang.Object r15, android.os.Bundle r16, java.util.List r17, boolean r18, boolean r19) {
        /*
            Method dump skipped, instruction units count: 331
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: L1.c2.q(java.lang.String, java.lang.String, java.lang.Object, android.os.Bundle, java.util.List, boolean, boolean):int");
    }

    public final int q0(String str) {
        if (!k0("event param", str)) {
            return 3;
        }
        if (!m0("event param", null, null, str)) {
            return 14;
        }
        ((C0146w0) this.f29k).getClass();
        return !n0(40, "event param", str) ? 3 : 0;
    }

    public final Object r(String str, Object obj) {
        boolean zEquals = "_ev".equals(str);
        int iMax = 500;
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        if (zEquals) {
            c0146w0.f2035n.getClass();
            return e0(Math.max(500, 256), obj, true, true);
        }
        if (I(str)) {
            c0146w0.f2035n.getClass();
            iMax = Math.max(500, 256);
        } else {
            c0146w0.f2035n.getClass();
        }
        return e0(iMax, obj, false, true);
    }

    public final int r0(String str) {
        if (!l0("event param", str)) {
            return 3;
        }
        if (!m0("event param", null, null, str)) {
            return 14;
        }
        ((C0146w0) this.f29k).getClass();
        return !n0(40, "event param", str) ? 3 : 0;
    }

    public final Bundle s(String str, Bundle bundle, List list, boolean z5) {
        int iQ0;
        List list2 = list;
        boolean zJ = J(str, M0.f1493d);
        if (bundle == null) {
            return null;
        }
        Bundle bundle2 = new Bundle(bundle);
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        c2 c2Var = ((C0146w0) c0146w0.f2035n.f29k).f2038s;
        C0146w0.j(c2Var);
        int i = c2Var.P(201500000) ? 100 : 25;
        int i5 = 0;
        boolean z6 = false;
        for (String str2 : new TreeSet(bundle.keySet())) {
            if (list2 == null || !list2.contains(str2)) {
                iQ0 = !z5 ? q0(str2) : 0;
                if (iQ0 == 0) {
                    iQ0 = r0(str2);
                }
            } else {
                iQ0 = 0;
            }
            if (iQ0 != 0) {
                w(bundle2, iQ0, str2, iQ0 == 3 ? str2 : null);
                bundle2.remove(str2);
            } else {
                int iQ = q(str, str2, bundle.get(str2), bundle2, list2, z5, zJ);
                if (iQ == 17) {
                    w(bundle2, 17, str2, Boolean.FALSE);
                } else if (iQ != 0 && !"_ev".equals(str2)) {
                    w(bundle2, iQ, iQ == 21 ? str : str2, bundle.get(str2));
                    bundle2.remove(str2);
                }
                if (i0(str2) && (i5 = i5 + 1) > i) {
                    if (!c0146w0.f2035n.u(null, F.e1) || !z6) {
                        StringBuilder sb = new StringBuilder(String.valueOf(i).length() + 37);
                        sb.append("Event can't contain more than ");
                        sb.append(i);
                        sb.append(" params");
                        String string = sb.toString();
                        X x5 = c0146w0.p;
                        C0146w0.l(x5);
                        Q q = c0146w0.f2039t;
                        x5.f1625r.d(q.a(str), q.e(bundle), string);
                    }
                    d0(5, bundle2);
                    bundle2.remove(str2);
                    z6 = true;
                }
            }
            list2 = list;
        }
        return bundle2;
    }

    public final void t(Y y5, int i) {
        Bundle bundle = (Bundle) y5.f1642e;
        int i5 = 0;
        boolean z5 = false;
        for (String str : new TreeSet(bundle.keySet())) {
            if (i0(str) && (i5 = i5 + 1) > i) {
                C0146w0 c0146w0 = (C0146w0) this.f29k;
                if (!c0146w0.f2035n.u(null, F.e1) || !z5) {
                    StringBuilder sb = new StringBuilder(String.valueOf(i).length() + 37);
                    sb.append("Event can't contain more than ");
                    sb.append(i);
                    sb.append(" params");
                    String string = sb.toString();
                    X x5 = c0146w0.p;
                    C0146w0.l(x5);
                    Q q = c0146w0.f2039t;
                    x5.f1625r.d(q.a((String) y5.f1640c), q.e(bundle), string);
                    d0(5, bundle);
                }
                bundle.remove(str);
                z5 = true;
            }
        }
    }

    public final boolean t0(String str, String str2, int i, Object obj) {
        if (obj == null || (obj instanceof Long) || (obj instanceof Float) || (obj instanceof Integer) || (obj instanceof Byte) || (obj instanceof Short) || (obj instanceof Boolean) || (obj instanceof Double)) {
            return true;
        }
        if (!(obj instanceof String) && !(obj instanceof Character) && !(obj instanceof CharSequence)) {
            return false;
        }
        String string = obj.toString();
        if (string.codePointCount(0, string.length()) > i) {
            X x5 = ((C0146w0) this.f29k).p;
            C0146w0.l(x5);
            x5.f1628u.e("Value is too long; discarded. Value kind, name, value length", str, str2, Integer.valueOf(string.length()));
            return false;
        }
        return true;
    }

    public final void u(Parcelable[] parcelableArr, int i) {
        s1.z.g(parcelableArr);
        for (Parcelable parcelable : parcelableArr) {
            Bundle bundle = (Bundle) parcelable;
            int i5 = 0;
            boolean z5 = false;
            for (String str : new TreeSet(bundle.keySet())) {
                if (i0(str) && !J(str, M0.f1497h) && (i5 = i5 + 1) > i) {
                    C0146w0 c0146w0 = (C0146w0) this.f29k;
                    if (!c0146w0.f2035n.u(null, F.e1) || !z5) {
                        X x5 = c0146w0.p;
                        C0146w0.l(x5);
                        StringBuilder sb = new StringBuilder(String.valueOf(i).length() + 60);
                        sb.append("Param can't contain more than ");
                        sb.append(i);
                        sb.append(" item-scoped custom parameters");
                        String string = sb.toString();
                        Q q = c0146w0.f2039t;
                        x5.f1625r.d(q.b(str), q.e(bundle), string);
                    }
                    d0(28, bundle);
                    bundle.remove(str);
                    z5 = true;
                }
            }
        }
    }

    public final void u0(String str, String str2, Bundle bundle, List list, boolean z5) {
        int iQ0;
        X x5;
        String str3;
        int iQ;
        List list2 = list;
        if (bundle == null) {
            return;
        }
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        c2 c2Var = ((C0146w0) c0146w0.f2035n.f29k).f2038s;
        C0146w0.j(c2Var);
        int i = true != c2Var.P(231100000) ? 0 : 35;
        int i5 = 0;
        boolean z6 = false;
        for (String str4 : new TreeSet(bundle.keySet())) {
            if (list2 == null || !list2.contains(str4)) {
                iQ0 = !z5 ? q0(str4) : 0;
                if (iQ0 == 0) {
                    iQ0 = r0(str4);
                }
            } else {
                iQ0 = 0;
            }
            if (iQ0 != 0) {
                w(bundle, iQ0, str4, iQ0 == 3 ? str4 : null);
                bundle.remove(str4);
            } else {
                boolean zS0 = s0(bundle.get(str4));
                X x6 = c0146w0.p;
                if (zS0) {
                    C0146w0.l(x6);
                    x6.f1628u.e("Nested Bundle parameters are not allowed; discarded. event name, param name, child param name", str, str2, str4);
                    iQ = 22;
                    x5 = x6;
                    str3 = null;
                } else {
                    x5 = x6;
                    str3 = null;
                    iQ = q(str, str4, bundle.get(str4), bundle, list2, z5, false);
                }
                if (iQ != 0 && !"_ev".equals(str4)) {
                    w(bundle, iQ, str4, bundle.get(str4));
                    bundle.remove(str4);
                } else if (i0(str4) && !J(str4, M0.f1497h)) {
                    i5++;
                    boolean zP = P(231100000);
                    Q q = c0146w0.f2039t;
                    if (zP) {
                        X x7 = x5;
                        if (i5 > i) {
                            if (!c0146w0.f2035n.u(str3, F.e1) || !z6) {
                                C0146w0.l(x7);
                                StringBuilder sb = new StringBuilder(String.valueOf(i).length() + 55);
                                sb.append("Item can't contain more than ");
                                sb.append(i);
                                sb.append(" item-scoped custom params");
                                x7.f1625r.d(q.a(str), q.e(bundle), sb.toString());
                            }
                            d0(28, bundle);
                            bundle.remove(str4);
                            list2 = list;
                            z6 = true;
                        }
                    } else {
                        C0146w0.l(x5);
                        x5.f1625r.d(q.a(str), q.e(bundle), "Item array not supported on client's version of Google Play Services (Android Only)");
                        d0(23, bundle);
                        bundle.remove(str4);
                    }
                }
            }
            list2 = list;
        }
    }

    public final void v(Bundle bundle, Bundle bundle2) {
        if (bundle2 == null) {
            return;
        }
        for (String str : bundle2.keySet()) {
            if (!bundle.containsKey(str)) {
                c2 c2Var = ((C0146w0) this.f29k).f2038s;
                C0146w0.j(c2Var);
                c2Var.z(bundle, str, bundle2.get(str));
            }
        }
    }

    public final void w(Bundle bundle, int i, String str, Object obj) {
        if (d0(i, bundle)) {
            ((C0146w0) this.f29k).getClass();
            bundle.putString("_ev", p(40, str, true));
            if (obj != null) {
                if ((obj instanceof String) || (obj instanceof CharSequence)) {
                    bundle.putLong("_el", obj.toString().length());
                }
            }
        }
    }

    public final int x(String str, Object obj) {
        return "_ldl".equals(str) ? t0("user property referrer", str, f0(str), obj) : t0("user property", str, f0(str), obj) ? 0 : 7;
    }

    public final Object y(String str, Object obj) {
        return "_ldl".equals(str) ? e0(f0(str), obj, true, false) : e0(f0(str), obj, false, false);
    }

    public final void z(Bundle bundle, String str, Object obj) {
        if (bundle == null) {
            return;
        }
        if (obj instanceof Long) {
            bundle.putLong(str, ((Long) obj).longValue());
            return;
        }
        if (obj instanceof String) {
            bundle.putString(str, String.valueOf(obj));
            return;
        }
        if (obj instanceof Double) {
            bundle.putDouble(str, ((Double) obj).doubleValue());
            return;
        }
        if (obj instanceof Bundle[]) {
            bundle.putParcelableArray(str, (Bundle[]) obj);
            return;
        }
        if (str != null) {
            String simpleName = obj != null ? obj.getClass().getSimpleName() : null;
            C0146w0 c0146w0 = (C0146w0) this.f29k;
            X x5 = c0146w0.p;
            C0146w0.l(x5);
            x5.f1628u.d(c0146w0.f2039t.b(str), simpleName, "Not putting event parameter. Invalid value type. name, type");
        }
    }
}
