package o;

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.common.internal.Preconditions;
import com.google.android.gms.common.internal.safeparcel.SafeParcelReader;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
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;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.kv0, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C1720kv0 extends Iu0 {
    public static final Br0 A(String str, C2756vr0 c2756vr0) {
        for (Br0 br0 : c2756vr0.p()) {
            if (br0.q().equals(str)) {
                return br0;
            }
        }
        return null;
    }

    public static final Serializable B(String str, C2756vr0 c2756vr0) {
        Br0 br0A = A(str, c2756vr0);
        if (br0A == null) {
            return null;
        }
        return H(br0A);
    }

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

    public static final void F(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 G(boolean z, boolean z2, boolean z3) {
        StringBuilder sb = new StringBuilder();
        if (z) {
            sb.append("Dynamic ");
        }
        if (z2) {
            sb.append("Sequence ");
        }
        if (z3) {
            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 H(Br0 br0) {
        if (br0.r()) {
            return br0.s();
        }
        if (br0.t()) {
            return Long.valueOf(br0.u());
        }
        if (br0.x()) {
            return Double.valueOf(br0.y());
        }
        if (br0.A() > 0) {
            return c0((Dt0) br0.z());
        }
        return null;
    }

    public static final void I(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) {
                F(builder, str3, string, set);
            }
        }
    }

    public static final void J(StringBuilder sb, String str, Rr0 rr0) {
        if (rr0 == null) {
            return;
        }
        E(3, sb);
        sb.append(str);
        sb.append(" {\n");
        if (rr0.s() != 0) {
            E(4, sb);
            sb.append("results: ");
            int i = 0;
            for (Long l : rr0.r()) {
                int i2 = i + 1;
                if (i != 0) {
                    sb.append(", ");
                }
                sb.append(l);
                i = i2;
            }
            sb.append('\n');
        }
        if (rr0.q() != 0) {
            E(4, sb);
            sb.append("status: ");
            int i3 = 0;
            for (Long l2 : rr0.p()) {
                int i4 = i3 + 1;
                if (i3 != 0) {
                    sb.append(", ");
                }
                sb.append(l2);
                i3 = i4;
            }
            sb.append('\n');
        }
        if (rr0.u() != 0) {
            E(4, sb);
            sb.append("dynamic_filter_timestamps: {");
            int i5 = 0;
            for (C2566tr0 c2566tr0 : rr0.t()) {
                int i6 = i5 + 1;
                if (i5 != 0) {
                    sb.append(", ");
                }
                sb.append(c2566tr0.p() ? Integer.valueOf(c2566tr0.q()) : null);
                sb.append(":");
                sb.append(c2566tr0.r() ? Long.valueOf(c2566tr0.s()) : null);
                i5 = i6;
            }
            sb.append("}\n");
        }
        if (rr0.w() != 0) {
            E(4, sb);
            sb.append("sequence_filter_timestamps: {");
            int i7 = 0;
            for (Ur0 ur0 : rr0.v()) {
                int i8 = i7 + 1;
                if (i7 != 0) {
                    sb.append(", ");
                }
                sb.append(ur0.p() ? Integer.valueOf(ur0.q()) : null);
                sb.append(": [");
                Iterator it = ur0.r().iterator();
                int i9 = 0;
                while (it.hasNext()) {
                    long jLongValue = ((Long) it.next()).longValue();
                    int i10 = i9 + 1;
                    if (i9 != 0) {
                        sb.append(", ");
                    }
                    sb.append(jLongValue);
                    i9 = i10;
                }
                sb.append("]");
                i7 = i8;
            }
            sb.append("}\n");
        }
        E(3, sb);
        sb.append("}\n");
    }

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

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

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

    public static boolean U(Ct0 ct0, int i) {
        if (i < ((Nt0) ct0).n * 64) {
            return ((1 << (i % 64)) & ((Long) ((Nt0) ct0).get(i / 64)).longValue()) != 0;
        }
        return false;
    }

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

    public static AbstractC2286qt0 a0(AbstractC2286qt0 abstractC2286qt0, byte[] bArr) throws Gt0 {
        C1239ft0 c1239ft0P;
        C1239ft0 c1239ft0 = C1239ft0.a;
        if (c1239ft0 == null) {
            synchronized (C1239ft0.class) {
                try {
                    c1239ft0P = C1239ft0.a;
                    if (c1239ft0P == null) {
                        C1241fu0 c1241fu0 = C1241fu0.c;
                        c1239ft0P = AbstractC2001nt0.P();
                        C1239ft0.a = c1239ft0P;
                    }
                } finally {
                }
            }
            c1239ft0 = c1239ft0P;
        }
        if (c1239ft0 != null) {
            abstractC2286qt0.getClass();
            abstractC2286qt0.g(bArr, bArr.length, c1239ft0);
            return abstractC2286qt0;
        }
        abstractC2286qt0.getClass();
        int length = bArr.length;
        C1239ft0 c1239ft02 = C1239ft0.a;
        C1241fu0 c1241fu02 = C1241fu0.c;
        abstractC2286qt0.g(bArr, length, C1239ft0.b);
        return abstractC2286qt0;
    }

    public static int b0(String str, Lr0 lr0) {
        for (int i = 0; i < ((Nr0) lr0.m).V1(); i++) {
            if (str.equals(((Nr0) lr0.m).W1(i).r())) {
                return i;
            }
        }
        return -1;
    }

    public static Bundle[] c0(Dt0 dt0) {
        ArrayList arrayList = new ArrayList();
        Iterator it = dt0.iterator();
        while (it.hasNext()) {
            Br0 br0 = (Br0) it.next();
            if (br0 != null) {
                Bundle bundle = new Bundle();
                for (Br0 br02 : br0.z()) {
                    if (br02.r()) {
                        bundle.putString(br02.q(), br02.s());
                    } else if (br02.t()) {
                        bundle.putLong(br02.q(), br02.u());
                    } else if (br02.x()) {
                        bundle.putDouble(br02.q(), br02.y());
                    }
                }
                if (!bundle.isEmpty()) {
                    arrayList.add(bundle);
                }
            }
        }
        return (Bundle[]) arrayList.toArray(new Bundle[arrayList.size()]);
    }

    public static HashMap d0(Bundle bundle, boolean z) {
        HashMap map = new HashMap();
        for (String str : bundle.keySet()) {
            Object obj = bundle.get(str);
            boolean z2 = obj instanceof Parcelable[];
            if (z2 || (obj instanceof ArrayList) || (obj instanceof Bundle)) {
                if (z) {
                    ArrayList arrayList = new ArrayList();
                    if (z2) {
                        for (Parcelable parcelable : (Parcelable[]) obj) {
                            if (parcelable instanceof Bundle) {
                                arrayList.add(d0((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(d0((Bundle) obj2, false));
                            }
                        }
                    } else if (obj instanceof Bundle) {
                        arrayList.add(d0((Bundle) obj, false));
                    }
                    map.put(str, arrayList);
                }
            } else if (obj != null) {
                map.put(str, obj);
            }
        }
        return map;
    }

    public static No0 w(Kn0 kn0) {
        Object obj;
        Bundle bundleX = x(kn0.c, true);
        String string = (!bundleX.containsKey("_o") || (obj = bundleX.get("_o")) == null) ? "app" : obj.toString();
        String strO = AbstractC0662Zn.O(kn0.a, AbstractC2841wm0.k, AbstractC2841wm0.m);
        if (strO == null) {
            strO = kn0.a;
        }
        return new No0(strO, new Lo0(bundleX), string, kn0.b);
    }

    public static Bundle x(Map map, boolean z) {
        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 (z) {
                ArrayList arrayList = (ArrayList) obj;
                ArrayList arrayList2 = new ArrayList();
                int size = arrayList.size();
                for (int i = 0; i < size; i++) {
                    arrayList2.add(x((Map) arrayList.get(i), false));
                }
                bundle.putParcelableArray(str, (Parcelable[]) arrayList2.toArray(new Parcelable[0]));
            }
        }
        return bundle;
    }

    public static final void y(C2661ur0 c2661ur0, String str, Long l) {
        List listH = c2661ur0.h();
        int i = 0;
        while (true) {
            if (i >= listH.size()) {
                i = -1;
                break;
            } else if (str.equals(((Br0) listH.get(i)).q())) {
                break;
            } else {
                i++;
            }
        }
        C3136zr0 c3136zr0B = Br0.B();
        c3136zr0B.h(str);
        c3136zr0B.j(l.longValue());
        if (i < 0) {
            c2661ur0.l(c3136zr0B);
        } else {
            c2661ur0.b();
            ((C2756vr0) c2661ur0.m).A(i, (Br0) c3136zr0B.e());
        }
    }

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

    public final void C(StringBuilder sb, int i, Dt0 dt0) {
        if (dt0 == null) {
            return;
        }
        int i2 = i + 1;
        Iterator it = dt0.iterator();
        while (it.hasNext()) {
            Br0 br0 = (Br0) it.next();
            if (br0 != null) {
                E(i2, sb);
                sb.append("param {\n");
                K(sb, i2, "name", br0.p() ? ((Kr0) this.a).j.b(br0.q()) : null);
                K(sb, i2, "string_value", br0.r() ? br0.s() : null);
                K(sb, i2, "int_value", br0.t() ? Long.valueOf(br0.u()) : null);
                K(sb, i2, "double_value", br0.x() ? Double.valueOf(br0.y()) : null);
                if (br0.A() > 0) {
                    C(sb, i2, (Dt0) br0.z());
                }
                E(i2, sb);
                sb.append("}\n");
            }
        }
    }

    public final void D(StringBuilder sb, int i, C0946cq0 c0946cq0) {
        String str;
        if (c0946cq0 == null) {
            return;
        }
        E(i, sb);
        sb.append("filter {\n");
        if (c0946cq0.t()) {
            K(sb, i, "complement", Boolean.valueOf(c0946cq0.u()));
        }
        if (c0946cq0.v()) {
            K(sb, i, "param_name", ((Kr0) this.a).j.b(c0946cq0.w()));
        }
        if (c0946cq0.p()) {
            int i2 = i + 1;
            C1520iq0 c1520iq0Q = c0946cq0.q();
            if (c1520iq0Q != null) {
                E(i2, sb);
                sb.append("string_filter {\n");
                if (c1520iq0Q.p()) {
                    switch (c1520iq0Q.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;
                    }
                    K(sb, i2, "match_type", str);
                }
                if (c1520iq0Q.q()) {
                    K(sb, i2, "expression", c1520iq0Q.r());
                }
                if (c1520iq0Q.s()) {
                    K(sb, i2, "case_sensitive", Boolean.valueOf(c1520iq0Q.t()));
                }
                if (c1520iq0Q.v() > 0) {
                    E(i + 2, sb);
                    sb.append("expression_list {\n");
                    for (String str2 : c1520iq0Q.u()) {
                        E(i + 3, sb);
                        sb.append(str2);
                        sb.append("\n");
                    }
                    sb.append("}\n");
                }
                E(i2, sb);
                sb.append("}\n");
            }
        }
        if (c0946cq0.r()) {
            L(sb, i + 1, "number_filter", c0946cq0.s());
        }
        E(i, sb);
        sb.append("}\n");
    }

    public final void M(Yr0 yr0, Object obj) {
        Preconditions.checkNotNull(obj);
        yr0.b();
        ((Zr0) yr0.m).E();
        yr0.b();
        ((Zr0) yr0.m).G();
        yr0.b();
        ((Zr0) yr0.m).I();
        if (obj instanceof String) {
            yr0.b();
            ((Zr0) yr0.m).D((String) obj);
        } else if (obj instanceof Long) {
            long jLongValue = ((Long) obj).longValue();
            yr0.b();
            ((Zr0) yr0.m).F(jLongValue);
        } else if (obj instanceof Double) {
            double dDoubleValue = ((Double) obj).doubleValue();
            yr0.b();
            ((Zr0) yr0.m).H(dDoubleValue);
        } else {
            Nq0 nq0 = ((Kr0) this.a).f;
            Kr0.l(nq0);
            nq0.f.c(obj, "Ignoring invalid (type) user attribute value");
        }
    }

    public final void N(C3136zr0 c3136zr0, Object obj) {
        Preconditions.checkNotNull(obj);
        c3136zr0.b();
        ((Br0) c3136zr0.m).E();
        c3136zr0.b();
        ((Br0) c3136zr0.m).G();
        c3136zr0.b();
        ((Br0) c3136zr0.m).I();
        c3136zr0.b();
        ((Br0) c3136zr0.m).L();
        if (obj instanceof String) {
            c3136zr0.i((String) obj);
            return;
        }
        if (obj instanceof Long) {
            c3136zr0.j(((Long) obj).longValue());
            return;
        }
        if (obj instanceof Double) {
            double dDoubleValue = ((Double) obj).doubleValue();
            c3136zr0.b();
            ((Br0) c3136zr0.m).H(dDoubleValue);
            return;
        }
        if (!(obj instanceof Bundle[])) {
            Nq0 nq0 = ((Kr0) this.a).f;
            Kr0.l(nq0);
            nq0.f.c(obj, "Ignoring invalid (type) event param value");
            return;
        }
        ArrayList arrayList = new ArrayList();
        for (Bundle bundle : (Bundle[]) obj) {
            if (bundle != null) {
                C3136zr0 c3136zr0B = Br0.B();
                for (String str : bundle.keySet()) {
                    C3136zr0 c3136zr0B2 = Br0.B();
                    c3136zr0B2.h(str);
                    Object obj2 = bundle.get(str);
                    if (obj2 instanceof Long) {
                        c3136zr0B2.j(((Long) obj2).longValue());
                    } else if (obj2 instanceof String) {
                        c3136zr0B2.i((String) obj2);
                    } else if (obj2 instanceof Double) {
                        double dDoubleValue2 = ((Double) obj2).doubleValue();
                        c3136zr0B2.b();
                        ((Br0) c3136zr0B2.m).H(dDoubleValue2);
                    }
                    c3136zr0B.b();
                    ((Br0) c3136zr0B.m).J((Br0) c3136zr0B2.e());
                }
                if (((Br0) c3136zr0B.m).A() > 0) {
                    arrayList.add((Br0) c3136zr0B.e());
                }
            }
        }
        c3136zr0.b();
        ((Br0) c3136zr0.m).K(arrayList);
    }

    public final C2762vu0 O(String str, Lr0 lr0, C2661ur0 c2661ur0, String str2) {
        int iIndexOf;
        Xv0.a();
        Kr0 kr0 = (Kr0) this.a;
        C1421ho0 c1421ho0 = kr0.d;
        if (!c1421ho0.C(str, AbstractC1900mq0.P0)) {
            return null;
        }
        long jCurrentTimeMillis = kr0.k.currentTimeMillis();
        String[] strArrSplit = c1421ho0.y(str, AbstractC1900mq0.u0).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);
        C1051dv0 c1051dv0 = this.b;
        Mu0 mu0 = c1051dv0.j;
        C2851wr0 c2851wr0 = c1051dv0.a;
        C2851wr0 c2851wr02 = mu0.b.a;
        C1051dv0.T(c2851wr02);
        String strF = c2851wr02.F(str);
        Uri.Builder builder = new Uri.Builder();
        C1421ho0 c1421ho02 = ((Kr0) mu0.a).d;
        builder.scheme(c1421ho02.y(str, AbstractC1900mq0.n0));
        if (TextUtils.isEmpty(strF)) {
            builder.authority(c1421ho02.y(str, AbstractC1900mq0.o0));
        } else {
            String strY = c1421ho02.y(str, AbstractC1900mq0.o0);
            StringBuilder sb = new StringBuilder(String.valueOf(strF).length() + 1 + String.valueOf(strY).length());
            sb.append(strF);
            sb.append(".");
            sb.append(strY);
            builder.authority(sb.toString());
        }
        builder.path(c1421ho02.y(str, AbstractC1900mq0.p0));
        F(builder, "gmp_app_id", ((Nr0) lr0.m).E(), setUnmodifiableSet);
        c1421ho0.x();
        F(builder, "gmp_version", String.valueOf(133005L), setUnmodifiableSet);
        String strY2 = ((Nr0) lr0.m).y();
        C1805lq0 c1805lq0 = AbstractC1900mq0.S0;
        if (c1421ho0.C(str, c1805lq0)) {
            C1051dv0.T(c2851wr0);
            if (c2851wr0.L(str)) {
                strY2 = "";
            }
        }
        F(builder, "app_instance_id", strY2, setUnmodifiableSet);
        F(builder, "rdid", ((Nr0) lr0.m).v(), setUnmodifiableSet);
        F(builder, "bundle_id", lr0.o(), setUnmodifiableSet);
        String strN = c2661ur0.n();
        String strO = AbstractC0662Zn.O(strN, AbstractC2841wm0.m, AbstractC2841wm0.k);
        if (true != TextUtils.isEmpty(strO)) {
            strN = strO;
        }
        F(builder, "app_event_name", strN, setUnmodifiableSet);
        F(builder, "app_version", String.valueOf(((Nr0) lr0.m).K()), setUnmodifiableSet);
        String strI2 = ((Nr0) lr0.m).i2();
        if (c1421ho0.C(str, c1805lq0)) {
            C1051dv0.T(c2851wr0);
            if (c2851wr0.K(str) && !TextUtils.isEmpty(strI2) && (iIndexOf = strI2.indexOf(".")) != -1) {
                strI2 = strI2.substring(0, iIndexOf);
            }
        }
        F(builder, "os_version", strI2, setUnmodifiableSet);
        F(builder, "timestamp", String.valueOf(c2661ur0.o()), setUnmodifiableSet);
        if (((Nr0) lr0.m).x()) {
            F(builder, "lat", "1", setUnmodifiableSet);
        }
        F(builder, "privacy_sandbox_version", String.valueOf(((Nr0) lr0.m).G0()), setUnmodifiableSet);
        F(builder, "trigger_uri_source", "1", setUnmodifiableSet);
        F(builder, "trigger_uri_timestamp", String.valueOf(jCurrentTimeMillis), setUnmodifiableSet);
        F(builder, "request_uuid", str2, setUnmodifiableSet);
        List<Br0> listH = c2661ur0.h();
        Bundle bundle = new Bundle();
        for (Br0 br0 : listH) {
            String strQ = br0.q();
            if (br0.x()) {
                bundle.putString(strQ, String.valueOf(br0.y()));
            } else if (br0.v()) {
                bundle.putString(strQ, String.valueOf(br0.w()));
            } else if (br0.r()) {
                bundle.putString(strQ, br0.s());
            } else if (br0.t()) {
                bundle.putString(strQ, String.valueOf(br0.u()));
            }
        }
        I(builder, c1421ho0.y(str, AbstractC1900mq0.t0).split("\\|"), bundle, setUnmodifiableSet);
        List<Zr0> listUnmodifiableList = Collections.unmodifiableList(((Nr0) lr0.m).U1());
        Bundle bundle2 = new Bundle();
        for (Zr0 zr0 : listUnmodifiableList) {
            String strR = zr0.r();
            if (zr0.y()) {
                bundle2.putString(strR, String.valueOf(zr0.z()));
            } else if (zr0.w()) {
                bundle2.putString(strR, String.valueOf(zr0.x()));
            } else if (zr0.s()) {
                bundle2.putString(strR, zr0.t());
            } else if (zr0.u()) {
                bundle2.putString(strR, String.valueOf(zr0.v()));
            }
        }
        I(builder, c1421ho0.y(str, AbstractC1900mq0.s0).split("\\|"), bundle2, setUnmodifiableSet);
        F(builder, "dma", true != ((Nr0) lr0.m).D0() ? "0" : "1", setUnmodifiableSet);
        if (!((Nr0) lr0.m).F0().isEmpty()) {
            F(builder, "dma_cps", ((Nr0) lr0.m).F0(), setUnmodifiableSet);
        }
        if (((Nr0) lr0.m).L0()) {
            C0757ar0 c0757ar0M0 = ((Nr0) lr0.m).M0();
            if (!c0757ar0M0.z().isEmpty()) {
                F(builder, "dl_gclid", c0757ar0M0.z(), setUnmodifiableSet);
            }
            if (!c0757ar0M0.B().isEmpty()) {
                F(builder, "dl_gbraid", c0757ar0M0.B(), setUnmodifiableSet);
            }
            if (!c0757ar0M0.D().isEmpty()) {
                F(builder, "dl_gs", c0757ar0M0.D(), setUnmodifiableSet);
            }
            if (c0757ar0M0.F() > 0) {
                F(builder, "dl_ss_ts", String.valueOf(c0757ar0M0.F()), setUnmodifiableSet);
            }
            if (!c0757ar0M0.H().isEmpty()) {
                F(builder, "mr_gclid", c0757ar0M0.H(), setUnmodifiableSet);
            }
            if (!c0757ar0M0.J().isEmpty()) {
                F(builder, "mr_gbraid", c0757ar0M0.J(), setUnmodifiableSet);
            }
            if (!c0757ar0M0.L().isEmpty()) {
                F(builder, "mr_gs", c0757ar0M0.L(), setUnmodifiableSet);
            }
            if (c0757ar0M0.N() > 0) {
                F(builder, "mr_click_ts", String.valueOf(c0757ar0M0.N()), setUnmodifiableSet);
            }
        }
        return new C2762vu0(builder.build().toString(), 1, jCurrentTimeMillis);
    }

    public final C2756vr0 P(Io0 io0) {
        C2661ur0 c2661ur0Z = C2756vr0.z();
        long j = io0.e;
        c2661ur0Z.b();
        ((C2756vr0) c2661ur0Z.m).H(j);
        Lo0 lo0 = io0.f;
        Objects.requireNonNull(lo0);
        Bundle bundle = lo0.l;
        for (String str : bundle.keySet()) {
            C3136zr0 c3136zr0B = Br0.B();
            c3136zr0B.h(str);
            Object obj = bundle.get(str);
            Preconditions.checkNotNull(obj);
            N(c3136zr0B, obj);
            c2661ur0Z.l(c3136zr0B);
        }
        String str2 = io0.c;
        if (!TextUtils.isEmpty(str2) && bundle.get("_o") == null) {
            C3136zr0 c3136zr0B2 = Br0.B();
            c3136zr0B2.h("_o");
            c3136zr0B2.i(str2);
            c2661ur0Z.k((Br0) c3136zr0B2.e());
        }
        return (C2756vr0) c2661ur0Z.e();
    }

    public final String Q(Jr0 jr0) {
        C1331gr0 c1331gr0I0;
        StringBuilder sb = new StringBuilder();
        sb.append("\nbatch {\n");
        if (jr0.u()) {
            K(sb, 0, "upload_subdomain", jr0.v());
        }
        if (jr0.s()) {
            K(sb, 0, "sgtm_join_id", jr0.t());
        }
        for (Nr0 nr0 : jr0.p()) {
            if (nr0 != null) {
                E(1, sb);
                sb.append("bundle {\n");
                if (nr0.P()) {
                    K(sb, 1, "protocol_version", Integer.valueOf(nr0.P0()));
                }
                Kr0 kr0 = (Kr0) this.a;
                C1421ho0 c1421ho0 = kr0.d;
                Eq0 eq0 = kr0.j;
                if (c1421ho0.C(nr0.p(), AbstractC1900mq0.M0) && nr0.v0()) {
                    K(sb, 1, "session_stitching_token", nr0.w0());
                }
                K(sb, 1, "platform", nr0.h2());
                if (nr0.r()) {
                    K(sb, 1, "gmp_version", Long.valueOf(nr0.s()));
                }
                if (nr0.t()) {
                    K(sb, 1, "uploading_gmp_version", Long.valueOf(nr0.u()));
                }
                if (nr0.r0()) {
                    K(sb, 1, "dynamite_version", Long.valueOf(nr0.s0()));
                }
                if (nr0.L()) {
                    K(sb, 1, "config_version", Long.valueOf(nr0.M()));
                }
                K(sb, 1, "gmp_app_id", nr0.E());
                K(sb, 1, "app_id", nr0.p());
                K(sb, 1, "app_version", nr0.q());
                if (nr0.J()) {
                    K(sb, 1, "app_version_major", Integer.valueOf(nr0.K()));
                }
                K(sb, 1, "firebase_instance_id", nr0.I());
                if (nr0.z()) {
                    K(sb, 1, "dev_cert_hash", Long.valueOf(nr0.A()));
                }
                K(sb, 1, "app_store", nr0.n2());
                if (nr0.X1()) {
                    K(sb, 1, "upload_timestamp_millis", Long.valueOf(nr0.Y1()));
                }
                if (nr0.Z1()) {
                    K(sb, 1, "start_timestamp_millis", Long.valueOf(nr0.a2()));
                }
                if (nr0.b2()) {
                    K(sb, 1, "end_timestamp_millis", Long.valueOf(nr0.c2()));
                }
                if (nr0.d2()) {
                    K(sb, 1, "previous_bundle_start_timestamp_millis", Long.valueOf(nr0.e2()));
                }
                if (nr0.f2()) {
                    K(sb, 1, "previous_bundle_end_timestamp_millis", Long.valueOf(nr0.g2()));
                }
                K(sb, 1, "app_instance_id", nr0.y());
                K(sb, 1, "resettable_device_id", nr0.v());
                K(sb, 1, "ds_id", nr0.O());
                if (nr0.w()) {
                    K(sb, 1, "limited_ad_tracking", Boolean.valueOf(nr0.x()));
                }
                K(sb, 1, "os_version", nr0.i2());
                K(sb, 1, "device_model", nr0.j2());
                K(sb, 1, "user_default_language", nr0.k2());
                if (nr0.l2()) {
                    K(sb, 1, "time_zone_offset_minutes", Integer.valueOf(nr0.m2()));
                }
                if (nr0.B()) {
                    K(sb, 1, "bundle_sequential_index", Integer.valueOf(nr0.C()));
                }
                if (nr0.J0()) {
                    K(sb, 1, "delivery_index", Integer.valueOf(nr0.K0()));
                }
                if (nr0.F()) {
                    K(sb, 1, "service_upload", Boolean.valueOf(nr0.G()));
                }
                K(sb, 1, "health_monitor", nr0.D());
                if (nr0.p0()) {
                    K(sb, 1, "retry_counter", Integer.valueOf(nr0.q0()));
                }
                if (nr0.t0()) {
                    K(sb, 1, "consent_signals", nr0.u0());
                }
                if (nr0.C0()) {
                    K(sb, 1, "is_dma_region", Boolean.valueOf(nr0.D0()));
                }
                if (nr0.E0()) {
                    K(sb, 1, "core_platform_services", nr0.F0());
                }
                if (nr0.A0()) {
                    K(sb, 1, "consent_diagnostics", nr0.B0());
                }
                if (nr0.x0()) {
                    K(sb, 1, "target_os_version", Long.valueOf(nr0.y0()));
                }
                Xv0.a();
                if (kr0.d.C(nr0.p(), AbstractC1900mq0.P0)) {
                    K(sb, 1, "ad_services_version", Integer.valueOf(nr0.G0()));
                    if (nr0.H0() && (c1331gr0I0 = nr0.I0()) != null) {
                        E(2, sb);
                        sb.append("attribution_eligibility_status {\n");
                        K(sb, 2, "eligible", Boolean.valueOf(c1331gr0I0.p()));
                        K(sb, 2, "no_access_adservices_attribution_permission", Boolean.valueOf(c1331gr0I0.q()));
                        K(sb, 2, "pre_r", Boolean.valueOf(c1331gr0I0.r()));
                        K(sb, 2, "r_extensions_too_old", Boolean.valueOf(c1331gr0I0.s()));
                        K(sb, 2, "adservices_extension_too_old", Boolean.valueOf(c1331gr0I0.t()));
                        K(sb, 2, "ad_storage_not_allowed", Boolean.valueOf(c1331gr0I0.u()));
                        K(sb, 2, "measurement_manager_disabled", Boolean.valueOf(c1331gr0I0.v()));
                        E(2, sb);
                        sb.append("}\n");
                    }
                }
                if (nr0.L0()) {
                    C0757ar0 c0757ar0M0 = nr0.M0();
                    E(2, sb);
                    sb.append("ad_campaign_info {\n");
                    if (c0757ar0M0.y()) {
                        K(sb, 2, "deep_link_gclid", c0757ar0M0.z());
                    }
                    if (c0757ar0M0.A()) {
                        K(sb, 2, "deep_link_gbraid", c0757ar0M0.B());
                    }
                    if (c0757ar0M0.C()) {
                        K(sb, 2, "deep_link_gad_source", c0757ar0M0.D());
                    }
                    if (c0757ar0M0.E()) {
                        K(sb, 2, "deep_link_session_millis", Long.valueOf(c0757ar0M0.F()));
                    }
                    if (c0757ar0M0.G()) {
                        K(sb, 2, "market_referrer_gclid", c0757ar0M0.H());
                    }
                    if (c0757ar0M0.I()) {
                        K(sb, 2, "market_referrer_gbraid", c0757ar0M0.J());
                    }
                    if (c0757ar0M0.K()) {
                        K(sb, 2, "market_referrer_gad_source", c0757ar0M0.L());
                    }
                    if (c0757ar0M0.M()) {
                        K(sb, 2, "market_referrer_click_millis", Long.valueOf(c0757ar0M0.N()));
                    }
                    E(2, sb);
                    sb.append("}\n");
                }
                if (nr0.Q()) {
                    K(sb, 1, "batching_timestamp_millis", Long.valueOf(nr0.R()));
                }
                if (nr0.N0()) {
                    Xr0 xr0O0 = nr0.O0();
                    E(2, sb);
                    sb.append("sgtm_diagnostics {\n");
                    int iT = xr0O0.t();
                    K(sb, 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");
                    K(sb, 2, "client_upload_eligibility", xr0O0.p().name());
                    int iU = xr0O0.u();
                    K(sb, 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");
                    E(2, sb);
                    sb.append("}\n");
                }
                if (nr0.S()) {
                    C2187pr0 c2187pr0T = nr0.T();
                    E(2, sb);
                    sb.append("consent_info_extra {\n");
                    for (C2092or0 c2092or0 : c2187pr0T.p()) {
                        E(3, sb);
                        sb.append("limited_data_modes {\n");
                        int iQ = c2092or0.q();
                        K(sb, 3, "type", iQ != 1 ? iQ != 2 ? iQ != 3 ? iQ != 4 ? "AD_PERSONALIZATION" : "AD_USER_DATA" : "ANALYTICS_STORAGE" : "AD_STORAGE" : "CONSENT_TYPE_UNSPECIFIED");
                        int iR = c2092or0.r();
                        K(sb, 3, "mode", iR != 1 ? iR != 2 ? "NO_DATA_MODE" : "LIMITED_MODE" : "NOT_LIMITED");
                        E(3, sb);
                        sb.append("}\n");
                    }
                    E(2, sb);
                    sb.append("}\n");
                }
                Dt0<Zr0> dt0U1 = nr0.U1();
                if (dt0U1 != null) {
                    for (Zr0 zr0 : dt0U1) {
                        if (zr0 != null) {
                            E(2, sb);
                            sb.append("user_property {\n");
                            K(sb, 2, "set_timestamp_millis", zr0.p() ? Long.valueOf(zr0.q()) : null);
                            K(sb, 2, "name", eq0.c(zr0.r()));
                            K(sb, 2, "string_value", zr0.t());
                            K(sb, 2, "int_value", zr0.u() ? Long.valueOf(zr0.v()) : null);
                            K(sb, 2, "double_value", zr0.y() ? Double.valueOf(zr0.z()) : null);
                            E(2, sb);
                            sb.append("}\n");
                        }
                    }
                }
                Dt0<C1522ir0> dt0H = nr0.H();
                if (dt0H != null) {
                    for (C1522ir0 c1522ir0 : dt0H) {
                        if (c1522ir0 != null) {
                            E(2, sb);
                            sb.append("audience_membership {\n");
                            if (c1522ir0.p()) {
                                K(sb, 2, "audience_id", Integer.valueOf(c1522ir0.q()));
                            }
                            if (c1522ir0.u()) {
                                K(sb, 2, "new_audience", Boolean.valueOf(c1522ir0.v()));
                            }
                            J(sb, "current_data", c1522ir0.r());
                            if (c1522ir0.s()) {
                                J(sb, "previous_data", c1522ir0.t());
                            }
                            E(2, sb);
                            sb.append("}\n");
                        }
                    }
                }
                List<C2756vr0> listP1 = nr0.P1();
                if (listP1 != null) {
                    for (C2756vr0 c2756vr0 : listP1) {
                        if (c2756vr0 != null) {
                            E(2, sb);
                            sb.append("event {\n");
                            K(sb, 2, "name", eq0.a(c2756vr0.s()));
                            if (c2756vr0.t()) {
                                K(sb, 2, "timestamp_millis", Long.valueOf(c2756vr0.u()));
                            }
                            if (c2756vr0.v()) {
                                K(sb, 2, "previous_timestamp_millis", Long.valueOf(c2756vr0.w()));
                            }
                            if (c2756vr0.x()) {
                                K(sb, 2, "count", Integer.valueOf(c2756vr0.y()));
                            }
                            if (c2756vr0.q() != 0) {
                                C(sb, 2, (Dt0) c2756vr0.p());
                            }
                            E(2, sb);
                            sb.append("}\n");
                        }
                    }
                }
                E(1, sb);
                sb.append("}\n");
            }
        }
        sb.append("} // End-of-batch\n");
        return sb.toString();
    }

    public final String R(C1425hq0 c1425hq0) {
        StringBuilder sb = new StringBuilder();
        sb.append("\nproperty_filter {\n");
        if (c1425hq0.p()) {
            K(sb, 0, "filter_id", Integer.valueOf(c1425hq0.q()));
        }
        K(sb, 0, "property_name", ((Kr0) this.a).j.c(c1425hq0.r()));
        String strG = G(c1425hq0.t(), c1425hq0.u(), c1425hq0.w());
        if (!strG.isEmpty()) {
            K(sb, 0, "filter_type", strG);
        }
        D(sb, 1, c1425hq0.s());
        sb.append("}\n");
        return sb.toString();
    }

    public final Parcelable S(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 (SafeParcelReader.ParseException unused) {
                Nq0 nq0 = ((Kr0) this.a).f;
                Kr0.l(nq0);
                nq0.f.b("Failed to load parcelable from buffer");
            }
            return parcelable;
        } finally {
            parcelObtain.recycle();
        }
    }

    public final List W(Ct0 ct0, List list) {
        int i;
        Kr0 kr0 = (Kr0) this.a;
        ArrayList arrayList = new ArrayList(ct0);
        Iterator it = list.iterator();
        while (it.hasNext()) {
            Integer num = (Integer) it.next();
            if (num.intValue() < 0) {
                Nq0 nq0 = kr0.f;
                Kr0.l(nq0);
                nq0.i.c(num, "Ignoring negative bit index to be cleared");
            } else {
                int iIntValue = num.intValue() / 64;
                if (iIntValue >= arrayList.size()) {
                    Nq0 nq02 = kr0.f;
                    Kr0.l(nq02);
                    nq02.i.d("Ignoring bit index greater than bitSet size", num, Integer.valueOf(arrayList.size()));
                } else {
                    arrayList.set(iIntValue, Long.valueOf(((Long) arrayList.get(iIntValue)).longValue() & (~(1 << (num.intValue() % 64)))));
                }
            }
        }
        int size = arrayList.size();
        int size2 = arrayList.size() - 1;
        while (true) {
            int i2 = size2;
            i = size;
            size = i2;
            if (size < 0 || ((Long) arrayList.get(size)).longValue() != 0) {
                break;
            }
            size2 = size - 1;
        }
        return arrayList.subList(0, i);
    }

    public final boolean X(long j, long j2) {
        return j == 0 || j2 <= 0 || Math.abs(((Kr0) this.a).k.currentTimeMillis() - j) > j2;
    }

    public final long Y(byte[] bArr) throws NoSuchAlgorithmException {
        Preconditions.checkNotNull(bArr);
        Kr0 kr0 = (Kr0) this.a;
        C2574tv0 c2574tv0 = kr0.i;
        Kr0.j(c2574tv0);
        c2574tv0.r();
        MessageDigest messageDigestJ = C2574tv0.J();
        if (messageDigestJ != null) {
            return C2574tv0.K(messageDigestJ.digest(bArr));
        }
        Nq0 nq0 = kr0.f;
        Kr0.l(nq0);
        nq0.f.b("Failed to get MD5");
        return 0L;
    }

    public final byte[] Z(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 e) {
            Nq0 nq0 = ((Kr0) this.a).f;
            Kr0.l(nq0);
            nq0.f.c(e, "Failed to gzip content");
            throw e;
        }
    }

    @Override // o.Iu0
    public final void v() {
    }
}
