package com.google.android.gms.measurement.internal;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
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.os.ext.SdkExtensions;
import android.text.TextUtils;
import androidx.media3.common.PlaybackException;
import androidx.privacysandbox.ads.adservices.java.measurement.MeasurementManagerFutures$Api33Ext5JavaImpl;
import com.google.android.gms.internal.measurement.ga;
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.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicLong;
import javax.security.auth.x500.X500Principal;

/* JADX INFO: loaded from: classes2.dex */
public final class n4 extends a2 {

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

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

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

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public int f21796e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public MeasurementManagerFutures$Api33Ext5JavaImpl f21797f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public Boolean f21798g;

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

    public n4(m1 m1Var) {
        super(m1Var);
        this.f21799h = null;
        this.f21795d = new AtomicLong(0L);
    }

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

    public static boolean B0(String str) {
        com.google.android.gms.common.internal.w.checkNotEmpty(str);
        return str.charAt(0) != '_' || str.equals("_ep");
    }

    public static long D(x xVar) {
        long length = 0;
        if (xVar == null) {
            return 0L;
        }
        w wVar = new w(xVar);
        while (wVar.f21947a.hasNext()) {
            Object obj = xVar.f21970a.get((String) wVar.next());
            if (obj instanceof Parcelable[]) {
                length += (long) ((Parcelable[]) obj).length;
            }
        }
        return length;
    }

    public static int D0(String str) {
        if ("_ldl".equals(str)) {
            return 2048;
        }
        if ("_id".equals(str)) {
            return 256;
        }
        return "_lgclid".equals(str) ? 100 : 36;
    }

    public static long E(byte[] bArr) {
        com.google.android.gms.common.internal.w.checkNotNull(bArr);
        int i10 = 0;
        com.google.android.gms.common.internal.w.g(bArr.length > 0);
        long j10 = 0;
        for (int length = bArr.length - 1; length >= 0 && length >= bArr.length - 8; length--) {
            j10 += (((long) bArr[length]) & 255) << i10;
            i10 += 8;
        }
        return j10;
    }

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

    public static Bundle I(List list) {
        Bundle bundle = new Bundle();
        if (list == null) {
            return bundle;
        }
        Iterator it = list.iterator();
        while (it.hasNext()) {
            i4 i4Var = (i4) it.next();
            String str = i4Var.zzd;
            String str2 = i4Var.f21666b;
            if (str != null) {
                bundle.putString(str2, str);
            } else {
                Long l10 = i4Var.zzc;
                if (l10 != null) {
                    bundle.putLong(str2, l10.longValue());
                } else {
                    Double d10 = i4Var.zzf;
                    if (d10 != null) {
                        bundle.putDouble(str2, d10.doubleValue());
                    }
                }
            }
        }
        return bundle;
    }

    public static String L(int i10, String str, boolean z10) {
        if (str == null) {
            return null;
        }
        if (str.codePointCount(0, str.length()) <= i10) {
            return str;
        }
        if (z10) {
            return u1.j(str.substring(0, str.offsetByCodePoints(0, i10)), "...");
        }
        return null;
    }

    public static void M(Bundle bundle, int i10, String str, Object obj) {
        if (r0(i10, bundle)) {
            bundle.putString("_ev", L(40, str, true));
            if (obj != null) {
                com.google.android.gms.common.internal.w.checkNotNull(bundle);
                if ((obj instanceof String) || (obj instanceof CharSequence)) {
                    bundle.putLong("_el", String.valueOf(obj).length());
                }
            }
        }
    }

    public static void X(x2 x2Var, Bundle bundle, boolean z10) {
        if (bundle == null || x2Var == null || (bundle.containsKey("_sc") && !z10)) {
            if (bundle != null && x2Var == null && z10) {
                bundle.remove("_sn");
                bundle.remove("_sc");
                bundle.remove("_si");
                return;
            }
            return;
        }
        String str = x2Var.zza;
        if (str != null) {
            bundle.putString("_sn", str);
        } else {
            bundle.remove("_sn");
        }
        String str2 = x2Var.zzb;
        if (str2 != null) {
            bundle.putString("_sc", str2);
        } else {
            bundle.remove("_sc");
        }
        bundle.putLong("_si", x2Var.f21977a);
    }

    public static void Y(m4 m4Var, String str, int i10, String str2, String str3, int i11) {
        Bundle bundle = new Bundle();
        r0(i10, bundle);
        if (!TextUtils.isEmpty(str2) && !TextUtils.isEmpty(str3)) {
            bundle.putString(str2, str3);
        }
        if (i10 == 6 || i10 == 7 || i10 == 2) {
            bundle.putLong("_el", i11);
        }
        m4Var.zza(str, "_err", bundle);
    }

