package o;

import android.adservices.measurement.MeasurementManager;
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.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 com.google.android.gms.common.GoogleApiAvailabilityLight;
import com.google.android.gms.common.internal.Preconditions;
import com.google.android.gms.common.util.CollectionUtils;
import com.google.android.gms.common.wrappers.Wrappers;
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.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.AtomicLong;
import javax.security.auth.x500.X500Principal;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.tv0, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C2574tv0 extends AbstractC1429hs0 {
    public static final String[] i = {"firebase_", "google_", "ga_"};
    public static final String[] j = {"_err"};
    public SecureRandom c;
    public final AtomicLong d;
    public int e;
    public C2614uO f;
    public Boolean g;
    public Integer h;

    public C2574tv0(Kr0 kr0) {
        super(kr0);
        this.h = null;
        this.d = new AtomicLong(0L);
    }

    public static void I(InterfaceC2384rv0 interfaceC2384rv0, String str, int i2, String str2, String str3, int i3) {
        Bundle bundle = new Bundle();
        k0(i2, bundle);
        if (!TextUtils.isEmpty(str2) && !TextUtils.isEmpty(str3)) {
            bundle.putString(str2, str3);
        }
        if (i2 == 6 || i2 == 7 || i2 == 2) {
            bundle.putLong("_el", i3);
        }
        interfaceC2384rv0.c(str, "_err", bundle);
    }

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

    public static long K(byte[] bArr) {
        Preconditions.checkNotNull(bArr);
        int length = bArr.length;
        int i2 = 0;
        Preconditions.checkState(length > 0);
        long j2 = 0;
        for (int i3 = length - 1; i3 >= 0 && i3 >= bArr.length - 8; i3--) {
            j2 += (bArr[i3] & 255) << i2;
            i2 += 8;
        }
        return j2;
    }

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

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

    public static boolean Q(String str, String[] strArr) {
        Preconditions.checkNotNull(strArr);
        for (String str2 : strArr) {
            if (Objects.equals(str, str2)) {
                return true;
            }
        }
        return false;
    }

    public static byte[] V(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 g0(List list) {
        if (list == null) {
            return new ArrayList(0);
        }
        ArrayList arrayList = new ArrayList(list.size());
        Iterator it = list.iterator();
        while (it.hasNext()) {
            Xn0 xn0 = (Xn0) it.next();
            Bundle bundle = new Bundle();
            bundle.putString("app_id", xn0.l);
            bundle.putString("origin", xn0.m);
            bundle.putLong("creation_timestamp", xn0.f413o);
            bundle.putString("name", xn0.n.m);
            AbstractC2001nt0.N(bundle, Preconditions.checkNotNull(xn0.n.b()));
            bundle.putBoolean("active", xn0.p);
            String str = xn0.q;
            if (str != null) {
                bundle.putString("trigger_event_name", str);
            }
            No0 no0 = xn0.r;
            if (no0 != null) {
                bundle.putString("timed_out_event_name", no0.l);
                Lo0 lo0 = no0.m;
                if (lo0 != null) {
                    bundle.putBundle("timed_out_event_params", lo0.f());
                }
            }
            bundle.putLong("trigger_timeout", xn0.s);
            No0 no02 = xn0.t;
            if (no02 != null) {
                bundle.putString("triggered_event_name", no02.l);
                Lo0 lo02 = no02.m;
                if (lo02 != null) {
                    bundle.putBundle("triggered_event_params", lo02.f());
                }
            }
            bundle.putLong("triggered_timestamp", xn0.n.n);
            bundle.putLong("time_to_live", xn0.u);
            No0 no03 = xn0.v;
            if (no03 != null) {
                bundle.putString("expired_event_name", no03.l);
                Lo0 lo03 = no03.m;
                if (lo03 != null) {
                    bundle.putBundle("expired_event_params", lo03.f());
                }
            }
            arrayList.add(bundle);
        }
        return arrayList;
    }

    public static boolean h0(Context context) {
        ActivityInfo receiverInfo;
        Preconditions.checkNotNull(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 i0(C1431ht0 c1431ht0, Bundle bundle, boolean z) {
        if (bundle != null && c1431ht0 != null) {
            if (!bundle.containsKey("_sc") || z) {
                String str = c1431ht0.a;
                if (str != null) {
                    bundle.putString("_sn", str);
                } else {
                    bundle.remove("_sn");
                }
                String str2 = c1431ht0.b;
                if (str2 != null) {
                    bundle.putString("_sc", str2);
                } else {
                    bundle.remove("_sc");
                }
                bundle.putLong("_si", c1431ht0.c);
                return;
            }
            z = false;
        }
        if (bundle != null && c1431ht0 == null && z) {
            bundle.remove("_sn");
            bundle.remove("_sc");
            bundle.remove("_si");
        }
    }

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

    public static boolean p0(String str) {
        Preconditions.checkNotEmpty(str);
        return str.charAt(0) != '_' || str.equals("_ep");
    }

    public static String x(String str, int i2, boolean z) {
        if (str != null) {
            if (str.codePointCount(0, str.length()) <= i2) {
                return str;
            }
            if (z) {
                return String.valueOf(str.substring(0, str.offsetByCodePoints(0, i2))).concat("...");
            }
        }
        return null;
    }

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

    public final Bundle A(String str, Bundle bundle, List list, boolean z) {
        int iX0;
        String str2;
        List list2 = list;
        boolean zQ = Q(str, AbstractC2841wm0.n);
        String str3 = null;
        if (bundle == null) {
            return null;
        }
        Bundle bundle2 = new Bundle(bundle);
        Kr0 kr0 = (Kr0) this.a;
        C1421ho0 c1421ho0 = kr0.d;
        Eq0 eq0 = kr0.j;
        C2574tv0 c2574tv0 = ((Kr0) c1421ho0.a).i;
        Kr0.j(c2574tv0);
        int i2 = c2574tv0.W(201500000) ? 100 : 25;
        Iterator it = new TreeSet(bundle.keySet()).iterator();
        int i3 = 0;
        boolean z2 = false;
        while (it.hasNext()) {
            String str4 = (String) it.next();
            if (list2 == null || !list2.contains(str4)) {
                iX0 = !z ? x0(str4) : 0;
                if (iX0 == 0) {
                    iX0 = y0(str4);
                }
            } else {
                iX0 = 0;
            }
            if (iX0 != 0) {
                E(bundle2, iX0, str4, iX0 == 3 ? str4 : str3);
                bundle2.remove(str4);
            } else {
                int iY = y(str, str4, bundle.get(str4), bundle2, list2, z, zQ);
                if (iY == 17) {
                    E(bundle2, 17, str4, Boolean.FALSE);
                } else if (iY != 0 && !"_ev".equals(str4)) {
                    E(bundle2, iY, iY == 21 ? str : str4, bundle.get(str4));
                    bundle2.remove(str4);
                }
                if (p0(str4)) {
                    i3++;
                    if (i3 > i2) {
                        if (kr0.d.C(str3, AbstractC1900mq0.e1) && z2) {
                            str2 = str3;
                        } else {
                            StringBuilder sb = new StringBuilder(String.valueOf(i2).length() + 37);
                            sb.append("Event can't contain more than ");
                            sb.append(i2);
                            sb.append(" params");
                            String string = sb.toString();
                            Nq0 nq0 = kr0.f;
                            Kr0.l(nq0);
                            str2 = str3;
                            nq0.h.d(string, eq0.a(str), eq0.e(bundle));
                        }
                        k0(5, bundle2);
                        bundle2.remove(str4);
                        z2 = true;
                        list2 = list;
                        str3 = str2;
                    } else {
                        list2 = list;
                    }
                }
            }
            str2 = str3;
            list2 = list;
            str3 = str2;
        }
        return bundle2;
    }

    public final boolean A0(String str, String str2, int i2, 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()) > i2) {
            Nq0 nq0 = ((Kr0) this.a).f;
            Kr0.l(nq0);
            nq0.k.e("Value is too long; discarded. Value kind, name, value length", str, str2, Integer.valueOf(string.length()));
            return false;
        }
        return true;
    }

    public final void B(Oq0 oq0, int i2) {
        Bundle bundle = (Bundle) oq0.e;
        Iterator it = new TreeSet(bundle.keySet()).iterator();
        int i3 = 0;
        boolean z = false;
        while (it.hasNext()) {
            String str = (String) it.next();
            if (p0(str) && (i3 = i3 + 1) > i2) {
                Kr0 kr0 = (Kr0) this.a;
                C1421ho0 c1421ho0 = kr0.d;
                Eq0 eq0 = kr0.j;
                if (!c1421ho0.C(null, AbstractC1900mq0.e1) || !z) {
                    StringBuilder sb = new StringBuilder(String.valueOf(i2).length() + 37);
                    sb.append("Event can't contain more than ");
                    sb.append(i2);
                    sb.append(" params");
                    String string = sb.toString();
                    Nq0 nq0 = kr0.f;
                    Kr0.l(nq0);
                    nq0.h.d(string, eq0.a((String) oq0.c), eq0.e(bundle));
                    k0(5, bundle);
                }
                bundle.remove(str);
                z = true;
            }
        }
    }

    public final void B0(String str, String str2, Bundle bundle, List list, boolean z) {
        int iX0;
        String str3;
        int iY;
        List list2 = list;
        if (bundle == null) {
            return;
        }
        Kr0 kr0 = (Kr0) this.a;
        C1421ho0 c1421ho0 = kr0.d;
        Nq0 nq0 = kr0.f;
        Eq0 eq0 = kr0.j;
        C2574tv0 c2574tv0 = ((Kr0) c1421ho0.a).i;
        Kr0.j(c2574tv0);
        int i2 = true != c2574tv0.W(231100000) ? 0 : 35;
        Iterator it = new TreeSet(bundle.keySet()).iterator();
        int i3 = 0;
        boolean z2 = false;
        while (it.hasNext()) {
            String str4 = (String) it.next();
            if (list2 == null || !list2.contains(str4)) {
                iX0 = !z ? x0(str4) : 0;
                if (iX0 == 0) {
                    iX0 = y0(str4);
                }
            } else {
                iX0 = 0;
            }
            if (iX0 != 0) {
                E(bundle, iX0, str4, iX0 == 3 ? str4 : null);
                bundle.remove(str4);
            } else {
                if (z0(bundle.get(str4))) {
                    Kr0.l(nq0);
                    nq0.k.e("Nested Bundle parameters are not allowed; discarded. event name, param name, child param name", str, str2, str4);
                    iY = 22;
                    str3 = null;
                } else {
                    str3 = null;
                    iY = y(str, str4, bundle.get(str4), bundle, list2, z, false);
                }
                if (iY != 0 && !"_ev".equals(str4)) {
                    E(bundle, iY, str4, bundle.get(str4));
                    bundle.remove(str4);
                } else if (p0(str4) && !Q(str4, AbstractC0940cn0.k)) {
                    int i4 = i3 + 1;
                    if (!W(231100000)) {
                        Kr0.l(nq0);
                        nq0.h.d("Item array not supported on client's version of Google Play Services (Android Only)", eq0.a(str), eq0.e(bundle));
                        k0(23, bundle);
                        bundle.remove(str4);
                    } else if (i4 > i2) {
                        if (!kr0.d.C(str3, AbstractC1900mq0.e1) || !z2) {
                            Kr0.l(nq0);
                            C1984nl c1984nl = nq0.h;
                            StringBuilder sb = new StringBuilder(String.valueOf(i2).length() + 55);
                            sb.append("Item can't contain more than ");
                            sb.append(i2);
                            sb.append(" item-scoped custom params");
                            c1984nl.d(sb.toString(), eq0.a(str), eq0.e(bundle));
                        }
                        k0(28, bundle);
                        bundle.remove(str4);
                        list2 = list;
                        i3 = i4;
                        z2 = true;
                    }
                    list2 = list;
                    i3 = i4;
                }
            }
            list2 = list;
        }
    }

    public final void C(Parcelable[] parcelableArr, int i2) {
        Preconditions.checkNotNull(parcelableArr);
        for (Parcelable parcelable : parcelableArr) {
            Bundle bundle = (Bundle) parcelable;
            Iterator it = new TreeSet(bundle.keySet()).iterator();
            int i3 = 0;
            boolean z = false;
            while (it.hasNext()) {
                String str = (String) it.next();
                if (p0(str) && !Q(str, AbstractC0940cn0.k) && (i3 = i3 + 1) > i2) {
                    Kr0 kr0 = (Kr0) this.a;
                    C1421ho0 c1421ho0 = kr0.d;
                    Eq0 eq0 = kr0.j;
                    if (!c1421ho0.C(null, AbstractC1900mq0.e1) || !z) {
                        Nq0 nq0 = kr0.f;
                        Kr0.l(nq0);
                        C1984nl c1984nl = nq0.h;
                        StringBuilder sb = new StringBuilder(String.valueOf(i2).length() + 60);
                        sb.append("Param can't contain more than ");
                        sb.append(i2);
                        sb.append(" item-scoped custom parameters");
                        c1984nl.d(sb.toString(), eq0.b(str), eq0.e(bundle));
                    }
                    k0(28, bundle);
                    bundle.remove(str);
                    z = true;
                }
            }
        }
    }

    public final void D(Bundle bundle, Bundle bundle2) {
        if (bundle2 == null) {
            return;
        }
        for (String str : bundle2.keySet()) {
            if (!bundle.containsKey(str)) {
                C2574tv0 c2574tv0 = ((Kr0) this.a).i;
                Kr0.j(c2574tv0);
                c2574tv0.H(bundle, str, bundle2.get(str));
            }
        }
    }

    public final void E(Bundle bundle, int i2, String str, Object obj) {
        if (k0(i2, bundle)) {
            ((Kr0) this.a).getClass();
            bundle.putString("_ev", x(str, 40, true));
            if (obj != null) {
                Preconditions.checkNotNull(bundle);
                if ((obj instanceof String) || (obj instanceof CharSequence)) {
                    bundle.putLong("_el", obj.toString().length());
                }
            }
        }
    }

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

    public final Object G(Object obj, String str) {
        return "_ldl".equals(str) ? l0(m0(str), obj, true, false) : l0(m0(str), obj, false, false);
    }

    public final void H(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;
            Kr0 kr0 = (Kr0) this.a;
            Nq0 nq0 = kr0.f;
            Kr0.l(nq0);
            nq0.k.d("Not putting event parameter. Invalid value type. name, type", kr0.j.b(str), simpleName);
        }
    }

    public final C2614uO L() {
        C2519tO c2519tO;
        if (this.f == null) {
            Context context = ((Kr0) this.a).a;
            int i2 = Build.VERSION.SDK_INT;
            M1 m1 = M1.a;
            if (i2 >= 33) {
                m1.a();
            }
            if ((i2 >= 33 ? m1.a() : 0) >= 5) {
                c2519tO = new C2519tO(EE.f(context.getSystemService(EE.q())));
            } else {
                L1 l1 = L1.a;
                if (((i2 == 31 || i2 == 32) ? l1.a() : 0) >= 9) {
                    try {
                        c2519tO = new C2519tO(MeasurementManager.get(context));
                    } catch (NoClassDefFoundError unused) {
                        int i3 = Build.VERSION.SDK_INT;
                        if (i3 == 31 || i3 == 32) {
                            l1.a();
                        }
                    }
                } else {
                    c2519tO = null;
                }
            }
            this.f = c2519tO != null ? new C2614uO(c2519tO) : null;
        }
        return this.f;
    }

    /* JADX WARN: Removed duplicated region for block: B:59:0x00be  */
    /* JADX WARN: Removed duplicated region for block: B:62:0x00c4 A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:64:0x00c7 A[RETURN] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final long M() {
        /*
            Method dump skipped, instructions count: 200
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: o.C2574tv0.M():long");
    }

    public final boolean O(String str) {
        r();
        Kr0 kr0 = (Kr0) this.a;
        if (Wrappers.packageManager(kr0.a).checkCallingOrSelfPermission(str) == 0) {
            return true;
        }
        Nq0 nq0 = kr0.f;
        Kr0.l(nq0);
        nq0.m.c(str, "Permission not granted");
        return false;
    }

    public final boolean R(String str, String str2) {
        if (!TextUtils.isEmpty(str2)) {
            return true;
        }
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        return ((Kr0) this.a).d.w("debug.firebase.analytics.app").equals(str);
    }

    public final Bundle S(Bundle bundle) {
        Bundle bundle2 = new Bundle();
        if (bundle != null) {
            for (String str : bundle.keySet()) {
                Object objZ = z(bundle.get(str), str);
                if (objZ == null) {
                    Kr0 kr0 = (Kr0) this.a;
                    Nq0 nq0 = kr0.f;
                    Kr0.l(nq0);
                    nq0.k.c(kr0.j.b(str), "Param value can't be null");
                } else {
                    H(bundle2, str, objZ);
                }
            }
        }
        return bundle2;
    }

    public final No0 T(String str, Bundle bundle, String str2, long j2, boolean z) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        if (v0(str) != 0) {
            Kr0 kr0 = (Kr0) this.a;
            Nq0 nq0 = kr0.f;
            Kr0.l(nq0);
            nq0.f.c(kr0.j.c(str), "Invalid conditional property event name");
            throw new IllegalArgumentException();
        }
        Bundle bundle2 = bundle != null ? new Bundle(bundle) : new Bundle();
        bundle2.putString("_o", str2);
        Bundle bundleA = A(str, bundle2, CollectionUtils.listOf("_o"), true);
        if (z) {
            bundleA = S(bundleA);
        }
        Preconditions.checkNotNull(bundleA);
        return new No0(str, new Lo0(bundleA), str2, j2);
    }

    public final boolean U(Context context, String str) {
        Signature[] signatureArr;
        Kr0 kr0 = (Kr0) this.a;
        X500Principal x500Principal = new X500Principal("CN=Android Debug,O=Android,C=US");
        try {
            PackageInfo packageInfo = Wrappers.packageManager(context).getPackageInfo(str, 64);
            if (packageInfo == null || (signatureArr = packageInfo.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 e) {
            Nq0 nq0 = kr0.f;
            Kr0.l(nq0);
            nq0.f.c(e, "Package name not found");
            return true;
        } catch (CertificateException e2) {
            Nq0 nq02 = kr0.f;
            Kr0.l(nq02);
            nq02.f.c(e2, "Error obtaining certificate");
            return true;
        }
    }

    public final boolean W(int i2) {
        Boolean bool = ((Kr0) this.a).o().e;
        if (X() < i2 / 1000) {
            return (bool == null || bool.booleanValue()) ? false : true;
        }
        return true;
    }

    public final int X() {
        if (this.h == null) {
            this.h = Integer.valueOf(GoogleApiAvailabilityLight.getInstance().getApkVersion(((Kr0) this.a).a) / 1000);
        }
        return this.h.intValue();
    }

    public final void Y(Bundle bundle, long j2) {
        long j3 = bundle.getLong("_et");
        if (j3 != 0) {
            Nq0 nq0 = ((Kr0) this.a).f;
            Kr0.l(nq0);
            nq0.i.c(Long.valueOf(j3), "Params already contained engagement");
        } else {
            j3 = 0;
        }
        bundle.putLong("_et", j2 + j3);
    }

    public final void Z(String str, InterfaceC2183pp0 interfaceC2183pp0) {
        Bundle bundle = new Bundle();
        bundle.putString("r", str);
        try {
            interfaceC2183pp0.k(bundle);
        } catch (RemoteException e) {
            Nq0 nq0 = ((Kr0) this.a).f;
            Kr0.l(nq0);
            nq0.i.c(e, "Error returning string value to wrapper");
        }
    }

    public final void a0(InterfaceC2183pp0 interfaceC2183pp0, long j2) {
        Bundle bundle = new Bundle();
        bundle.putLong("r", j2);
        try {
            interfaceC2183pp0.k(bundle);
        } catch (RemoteException e) {
            Nq0 nq0 = ((Kr0) this.a).f;
            Kr0.l(nq0);
            nq0.i.c(e, "Error returning long value to wrapper");
        }
    }

    public final void b0(InterfaceC2183pp0 interfaceC2183pp0, int i2) {
        Bundle bundle = new Bundle();
        bundle.putInt("r", i2);
        try {
            interfaceC2183pp0.k(bundle);
        } catch (RemoteException e) {
            Nq0 nq0 = ((Kr0) this.a).f;
            Kr0.l(nq0);
            nq0.i.c(e, "Error returning int value to wrapper");
        }
    }

    public final void c0(InterfaceC2183pp0 interfaceC2183pp0, byte[] bArr) {
        Bundle bundle = new Bundle();
        bundle.putByteArray("r", bArr);
        try {
            interfaceC2183pp0.k(bundle);
        } catch (RemoteException e) {
            Nq0 nq0 = ((Kr0) this.a).f;
            Kr0.l(nq0);
            nq0.i.c(e, "Error returning byte array to wrapper");
        }
    }

    public final void d0(InterfaceC2183pp0 interfaceC2183pp0, boolean z) {
        Bundle bundle = new Bundle();
        bundle.putBoolean("r", z);
        try {
            interfaceC2183pp0.k(bundle);
        } catch (RemoteException e) {
            Nq0 nq0 = ((Kr0) this.a).f;
            Kr0.l(nq0);
            nq0.i.c(e, "Error returning boolean value to wrapper");
        }
    }

    public final void e0(InterfaceC2183pp0 interfaceC2183pp0, Bundle bundle) {
        try {
            interfaceC2183pp0.k(bundle);
        } catch (RemoteException e) {
            Nq0 nq0 = ((Kr0) this.a).f;
            Kr0.l(nq0);
            nq0.i.c(e, "Error returning bundle value to wrapper");
        }
    }

    public final void f0(InterfaceC2183pp0 interfaceC2183pp0, ArrayList arrayList) {
        Bundle bundle = new Bundle();
        bundle.putParcelableArrayList("r", arrayList);
        try {
            interfaceC2183pp0.k(bundle);
        } catch (RemoteException e) {
            Nq0 nq0 = ((Kr0) this.a).f;
            Kr0.l(nq0);
            nq0.i.c(e, "Error returning bundle list to wrapper");
        }
    }

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

    public final Object l0(int i2, Object obj, boolean z, boolean z2) {
        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 x(obj.toString(), i2, z);
        }
        if (!z2) {
            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 bundleS = S((Bundle) parcelable);
                if (!bundleS.isEmpty()) {
                    arrayList.add(bundleS);
                }
            }
        }
        return arrayList.toArray(new Bundle[arrayList.size()]);
    }

    public final int m0(String str) {
        Kr0 kr0 = (Kr0) this.a;
        if ("_ldl".equals(str)) {
            kr0.getClass();
            return 2048;
        }
        if ("_id".equals(str)) {
            kr0.getClass();
            return 256;
        }
        if ("_lgclid".equals(str)) {
            kr0.getClass();
            return 100;
        }
        kr0.getClass();
        return 36;
    }

    public final long n0() {
        long andIncrement;
        long j2;
        AtomicLong atomicLong = this.d;
        if (atomicLong.get() != 0) {
            AtomicLong atomicLong2 = this.d;
            synchronized (atomicLong2) {
                atomicLong2.compareAndSet(-1L, 1L);
                andIncrement = atomicLong2.getAndIncrement();
            }
            return andIncrement;
        }
        synchronized (atomicLong) {
            long jNextLong = new Random(System.nanoTime() ^ ((Kr0) this.a).k.currentTimeMillis()).nextLong();
            int i2 = this.e + 1;
            this.e = i2;
            j2 = jNextLong + i2;
        }
        return j2;
    }

    public final SecureRandom o0() {
        r();
        if (this.c == null) {
            this.c = new SecureRandom();
        }
        return this.c;
    }

    public final Bundle q0(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 e) {
            Nq0 nq0 = ((Kr0) this.a).f;
            Kr0.l(nq0);
            nq0.i.c(e, "Install referrer url isn't a hierarchical URI");
            return null;
        }
    }

    public final boolean r0(String str, String str2) {
        Kr0 kr0 = (Kr0) this.a;
        if (str2 == null) {
            Nq0 nq0 = kr0.f;
            Kr0.l(nq0);
            nq0.h.c(str, "Name is required and can't be null. Type");
            return false;
        }
        if (str2.length() == 0) {
            Nq0 nq02 = kr0.f;
            Kr0.l(nq02);
            nq02.h.c(str, "Name is required and can't be empty. Type");
            return false;
        }
        int iCodePointAt = str2.codePointAt(0);
        if (!Character.isLetter(iCodePointAt)) {
            Nq0 nq03 = kr0.f;
            Kr0.l(nq03);
            nq03.h.d("Name must start with a letter. Type, name", str, str2);
            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)) {
                Nq0 nq04 = kr0.f;
                Kr0.l(nq04);
                nq04.h.d("Name must consist of letters, digits or _ (underscores). Type, name", str, str2);
                return false;
            }
            iCharCount += Character.charCount(iCodePointAt2);
        }
        return true;
    }

    public final boolean s0(String str, String str2) {
        Kr0 kr0 = (Kr0) this.a;
        if (str2 == null) {
            Nq0 nq0 = kr0.f;
            Kr0.l(nq0);
            nq0.h.c(str, "Name is required and can't be null. Type");
            return false;
        }
        if (str2.length() == 0) {
            Nq0 nq02 = kr0.f;
            Kr0.l(nq02);
            nq02.h.c(str, "Name is required and can't be empty. Type");
            return false;
        }
        int iCodePointAt = str2.codePointAt(0);
        if (!Character.isLetter(iCodePointAt)) {
            if (iCodePointAt != 95) {
                Nq0 nq03 = kr0.f;
                Kr0.l(nq03);
                nq03.h.d("Name must start with a letter or _ (underscore). Type, name", str, str2);
                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)) {
                Nq0 nq04 = kr0.f;
                Kr0.l(nq04);
                nq04.h.d("Name must consist of letters, digits or _ (underscores). Type, name", str, str2);
                return false;
            }
            iCharCount += Character.charCount(iCodePointAt2);
        }
        return true;
    }

    @Override // o.AbstractC1429hs0
    public final boolean t() {
        return true;
    }

    public final boolean t0(String str, String[] strArr, String[] strArr2, String str2) {
        Kr0 kr0 = (Kr0) this.a;
        if (str2 == null) {
            Nq0 nq0 = kr0.f;
            Kr0.l(nq0);
            nq0.h.c(str, "Name is required and can't be null. Type");
            return false;
        }
        Preconditions.checkNotNull(str2);
        for (int i2 = 0; i2 < 3; i2++) {
            if (str2.startsWith(i[i2])) {
                Nq0 nq02 = kr0.f;
                Kr0.l(nq02);
                nq02.h.d("Name starts with reserved prefix. Type, name", str, str2);
                return false;
            }
        }
        if (strArr == null || !Q(str2, strArr)) {
            return true;
        }
        if (strArr2 != null && Q(str2, strArr2)) {
            return true;
        }
        Nq0 nq03 = kr0.f;
        Kr0.l(nq03);
        nq03.h.d("Name is reserved. Type, name", str, str2);
        return false;
    }

    public final boolean u0(int i2, String str, String str2) {
        Kr0 kr0 = (Kr0) this.a;
        if (str2 == null) {
            Nq0 nq0 = kr0.f;
            Kr0.l(nq0);
            nq0.h.c(str, "Name is required and can't be null. Type");
            return false;
        }
        if (str2.codePointCount(0, str2.length()) <= i2) {
            return true;
        }
        Nq0 nq02 = kr0.f;
        Kr0.l(nq02);
        nq02.h.e("Name is too long. Type, maximum supported length, name", str, Integer.valueOf(i2), str2);
        return false;
    }

    public final int v0(String str) {
        if (!s0("event", str)) {
            return 2;
        }
        if (!t0("event", AbstractC2841wm0.k, AbstractC2841wm0.l, str)) {
            return 13;
        }
        ((Kr0) this.a).getClass();
        return !u0(40, "event", str) ? 2 : 0;
    }

    public final boolean w(String str) {
        Kr0 kr0 = (Kr0) this.a;
        if (TextUtils.isEmpty(str)) {
            Nq0 nq0 = kr0.f;
            Kr0.l(nq0);
            nq0.h.b("Missing google_app_id. Firebase Analytics disabled. See https://goo.gl/NAOOOI");
            return false;
        }
        Preconditions.checkNotNull(str);
        if (str.matches("^1:\\d+:android:[a-f0-9]+$")) {
            return true;
        }
        Nq0 nq02 = kr0.f;
        Kr0.l(nq02);
        nq02.h.c(Nq0.A(str), "Invalid google_app_id. Firebase Analytics disabled. See https://goo.gl/NAOOOI. provided id");
        return false;
    }

    public final int w0(String str) {
        if (!s0("user property", str)) {
            return 6;
        }
        if (!t0("user property", Co0.f, null, str)) {
            return 15;
        }
        ((Kr0) this.a).getClass();
        return !u0(24, "user property", str) ? 6 : 0;
    }

    public final int x0(String str) {
        if (!r0("event param", str)) {
            return 3;
        }
        if (!t0("event param", null, null, str)) {
            return 14;
        }
        ((Kr0) this.a).getClass();
        return !u0(40, "event param", str) ? 3 : 0;
    }

    /* JADX WARN: Removed duplicated region for block: B:34:0x009c  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final int y(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, instructions count: 332
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: o.C2574tv0.y(java.lang.String, java.lang.String, java.lang.Object, android.os.Bundle, java.util.List, boolean, boolean):int");
    }

    public final int y0(String str) {
        if (!s0("event param", str)) {
            return 3;
        }
        if (!t0("event param", null, null, str)) {
            return 14;
        }
        ((Kr0) this.a).getClass();
        return !u0(40, "event param", str) ? 3 : 0;
    }

    public final Object z(Object obj, String str) {
        Kr0 kr0 = (Kr0) this.a;
        int iMax = 500;
        if ("_ev".equals(str)) {
            kr0.d.getClass();
            return l0(Math.max(500, 256), obj, true, true);
        }
        if (P(str)) {
            kr0.d.getClass();
            iMax = Math.max(500, 256);
        } else {
            kr0.d.getClass();
        }
        return l0(iMax, obj, false, true);
    }
}
