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

import android.net.Uri;
import android.text.TextUtils;
import androidx.media3.exoplayer.rtsp.SessionDescription;
import com.google.android.gms.internal.measurement.ga;
import java.util.HashMap;

/* JADX INFO: loaded from: classes2.dex */
public final class x3 extends w3 {
    public static String B(g0 g0Var) {
        Uri.Builder builder = new Uri.Builder();
        String strZzah = g0Var.zzah();
        if (TextUtils.isEmpty(strZzah)) {
            strZzah = g0Var.zzaa();
        }
        builder.scheme((String) z.f22030f.a(null)).encodedAuthority((String) z.f22033g.a(null)).path("config/app/" + strZzah).appendQueryParameter("platform", "android").appendQueryParameter("gmp_version", "106000").appendQueryParameter("runtime_version", SessionDescription.SUPPORTED_SDP_VERSION);
        return builder.build().toString();
    }

    public final a4 A(String str) {
        g0 g0VarW0;
        ga.a();
        a4 a4Var = null;
        boolean zJ = s().J(null, z.f22071w0);
        zznt zzntVar = zznt.GOOGLE_ANALYTICS;
        if (zJ) {
            v();
            if (n4.y0(str)) {
                zzj().f21842n.c("sgtm feature flag enabled.");
                g0 g0VarW02 = y().w0(str);
                if (g0VarW02 == null) {
                    return new a4(C(str), zzntVar);
                }
                String strZzad = g0VarW02.zzad();
                com.google.android.gms.internal.measurement.t2 t2VarN = z().N(str);
                if (t2VarN == null || (g0VarW0 = y().w0(str)) == null || ((!t2VarN.H() || t2VarN.y().p() != 100) && !v().w0(str, g0VarW0.zzam()) && (!s().J(null, z.f22075y0) ? !(TextUtils.isEmpty(strZzad) || strZzad.hashCode() % 100 >= t2VarN.y().p()) : !(TextUtils.isEmpty(strZzad) || Math.abs(strZzad.hashCode() % 100) >= t2VarN.y().p())))) {
                    return new a4(C(str), zzntVar);
                }
                if (g0VarW02.f()) {
                    zzj().f21842n.c("sgtm upload enabled in manifest.");
                    com.google.android.gms.internal.measurement.t2 t2VarN2 = z().N(g0VarW02.b());
                    if (t2VarN2 != null && t2VarN2.H()) {
                        String strT = t2VarN2.y().t();
                        if (!TextUtils.isEmpty(strT)) {
                            String strS = t2VarN2.y().s();
                            zzj().f21842n.a(strT, TextUtils.isEmpty(strS) ? "Y" : "N", "sgtm configured with upload_url, server_info");
                            boolean zIsEmpty = TextUtils.isEmpty(strS);
                            zznt zzntVar2 = zznt.SGTM;
                            if (zIsEmpty) {
                                a4Var = new a4(strT, zzntVar2);
                            } else {
                                HashMap mapO = u1.o("x-sgtm-server-info", strS);
                                if (!TextUtils.isEmpty(g0VarW02.zzam())) {
                                    mapO.put("x-gtm-server-preview", g0VarW02.zzam());
                                }
                                a4Var = new a4(strT, mapO, zzntVar2);
                            }
                        }
                    }
                }
                if (a4Var != null) {
                    return a4Var;
                }
            }
        }
        return new a4(C(str), zzntVar);
    }

    public final String C(String str) {
        String strR = z().R(str);
        if (TextUtils.isEmpty(strR)) {
            return (String) z.f22060r.a(null);
        }
        Uri uri = Uri.parse((String) z.f22060r.a(null));
        Uri.Builder builderBuildUpon = uri.buildUpon();
        builderBuildUpon.authority(strR + "." + uri.getAuthority());
        return builderBuildUpon.build().toString();
    }
}