    public static boolean d0(Context context) {
        ActivityInfo receiverInfo;
        com.google.android.gms.common.internal.w.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 boolean e0(Intent intent) {
        String stringExtra = intent.getStringExtra("android.intent.extra.REFERRER_NAME");
        return "android-app://com.google.android.googlequicksearchbox/https/www.google.com".equals(stringExtra) || "https://www.google.com".equals(stringExtra) || "android-app://com.google.appcrawler".equals(stringExtra);
    }

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

    public static boolean i0(String str, String str2, String str3, String str4) {
        boolean zIsEmpty = TextUtils.isEmpty(str);
        boolean zIsEmpty2 = TextUtils.isEmpty(str2);
        if (!zIsEmpty && !zIsEmpty2) {
            com.google.android.gms.common.internal.w.checkNotNull(str);
            return !str.equals(str2);
        }
        if (zIsEmpty && zIsEmpty2) {
            return (TextUtils.isEmpty(str3) || TextUtils.isEmpty(str4)) ? !TextUtils.isEmpty(str4) : !str3.equals(str4);
        }
        if (zIsEmpty || !zIsEmpty2) {
            return TextUtils.isEmpty(str3) || !str3.equals(str4);
        }
        if (TextUtils.isEmpty(str4)) {
            return false;
        }
        return TextUtils.isEmpty(str3) || !str3.equals(str4);
    }

    public static boolean j0(String str, String[] strArr) {
        com.google.android.gms.common.internal.w.checkNotNull(strArr);
        for (String str2 : strArr) {
            if (Objects.equals(str, str2)) {
                return true;
            }
        }
        return false;
    }

    public static byte[] l0(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 q0(List list) {
        if (list == null) {
            return new ArrayList(0);
        }
        ArrayList arrayList = new ArrayList(list.size());
        Iterator it = list.iterator();
        while (it.hasNext()) {
            e eVar = (e) it.next();
            Bundle bundle = new Bundle();
            bundle.putString("app_id", eVar.zza);
            bundle.putString("origin", eVar.f21542a);
            bundle.putLong("creation_timestamp", eVar.f21544c);
            bundle.putString("name", eVar.f21543b.f21666b);
            c2.r(bundle, com.google.android.gms.common.internal.w.checkNotNull(eVar.f21543b.zza()));
            bundle.putBoolean("active", eVar.f21545d);
            String str = eVar.zzf;
            if (str != null) {
                bundle.putString("trigger_event_name", str);
            }
            y yVar = eVar.zzg;
            if (yVar != null) {
                bundle.putString("timed_out_event_name", yVar.f21981a);
                x xVar = yVar.f21982b;
                if (xVar != null) {
                    bundle.putBundle("timed_out_event_params", xVar.x());
                }
            }
            bundle.putLong("trigger_timeout", eVar.f21546e);
            y yVar2 = eVar.zzi;
            if (yVar2 != null) {
                bundle.putString("triggered_event_name", yVar2.f21981a);
                x xVar2 = yVar2.f21982b;
                if (xVar2 != null) {
                    bundle.putBundle("triggered_event_params", xVar2.x());
                }
            }
            bundle.putLong("triggered_timestamp", eVar.f21543b.f21667c);
            bundle.putLong("time_to_live", eVar.f21547f);
            y yVar3 = eVar.zzk;
            if (yVar3 != null) {
                bundle.putString("expired_event_name", yVar3.f21981a);
                x xVar3 = yVar3.f21982b;
                if (xVar3 != null) {
                    bundle.putBundle("expired_event_params", xVar3.x());
                }
            }
            arrayList.add(bundle);
        }
        return arrayList;
    }

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

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

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

    public final int B(String str) {
        if (!t0("event", str)) {
            return 2;
        }
        if (k0("event", c2.f21498a, c2.f21499b, str)) {
            return !c0(40, "event", str) ? 2 : 0;
        }
        return 13;
    }

    /* JADX WARN: Removed duplicated region for block: B:37:0x009c  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int C(String str, String str2, Object obj, Bundle bundle, List list, boolean z10, boolean z11) {
        int i10;
        int size;
        w();
        int i11 = 0;
        if (!f0(obj)) {
            i10 = 0;
        } else {
            if (!z11) {
                return 21;
            }
            if (!j0(str2, c2.f21506i)) {
                return 20;
            }
            a3 a3VarL = ((m1) this.f31277a).l();
            a3VarL.w();
            a3VarL.D();
            if (a3VarL.P() && a3VarL.v().z0() < 200900) {
                return 25;
            }
            boolean z12 = obj instanceof Parcelable[];
            if (z12) {
                size = ((Parcelable[]) obj).length;
            } else {
                if (obj instanceof ArrayList) {
                    size = ((ArrayList) obj).size();
                }
                i10 = 0;
            }
            if (size > 200) {
                zzj().f21839k.d("Parameter array is too long; discarded. Value kind, name, array length", "param", str2, Integer.valueOf(size));
                if (z12) {
                    Parcelable[] parcelableArr = (Parcelable[]) obj;
                    if (parcelableArr.length > 200) {
                        bundle.putParcelableArray(str2, (Parcelable[]) Arrays.copyOf(parcelableArr, 200));
                    }
                } else if (obj instanceof ArrayList) {
                    ArrayList arrayList = (ArrayList) obj;
                    if (arrayList.size() > 200) {
                        bundle.putParcelableArrayList(str2, new ArrayList<>(arrayList.subList(0, 200)));
                    }
                }
                i10 = 17;
            }
        }
        if (h0("param", str2, (A0(str) || A0(str2)) ? Math.max(s().y(null, false), 256) : s().y(null, false), obj)) {
            return i10;
        }
        if (!z11) {
            return 4;
        }
        if (obj instanceof Bundle) {
            a0(str, str2, (Bundle) obj, list, z10);
        } else if (obj instanceof Parcelable[]) {
            for (Parcelable parcelable : (Parcelable[]) obj) {
                if (!(parcelable instanceof Bundle)) {
                    zzj().f21839k.a(parcelable.getClass(), str2, "All Parcelable[] elements must be of type Bundle. Value type, name");
                    return 4;
                }
                a0(str, str2, (Bundle) parcelable, list, z10);
            }
        } else {
            if (!(obj instanceof ArrayList)) {
                return 4;
            }
            ArrayList arrayList2 = (ArrayList) obj;
            int size2 = arrayList2.size();
            while (i11 < size2) {
                Object obj2 = arrayList2.get(i11);
                int i12 = i11 + 1;
                if (!(obj2 instanceof Bundle)) {
                    zzj().f21839k.a(obj2 != null ? obj2.getClass() : "null", str2, "All ArrayList elements must be of type Bundle. Value type, name");
                    return 4;
                }
                a0(str, str2, (Bundle) obj2, list, z10);
                i11 = i12;
            }
        }
        return i10;
    }

    public final boolean C0(String str) {
        List<ResolveInfo> listQueryIntentActivities;
        return (TextUtils.isEmpty(str) || (listQueryIntentActivities = zza().getPackageManager().queryIntentActivities(new Intent("android.intent.action.VIEW", Uri.parse(str)), 0)) == null || listQueryIntentActivities.isEmpty()) ? false : true;
    }

    /* JADX WARN: Removed duplicated region for block: B:54:0x00b4  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final long E0() {
        long j10;
        Integer num;
        Object e10;
        w();
        String strG = ((m1) this.f31277a).j().G();
        String str = (String) z.f22025d0.a(null);
        boolean z10 = true;
        if (!(str.equals("*") || Arrays.asList(str.split(",")).contains(strG))) {
            return 0L;
        }
        int i10 = Build.VERSION.SDK_INT;
        if (i10 < 30) {
            j10 = 4;
        } else if (SdkExtensions.getExtensionVersion(30) < 4) {
            j10 = 8;
        } else {
            j10 = ((i10 < 30 || SdkExtensions.getExtensionVersion(30) <= 3) ? 0 : SdkExtensions.getExtensionVersion(PlaybackException.CUSTOM_ERROR_CODE_BASE)) < ((Integer) z.X.a(null)).intValue() ? 16L : 0L;
        }
        if (!x0("android.permission.ACCESS_ADSERVICES_ATTRIBUTION")) {
            j10 |= 2;
        }
        if (j10 == 0) {
            if (this.f21798g == null) {
                if (this.f21797f == null) {
                    this.f21797f = androidx.privacysandbox.ads.adservices.java.measurement.a.a(zza());
                }
                MeasurementManagerFutures$Api33Ext5JavaImpl measurementManagerFutures$Api33Ext5JavaImpl = this.f21797f;
                if (measurementManagerFutures$Api33Ext5JavaImpl != null) {
                    try {
                        num = (Integer) measurementManagerFutures$Api33Ext5JavaImpl.d().get(10000L, TimeUnit.MILLISECONDS);
                    } catch (InterruptedException | CancellationException | ExecutionException | TimeoutException e11) {
                        num = null;
                        e10 = e11;
                    }
                    if (num != null) {
                        try {
                            if (num.intValue() != 1) {
                                z10 = false;
                            }
                            this.f21798g = Boolean.valueOf(z10);
                        } catch (InterruptedException e12) {
                            e10 = e12;
                            zzj().f21837i.b(e10, "Measurement manager api exception");
                            this.f21798g = Boolean.FALSE;
                        } catch (CancellationException e13) {
                            e10 = e13;
                            zzj().f21837i.b(e10, "Measurement manager api exception");
                            this.f21798g = Boolean.FALSE;
                        } catch (ExecutionException e14) {
                            e10 = e14;
                            zzj().f21837i.b(e10, "Measurement manager api exception");
                            this.f21798g = Boolean.FALSE;
                        } catch (TimeoutException e15) {
                            e10 = e15;
                            zzj().f21837i.b(e10, "Measurement manager api exception");
                            this.f21798g = Boolean.FALSE;
                        }
                        zzj().f21842n.b(num, "Measurement manager api status result");
                        if (!this.f21798g.booleanValue()) {
                        }
                    }
                }
                j10 |= 64;
            } else if (!this.f21798g.booleanValue()) {
                j10 |= 64;
            }
        }
        if (j10 == 0) {
            return 1L;
        }
        return j10;
    }

    public final Bundle F(Uri uri, boolean z10) {
        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 = z10 ? uri.getQueryParameter("gbraid") : null;
                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) && ((!z10 || 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 (z10 && !TextUtils.isEmpty(queryParameter5)) {
                bundle.putString("gbraid", queryParameter5);
            }
            String queryParameter10 = uri.getQueryParameter("gad_source");
            if (z10 && !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);
            }
            return bundle;
        } catch (UnsupportedOperationException e10) {
            zzj().f21837i.b(e10, "Install referrer url isn't a hierarchical URI");
            return null;
        }
    }

    public final long F0() {
        long andIncrement;
        long j10;
        if (this.f21795d.get() != 0) {
            synchronized (this.f21795d) {
                this.f21795d.compareAndSet(-1L, 1L);
                andIncrement = this.f21795d.getAndIncrement();
            }
            return andIncrement;
        }
        synchronized (this.f21795d) {
            long jNanoTime = System.nanoTime();
            ((i8.d) zzb()).getClass();
            long jNextLong = new Random(jNanoTime ^ System.currentTimeMillis()).nextLong();
            int i10 = this.f21796e + 1;
            this.f21796e = i10;
            j10 = jNextLong + ((long) i10);
        }
        return j10;
    }

    public final Bundle G(Bundle bundle) {
        Bundle bundle2 = new Bundle();
        if (bundle != null) {
            for (String str : bundle.keySet()) {
                Object objP0 = p0(bundle.get(str), str);
                if (objP0 == null) {
                    p0 p0VarZzj = zzj();
                    p0VarZzj.f21839k.b(t().f(str), "Param value can't be null");
                } else {
                    P(bundle2, str, objP0);
                }
            }
        }
        return bundle2;
    }

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

    /* JADX WARN: Removed duplicated region for block: B:22:0x0067  */
    /* JADX WARN: Removed duplicated region for block: B:29:0x0078  */
    /* JADX WARN: Removed duplicated region for block: B:31:0x007c  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x0082  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Bundle H(String str, Bundle bundle, List list, boolean z10) {
        int i10;
        boolean zJ0 = j0(str, c2.f21501d);
        String[] strArr = null;
        if (bundle == null) {
            return null;
        }
        Bundle bundle2 = new Bundle(bundle);
        int i11 = s().v().m0(201500000) ? 100 : 25;
        int i12 = 0;
        for (String str2 : new TreeSet(bundle.keySet())) {
            if (list != null && list.contains(str2)) {
                i10 = 0;
            } else if (z10) {
                i10 = 0;
                if (i10 == 0) {
                    if (t0("event param", str2)) {
                        int i13 = k0("event param", strArr, strArr, str2) ? !c0(40, "event param", str2) ? 3 : 0 : 14;
                        i10 = i13;
                    }
                }
            } else if (v0("event param", str2)) {
                if (k0("event param", strArr, strArr, str2)) {
                    if (!c0(40, "event param", str2)) {
                        i10 = 3;
                    }
                    if (i10 == 0) {
                    }
                } else {
                    i10 = 14;
                    if (i10 == 0) {
                    }
                }
            }
            if (i10 != 0) {
                M(bundle2, i10, str2, i10 == 3 ? str2 : strArr);
                bundle2.remove(str2);
            } else {
                int iC = C(str, str2, bundle.get(str2), bundle2, list, z10, zJ0);
                if (iC == 17) {
                    M(bundle2, iC, str2, Boolean.FALSE);
                } else if (iC != 0 && !"_ev".equals(str2)) {
                    M(bundle2, iC, iC == 21 ? str : str2, bundle.get(str2));
                    bundle2.remove(str2);
                }
                if (B0(str2)) {
                    int i14 = i12 + 1;
                    if (i14 > i11) {
                        zzj().f21836h.a(t().c(str), t().a(bundle), defpackage.e.e("Event can't contain more than ", i11, " params"));
                        r0(5, bundle2);
                        bundle2.remove(str2);
                    }
                    i12 = i14;
                }
            }
            strArr = null;
        }
        return bundle2;
    }

    public final SecureRandom I0() {
        w();
        if (this.f21794c == null) {
            this.f21794c = new SecureRandom();
        }
        return this.f21794c;
    }

    public final y J(String str, Bundle bundle, String str2, long j10, boolean z10) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        if (B(str) != 0) {
            zzj().f21834f.b(t().g(str), "Invalid conditional property event name");
            throw new IllegalArgumentException();
        }
        Bundle bundle2 = bundle != null ? new Bundle(bundle) : new Bundle();
        bundle2.putString("_o", str2);
        Bundle bundleH = H(str, bundle2, Collections.singletonList("_o"), true);
        if (z10) {
            bundleH = G(bundleH);
        }
        com.google.android.gms.common.internal.w.checkNotNull(bundleH);
        return new y(str, new x(bundleH), str2, j10);
    }

    public final Object K(int i10, Object obj, boolean z10, boolean z11) {
        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(((Boolean) obj).booleanValue() ? 1L : 0L);
        }
        if (obj instanceof Float) {
            return Double.valueOf(((Float) obj).doubleValue());
        }
        if ((obj instanceof String) || (obj instanceof Character) || (obj instanceof CharSequence)) {
            return L(i10, String.valueOf(obj), z10);
        }
        if (!z11 || (!(obj instanceof Bundle[]) && !(obj instanceof Parcelable[]))) {
            return null;
        }
        ArrayList arrayList = new ArrayList();
        for (Parcelable parcelable : (Parcelable[]) obj) {
            if (parcelable instanceof Bundle) {
                Bundle bundleG = G((Bundle) parcelable);
                if (!bundleG.isEmpty()) {
                    arrayList.add(bundleG);
                }
            }
        }
        return arrayList.toArray(new Bundle[arrayList.size()]);
    }

    public final void N(Bundle bundle, long j10) {
        long j11 = bundle.getLong("_et");
        if (j11 != 0) {
            p0 p0VarZzj = zzj();
            p0VarZzj.f21837i.b(Long.valueOf(j11), "Params already contained engagement");
        }
        bundle.putLong("_et", j10 + j11);
    }

    public final void O(Bundle bundle, Bundle bundle2) {
        if (bundle2 == null) {
            return;
        }
        for (String str : bundle2.keySet()) {
            if (!bundle.containsKey(str)) {
                v().P(bundle, str, bundle2.get(str));
            }
        }
    }

    public final void P(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);
        } else if (str != null) {
            String simpleName = obj != null ? obj.getClass().getSimpleName() : null;
            zzj().f21839k.a(t().f(str), simpleName, "Not putting event parameter. Invalid value type. name, type");
        }
    }

    public final void Q(com.google.android.gms.internal.measurement.x0 x0Var, int i10) {
        Bundle bundle = new Bundle();
        bundle.putInt("r", i10);
        try {
            x0Var.H(bundle);
        } catch (RemoteException e10) {
            p0 p0Var = ((m1) this.f31277a).f21757i;
            m1.d(p0Var);
            p0Var.f21837i.b(e10, "Error returning int value to wrapper");
        }
    }

    public final void R(com.google.android.gms.internal.measurement.x0 x0Var, long j10) {
        Bundle bundle = new Bundle();
        bundle.putLong("r", j10);
        try {
            x0Var.H(bundle);
        } catch (RemoteException e10) {
            p0 p0Var = ((m1) this.f31277a).f21757i;
            m1.d(p0Var);
            p0Var.f21837i.b(e10, "Error returning long value to wrapper");
        }
    }

    public final void S(com.google.android.gms.internal.measurement.x0 x0Var, Bundle bundle) {
        try {
            x0Var.H(bundle);
        } catch (RemoteException e10) {
            p0 p0Var = ((m1) this.f31277a).f21757i;
            m1.d(p0Var);
            p0Var.f21837i.b(e10, "Error returning bundle value to wrapper");
        }
    }

    public final void T(com.google.android.gms.internal.measurement.x0 x0Var, ArrayList arrayList) {
        Bundle bundle = new Bundle();
        bundle.putParcelableArrayList("r", arrayList);
        try {
            x0Var.H(bundle);
        } catch (RemoteException e10) {
            p0 p0Var = ((m1) this.f31277a).f21757i;
            m1.d(p0Var);
            p0Var.f21837i.b(e10, "Error returning bundle list to wrapper");
        }
    }

    public final void U(com.google.android.gms.internal.measurement.x0 x0Var, boolean z10) {
        Bundle bundle = new Bundle();
        bundle.putBoolean("r", z10);
        try {
            x0Var.H(bundle);
        } catch (RemoteException e10) {
            p0 p0Var = ((m1) this.f31277a).f21757i;
            m1.d(p0Var);
            p0Var.f21837i.b(e10, "Error returning boolean value to wrapper");
        }
    }

    public final void V(com.google.android.gms.internal.measurement.x0 x0Var, byte[] bArr) {
        Bundle bundle = new Bundle();
        bundle.putByteArray("r", bArr);
        try {
            x0Var.H(bundle);
        } catch (RemoteException e10) {
            p0 p0Var = ((m1) this.f31277a).f21757i;
            m1.d(p0Var);
            p0Var.f21837i.b(e10, "Error returning byte array to wrapper");
        }
    }

    public final void W(t0 t0Var, int i10) {
        int i11 = 0;
        for (String str : new TreeSet(t0Var.f21906d.keySet())) {
            if (B0(str) && (i11 = i11 + 1) > i10) {
                String strE = defpackage.e.e("Event can't contain more than ", i10, " params");
                p0 p0VarZzj = zzj();
                String strC = t().c(t0Var.f21903a);
                m0 m0VarT = t();
                Bundle bundle = t0Var.f21906d;
                p0VarZzj.f21836h.a(strC, m0VarT.a(bundle), strE);
                r0(5, bundle);
                bundle.remove(str);
            }
        }
    }

    public final void Z(String str, com.google.android.gms.internal.measurement.x0 x0Var) {
        Bundle bundle = new Bundle();
        bundle.putString("r", str);
        try {
            x0Var.H(bundle);
        } catch (RemoteException e10) {
            p0 p0Var = ((m1) this.f31277a).f21757i;
            m1.d(p0Var);
            p0Var.f21837i.b(e10, "Error returning string value to wrapper");
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:22:0x0058  */
    /* JADX WARN: Removed duplicated region for block: B:29:0x0069  */
    /* JADX WARN: Removed duplicated region for block: B:31:0x006c  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x0072  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void a0(String str, String str2, Bundle bundle, List list, boolean z10) {
        int i10;
        String str3;
        int iC;
        if (bundle == null) {
            return;
        }
        int i11 = s().v().m0(231100000) ? 35 : 0;
        int i12 = 0;
        for (String str4 : new TreeSet(bundle.keySet())) {
            if (list != null && list.contains(str4)) {
                i10 = 0;
            } else if (z10) {
                i10 = 0;
                if (i10 == 0) {
                    if (t0("event param", str4)) {
                        int i13 = k0("event param", null, null, str4) ? !c0(40, "event param", str4) ? 3 : 0 : 14;
                        i10 = i13;
                    }
                }
            } else if (v0("event param", str4)) {
                if (k0("event param", null, null, str4)) {
                    if (!c0(40, "event param", str4)) {
                        i10 = 3;
                    }
                    if (i10 == 0) {
                    }
                } else {
                    i10 = 14;
                    if (i10 == 0) {
                    }
                }
            }
            if (i10 != 0) {
                M(bundle, i10, str4, i10 == 3 ? str4 : null);
                bundle.remove(str4);
            } else {
                if (f0(bundle.get(str4))) {
                    zzj().f21839k.d("Nested Bundle parameters are not allowed; discarded. event name, param name, child param name", str, str2, str4);
                    iC = 22;
                    str3 = str4;
                } else {
                    str3 = str4;
                    iC = C(str, str4, bundle.get(str4), bundle, list, z10, false);
                }
                if (iC != 0 && !"_ev".equals(str3)) {
                    M(bundle, iC, str3, bundle.get(str3));
                    bundle.remove(str3);
                } else if (B0(str3) && !j0(str3, c2.f21507j)) {
                    int i14 = i12 + 1;
                    if (!m0(231100000)) {
                        zzj().f21836h.a(t().c(str), t().a(bundle), "Item array not supported on client's version of Google Play Services (Android Only)");
                        r0(23, bundle);
                        bundle.remove(str3);
                    } else if (i14 > i11) {
                        zzj().f21836h.a(t().c(str), t().a(bundle), defpackage.e.e("Item can't contain more than ", i11, " item-scoped custom params"));
                        r0(28, bundle);
                        bundle.remove(str3);
                    }
                    i12 = i14;
                }
            }
        }
    }

    public final void b0(Parcelable[] parcelableArr, int i10) {
        com.google.android.gms.common.internal.w.checkNotNull(parcelableArr);
        for (Parcelable parcelable : parcelableArr) {
            Bundle bundle = (Bundle) parcelable;
            int i11 = 0;
            for (String str : new TreeSet(bundle.keySet())) {
                if (B0(str) && !j0(str, c2.f21507j) && (i11 = i11 + 1) > i10) {
                    zzj().f21836h.a(t().f(str), t().a(bundle), defpackage.e.e("Param can't contain more than ", i10, " item-scoped custom parameters"));
                    r0(28, bundle);
                    bundle.remove(str);
                }
            }
        }
    }

    public final boolean c0(int i10, String str, String str2) {
        if (str2 == null) {
            zzj().f21836h.b(str, "Name is required and can't be null. Type");
            return false;
        }
        if (str2.codePointCount(0, str2.length()) <= i10) {
            return true;
        }
        p0 p0VarZzj = zzj();
        p0VarZzj.f21836h.d("Name is too long. Type, maximum supported length, name", str, Integer.valueOf(i10), str2);
        return false;
    }

    public final boolean g0(String str, String str2) {
        boolean zIsEmpty = TextUtils.isEmpty(str);
        Object obj = this.f31277a;
        if (!zIsEmpty) {
            com.google.android.gms.common.internal.w.checkNotNull(str);
            if (str.matches("^(1:\\d+:android:[a-f0-9]+|ca-app-pub-.*)$")) {
                return true;
            }
            if (TextUtils.isEmpty(((m1) obj).f21750b)) {
                p0 p0VarZzj = zzj();
                p0VarZzj.f21836h.b(p0.A(str), "Invalid google_app_id. Firebase Analytics disabled. See https://goo.gl/NAOOOI. provided id");
            }
            return false;
        }
        if (TextUtils.isEmpty(str2)) {
            if (TextUtils.isEmpty(((m1) obj).f21750b)) {
                zzj().f21836h.c("Missing google_app_id. Firebase Analytics disabled. See https://goo.gl/NAOOOI");
            }
            return false;
        }
        com.google.android.gms.common.internal.w.checkNotNull(str2);
        if (str2.matches("^(1:\\d+:android:[a-f0-9]+|ca-app-pub-.*)$")) {
            return true;
        }
        p0 p0VarZzj2 = zzj();
        p0VarZzj2.f21836h.b(p0.A(str2), "Invalid admob_app_id. Analytics disabled.");
        return false;
    }

    public final boolean h0(String str, String str2, int i10, 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)) {
            if (!(obj instanceof String) && !(obj instanceof Character) && !(obj instanceof CharSequence)) {
                return false;
            }
            String strValueOf = String.valueOf(obj);
            if (strValueOf.codePointCount(0, strValueOf.length()) > i10) {
                p0 p0VarZzj = zzj();
                p0VarZzj.f21839k.d("Value is too long; discarded. Value kind, name, value length", str, str2, Integer.valueOf(strValueOf.length()));
                return false;
            }
        }
        return true;
    }

    public final boolean k0(String str, String[] strArr, String[] strArr2, String str2) {
        if (str2 == null) {
            zzj().f21836h.b(str, "Name is required and can't be null. Type");
            return false;
        }
        com.google.android.gms.common.internal.w.checkNotNull(str2);
        String[] strArr3 = f21792i;
        for (int i10 = 0; i10 < 3; i10++) {
            if (str2.startsWith(strArr3[i10])) {
                zzj().f21836h.a(str, str2, "Name starts with reserved prefix. Type, name");
                return false;
            }
        }
        if (strArr == null || !j0(str2, strArr)) {
            return true;
        }
        if (strArr2 != null && j0(str2, strArr2)) {
            return true;
        }
        zzj().f21836h.a(str, str2, "Name is reserved. Type, name");
        return false;
    }

    public final boolean m0(int i10) {
        Boolean bool = ((m1) this.f31277a).l().f21473e;
        if (z0() < i10 / 1000) {
            return (bool == null || bool.booleanValue()) ? false : true;
        }
        return true;
    }

    public final void n0() {
        w();
        SecureRandom secureRandom = new SecureRandom();
        long jNextLong = secureRandom.nextLong();
        if (jNextLong == 0) {
            jNextLong = secureRandom.nextLong();
            if (jNextLong == 0) {
                zzj().f21837i.c("Utils falling back to Random for random id");
            }
        }
        this.f21795d.set(jNextLong);
    }

    public final int o0(String str) {
        if (!t0("user property", str)) {
            return 6;
        }
        if (k0("user property", c2.f21502e, null, str)) {
            return !c0(24, "user property", str) ? 6 : 0;
        }
        return 15;
    }

    public final Object p0(Object obj, String str) {
        if ("_ev".equals(str)) {
            return K(Math.max(s().y(null, false), 256), obj, true, true);
        }
        return K(A0(str) ? Math.max(s().y(null, false), 256) : s().y(null, false), obj, false, true);
    }

    public final boolean s0(Context context, String str) {
        Signature[] signatureArr;
        X500Principal x500Principal = new X500Principal("CN=Android Debug,O=Android,C=US");
        try {
            PackageInfo packageInfoB = j8.e.a(context).b(64, str);
            if (packageInfoB == null || (signatureArr = packageInfoB.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 e10) {
            zzj().f21834f.b(e10, "Package name not found");
            return true;
        } catch (CertificateException e11) {
            zzj().f21834f.b(e11, "Error obtaining certificate");
            return true;
        }
    }

    public final boolean t0(String str, String str2) {
        if (str2 == null) {
            zzj().f21836h.b(str, "Name is required and can't be null. Type");
            return false;
        }
        if (str2.length() == 0) {
            zzj().f21836h.b(str, "Name is required and can't be empty. Type");
            return false;
        }
        int iCodePointAt = str2.codePointAt(0);
        if (!Character.isLetter(iCodePointAt) && iCodePointAt != 95) {
            zzj().f21836h.a(str, str2, "Name must start with a letter or _ (underscore). 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)) {
                zzj().f21836h.a(str, str2, "Name must consist of letters, digits or _ (underscores). Type, name");
                return false;
            }
            iCharCount += Character.charCount(iCodePointAt2);
        }
        return true;
    }

    public final Object u0(Object obj, String str) {
        return "_ldl".equals(str) ? K(D0(str), obj, true, false) : K(D0(str), obj, false, false);
    }

    public final boolean v0(String str, String str2) {
        if (str2 == null) {
            zzj().f21836h.b(str, "Name is required and can't be null. Type");
            return false;
        }
        if (str2.length() == 0) {
            zzj().f21836h.b(str, "Name is required and can't be empty. Type");
            return false;
        }
        int iCodePointAt = str2.codePointAt(0);
        if (!Character.isLetter(iCodePointAt)) {
            zzj().f21836h.a(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)) {
                zzj().f21836h.a(str, str2, "Name must consist of letters, digits or _ (underscores). Type, name");
                return false;
            }
            iCharCount += Character.charCount(iCodePointAt2);
        }
        return true;
    }

    public final boolean w0(String str, String str2) {
        ga.a();
        if (s().J(null, z.f22073x0) && !TextUtils.isEmpty(str2)) {
            return true;
        }
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        return s().z("debug.firebase.analytics.app").equals(str);
    }

    public final boolean x0(String str) {
        w();
        if (j8.e.a(zza()).f28722a.checkCallingOrSelfPermission(str) == 0) {
            return true;
        }
        zzj().f21841m.b(str, "Permission not granted");
        return false;
    }

    @Override // com.google.android.gms.measurement.internal.a2
    public final boolean z() {
        return true;
    }

    public final int z0() {
        if (this.f21799h == null) {
            e8.e eVar = e8.e.f25522b;
            Context contextZza = zza();
            eVar.getClass();
            this.f21799h = Integer.valueOf(e8.e.a(contextZza) / 1000);
        }
        return this.f21799h.intValue();
    }
}
