package L1;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
import com.google.android.gms.internal.measurement.AbstractC0366e2;
import com.google.android.gms.internal.measurement.AbstractC0376g2;
import com.google.android.gms.internal.measurement.C0345a1;
import com.google.android.gms.internal.measurement.C0346a2;
import com.google.android.gms.internal.measurement.C0348b;
import com.google.android.gms.internal.measurement.C0350b1;
import com.google.android.gms.internal.measurement.C0355c1;
import com.google.android.gms.internal.measurement.C0365e1;
import com.google.android.gms.internal.measurement.C0370f1;
import com.google.android.gms.internal.measurement.C0385i1;
import com.google.android.gms.internal.measurement.C0390j1;
import com.google.android.gms.internal.measurement.C0395k1;
import com.google.android.gms.internal.measurement.C0410n1;
import com.google.android.gms.internal.measurement.C0420p1;
import com.google.android.gms.internal.measurement.C0426q2;
import com.google.android.gms.internal.measurement.C0428r0;
import com.google.android.gms.internal.measurement.C0429r1;
import com.google.android.gms.internal.measurement.C0434s1;
import com.google.android.gms.internal.measurement.C0439t1;
import com.google.android.gms.internal.measurement.C0443u0;
import com.google.android.gms.internal.measurement.C0445u2;
import com.google.android.gms.internal.measurement.C0453w0;
import com.google.android.gms.internal.measurement.C0458x0;
import com.google.android.gms.internal.measurement.F2;
import com.google.android.gms.internal.measurement.InterfaceC0406m2;
import com.google.android.gms.internal.measurement.InterfaceC0411n2;
import com.google.android.gms.internal.measurement.P3;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.BitSet;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.zip.GZIPOutputStream;
import p0.AbstractC0928a;
import t1.C1023b;

