package d3;

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.ServiceInfo;
import android.content.pm.Signature;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.RemoteException;
import android.os.ext.SdkExtensions;
import android.text.TextUtils;
import android.util.Log;
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: classes.dex */
public final class W1 extends A0 {

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

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

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

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

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

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public J1.d f11802v;

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

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

    public W1(C0817r0 c0817r0) {
        super(c0817r0);
        this.f11804x = null;
        this.f11800t = new AtomicLong(0L);
    }

    public static boolean A0(Context context) {
        ActivityInfo receiverInfo;
        P2.w.f(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 B0(Context context, String str) {
        ServiceInfo serviceInfo;
        try {
            PackageManager packageManager = context.getPackageManager();
            if (packageManager != null && (serviceInfo = packageManager.getServiceInfo(new ComponentName(context, str), 0)) != null) {
                if (serviceInfo.enabled) {
                    return true;
                }
            }
        } catch (PackageManager.NameNotFoundException unused) {
        }
        return false;
    }

    public static boolean C0(Context context) {
        P2.w.f(context);
        return Build.VERSION.SDK_INT >= 24 ? B0(context, "com.google.android.gms.measurement.AppMeasurementJobService") : B0(context, "com.google.android.gms.measurement.AppMeasurementService");
    }

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

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

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

    public static long O0(byte[] bArr) {
        P2.w.f(bArr);
        int length = bArr.length;
        if (length <= 0) {
            throw new IllegalStateException();
        }
        int i = 0;
        long j8 = 0;
        for (int i5 = length - 1; i5 >= 0 && i5 >= bArr.length - 8; i5--) {
            j8 += (((long) bArr[i5]) & 255) << i;
            i += 8;
        }
        return j8;
    }

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

    public static ArrayList R(List list) {
        if (list == null) {
            return new ArrayList(0);
        }
        ArrayList arrayList = new ArrayList(list.size());
        Iterator it = list.iterator();
        while (it.hasNext()) {
            C0778e c0778e = (C0778e) it.next();
            Bundle bundle = new Bundle();
            bundle.putString("app_id", c0778e.f11918q);
            bundle.putString("origin", c0778e.f11919r);
            bundle.putLong("creation_timestamp", c0778e.f11921t);
            bundle.putString("name", c0778e.f11920s.f11723r);
            Object objA = c0778e.f11920s.a();
            P2.w.f(objA);
            G0.e(bundle, objA);
            bundle.putBoolean("active", c0778e.f11922u);
            String str = c0778e.f11923v;
            if (str != null) {
                bundle.putString("trigger_event_name", str);
            }
            C0828v c0828v = c0778e.f11924w;
            if (c0828v != null) {
                bundle.putString("timed_out_event_name", c0828v.f12193q);
                C0825u c0825u = c0828v.f12194r;
                if (c0825u != null) {
                    bundle.putBundle("timed_out_event_params", c0825u.a());
                }
            }
            bundle.putLong("trigger_timeout", c0778e.f11925x);
            C0828v c0828v2 = c0778e.f11926y;
            if (c0828v2 != null) {
                bundle.putString("triggered_event_name", c0828v2.f12193q);
                C0825u c0825u2 = c0828v2.f12194r;
                if (c0825u2 != null) {
                    bundle.putBundle("triggered_event_params", c0825u2.a());
                }
            }
            bundle.putLong("triggered_timestamp", c0778e.f11920s.f11724s);
            bundle.putLong("time_to_live", c0778e.f11927z);
            C0828v c0828v3 = c0778e.f11917A;
            if (c0828v3 != null) {
                bundle.putString("expired_event_name", c0828v3.f12193q);
                C0825u c0825u3 = c0828v3.f12194r;
                if (c0825u3 != null) {
                    bundle.putBundle("expired_event_params", c0825u3.a());
                }
            }
            arrayList.add(bundle);
        }
        return arrayList;
    }

    public static void U(C0786g1 c0786g1, Bundle bundle, boolean z8) {
        if (bundle != null && c0786g1 != null) {
            if (!bundle.containsKey("_sc") || z8) {
                String str = c0786g1.f11979a;
                if (str != null) {
                    bundle.putString("_sn", str);
                } else {
                    bundle.remove("_sn");
                }
                String str2 = c0786g1.f11980b;
                if (str2 != null) {
                    bundle.putString("_sc", str2);
                } else {
                    bundle.remove("_sc");
                }
                bundle.putLong("_si", c0786g1.f11981c);
                return;
            }
            z8 = false;
        }
        if (bundle != null && c0786g1 == null && z8) {
            bundle.remove("_sn");
            bundle.remove("_sc");
            bundle.remove("_si");
        }
    }

    public static void Y(V1 v12, String str, int i, String str2, String str3, int i5) {
        Bundle bundle = new Bundle();
        G0(i, bundle);
        if (!TextUtils.isEmpty(str2) && !TextUtils.isEmpty(str3)) {
            bundle.putString(str2, str3);
        }
        if (i == 6 || i == 7 || i == 2) {
            bundle.putLong("_el", i5);
        }
        v12.b(str, "_err", bundle);
    }

    public static boolean k0(String str, String[] strArr) {
        P2.w.f(strArr);
        for (String str2 : strArr) {
            if (Objects.equals(str, str2)) {
                return true;
            }
        }
        return false;
    }

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

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

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

    public static boolean z0(String str) {
        P2.w.c(str);
        return str.charAt(0) != '_' || str.equals("_ep");
    }

    /* JADX WARN: Removed duplicated region for block: B:43:0x007f A[RETURN] */
    /* JADX WARN: Removed duplicated region for block: B:44:0x0080 A[RETURN] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final boolean D0(String str, String str2, String str3, String str4) {
        if (((C0817r0) this.f5146q).f12148w.R(null, I.f11580q1)) {
            boolean zIsEmpty = TextUtils.isEmpty(str);
            boolean zIsEmpty2 = TextUtils.isEmpty(str2);
            if (!zIsEmpty && !zIsEmpty2) {
                P2.w.f(str);
                if (!str.equals(str2)) {
                    return true;
                }
            }
            return false;
        }
        boolean zIsEmpty3 = TextUtils.isEmpty(str);
        boolean zIsEmpty4 = TextUtils.isEmpty(str2);
        if (zIsEmpty3 || zIsEmpty4) {
            return !(zIsEmpty3 && zIsEmpty4) ? !(zIsEmpty3 ? TextUtils.isEmpty(str3) || !str3.equals(str4) : !TextUtils.isEmpty(str4) && (TextUtils.isEmpty(str3) || !str3.equals(str4))) : !(TextUtils.isEmpty(str3) || TextUtils.isEmpty(str4) ? !TextUtils.isEmpty(str4) : !str3.equals(str4));
        }
        P2.w.f(str);
        if (!str.equals(str2)) {
        }
    }

    public final boolean E0(String str) {
        P2.w.f(str);
        return str.matches(true != ((C0817r0) this.f5146q).f12148w.R(null, I.f11580q1) ? "^(1:\\d+:android:[a-f0-9]+|ca-app-pub-.*)$" : "^1:\\d+:android:[a-f0-9]+$");
    }

    @Override // d3.A0
    public final boolean F() {
        return true;
    }

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

    public final Bundle I(String str, Bundle bundle, List list, boolean z8) {
        int iK0;
        List list2 = list;
        boolean zK0 = k0(str, G0.f11466d);
        if (bundle == null) {
            return null;
        }
        Bundle bundle2 = new Bundle(bundle);
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        W1 w12 = ((C0817r0) c0817r0.f12148w.f5146q).f12122B;
        C0817r0.i(w12);
        int i = w12.x0(201500000) ? 100 : 25;
        int i5 = 0;
        boolean z9 = false;
        for (String str2 : new TreeSet(bundle.keySet())) {
            if (list2 == null || !list2.contains(str2)) {
                iK0 = !z8 ? K0(str2) : 0;
                if (iK0 == 0) {
                    iK0 = J0(str2);
                }
            } else {
                iK0 = 0;
            }
            if (iK0 != 0) {
                T(bundle2, iK0, str2, iK0 == 3 ? str2 : null);
                bundle2.remove(str2);
            } else {
                int iH0 = h0(str, str2, bundle.get(str2), bundle2, list2, z8, zK0);
                if (iH0 == 17) {
                    T(bundle2, 17, str2, Boolean.FALSE);
                } else if (iH0 != 0 && !"_ev".equals(str2)) {
                    T(bundle2, iH0, iH0 == 21 ? str : str2, bundle.get(str2));
                    bundle2.remove(str2);
                }
                if (z0(str2) && (i5 = i5 + 1) > i) {
                    if (!c0817r0.f12148w.R(null, I.f11586s1) || !z9) {
                        String strK = I1.a.k(i, "Event can't contain more than ", " params");
                        Z z10 = c0817r0.f12150y;
                        C0817r0.k(z10);
                        T t6 = c0817r0.f12123C;
                        z10.f11877x.d(strK, t6.d(str), t6.b(bundle));
                    }
                    G0(5, bundle2);
                    bundle2.remove(str2);
                    z9 = true;
                }
            }
            list2 = list;
        }
        return bundle2;
    }

    public final int I0(String str) {
        if (!r0("event", str)) {
            return 2;
        }
        if (!p0("event", G0.f11463a, G0.f11464b, str)) {
            return 13;
        }
        ((C0817r0) this.f5146q).getClass();
        return !o0(40, "event", str) ? 2 : 0;
    }

    public final J1.d J() {
        K1.b bVar;
        if (this.f11802v == null) {
            Context context = ((C0817r0) this.f5146q).f12142q;
            P6.g.e(context, "context");
            StringBuilder sb = new StringBuilder("AdServicesInfo.version=");
            int i = Build.VERSION.SDK_INT;
            H1.b bVar2 = H1.b.f3071a;
            sb.append(i >= 33 ? bVar2.a() : 0);
            Log.d("MeasurementManager", sb.toString());
            if ((i >= 33 ? bVar2.a() : 0) >= 5) {
                Object systemService = context.getSystemService((Class<Object>) D1.z.g());
                P6.g.d(systemService, "context.getSystemService…ementManager::class.java)");
                bVar = new K1.b(D1.z.b(systemService));
            } else {
                H1.a aVar = H1.a.f3070a;
                if (((i == 31 || i == 32) ? aVar.a() : 0) >= 9) {
                    try {
                        MeasurementManager measurementManager = MeasurementManager.get(context);
                        P6.g.d(measurementManager, "get(context)");
                        bVar = new K1.b(measurementManager);
                    } catch (NoClassDefFoundError unused) {
                        StringBuilder sb2 = new StringBuilder("Unable to find adservices code, check manifest for uses-library tag, versionS=");
                        int i5 = Build.VERSION.SDK_INT;
                        sb2.append((i5 == 31 || i5 == 32) ? aVar.a() : 0);
                        Log.d("MeasurementManager", sb2.toString());
                        bVar = null;
                    }
                } else {
                    bVar = null;
                }
            }
            this.f11802v = bVar != null ? new J1.d(bVar) : null;
        }
        return this.f11802v;
    }

    public final int J0(String str) {
        if (!r0("event param", str)) {
            return 3;
        }
        if (!p0("event param", null, null, str)) {
            return 14;
        }
        ((C0817r0) this.f5146q).getClass();
        return !o0(40, "event param", str) ? 3 : 0;
    }

    public final C0828v K(String str, Bundle bundle, String str2, long j8, boolean z8) {
        if (TextUtils.isEmpty(str)) {
            return null;
        }
        if (I0(str) != 0) {
            C0817r0 c0817r0 = (C0817r0) this.f5146q;
            Z z9 = c0817r0.f12150y;
            C0817r0.k(z9);
            z9.f11875v.c(c0817r0.f12123C.f(str), "Invalid conditional property event name");
            throw new IllegalArgumentException();
        }
        Bundle bundle2 = bundle != null ? new Bundle(bundle) : new Bundle();
        bundle2.putString("_o", str2);
        Bundle bundleI = I(str, bundle2, Collections.singletonList("_o"), true);
        if (z8) {
            bundleI = R0(bundleI);
        }
        P2.w.f(bundleI);
        return new C0828v(str, new C0825u(bundleI), str2, j8);
    }

    public final int K0(String str) {
        if (!s0("event param", str)) {
            return 3;
        }
        if (!p0("event param", null, null, str)) {
            return 14;
        }
        ((C0817r0) this.f5146q).getClass();
        return !o0(40, "event param", str) ? 3 : 0;
    }

    public final Object L(Object obj, String str) {
        boolean zEquals = "_ev".equals(str);
        int iMax = 500;
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        if (zEquals) {
            c0817r0.f12148w.getClass();
            return j0(Math.max(500, 256), obj, true, true);
        }
        if (y0(str)) {
            c0817r0.f12148w.getClass();
            iMax = Math.max(500, 256);
        } else {
            c0817r0.f12148w.getClass();
        }
        return j0(iMax, obj, false, true);
    }

    public final int L0(String str) {
        if (!r0("user property", str)) {
            return 6;
        }
        if (!p0("user property", G0.i, null, str)) {
            return 15;
        }
        ((C0817r0) this.f5146q).getClass();
        return !o0(24, "user property", str) ? 6 : 0;
    }

    public final Object M(Object obj, String str) {
        return "_ldl".equals(str) ? j0(i0(str), obj, true, false) : j0(i0(str), obj, false, false);
    }

    public final int M0() {
        if (this.f11804x == null) {
            M2.f fVar = M2.f.f4167b;
            Context context = ((C0817r0) this.f5146q).f12142q;
            fVar.getClass();
            int i = M2.g.f4172e;
            int i5 = 0;
            try {
                i5 = context.getPackageManager().getPackageInfo("com.google.android.gms", 0).versionCode;
            } catch (PackageManager.NameNotFoundException unused) {
                Log.w("GooglePlayServicesUtil", "Google Play services is missing.");
            }
            this.f11804x = Integer.valueOf(i5 / 1000);
        }
        return this.f11804x.intValue();
    }

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

    /* JADX WARN: Removed duplicated region for block: B:59:0x00be  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final long N0() {
        long j8;
        Object e8;
        Integer num;
        E();
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        P pN = c0817r0.n();
        Z z8 = c0817r0.f12150y;
        if (!m0(pN.K())) {
            return 0L;
        }
        int i = Build.VERSION.SDK_INT;
        boolean zBooleanValue = false;
        Integer num2 = null;
        if (i < 30) {
            j8 = 4;
        } else if (SdkExtensions.getExtensionVersion(30) < 4) {
            j8 = 8;
        } else {
            j8 = ((i < 30 || SdkExtensions.getExtensionVersion(30) <= 3) ? 0 : SdkExtensions.getExtensionVersion(1000000)) < ((Integer) I.f11566l0.a(null)).intValue() ? 16L : 0L;
        }
        if (!t0("android.permission.ACCESS_ADSERVICES_ATTRIBUTION")) {
            j8 |= 2;
        }
        if (j8 == 0) {
            if (this.f11803w != null) {
                zBooleanValue = this.f11803w.booleanValue();
                if (!zBooleanValue) {
                    j8 = 64;
                }
            } else {
                J1.d dVarJ = J();
                if (dVarJ != null) {
                    try {
                        num = (Integer) dVarJ.b().get(10000L, TimeUnit.MILLISECONDS);
                        if (num != null) {
                            try {
                                if (num.intValue() == 1) {
                                    zBooleanValue = true;
                                }
                            } catch (InterruptedException e9) {
                                e8 = e9;
                                num2 = num;
                                C0817r0.k(z8);
                                z8.f11878y.c(e8, "Measurement manager api exception");
                                this.f11803w = Boolean.FALSE;
                                num = num2;
                            } catch (CancellationException e10) {
                                e8 = e10;
                                num2 = num;
                                C0817r0.k(z8);
                                z8.f11878y.c(e8, "Measurement manager api exception");
                                this.f11803w = Boolean.FALSE;
                                num = num2;
                            } catch (ExecutionException e11) {
                                e8 = e11;
                                num2 = num;
                                C0817r0.k(z8);
                                z8.f11878y.c(e8, "Measurement manager api exception");
                                this.f11803w = Boolean.FALSE;
                                num = num2;
                            } catch (TimeoutException e12) {
                                e8 = e12;
                                num2 = num;
                                C0817r0.k(z8);
                                z8.f11878y.c(e8, "Measurement manager api exception");
                                this.f11803w = Boolean.FALSE;
                                num = num2;
                            }
                        }
                        this.f11803w = Boolean.valueOf(zBooleanValue);
                    } catch (InterruptedException | CancellationException | ExecutionException | TimeoutException e13) {
                        e8 = e13;
                    }
                    C0817r0.k(z8);
                    z8.D.c(num, "Measurement manager api status result");
                    zBooleanValue = this.f11803w.booleanValue();
                }
                if (!zBooleanValue) {
                }
            }
        }
        if (j8 == 0) {
            return 1L;
        }
        return j8;
    }

    public final long P0() {
        long andIncrement;
        long j8;
        AtomicLong atomicLong = this.f11800t;
        if (atomicLong.get() != 0) {
            AtomicLong atomicLong2 = this.f11800t;
            synchronized (atomicLong2) {
                atomicLong2.compareAndSet(-1L, 1L);
                andIncrement = atomicLong2.getAndIncrement();
            }
            return andIncrement;
        }
        synchronized (atomicLong) {
            long jNanoTime = System.nanoTime();
            ((C0817r0) this.f5146q).D.getClass();
            long jNextLong = new Random(jNanoTime ^ System.currentTimeMillis()).nextLong();
            int i = this.f11801u + 1;
            this.f11801u = i;
            j8 = jNextLong + ((long) i);
        }
        return j8;
    }

    public final SecureRandom Q() {
        E();
        if (this.f11799s == null) {
            this.f11799s = new SecureRandom();
        }
        return this.f11799s;
    }

    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);
            }
            return bundle;
        } catch (UnsupportedOperationException e8) {
            Z z8 = ((C0817r0) this.f5146q).f12150y;
            C0817r0.k(z8);
            z8.f11878y.c(e8, "Install referrer url isn't a hierarchical URI");
            return null;
        }
    }

    public final Bundle R0(Bundle bundle) {
        Bundle bundle2 = new Bundle();
        if (bundle != null) {
            for (String str : bundle.keySet()) {
                Object objL = L(bundle.get(str), str);
                if (objL == null) {
                    C0817r0 c0817r0 = (C0817r0) this.f5146q;
                    Z z8 = c0817r0.f12150y;
                    C0817r0.k(z8);
                    z8.f11869A.c(c0817r0.f12123C.e(str), "Param value can't be null");
                } else {
                    Z(bundle2, str, objL);
                }
            }
        }
        return bundle2;
    }

    public final void S(Bundle bundle, long j8) {
        long j9 = bundle.getLong("_et");
        if (j9 != 0) {
            Z z8 = ((C0817r0) this.f5146q).f12150y;
            C0817r0.k(z8);
            z8.f11878y.c(Long.valueOf(j9), "Params already contained engagement");
        } else {
            j9 = 0;
        }
        bundle.putLong("_et", j8 + j9);
    }

    public final void T(Bundle bundle, int i, String str, Object obj) {
        if (G0(i, bundle)) {
            ((C0817r0) this.f5146q).getClass();
            bundle.putString("_ev", O(40, str, true));
            if (obj != null) {
                if ((obj instanceof String) || (obj instanceof CharSequence)) {
                    bundle.putLong("_el", obj.toString().length());
                }
            }
        }
    }

    public final void V(Bundle bundle, Bundle bundle2) {
        if (bundle2 == null) {
            return;
        }
        for (String str : bundle2.keySet()) {
            if (!bundle.containsKey(str)) {
                W1 w12 = ((C0817r0) this.f5146q).f12122B;
                C0817r0.i(w12);
                w12.Z(bundle, str, bundle2.get(str));
            }
        }
    }

    public final void W(Parcelable[] parcelableArr, int i) {
        P2.w.f(parcelableArr);
        for (Parcelable parcelable : parcelableArr) {
            Bundle bundle = (Bundle) parcelable;
            int i5 = 0;
            boolean z8 = false;
            for (String str : new TreeSet(bundle.keySet())) {
                if (z0(str) && !k0(str, G0.f11470h) && (i5 = i5 + 1) > i) {
                    C0817r0 c0817r0 = (C0817r0) this.f5146q;
                    if (!c0817r0.f12148w.R(null, I.f11586s1) || !z8) {
                        Z z9 = c0817r0.f12150y;
                        C0817r0.k(z9);
                        T t6 = c0817r0.f12123C;
                        z9.f11877x.d("Param can't contain more than " + i + " item-scoped custom parameters", t6.e(str), t6.b(bundle));
                    }
                    G0(28, bundle);
                    bundle.remove(str);
                    z8 = true;
                }
            }
        }
    }

    public final void X(R0.m mVar, int i) {
        Bundle bundle = (Bundle) mVar.f5955e;
        int i5 = 0;
        boolean z8 = false;
        for (String str : new TreeSet(bundle.keySet())) {
            if (z0(str) && (i5 = i5 + 1) > i) {
                C0817r0 c0817r0 = (C0817r0) this.f5146q;
                if (!c0817r0.f12148w.R(null, I.f11586s1) || !z8) {
                    String strK = I1.a.k(i, "Event can't contain more than ", " params");
                    Z z9 = c0817r0.f12150y;
                    C0817r0.k(z9);
                    T t6 = c0817r0.f12123C;
                    z9.f11877x.d(strK, t6.d((String) mVar.f5953c), t6.b(bundle));
                    G0(5, bundle);
                }
                bundle.remove(str);
                z8 = true;
            }
        }
    }

    public final void Z(Bundle bundle, String str, Object obj) {
        if (bundle == null) {
            return;
        }
        if (obj instanceof Long) {
            bundle.putLong(str, ((Long) obj).longValue());
            return;
        }
        if (obj instanceof String) {
            bundle.putString(str, String.valueOf(obj));
            return;
        }
        if (obj instanceof Double) {
            bundle.putDouble(str, ((Double) obj).doubleValue());
            return;
        }
        if (obj instanceof Bundle[]) {
            bundle.putParcelableArray(str, (Bundle[]) obj);
            return;
        }
        if (str != null) {
            String simpleName = obj != null ? obj.getClass().getSimpleName() : null;
            C0817r0 c0817r0 = (C0817r0) this.f5146q;
            Z z8 = c0817r0.f12150y;
            C0817r0.k(z8);
            z8.f11869A.d("Not putting event parameter. Invalid value type. name, type", c0817r0.f12123C.e(str), simpleName);
        }
    }

    public final void a0(com.google.android.gms.internal.measurement.L l8, boolean z8) {
        Bundle bundle = new Bundle();
        bundle.putBoolean("r", z8);
        try {
            l8.m(bundle);
        } catch (RemoteException e8) {
            Z z9 = ((C0817r0) this.f5146q).f12150y;
            C0817r0.k(z9);
            z9.f11878y.c(e8, "Error returning boolean value to wrapper");
        }
    }

    public final void b0(com.google.android.gms.internal.measurement.L l8, ArrayList arrayList) {
        Bundle bundle = new Bundle();
        bundle.putParcelableArrayList("r", arrayList);
        try {
            l8.m(bundle);
        } catch (RemoteException e8) {
            Z z8 = ((C0817r0) this.f5146q).f12150y;
            C0817r0.k(z8);
            z8.f11878y.c(e8, "Error returning bundle list to wrapper");
        }
    }

    public final void c0(com.google.android.gms.internal.measurement.L l8, Bundle bundle) {
        try {
            l8.m(bundle);
        } catch (RemoteException e8) {
            Z z8 = ((C0817r0) this.f5146q).f12150y;
            C0817r0.k(z8);
            z8.f11878y.c(e8, "Error returning bundle value to wrapper");
        }
    }

    public final void d0(com.google.android.gms.internal.measurement.L l8, byte[] bArr) {
        Bundle bundle = new Bundle();
        bundle.putByteArray("r", bArr);
        try {
            l8.m(bundle);
        } catch (RemoteException e8) {
            Z z8 = ((C0817r0) this.f5146q).f12150y;
            C0817r0.k(z8);
            z8.f11878y.c(e8, "Error returning byte array to wrapper");
        }
    }

    public final void e0(com.google.android.gms.internal.measurement.L l8, int i) {
        Bundle bundle = new Bundle();
        bundle.putInt("r", i);
        try {
            l8.m(bundle);
        } catch (RemoteException e8) {
            Z z8 = ((C0817r0) this.f5146q).f12150y;
            C0817r0.k(z8);
            z8.f11878y.c(e8, "Error returning int value to wrapper");
        }
    }

    public final void f0(com.google.android.gms.internal.measurement.L l8, long j8) {
        Bundle bundle = new Bundle();
        bundle.putLong("r", j8);
        try {
            l8.m(bundle);
        } catch (RemoteException e8) {
            Z z8 = ((C0817r0) this.f5146q).f12150y;
            C0817r0.k(z8);
            z8.f11878y.c(e8, "Error returning long value to wrapper");
        }
    }

    public final void g0(String str, com.google.android.gms.internal.measurement.L l8) {
        Bundle bundle = new Bundle();
        bundle.putString("r", str);
        try {
            l8.m(bundle);
        } catch (RemoteException e8) {
            Z z8 = ((C0817r0) this.f5146q).f12150y;
            C0817r0.k(z8);
            z8.f11878y.c(e8, "Error returning string value to wrapper");
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:34:0x009b  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int h0(String str, String str2, Object obj, Bundle bundle, List list, boolean z8, boolean z9) {
        int i;
        int size;
        E();
        boolean zV0 = v0(obj);
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        int i5 = 0;
        if (!zV0) {
            i = 0;
        } else {
            if (!z9) {
                return 21;
            }
            if (!k0(str2, G0.f11469g)) {
                return 20;
            }
            C0824t1 c0824t1R = c0817r0.r();
            c0824t1R.E();
            c0824t1R.F();
            if (c0824t1R.R()) {
                W1 w12 = ((C0817r0) c0824t1R.f5146q).f12122B;
                C0817r0.i(w12);
                if (w12.M0() < 200900) {
                    return 25;
                }
            }
            boolean z10 = obj instanceof Parcelable[];
            if (z10) {
                size = ((Parcelable[]) obj).length;
            } else {
                if (obj instanceof ArrayList) {
                    size = ((ArrayList) obj).size();
                }
                i = 0;
            }
            if (size > 200) {
                Z z11 = c0817r0.f12150y;
                C0817r0.k(z11);
                z11.f11869A.e("Parameter array is too long; discarded. Value kind, name, array length", "param", str2, Integer.valueOf(size));
                i = 17;
                if (z10) {
                    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)));
                    }
                }
            }
        }
        int iMax = 500;
        if (y0(str) || y0(str2)) {
            c0817r0.f12148w.getClass();
            iMax = Math.max(500, 256);
        } else {
            c0817r0.f12148w.getClass();
        }
        if (!q0("param", str2, iMax, obj)) {
            if (!z9) {
                return 4;
            }
            if (obj instanceof Bundle) {
                l0(str, str2, (Bundle) obj, list, z8);
                return i;
            }
            if (obj instanceof Parcelable[]) {
                Parcelable[] parcelableArr2 = (Parcelable[]) obj;
                int length = parcelableArr2.length;
                while (i5 < length) {
                    Parcelable parcelable = parcelableArr2[i5];
                    if (!(parcelable instanceof Bundle)) {
                        Z z12 = c0817r0.f12150y;
                        C0817r0.k(z12);
                        z12.f11869A.d("All Parcelable[] elements must be of type Bundle. Value type, name", parcelable.getClass(), str2);
                        return 4;
                    }
                    l0(str, str2, (Bundle) parcelable, list, z8);
                    i5++;
                }
            } else {
                if (!(obj instanceof ArrayList)) {
                    return 4;
                }
                ArrayList arrayList2 = (ArrayList) obj;
                int size2 = arrayList2.size();
                while (i5 < size2) {
                    Object obj2 = arrayList2.get(i5);
                    if (!(obj2 instanceof Bundle)) {
                        Z z13 = c0817r0.f12150y;
                        C0817r0.k(z13);
                        z13.f11869A.d("All ArrayList elements must be of type Bundle. Value type, name", obj2 != null ? obj2.getClass() : "null", str2);
                        return 4;
                    }
                    l0(str, str2, (Bundle) obj2, list, z8);
                    i5++;
                }
            }
        }
        return i;
    }

    public final int i0(String str) {
        boolean zEquals = "_ldl".equals(str);
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        if (zEquals) {
            c0817r0.getClass();
            return 2048;
        }
        if ("_id".equals(str)) {
            c0817r0.getClass();
            return 256;
        }
        if ("_lgclid".equals(str)) {
            c0817r0.getClass();
            return 100;
        }
        c0817r0.getClass();
        return 36;
    }

    public final Object j0(int i, Object obj, boolean z8, boolean z9) {
        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 O(i, obj.toString(), z8);
        }
        if (!z9) {
            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 bundleR0 = R0((Bundle) parcelable);
                if (!bundleR0.isEmpty()) {
                    arrayList.add(bundleR0);
                }
            }
        }
        return arrayList.toArray(new Bundle[arrayList.size()]);
    }

    public final void l0(String str, String str2, Bundle bundle, List list, boolean z8) {
        int iK0;
        Z z9;
        String str3;
        int iH0;
        List list2 = list;
        if (bundle == null) {
            return;
        }
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        W1 w12 = ((C0817r0) c0817r0.f12148w.f5146q).f12122B;
        C0817r0.i(w12);
        int i = true != w12.x0(231100000) ? 0 : 35;
        int i5 = 0;
        boolean z10 = false;
        for (String str4 : new TreeSet(bundle.keySet())) {
            if (list2 == null || !list2.contains(str4)) {
                iK0 = !z8 ? K0(str4) : 0;
                if (iK0 == 0) {
                    iK0 = J0(str4);
                }
            } else {
                iK0 = 0;
            }
            if (iK0 != 0) {
                T(bundle, iK0, str4, iK0 == 3 ? str4 : null);
                bundle.remove(str4);
            } else {
                boolean zV0 = v0(bundle.get(str4));
                Z z11 = c0817r0.f12150y;
                if (zV0) {
                    C0817r0.k(z11);
                    z11.f11869A.e("Nested Bundle parameters are not allowed; discarded. event name, param name, child param name", str, str2, str4);
                    iH0 = 22;
                    z9 = z11;
                    str3 = null;
                } else {
                    z9 = z11;
                    str3 = null;
                    iH0 = h0(str, str4, bundle.get(str4), bundle, list2, z8, false);
                }
                if (iH0 != 0 && !"_ev".equals(str4)) {
                    T(bundle, iH0, str4, bundle.get(str4));
                    bundle.remove(str4);
                } else if (z0(str4) && !k0(str4, G0.f11470h)) {
                    i5++;
                    boolean zX0 = x0(231100000);
                    T t6 = c0817r0.f12123C;
                    if (zX0) {
                        Z z12 = z9;
                        if (i5 > i) {
                            if (!c0817r0.f12148w.R(str3, I.f11586s1) || !z10) {
                                C0817r0.k(z12);
                                z12.f11877x.d("Item can't contain more than " + i + " item-scoped custom params", t6.d(str), t6.b(bundle));
                            }
                            G0(28, bundle);
                            bundle.remove(str4);
                            list2 = list;
                            z10 = true;
                        }
                    } else {
                        C0817r0.k(z9);
                        z9.f11877x.d("Item array not supported on client's version of Google Play Services (Android Only)", t6.d(str), t6.b(bundle));
                        G0(23, bundle);
                        bundle.remove(str4);
                    }
                }
            }
            list2 = list;
        }
    }

    public final boolean n0(String str, String str2) {
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        boolean zR = c0817r0.f12148w.R(null, I.f11580q1);
        String str3 = c0817r0.f12143r;
        Z z8 = c0817r0.f12150y;
        if (zR) {
            if (TextUtils.isEmpty(str)) {
                if (TextUtils.isEmpty(str3)) {
                    C0817r0.k(z8);
                    z8.f11877x.b("Missing google_app_id. Firebase Analytics disabled. See https://goo.gl/NAOOOI");
                    return false;
                }
            } else {
                if (E0(str)) {
                    return true;
                }
                if (TextUtils.isEmpty(str3)) {
                    C0817r0.k(z8);
                    z8.f11877x.c(Z.M(str), "Invalid google_app_id. Firebase Analytics disabled. See https://goo.gl/NAOOOI. provided id");
                    return false;
                }
            }
        } else if (TextUtils.isEmpty(str)) {
            if (!TextUtils.isEmpty(str2)) {
                if (E0(str2)) {
                    return true;
                }
                C0817r0.k(z8);
                z8.f11877x.c(Z.M(str2), "Invalid admob_app_id. Analytics disabled.");
                return false;
            }
            if (TextUtils.isEmpty(str3)) {
                C0817r0.k(z8);
                z8.f11877x.b("Missing google_app_id. Firebase Analytics disabled. See https://goo.gl/NAOOOI");
            }
        } else {
            if (E0(str)) {
                return true;
            }
            if (TextUtils.isEmpty(str3)) {
                C0817r0.k(z8);
                z8.f11877x.c(Z.M(str), "Invalid google_app_id. Firebase Analytics disabled. See https://goo.gl/NAOOOI. provided id");
                return false;
            }
        }
        return false;
    }

    public final boolean o0(int i, String str, String str2) {
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        if (str2 == null) {
            Z z8 = c0817r0.f12150y;
            C0817r0.k(z8);
            z8.f11877x.c(str, "Name is required and can't be null. Type");
            return false;
        }
        if (str2.codePointCount(0, str2.length()) <= i) {
            return true;
        }
        Z z9 = c0817r0.f12150y;
        C0817r0.k(z9);
        z9.f11877x.e("Name is too long. Type, maximum supported length, name", str, Integer.valueOf(i), str2);
        return false;
    }

    public final boolean p0(String str, String[] strArr, String[] strArr2, String str2) {
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        if (str2 == null) {
            Z z8 = c0817r0.f12150y;
            C0817r0.k(z8);
            z8.f11877x.c(str, "Name is required and can't be null. Type");
            return false;
        }
        String[] strArr3 = f11797y;
        for (int i = 0; i < 3; i++) {
            if (str2.startsWith(strArr3[i])) {
                Z z9 = c0817r0.f12150y;
                C0817r0.k(z9);
                z9.f11877x.d("Name starts with reserved prefix. Type, name", str, str2);
                return false;
            }
        }
        if (strArr == null || !k0(str2, strArr)) {
            return true;
        }
        if (strArr2 != null && k0(str2, strArr2)) {
            return true;
        }
        Z z10 = c0817r0.f12150y;
        C0817r0.k(z10);
        z10.f11877x.d("Name is reserved. Type, name", str, str2);
        return false;
    }

    public final boolean q0(String str, String str2, int i, Object obj) {
        if (obj == null || (obj instanceof Long) || (obj instanceof Float) || (obj instanceof Integer) || (obj instanceof Byte) || (obj instanceof Short) || (obj instanceof Boolean) || (obj instanceof Double)) {
            return true;
        }
        if (!(obj instanceof String) && !(obj instanceof Character) && !(obj instanceof CharSequence)) {
            return false;
        }
        String string = obj.toString();
        if (string.codePointCount(0, string.length()) > i) {
            Z z8 = ((C0817r0) this.f5146q).f12150y;
            C0817r0.k(z8);
            z8.f11869A.e("Value is too long; discarded. Value kind, name, value length", str, str2, Integer.valueOf(string.length()));
            return false;
        }
        return true;
    }

    public final boolean r0(String str, String str2) {
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        if (str2 == null) {
            Z z8 = c0817r0.f12150y;
            C0817r0.k(z8);
            z8.f11877x.c(str, "Name is required and can't be null. Type");
            return false;
        }
        if (str2.length() == 0) {
            Z z9 = c0817r0.f12150y;
            C0817r0.k(z9);
            z9.f11877x.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) {
                Z z10 = c0817r0.f12150y;
                C0817r0.k(z10);
                z10.f11877x.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)) {
                Z z11 = c0817r0.f12150y;
                C0817r0.k(z11);
                z11.f11877x.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) {
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        if (str2 == null) {
            Z z8 = c0817r0.f12150y;
            C0817r0.k(z8);
            z8.f11877x.c(str, "Name is required and can't be null. Type");
            return false;
        }
        if (str2.length() == 0) {
            Z z9 = c0817r0.f12150y;
            C0817r0.k(z9);
            z9.f11877x.c(str, "Name is required and can't be empty. Type");
            return false;
        }
        int iCodePointAt = str2.codePointAt(0);
        if (!Character.isLetter(iCodePointAt)) {
            Z z10 = c0817r0.f12150y;
            C0817r0.k(z10);
            z10.f11877x.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)) {
                Z z11 = c0817r0.f12150y;
                C0817r0.k(z11);
                z11.f11877x.d("Name must consist of letters, digits or _ (underscores). Type, name", str, str2);
                return false;
            }
            iCharCount += Character.charCount(iCodePointAt2);
        }
        return true;
    }

    public final boolean t0(String str) {
        E();
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        if (U2.b.a(c0817r0.f12142q).f3229q.checkCallingOrSelfPermission(str) == 0) {
            return true;
        }
        Z z8 = c0817r0.f12150y;
        C0817r0.k(z8);
        z8.f11871C.c(str, "Permission not granted");
        return false;
    }

    public final boolean u0(String str, String str2) {
        if (!TextUtils.isEmpty(str2)) {
            return true;
        }
        if (TextUtils.isEmpty(str)) {
            return false;
        }
        return ((C0817r0) this.f5146q).f12148w.I("debug.firebase.analytics.app").equals(str);
    }

    public final boolean w0(Context context, String str) {
        Signature[] signatureArr;
        C0817r0 c0817r0 = (C0817r0) this.f5146q;
        X500Principal x500Principal = new X500Principal("CN=Android Debug,O=Android,C=US");
        try {
            PackageInfo packageInfoC = U2.b.a(context).c(64, str);
            if (packageInfoC == null || (signatureArr = packageInfoC.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 e8) {
            Z z8 = c0817r0.f12150y;
            C0817r0.k(z8);
            z8.f11875v.c(e8, "Package name not found");
            return true;
        } catch (CertificateException e9) {
            Z z9 = c0817r0.f12150y;
            C0817r0.k(z9);
            z9.f11875v.c(e9, "Error obtaining certificate");
            return true;
        }
    }

    public final boolean x0(int i) {
        Boolean bool = ((C0817r0) this.f5146q).r().f12180u;
        if (M0() < i / 1000) {
            return (bool == null || bool.booleanValue()) ? false : true;
        }
        return true;
    }
}