/* JADX INFO: renamed from: L1.b0, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0084b0 extends Q1 {

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final /* synthetic */ int f1681n;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ C0084b0(W1 w12, int i) {
        super(w12);
        this.f1681n = i;
    }

    public static final void A(Uri.Builder builder, String[] strArr, Bundle bundle, Set set) {
        for (String str : strArr) {
            String[] strArrSplit = str.split(",");
            String str2 = strArrSplit[0];
            String str3 = strArrSplit[strArrSplit.length - 1];
            String string = bundle.getString(str2);
            if (string != null) {
                x(builder, str3, string, set);
            }
        }
    }

    public static final void B(StringBuilder sb, String str, C0410n1 c0410n1) {
        if (c0410n1 == null) {
            return;
        }
        w(3, sb);
        sb.append(str);
        sb.append(" {\n");
        if (c0410n1.s() != 0) {
            w(4, sb);
            sb.append("results: ");
            int i = 0;
            for (Long l5 : c0410n1.r()) {
                int i5 = i + 1;
                if (i != 0) {
                    sb.append(", ");
                }
                sb.append(l5);
                i = i5;
            }
            sb.append('\n');
        }
        if (c0410n1.q() != 0) {
            w(4, sb);
            sb.append("status: ");
            int i6 = 0;
            for (Long l6 : c0410n1.p()) {
                int i7 = i6 + 1;
                if (i6 != 0) {
                    sb.append(", ");
                }
                sb.append(l6);
                i6 = i7;
            }
            sb.append('\n');
        }
        if (c0410n1.u() != 0) {
            w(4, sb);
            sb.append("dynamic_filter_timestamps: {");
            int i8 = 0;
            for (C0345a1 c0345a1 : c0410n1.t()) {
                int i9 = i8 + 1;
                if (i8 != 0) {
                    sb.append(", ");
                }
                sb.append(c0345a1.p() ? Integer.valueOf(c0345a1.q()) : null);
                sb.append(":");
                sb.append(c0345a1.r() ? Long.valueOf(c0345a1.s()) : null);
                i8 = i9;
            }
            sb.append("}\n");
        }
        if (c0410n1.w() != 0) {
            w(4, sb);
            sb.append("sequence_filter_timestamps: {");
            int i10 = 0;
            for (C0420p1 c0420p1 : c0410n1.v()) {
                int i11 = i10 + 1;
                if (i10 != 0) {
                    sb.append(", ");
                }
                sb.append(c0420p1.p() ? Integer.valueOf(c0420p1.q()) : null);
                sb.append(": [");
                Iterator it = c0420p1.r().iterator();
                int i12 = 0;
                while (it.hasNext()) {
                    long jLongValue = ((Long) it.next()).longValue();
                    int i13 = i12 + 1;
                    if (i12 != 0) {
                        sb.append(", ");
                    }
                    sb.append(jLongValue);
                    i12 = i13;
                }
                sb.append("]");
                i10 = i11;
            }
            sb.append("}\n");
        }
        w(3, sb);
        sb.append("}\n");
    }

    public static final void C(StringBuilder sb, int i, String str, Object obj) {
        if (obj == null) {
            return;
        }
        w(i + 1, sb);
        sb.append(str);
        sb.append(": ");
        sb.append(obj);
        sb.append('\n');
    }

    public static final void D(StringBuilder sb, int i, String str, C0443u0 c0443u0) {
        if (c0443u0 == null) {
            return;
        }
        w(i, sb);
        sb.append(str);
        sb.append(" {\n");
        if (c0443u0.p()) {
            int iZ = c0443u0.z();
            C(sb, i, "comparison_type", iZ != 1 ? iZ != 2 ? iZ != 3 ? iZ != 4 ? "BETWEEN" : "EQUAL" : "GREATER_THAN" : "LESS_THAN" : "UNKNOWN_COMPARISON_TYPE");
        }
        if (c0443u0.q()) {
            C(sb, i, "match_as_float", Boolean.valueOf(c0443u0.r()));
        }
        if (c0443u0.s()) {
            C(sb, i, "comparison_value", c0443u0.t());
        }
        if (c0443u0.u()) {
            C(sb, i, "min_comparison_value", c0443u0.v());
        }
        if (c0443u0.w()) {
            C(sb, i, "max_comparison_value", c0443u0.x());
        }
        w(i, sb);
        sb.append("}\n");
    }

    public static boolean Q(String str) {
        return str != null && str.matches("([+-])?([0-9]+\\.?[0-9]*|[0-9]*\\.?[0-9]+)") && str.length() <= 310;
    }

    public static boolean R(InterfaceC0406m2 interfaceC0406m2, int i) {
        if (i < ((C0445u2) interfaceC0406m2).f5248m * 64) {
            return ((1 << (i % 64)) & ((Long) ((C0445u2) interfaceC0406m2).get(i / 64)).longValue()) != 0;
        }
        return false;
    }

    public static ArrayList S(BitSet bitSet) {
        int length = (bitSet.length() + 63) / 64;
        ArrayList arrayList = new ArrayList(length);
        for (int i = 0; i < length; i++) {
            long j5 = 0;
            for (int i5 = 0; i5 < 64; i5++) {
                int i6 = (i * 64) + i5;
                if (i6 >= bitSet.length()) {
                    break;
                }
                if (bitSet.get(i6)) {
                    j5 |= 1 << i5;
                }
            }
            arrayList.add(Long.valueOf(j5));
        }
        return arrayList;
    }

    public static AbstractC0376g2 X(AbstractC0376g2 abstractC0376g2, byte[] bArr) throws C0426q2 {
        C0346a2 c0346a2F;
        C0346a2 c0346a2 = C0346a2.f5029a;
        if (c0346a2 == null) {
            synchronized (C0346a2.class) {
                try {
                    c0346a2F = C0346a2.f5029a;
                    if (c0346a2F == null) {
                        F2 f22 = F2.f4869c;
                        c0346a2F = AbstractC0366e2.F();
                        C0346a2.f5029a = c0346a2F;
                    }
                } finally {
                }
            }
            c0346a2 = c0346a2F;
        }
        if (c0346a2 != null) {
            abstractC0376g2.getClass();
            abstractC0376g2.g(bArr, bArr.length, c0346a2);
            return abstractC0376g2;
        }
        abstractC0376g2.getClass();
        int length = bArr.length;
        C0346a2 c0346a22 = C0346a2.f5029a;
        F2 f23 = F2.f4869c;
        abstractC0376g2.g(bArr, length, C0346a2.f5030b);
        return abstractC0376g2;
    }

    public static int Y(C0390j1 c0390j1, String str) {
        for (int i = 0; i < ((C0395k1) c0390j1.f5142l).V1(); i++) {
            if (str.equals(((C0395k1) c0390j1.f5142l).W1(i).r())) {
                return i;
            }
        }
        return -1;
    }

    public static Bundle[] Z(InterfaceC0411n2 interfaceC0411n2) {
        ArrayList arrayList = new ArrayList();
        Iterator it = interfaceC0411n2.iterator();
        while (it.hasNext()) {
            C0370f1 c0370f1 = (C0370f1) it.next();
            if (c0370f1 != null) {
                Bundle bundle = new Bundle();
                for (C0370f1 c0370f12 : c0370f1.z()) {
                    if (c0370f12.r()) {
                        bundle.putString(c0370f12.q(), c0370f12.s());
                    } else if (c0370f12.t()) {
                        bundle.putLong(c0370f12.q(), c0370f12.u());
                    } else if (c0370f12.x()) {
                        bundle.putDouble(c0370f12.q(), c0370f12.y());
                    }
                }
                if (!bundle.isEmpty()) {
                    arrayList.add(bundle);
                }
            }
        }
        return (Bundle[]) arrayList.toArray(new Bundle[arrayList.size()]);
    }

    public static HashMap a0(Bundle bundle, boolean z5) {
        HashMap map = new HashMap();
        for (String str : bundle.keySet()) {
            Object obj = bundle.get(str);
            boolean z6 = obj instanceof Parcelable[];
            if (z6 || (obj instanceof ArrayList) || (obj instanceof Bundle)) {
                if (z5) {
                    ArrayList arrayList = new ArrayList();
                    if (z6) {
                        for (Parcelable parcelable : (Parcelable[]) obj) {
                            if (parcelable instanceof Bundle) {
                                arrayList.add(a0((Bundle) parcelable, false));
                            }
                        }
                    } else if (obj instanceof ArrayList) {
                        ArrayList arrayList2 = (ArrayList) obj;
                        int size = arrayList2.size();
                        for (int i = 0; i < size; i++) {
                            Object obj2 = arrayList2.get(i);
                            if (obj2 instanceof Bundle) {
                                arrayList.add(a0((Bundle) obj2, false));
                            }
                        }
                    } else if (obj instanceof Bundle) {
                        arrayList.add(a0((Bundle) obj, false));
                    }
                    map.put(str, arrayList);
                }
            } else if (obj != null) {
                map.put(str, obj);
            }
        }
        return map;
    }

    public static C0142v o(C0348b c0348b) {
        Object obj;
        Bundle bundleP = p(c0348b.f5035c, true);
        String string = (!bundleP.containsKey("_o") || (obj = bundleP.get("_o")) == null) ? "app" : obj.toString();
        String strG = M0.g(c0348b.f5033a, M0.f1490a, M0.f1492c);
        if (strG == null) {
            strG = c0348b.f5033a;
        }
        return new C0142v(strG, new C0139u(bundleP), string, c0348b.f5034b);
    }

    public static Bundle p(Map map, boolean z5) {
        Bundle bundle = new Bundle();
        for (String str : map.keySet()) {
            Object obj = map.get(str);
            if (obj == null) {
                bundle.putString(str, null);
            } else if (obj instanceof Long) {
                bundle.putLong(str, ((Long) obj).longValue());
            } else if (obj instanceof Double) {
                bundle.putDouble(str, ((Double) obj).doubleValue());
            } else if (!(obj instanceof ArrayList)) {
                bundle.putString(str, obj.toString());
            } else if (z5) {
                ArrayList arrayList = (ArrayList) obj;
                ArrayList arrayList2 = new ArrayList();
                int size = arrayList.size();
                for (int i = 0; i < size; i++) {
                    arrayList2.add(p((Map) arrayList.get(i), false));
                }
                bundle.putParcelableArray(str, (Parcelable[]) arrayList2.toArray(new Parcelable[0]));
            }
        }
        return bundle;
    }

    public static final void q(C0350b1 c0350b1, String str, Long l5) {
        List listH = c0350b1.h();
        int i = 0;
        while (true) {
            if (i >= listH.size()) {
                i = -1;
                break;
            } else if (str.equals(((C0370f1) listH.get(i)).q())) {
                break;
            } else {
                i++;
            }
        }
        C0365e1 c0365e1B = C0370f1.B();
        c0365e1B.h(str);
        c0365e1B.j(l5.longValue());
        if (i < 0) {
            c0350b1.l(c0365e1B);
        } else {
            c0350b1.b();
            ((C0355c1) c0350b1.f5142l).A(i, (C0370f1) c0365e1B.e());
        }
    }

    public static final Bundle r(List list) {
        Bundle bundle = new Bundle();
        Iterator it = list.iterator();
        while (it.hasNext()) {
            C0370f1 c0370f1 = (C0370f1) it.next();
            String strQ = c0370f1.q();
            if (c0370f1.x()) {
                bundle.putDouble(strQ, c0370f1.y());
            } else if (c0370f1.v()) {
                bundle.putFloat(strQ, c0370f1.w());
            } else if (c0370f1.r()) {
                bundle.putString(strQ, c0370f1.s());
            } else if (c0370f1.t()) {
                bundle.putLong(strQ, c0370f1.u());
            }
        }
        return bundle;
    }

    public static final C0370f1 s(C0355c1 c0355c1, String str) {
        for (C0370f1 c0370f1 : c0355c1.p()) {
            if (c0370f1.q().equals(str)) {
                return c0370f1;
            }
        }
        return null;
    }

    public static final Serializable t(C0355c1 c0355c1, String str) {
        C0370f1 c0370f1S = s(c0355c1, str);
        if (c0370f1S == null) {
            return null;
        }
        return z(c0370f1S);
    }

    public static final void w(int i, StringBuilder sb) {
        for (int i5 = 0; i5 < i; i5++) {
            sb.append("  ");
        }
    }

    public static final void x(Uri.Builder builder, String str, String str2, Set set) {
        if (set.contains(str) || TextUtils.isEmpty(str2)) {
            return;
        }
        builder.appendQueryParameter(str, str2);
    }

    public static final String y(boolean z5, boolean z6, boolean z7) {
        StringBuilder sb = new StringBuilder();
        if (z5) {
            sb.append("Dynamic ");
        }
        if (z6) {
            sb.append("Sequence ");
        }
        if (z7) {
            sb.append("Session-Scoped ");
        }
        return sb.toString();
    }

    /* JADX WARN: Type inference failed for: r2v4, types: [android.os.Bundle[], java.io.Serializable] */
    public static final Serializable z(C0370f1 c0370f1) {
        if (c0370f1.r()) {
            return c0370f1.s();
        }
        if (c0370f1.t()) {
            return Long.valueOf(c0370f1.u());
        }
        if (c0370f1.x()) {
            return Double.valueOf(c0370f1.y());
        }
        if (c0370f1.A() > 0) {
            return Z((InterfaceC0411n2) c0370f1.z());
        }
        return null;
    }

    public boolean E() {
        l();
        ConnectivityManager connectivityManager = (ConnectivityManager) ((C0146w0) this.f29k).f2032k.getSystemService("connectivity");
        NetworkInfo activeNetworkInfo = null;
        if (connectivityManager != null) {
            try {
                activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
            } catch (SecurityException unused) {
            }
        }
        return activeNetworkInfo != null && activeNetworkInfo.isConnected();
    }

    public void I(C0434s1 c0434s1, Object obj) {
        s1.z.g(obj);
        c0434s1.b();
        ((C0439t1) c0434s1.f5142l).E();
        c0434s1.b();
        ((C0439t1) c0434s1.f5142l).G();
        c0434s1.b();
        ((C0439t1) c0434s1.f5142l).I();
        if (obj instanceof String) {
            c0434s1.b();
            ((C0439t1) c0434s1.f5142l).D((String) obj);
        } else if (obj instanceof Long) {
            long jLongValue = ((Long) obj).longValue();
            c0434s1.b();
            ((C0439t1) c0434s1.f5142l).F(jLongValue);
        } else if (obj instanceof Double) {
            double dDoubleValue = ((Double) obj).doubleValue();
            c0434s1.b();
            ((C0439t1) c0434s1.f5142l).H(dDoubleValue);
        } else {
            X x5 = ((C0146w0) this.f29k).p;
            C0146w0.l(x5);
            x5.p.c("Ignoring invalid (type) user attribute value", obj);
        }
    }

    public void J(String str, R1 r12, C0385i1 c0385i1, Z z5) {
        String str2;
        URL url;
        byte[] bArrA;
        C0137t0 c0137t0;
        Map map;
        String str3 = r12.f1547a;
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        k();
        l();
        try {
            url = new URI(str3).toURL();
            this.f1500l.i0();
            bArrA = c0385i1.a();
            c0137t0 = c0146w0.q;
            C0146w0.l(c0137t0);
            map = r12.f1548b;
            if (map == null) {
                map = Collections.EMPTY_MAP;
            }
            str2 = str;
        } catch (IllegalArgumentException | MalformedURLException | URISyntaxException unused) {
            str2 = str;
        }
        try {
            c0137t0.w(new RunnableC0081a0(this, str2, url, bArrA, map, z5));
        } catch (IllegalArgumentException | MalformedURLException | URISyntaxException unused2) {
            X x5 = c0146w0.p;
            C0146w0.l(x5);
            x5.p.d(X.s(str2), str3, "Failed to parse URL. Not uploading MeasurementBatch. appId");
        }
    }

    public void K(C0365e1 c0365e1, Object obj) {
        c0365e1.b();
        ((C0370f1) c0365e1.f5142l).E();
        c0365e1.b();
        ((C0370f1) c0365e1.f5142l).G();
        c0365e1.b();
        ((C0370f1) c0365e1.f5142l).I();
        c0365e1.b();
        ((C0370f1) c0365e1.f5142l).L();
        if (obj instanceof String) {
            c0365e1.i((String) obj);
            return;
        }
        if (obj instanceof Long) {
            c0365e1.j(((Long) obj).longValue());
            return;
        }
        if (obj instanceof Double) {
            double dDoubleValue = ((Double) obj).doubleValue();
            c0365e1.b();
            ((C0370f1) c0365e1.f5142l).H(dDoubleValue);
            return;
        }
        if (!(obj instanceof Bundle[])) {
            X x5 = ((C0146w0) this.f29k).p;
            C0146w0.l(x5);
            x5.p.c("Ignoring invalid (type) event param value", obj);
            return;
        }
        ArrayList arrayList = new ArrayList();
        for (Bundle bundle : (Bundle[]) obj) {
            if (bundle != null) {
                C0365e1 c0365e1B = C0370f1.B();
                for (String str : bundle.keySet()) {
                    C0365e1 c0365e1B2 = C0370f1.B();
                    c0365e1B2.h(str);
                    Object obj2 = bundle.get(str);
                    if (obj2 instanceof Long) {
                        c0365e1B2.j(((Long) obj2).longValue());
                    } else if (obj2 instanceof String) {
                        c0365e1B2.i((String) obj2);
                    } else if (obj2 instanceof Double) {
                        double dDoubleValue2 = ((Double) obj2).doubleValue();
                        c0365e1B2.b();
                        ((C0370f1) c0365e1B2.f5142l).H(dDoubleValue2);
                    }
                    c0365e1B.b();
                    ((C0370f1) c0365e1B.f5142l).J((C0370f1) c0365e1B2.e());
                }
                if (((C0370f1) c0365e1B.f5142l).A() > 0) {
                    arrayList.add((C0370f1) c0365e1B.e());
                }
            }
        }
        c0365e1.b();
        ((C0370f1) c0365e1.f5142l).K(arrayList);
    }

    public K1 L(String str, C0390j1 c0390j1, C0350b1 c0350b1, String str2) {
        int iIndexOf;
        P3.a();
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        if (!c0146w0.f2035n.u(str, F.f1375P0)) {
            return null;
        }
        c0146w0.f2040u.getClass();
        long jCurrentTimeMillis = System.currentTimeMillis();
        E e2 = F.f1440u0;
        C0098g c0098g = c0146w0.f2035n;
        String[] strArrSplit = c0098g.q(str, e2).split(",");
        HashSet hashSet = new HashSet(strArrSplit.length);
        for (String str3 : strArrSplit) {
            Objects.requireNonNull(str3);
            if (!hashSet.add(str3)) {
                throw new IllegalArgumentException("duplicate element: " + ((Object) str3));
            }
        }
        Set setUnmodifiableSet = Collections.unmodifiableSet(hashSet);
        W1 w12 = this.f1500l;
        S1 s12 = w12.f1615t;
        C0126p0 c0126p0 = s12.f1500l.f1608k;
        W1.T(c0126p0);
        String strX = c0126p0.x(str);
        Uri.Builder builder = new Uri.Builder();
        C0146w0 c0146w02 = (C0146w0) s12.f29k;
        builder.scheme(c0146w02.f2035n.q(str, F.f1428n0));
        boolean zIsEmpty = TextUtils.isEmpty(strX);
        C0098g c0098g2 = c0146w02.f2035n;
        if (zIsEmpty) {
            builder.authority(c0098g2.q(str, F.f1430o0));
        } else {
            String strQ = c0098g2.q(str, F.f1430o0);
            StringBuilder sb = new StringBuilder(String.valueOf(strX).length() + 1 + String.valueOf(strQ).length());
            sb.append(strX);
            sb.append(".");
            sb.append(strQ);
            builder.authority(sb.toString());
        }
        builder.path(c0098g2.q(str, F.f1431p0));
        x(builder, "gmp_app_id", ((C0395k1) c0390j1.f5142l).E(), setUnmodifiableSet);
        c0098g.p();
        x(builder, "gmp_version", String.valueOf(133005L), setUnmodifiableSet);
        String strY = ((C0395k1) c0390j1.f5142l).y();
        E e6 = F.S0;
        boolean zU = c0098g.u(str, e6);
        C0126p0 c0126p02 = w12.f1608k;
        if (zU) {
            W1.T(c0126p02);
            if (c0126p02.D(str)) {
                strY = "";
            }
        }
        x(builder, "app_instance_id", strY, setUnmodifiableSet);
        x(builder, "rdid", ((C0395k1) c0390j1.f5142l).v(), setUnmodifiableSet);
        x(builder, "bundle_id", c0390j1.o(), setUnmodifiableSet);
        String strN = c0350b1.n();
        String strG = M0.g(strN, M0.f1492c, M0.f1490a);
        if (true != TextUtils.isEmpty(strG)) {
            strN = strG;
        }
        x(builder, "app_event_name", strN, setUnmodifiableSet);
        x(builder, "app_version", String.valueOf(((C0395k1) c0390j1.f5142l).K()), setUnmodifiableSet);
        String strI2 = ((C0395k1) c0390j1.f5142l).i2();
        if (c0098g.u(str, e6)) {
            W1.T(c0126p02);
            if (c0126p02.C(str) && !TextUtils.isEmpty(strI2) && (iIndexOf = strI2.indexOf(".")) != -1) {
                strI2 = strI2.substring(0, iIndexOf);
            }
        }
        x(builder, "os_version", strI2, setUnmodifiableSet);
        x(builder, "timestamp", String.valueOf(c0350b1.o()), setUnmodifiableSet);
        if (((C0395k1) c0390j1.f5142l).x()) {
            x(builder, "lat", "1", setUnmodifiableSet);
        }
        x(builder, "privacy_sandbox_version", String.valueOf(((C0395k1) c0390j1.f5142l).G0()), setUnmodifiableSet);
        x(builder, "trigger_uri_source", "1", setUnmodifiableSet);
        x(builder, "trigger_uri_timestamp", String.valueOf(jCurrentTimeMillis), setUnmodifiableSet);
        x(builder, "request_uuid", str2, setUnmodifiableSet);
        List<C0370f1> listH = c0350b1.h();
        Bundle bundle = new Bundle();
        for (C0370f1 c0370f1 : listH) {
            String strQ2 = c0370f1.q();
            if (c0370f1.x()) {
                bundle.putString(strQ2, String.valueOf(c0370f1.y()));
            } else if (c0370f1.v()) {
                bundle.putString(strQ2, String.valueOf(c0370f1.w()));
            } else if (c0370f1.r()) {
                bundle.putString(strQ2, c0370f1.s());
            } else if (c0370f1.t()) {
                bundle.putString(strQ2, String.valueOf(c0370f1.u()));
            }
        }
        A(builder, c0098g.q(str, F.f1438t0).split("\\|"), bundle, setUnmodifiableSet);
        List<C0439t1> listUnmodifiableList = Collections.unmodifiableList(((C0395k1) c0390j1.f5142l).U1());
        Bundle bundle2 = new Bundle();
        for (C0439t1 c0439t1 : listUnmodifiableList) {
            String strR = c0439t1.r();
            if (c0439t1.y()) {
                bundle2.putString(strR, String.valueOf(c0439t1.z()));
            } else if (c0439t1.w()) {
                bundle2.putString(strR, String.valueOf(c0439t1.x()));
            } else if (c0439t1.s()) {
                bundle2.putString(strR, c0439t1.t());
            } else if (c0439t1.u()) {
                bundle2.putString(strR, String.valueOf(c0439t1.v()));
            }
        }
        A(builder, c0098g.q(str, F.f1436s0).split("\\|"), bundle2, setUnmodifiableSet);
        x(builder, "dma", true != ((C0395k1) c0390j1.f5142l).D0() ? "0" : "1", setUnmodifiableSet);
        if (!((C0395k1) c0390j1.f5142l).F0().isEmpty()) {
            x(builder, "dma_cps", ((C0395k1) c0390j1.f5142l).F0(), setUnmodifiableSet);
        }
        if (((C0395k1) c0390j1.f5142l).L0()) {
            com.google.android.gms.internal.measurement.P0 p0M0 = ((C0395k1) c0390j1.f5142l).M0();
            if (!p0M0.z().isEmpty()) {
                x(builder, "dl_gclid", p0M0.z(), setUnmodifiableSet);
            }
            if (!p0M0.B().isEmpty()) {
                x(builder, "dl_gbraid", p0M0.B(), setUnmodifiableSet);
            }
            if (!p0M0.D().isEmpty()) {
                x(builder, "dl_gs", p0M0.D(), setUnmodifiableSet);
            }
            if (p0M0.F() > 0) {
                x(builder, "dl_ss_ts", String.valueOf(p0M0.F()), setUnmodifiableSet);
            }
            if (!p0M0.H().isEmpty()) {
                x(builder, "mr_gclid", p0M0.H(), setUnmodifiableSet);
            }
            if (!p0M0.J().isEmpty()) {
                x(builder, "mr_gbraid", p0M0.J(), setUnmodifiableSet);
            }
            if (!p0M0.L().isEmpty()) {
                x(builder, "mr_gs", p0M0.L(), setUnmodifiableSet);
            }
            if (p0M0.N() > 0) {
                x(builder, "mr_click_ts", String.valueOf(p0M0.N()), setUnmodifiableSet);
            }
        }
        return new K1(jCurrentTimeMillis, builder.build().toString(), 1);
    }

    public C0355c1 M(r rVar) {
        C0350b1 c0350b1Z = C0355c1.z();
        c0350b1Z.b();
        ((C0355c1) c0350b1Z.f5142l).H(rVar.f1969e);
        C0139u c0139u = rVar.f1970f;
        Objects.requireNonNull(c0139u);
        Bundle bundle = c0139u.f2007k;
        for (String str : bundle.keySet()) {
            C0365e1 c0365e1B = C0370f1.B();
            c0365e1B.h(str);
            Object obj = bundle.get(str);
            s1.z.g(obj);
            K(c0365e1B, obj);
            c0350b1Z.l(c0365e1B);
        }
        String str2 = rVar.f1967c;
        if (!TextUtils.isEmpty(str2) && bundle.get("_o") == null) {
            C0365e1 c0365e1B2 = C0370f1.B();
            c0365e1B2.h("_o");
            c0365e1B2.i(str2);
            c0350b1Z.k((C0370f1) c0365e1B2.e());
        }
        return (C0355c1) c0350b1Z.e();
    }

    public String N(C0385i1 c0385i1) {
        com.google.android.gms.internal.measurement.S0 s0I0;
        StringBuilder sbB = u.e.b("\nbatch {\n");
        if (c0385i1.u()) {
            C(sbB, 0, "upload_subdomain", c0385i1.v());
        }
        if (c0385i1.s()) {
            C(sbB, 0, "sgtm_join_id", c0385i1.t());
        }
        for (C0395k1 c0395k1 : c0385i1.p()) {
            if (c0395k1 != null) {
                w(1, sbB);
                sbB.append("bundle {\n");
                if (c0395k1.P()) {
                    C(sbB, 1, "protocol_version", Integer.valueOf(c0395k1.P0()));
                }
                C0146w0 c0146w0 = (C0146w0) this.f29k;
                if (c0146w0.f2035n.u(c0395k1.p(), F.f1370M0) && c0395k1.v0()) {
                    C(sbB, 1, "session_stitching_token", c0395k1.w0());
                }
                C(sbB, 1, "platform", c0395k1.h2());
                if (c0395k1.r()) {
                    C(sbB, 1, "gmp_version", Long.valueOf(c0395k1.s()));
                }
                if (c0395k1.t()) {
                    C(sbB, 1, "uploading_gmp_version", Long.valueOf(c0395k1.u()));
                }
                if (c0395k1.r0()) {
                    C(sbB, 1, "dynamite_version", Long.valueOf(c0395k1.s0()));
                }
                if (c0395k1.L()) {
                    C(sbB, 1, "config_version", Long.valueOf(c0395k1.M()));
                }
                C(sbB, 1, "gmp_app_id", c0395k1.E());
                C(sbB, 1, "app_id", c0395k1.p());
                C(sbB, 1, "app_version", c0395k1.q());
                if (c0395k1.J()) {
                    C(sbB, 1, "app_version_major", Integer.valueOf(c0395k1.K()));
                }
                C(sbB, 1, "firebase_instance_id", c0395k1.I());
                if (c0395k1.z()) {
                    C(sbB, 1, "dev_cert_hash", Long.valueOf(c0395k1.A()));
                }
                C(sbB, 1, "app_store", c0395k1.n2());
                if (c0395k1.X1()) {
                    C(sbB, 1, "upload_timestamp_millis", Long.valueOf(c0395k1.Y1()));
                }
                if (c0395k1.Z1()) {
                    C(sbB, 1, "start_timestamp_millis", Long.valueOf(c0395k1.a2()));
                }
                if (c0395k1.b2()) {
                    C(sbB, 1, "end_timestamp_millis", Long.valueOf(c0395k1.c2()));
                }
                if (c0395k1.d2()) {
                    C(sbB, 1, "previous_bundle_start_timestamp_millis", Long.valueOf(c0395k1.e2()));
                }
                if (c0395k1.f2()) {
                    C(sbB, 1, "previous_bundle_end_timestamp_millis", Long.valueOf(c0395k1.g2()));
                }
                C(sbB, 1, "app_instance_id", c0395k1.y());
                C(sbB, 1, "resettable_device_id", c0395k1.v());
                C(sbB, 1, "ds_id", c0395k1.O());
                if (c0395k1.w()) {
                    C(sbB, 1, "limited_ad_tracking", Boolean.valueOf(c0395k1.x()));
                }
                C(sbB, 1, "os_version", c0395k1.i2());
                C(sbB, 1, "device_model", c0395k1.j2());
                C(sbB, 1, "user_default_language", c0395k1.k2());
                if (c0395k1.l2()) {
                    C(sbB, 1, "time_zone_offset_minutes", Integer.valueOf(c0395k1.m2()));
                }
                if (c0395k1.B()) {
                    C(sbB, 1, "bundle_sequential_index", Integer.valueOf(c0395k1.C()));
                }
                if (c0395k1.J0()) {
                    C(sbB, 1, "delivery_index", Integer.valueOf(c0395k1.K0()));
                }
                if (c0395k1.F()) {
                    C(sbB, 1, "service_upload", Boolean.valueOf(c0395k1.G()));
                }
                C(sbB, 1, "health_monitor", c0395k1.D());
                if (c0395k1.p0()) {
                    C(sbB, 1, "retry_counter", Integer.valueOf(c0395k1.q0()));
                }
                if (c0395k1.t0()) {
                    C(sbB, 1, "consent_signals", c0395k1.u0());
                }
                if (c0395k1.C0()) {
                    C(sbB, 1, "is_dma_region", Boolean.valueOf(c0395k1.D0()));
                }
                if (c0395k1.E0()) {
                    C(sbB, 1, "core_platform_services", c0395k1.F0());
                }
                if (c0395k1.A0()) {
                    C(sbB, 1, "consent_diagnostics", c0395k1.B0());
                }
                if (c0395k1.x0()) {
                    C(sbB, 1, "target_os_version", Long.valueOf(c0395k1.y0()));
                }
                P3.a();
                if (c0146w0.f2035n.u(c0395k1.p(), F.f1375P0)) {
                    C(sbB, 1, "ad_services_version", Integer.valueOf(c0395k1.G0()));
                    if (c0395k1.H0() && (s0I0 = c0395k1.I0()) != null) {
                        w(2, sbB);
                        sbB.append("attribution_eligibility_status {\n");
                        C(sbB, 2, "eligible", Boolean.valueOf(s0I0.p()));
                        C(sbB, 2, "no_access_adservices_attribution_permission", Boolean.valueOf(s0I0.q()));
                        C(sbB, 2, "pre_r", Boolean.valueOf(s0I0.r()));
                        C(sbB, 2, "r_extensions_too_old", Boolean.valueOf(s0I0.s()));
                        C(sbB, 2, "adservices_extension_too_old", Boolean.valueOf(s0I0.t()));
                        C(sbB, 2, "ad_storage_not_allowed", Boolean.valueOf(s0I0.u()));
                        C(sbB, 2, "measurement_manager_disabled", Boolean.valueOf(s0I0.v()));
                        w(2, sbB);
                        sbB.append("}\n");
                    }
                }
                if (c0395k1.L0()) {
                    com.google.android.gms.internal.measurement.P0 p0M0 = c0395k1.M0();
                    w(2, sbB);
                    sbB.append("ad_campaign_info {\n");
                    if (p0M0.y()) {
                        C(sbB, 2, "deep_link_gclid", p0M0.z());
                    }
                    if (p0M0.A()) {
                        C(sbB, 2, "deep_link_gbraid", p0M0.B());
                    }
                    if (p0M0.C()) {
                        C(sbB, 2, "deep_link_gad_source", p0M0.D());
                    }
                    if (p0M0.E()) {
                        C(sbB, 2, "deep_link_session_millis", Long.valueOf(p0M0.F()));
                    }
                    if (p0M0.G()) {
                        C(sbB, 2, "market_referrer_gclid", p0M0.H());
                    }
                    if (p0M0.I()) {
                        C(sbB, 2, "market_referrer_gbraid", p0M0.J());
                    }
                    if (p0M0.K()) {
                        C(sbB, 2, "market_referrer_gad_source", p0M0.L());
                    }
                    if (p0M0.M()) {
                        C(sbB, 2, "market_referrer_click_millis", Long.valueOf(p0M0.N()));
                    }
                    w(2, sbB);
                    sbB.append("}\n");
                }
                if (c0395k1.Q()) {
                    C(sbB, 1, "batching_timestamp_millis", Long.valueOf(c0395k1.R()));
                }
                if (c0395k1.N0()) {
                    C0429r1 c0429r1O0 = c0395k1.O0();
                    w(2, sbB);
                    sbB.append("sgtm_diagnostics {\n");
                    int iT = c0429r1O0.t();
                    C(sbB, 2, "upload_type", iT != 1 ? iT != 2 ? iT != 3 ? iT != 4 ? "SDK_SERVICE_UPLOAD" : "PACKAGE_SERVICE_UPLOAD" : "SDK_CLIENT_UPLOAD" : "GA_UPLOAD" : "UPLOAD_TYPE_UNKNOWN");
                    C(sbB, 2, "client_upload_eligibility", AbstractC0928a.x(c0429r1O0.p()));
                    int iU = c0429r1O0.u();
                    C(sbB, 2, "service_upload_eligibility", iU != 1 ? iU != 2 ? iU != 3 ? iU != 4 ? iU != 5 ? "NON_PLAY_MISSING_SGTM_SERVER_URL" : "MISSING_SGTM_PROXY_INFO" : "MISSING_SGTM_SETTINGS" : "NOT_IN_ROLLOUT" : "SERVICE_UPLOAD_ELIGIBLE" : "SERVICE_UPLOAD_ELIGIBILITY_UNKNOWN");
                    w(2, sbB);
                    sbB.append("}\n");
                }
                if (c0395k1.S()) {
                    com.google.android.gms.internal.measurement.Y0 y0T = c0395k1.T();
                    w(2, sbB);
                    sbB.append("consent_info_extra {\n");
                    for (com.google.android.gms.internal.measurement.X0 x02 : y0T.p()) {
                        w(3, sbB);
                        sbB.append("limited_data_modes {\n");
                        int iQ = x02.q();
                        C(sbB, 3, "type", iQ != 1 ? iQ != 2 ? iQ != 3 ? iQ != 4 ? "AD_PERSONALIZATION" : "AD_USER_DATA" : "ANALYTICS_STORAGE" : "AD_STORAGE" : "CONSENT_TYPE_UNSPECIFIED");
                        int iR = x02.r();
                        C(sbB, 3, "mode", iR != 1 ? iR != 2 ? "NO_DATA_MODE" : "LIMITED_MODE" : "NOT_LIMITED");
                        w(3, sbB);
                        sbB.append("}\n");
                    }
                    w(2, sbB);
                    sbB.append("}\n");
                }
                InterfaceC0411n2<C0439t1> interfaceC0411n2U1 = c0395k1.U1();
                Q q = c0146w0.f2039t;
                if (interfaceC0411n2U1 != null) {
                    for (C0439t1 c0439t1 : interfaceC0411n2U1) {
                        if (c0439t1 != null) {
                            w(2, sbB);
                            sbB.append("user_property {\n");
                            C(sbB, 2, "set_timestamp_millis", c0439t1.p() ? Long.valueOf(c0439t1.q()) : null);
                            C(sbB, 2, "name", q.c(c0439t1.r()));
                            C(sbB, 2, "string_value", c0439t1.t());
                            C(sbB, 2, "int_value", c0439t1.u() ? Long.valueOf(c0439t1.v()) : null);
                            C(sbB, 2, "double_value", c0439t1.y() ? Double.valueOf(c0439t1.z()) : null);
                            w(2, sbB);
                            sbB.append("}\n");
                        }
                    }
                }
                InterfaceC0411n2<com.google.android.gms.internal.measurement.U0> interfaceC0411n2H = c0395k1.H();
                if (interfaceC0411n2H != null) {
                    for (com.google.android.gms.internal.measurement.U0 u02 : interfaceC0411n2H) {
                        if (u02 != null) {
                            w(2, sbB);
                            sbB.append("audience_membership {\n");
                            if (u02.p()) {
                                C(sbB, 2, "audience_id", Integer.valueOf(u02.q()));
                            }
                            if (u02.u()) {
                                C(sbB, 2, "new_audience", Boolean.valueOf(u02.v()));
                            }
                            B(sbB, "current_data", u02.r());
                            if (u02.s()) {
                                B(sbB, "previous_data", u02.t());
                            }
                            w(2, sbB);
                            sbB.append("}\n");
                        }
                    }
                }
                List<C0355c1> listP1 = c0395k1.P1();
                if (listP1 != null) {
                    for (C0355c1 c0355c1 : listP1) {
                        if (c0355c1 != null) {
                            w(2, sbB);
                            sbB.append("event {\n");
                            C(sbB, 2, "name", q.a(c0355c1.s()));
                            if (c0355c1.t()) {
                                C(sbB, 2, "timestamp_millis", Long.valueOf(c0355c1.u()));
                            }
                            if (c0355c1.v()) {
                                C(sbB, 2, "previous_timestamp_millis", Long.valueOf(c0355c1.w()));
                            }
                            if (c0355c1.x()) {
                                C(sbB, 2, "count", Integer.valueOf(c0355c1.y()));
                            }
                            if (c0355c1.q() != 0) {
                                u(sbB, 2, (InterfaceC0411n2) c0355c1.p());
                            }
                            w(2, sbB);
                            sbB.append("}\n");
                        }
                    }
                }
                w(1, sbB);
                sbB.append("}\n");
            }
        }
        sbB.append("} // End-of-batch\n");
        return sbB.toString();
    }

    public String O(C0453w0 c0453w0) {
        StringBuilder sbB = u.e.b("\nproperty_filter {\n");
        if (c0453w0.p()) {
            C(sbB, 0, "filter_id", Integer.valueOf(c0453w0.q()));
        }
        C(sbB, 0, "property_name", ((C0146w0) this.f29k).f2039t.c(c0453w0.r()));
        String strY = y(c0453w0.t(), c0453w0.u(), c0453w0.w());
        if (!strY.isEmpty()) {
            C(sbB, 0, "filter_type", strY);
        }
        v(sbB, 1, c0453w0.s());
        sbB.append("}\n");
        return sbB.toString();
    }

    public Parcelable P(byte[] bArr, Parcelable.Creator creator) {
        Parcelable parcelable = null;
        if (bArr == null) {
            return null;
        }
        Parcel parcelObtain = Parcel.obtain();
        try {
            try {
                parcelObtain.unmarshall(bArr, 0, bArr.length);
                parcelObtain.setDataPosition(0);
                parcelable = (Parcelable) creator.createFromParcel(parcelObtain);
            } catch (C1023b unused) {
                X x5 = ((C0146w0) this.f29k).p;
                C0146w0.l(x5);
                x5.p.b("Failed to load parcelable from buffer");
            }
            return parcelable;
        } finally {
            parcelObtain.recycle();
        }
    }

    public List T(InterfaceC0406m2 interfaceC0406m2, List list) {
        int i;
        ArrayList arrayList = new ArrayList(interfaceC0406m2);
        Iterator it = list.iterator();
        while (it.hasNext()) {
            Integer num = (Integer) it.next();
            int iIntValue = num.intValue();
            C0146w0 c0146w0 = (C0146w0) this.f29k;
            if (iIntValue < 0) {
                X x5 = c0146w0.p;
                C0146w0.l(x5);
                x5.f1626s.c("Ignoring negative bit index to be cleared", num);
            } else {
                int iIntValue2 = num.intValue() / 64;
                if (iIntValue2 >= arrayList.size()) {
                    X x6 = c0146w0.p;
                    C0146w0.l(x6);
                    x6.f1626s.d(num, Integer.valueOf(arrayList.size()), "Ignoring bit index greater than bitSet size");
                } else {
                    arrayList.set(iIntValue2, Long.valueOf(((Long) arrayList.get(iIntValue2)).longValue() & (~(1 << (num.intValue() % 64)))));
                }
            }
        }
        int size = arrayList.size();
        int size2 = arrayList.size() - 1;
        while (true) {
            int i5 = size2;
            i = size;
            size = i5;
            if (size < 0 || ((Long) arrayList.get(size)).longValue() != 0) {
                break;
            }
            size2 = size - 1;
        }
        return arrayList.subList(0, i);
    }

    public boolean U(long j5, long j6) {
        if (j5 == 0 || j6 <= 0) {
            return true;
        }
        ((C0146w0) this.f29k).f2040u.getClass();
        return Math.abs(System.currentTimeMillis() - j5) > j6;
    }

    public long V(byte[] bArr) {
        s1.z.g(bArr);
        C0146w0 c0146w0 = (C0146w0) this.f29k;
        c2 c2Var = c0146w0.f2038s;
        C0146w0.j(c2Var);
        c2Var.k();
        MessageDigest messageDigestB = c2.B();
        if (messageDigestB != null) {
            return c2.C(messageDigestB.digest(bArr));
        }
        X x5 = c0146w0.p;
        C0146w0.l(x5);
        x5.p.b("Failed to get MD5");
        return 0L;
    }

    public byte[] W(byte[] bArr) throws IOException {
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            GZIPOutputStream gZIPOutputStream = new GZIPOutputStream(byteArrayOutputStream);
            gZIPOutputStream.write(bArr);
            gZIPOutputStream.close();
            byteArrayOutputStream.close();
            return byteArrayOutputStream.toByteArray();
        } catch (IOException e2) {
            X x5 = ((C0146w0) this.f29k).p;
            C0146w0.l(x5);
            x5.p.c("Failed to gzip content", e2);
            throw e2;
        }
    }

    @Override // L1.Q1
    public final void n() {
        int i = this.f1681n;
    }

    public void u(StringBuilder sb, int i, InterfaceC0411n2 interfaceC0411n2) {
        if (interfaceC0411n2 == null) {
            return;
        }
        int i5 = i + 1;
        Iterator it = interfaceC0411n2.iterator();
        while (it.hasNext()) {
            C0370f1 c0370f1 = (C0370f1) it.next();
            if (c0370f1 != null) {
                w(i5, sb);
                sb.append("param {\n");
                C(sb, i5, "name", c0370f1.p() ? ((C0146w0) this.f29k).f2039t.b(c0370f1.q()) : null);
                C(sb, i5, "string_value", c0370f1.r() ? c0370f1.s() : null);
                C(sb, i5, "int_value", c0370f1.t() ? Long.valueOf(c0370f1.u()) : null);
                C(sb, i5, "double_value", c0370f1.x() ? Double.valueOf(c0370f1.y()) : null);
                if (c0370f1.A() > 0) {
                    u(sb, i5, (InterfaceC0411n2) c0370f1.z());
                }
                w(i5, sb);
                sb.append("}\n");
            }
        }
    }

    public void v(StringBuilder sb, int i, C0428r0 c0428r0) {
        String str;
        if (c0428r0 == null) {
            return;
        }
        w(i, sb);
        sb.append("filter {\n");
        if (c0428r0.t()) {
            C(sb, i, "complement", Boolean.valueOf(c0428r0.u()));
        }
        if (c0428r0.v()) {
            C(sb, i, "param_name", ((C0146w0) this.f29k).f2039t.b(c0428r0.w()));
        }
        if (c0428r0.p()) {
            int i5 = i + 1;
            C0458x0 c0458x0Q = c0428r0.q();
            if (c0458x0Q != null) {
                w(i5, sb);
                sb.append("string_filter {\n");
                if (c0458x0Q.p()) {
                    switch (c0458x0Q.x()) {
                        case 1:
                            str = "UNKNOWN_MATCH_TYPE";
                            break;
                        case 2:
                            str = "REGEXP";
                            break;
                        case 3:
                            str = "BEGINS_WITH";
                            break;
                        case 4:
                            str = "ENDS_WITH";
                            break;
                        case 5:
                            str = "PARTIAL";
                            break;
                        case 6:
                            str = "EXACT";
                            break;
                        default:
                            str = "IN_LIST";
                            break;
                    }
                    C(sb, i5, "match_type", str);
                }
                if (c0458x0Q.q()) {
                    C(sb, i5, "expression", c0458x0Q.r());
                }
                if (c0458x0Q.s()) {
                    C(sb, i5, "case_sensitive", Boolean.valueOf(c0458x0Q.t()));
                }
                if (c0458x0Q.v() > 0) {
                    w(i + 2, sb);
                    sb.append("expression_list {\n");
                    for (String str2 : c0458x0Q.u()) {
                        w(i + 3, sb);
                        sb.append(str2);
                        sb.append("\n");
                    }
                    sb.append("}\n");
                }
                w(i5, sb);
                sb.append("}\n");
            }
        }
        if (c0428r0.r()) {
            D(sb, i + 1, "number_filter", c0428r0.s());
        }
        w(i, sb);
        sb.append("}\n");
    }

    private final void F() {
    }

    private final void G() {
    }

    private final void H() {
    }
}
