package d3;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.os.RemoteException;
import android.os.SystemClock;
import android.text.TextUtils;
import android.util.Pair;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.Objects;

/* JADX INFO: loaded from: classes.dex */
public final class P0 extends AbstractC0808o {

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final /* synthetic */ Y0 f11648f;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public /* synthetic */ P0(Y0 y02, B0 b02, int i) {
        super(b02);
        this.f11647e = i;
        this.f11648f = y02;
    }

    /* JADX WARN: Removed duplicated region for block: B:50:0x0122  */
    /* JADX WARN: Removed duplicated region for block: B:77:0x0270 A[Catch: IllegalArgumentException -> 0x0277, MalformedURLException -> 0x0279, TryCatch #5 {IllegalArgumentException -> 0x0277, MalformedURLException -> 0x0279, blocks: (B:75:0x0228, B:77:0x0270, B:82:0x027b, B:84:0x0281, B:86:0x0289, B:87:0x028f, B:88:0x0293), top: B:112:0x0228 }] */
    /* JADX WARN: Removed duplicated region for block: B:84:0x0281 A[Catch: IllegalArgumentException -> 0x0277, MalformedURLException -> 0x0279, TryCatch #5 {IllegalArgumentException -> 0x0277, MalformedURLException -> 0x0279, blocks: (B:75:0x0228, B:77:0x0270, B:82:0x027b, B:84:0x0281, B:86:0x0289, B:87:0x028f, B:88:0x0293), top: B:112:0x0228 }] */
    /* JADX WARN: Removed duplicated region for block: B:92:0x02ad  */
    /* JADX WARN: Removed duplicated region for block: B:93:0x02ca  */
    @Override // d3.AbstractC0808o
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void b() {
        Pair pair;
        NetworkInfo activeNetworkInfo;
        boolean z8;
        C0790i c0790iW;
        String string;
        C0817r0 c0817r0;
        URL url;
        switch (this.f11647e) {
            case n4.u0.f15495q /* 0 */:
                Y0 y02 = ((C0817r0) this.f11648f.f5146q).f12125F;
                C0817r0.j(y02);
                new Thread(new N0(y02, 1)).start();
                break;
            case 1:
                this.f11648f.S();
                break;
            case 2:
                this.f11648f.N();
                break;
            default:
                Y0 y03 = this.f11648f;
                C0817r0 c0817r02 = (C0817r0) y03.f5146q;
                C0815q0 c0815q0 = c0817r02.f12151z;
                C0817r0.k(c0815q0);
                c0815q0.E();
                C0774c1 c0774c1 = c0817r02.H;
                C0817r0.k(c0774c1);
                C0817r0.k(c0774c1);
                String strK = c0817r02.n().K();
                Boolean boolP = c0817r02.f12148w.P("google_analytics_adid_collection_enabled");
                boolean z9 = boolP == null || boolP.booleanValue();
                Z z10 = c0817r02.f12150y;
                if (z9) {
                    C0785g0 c0785g0 = c0817r02.f12149x;
                    C0817r0.i(c0785g0);
                    c0785g0.E();
                    if (c0785g0.L().k(E0.f11447r)) {
                        C0817r0 c0817r03 = (C0817r0) c0785g0.f5146q;
                        c0817r03.D.getClass();
                        long jElapsedRealtime = SystemClock.elapsedRealtime();
                        String str = c0785g0.f11977y;
                        if (str == null || jElapsedRealtime >= c0785g0.f11957A) {
                            c0785g0.f11957A = c0817r03.f12148w.M(strK, I.f11536b) + jElapsedRealtime;
                            try {
                                L2.a aVarA = L2.b.a(c0817r03.f12142q);
                                c0785g0.f11977y = "";
                                String str2 = aVarA.f3979c;
                                if (str2 != null) {
                                    c0785g0.f11977y = str2;
                                }
                                c0785g0.f11978z = aVarA.f3978b;
                            } catch (Exception e8) {
                                Z z11 = c0817r03.f12150y;
                                C0817r0.k(z11);
                                z11.f11871C.c(e8, "Unable to get advertising id");
                                c0785g0.f11977y = "";
                            }
                            pair = new Pair(c0785g0.f11977y, Boolean.valueOf(c0785g0.f11978z));
                        } else {
                            pair = new Pair(str, Boolean.valueOf(c0785g0.f11978z));
                        }
                    } else {
                        pair = new Pair("", Boolean.FALSE);
                    }
                    if (((Boolean) pair.second).booleanValue() || TextUtils.isEmpty((CharSequence) pair.first)) {
                        C0817r0.k(z10);
                        z10.D.b("ADID unavailable to retrieve Deferred Deep Link. Skipping");
                    } else {
                        C0817r0.k(c0774c1);
                        c0774c1.G();
                        C0817r0 c0817r04 = (C0817r0) c0774c1.f5146q;
                        ConnectivityManager connectivityManager = (ConnectivityManager) c0817r04.f12142q.getSystemService("connectivity");
                        if (connectivityManager != null) {
                            try {
                                activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
                            } catch (SecurityException unused) {
                                activeNetworkInfo = null;
                            }
                            if (activeNetworkInfo == null && activeNetworkInfo.isConnected()) {
                                StringBuilder sb = new StringBuilder();
                                C0824t1 c0824t1R = c0817r02.r();
                                c0824t1R.E();
                                c0824t1R.F();
                                if (!c0824t1R.R()) {
                                    Y0 y04 = c0817r02.f12125F;
                                    C0817r0.j(y04);
                                    y04.E();
                                    C0824t1 c0824t1R2 = ((C0817r0) y04.f5146q).r();
                                    c0824t1R2.E();
                                    c0824t1R2.F();
                                    K k8 = c0824t1R2.f12179t;
                                    C0817r0 c0817r05 = (C0817r0) c0824t1R2.f5146q;
                                    if (k8 == null) {
                                        c0824t1R2.I();
                                        Z z12 = c0817r05.f12150y;
                                        C0817r0.k(z12);
                                        z12.f11871C.b("Failed to get consents; not connected to service yet.");
                                        c0790iW = null;
                                        z8 = true;
                                    } else {
                                        z8 = true;
                                        try {
                                            c0790iW = k8.w(c0824t1R2.S(false));
                                            c0824t1R2.U();
                                        } catch (RemoteException e9) {
                                            Z z13 = c0817r05.f12150y;
                                            C0817r0.k(z13);
                                            z13.f11875v.c(e9, "Failed to get consents; remote exception");
                                            c0790iW = null;
                                        }
                                    }
                                    Bundle bundle = c0790iW != null ? c0790iW.f12003q : null;
                                    if (bundle == null) {
                                        int i = c0817r02.f12139U;
                                        c0817r02.f12139U = i + 1;
                                        z = i < 10 ? z8 : false;
                                        C0817r0.k(z10);
                                        z10.f11871C.c(Integer.valueOf(c0817r02.f12139U), I1.a.r(new StringBuilder("Failed to retrieve DMA consent from the service, "), i < 10 ? "Retrying." : "Skipping.", " retryCount"));
                                    } else {
                                        F0 f0D = F0.d(100, bundle);
                                        sb.append("&gcs=");
                                        sb.append(f0D.i());
                                        C0811p c0811pA = C0811p.a(100, bundle);
                                        sb.append("&dma=");
                                        sb.append(!Objects.equals(c0811pA.f12092c, Boolean.FALSE) ? 1 : 0);
                                        String str3 = c0811pA.f12093d;
                                        if (!TextUtils.isEmpty(str3)) {
                                            sb.append("&dma_cps=");
                                            sb.append(str3);
                                        }
                                        int i5 = !Objects.equals(C0811p.d(bundle), Boolean.TRUE) ? 1 : 0;
                                        sb.append("&npa=");
                                        sb.append(i5);
                                        C0817r0.k(z10);
                                        z10.D.c(sb, "Consent query parameters to Bow");
                                        W1 w12 = c0817r02.f12122B;
                                        C0817r0.i(w12);
                                        ((C0817r0) c0817r02.n().f5146q).f12148w.L();
                                        String str4 = (String) pair.first;
                                        long jG = c0785g0.f11966L.g() - 1;
                                        string = sb.toString();
                                        c0817r0 = (C0817r0) w12.f5146q;
                                        try {
                                            P2.w.c(str4);
                                            P2.w.c(strK);
                                            String strConcat = "https://www.googleadservices.com/pagead/conversion/app/deeplink?id_type=adid&sdk_version=" + ("v119002." + w12.M0()) + "&rdid=" + str4 + "&bundleid=" + strK + "&retry=" + jG;
                                            if (strK.equals(c0817r0.f12148w.I("debug.deferred.deeplink"))) {
                                                strConcat = strConcat.concat("&ddl_test=1");
                                            }
                                            if (!string.isEmpty()) {
                                                if (string.charAt(0) != '&') {
                                                    strConcat = strConcat.concat("&");
                                                }
                                                strConcat = strConcat.concat(string);
                                            }
                                            url = new URL(strConcat);
                                        } catch (IllegalArgumentException e10) {
                                            e = e10;
                                            Z z14 = c0817r0.f12150y;
                                            C0817r0.k(z14);
                                            z14.f11875v.c(e.getMessage(), "Failed to create BOW URL for Deferred Deep Link. exception");
                                            url = null;
                                        } catch (MalformedURLException e11) {
                                            e = e11;
                                            Z z142 = c0817r0.f12150y;
                                            C0817r0.k(z142);
                                            z142.f11875v.c(e.getMessage(), "Failed to create BOW URL for Deferred Deep Link. exception");
                                            url = null;
                                        }
                                        if (url != null) {
                                            C0817r0.k(c0774c1);
                                            C0791i0 c0791i0 = new C0791i0(c0817r02, 1);
                                            c0774c1.G();
                                            C0815q0 c0815q02 = c0817r04.f12151z;
                                            C0817r0.k(c0815q02);
                                            c0815q02.N(new RunnableC0770b0(c0774c1, strK, url, (byte[]) null, (HashMap) null, c0791i0));
                                        }
                                    }
                                    break;
                                } else {
                                    W1 w13 = ((C0817r0) c0824t1R.f5146q).f12122B;
                                    C0817r0.i(w13);
                                    if (w13.M0() < 234200) {
                                        W1 w122 = c0817r02.f12122B;
                                        C0817r0.i(w122);
                                        ((C0817r0) c0817r02.n().f5146q).f12148w.L();
                                        String str42 = (String) pair.first;
                                        long jG2 = c0785g0.f11966L.g() - 1;
                                        string = sb.toString();
                                        c0817r0 = (C0817r0) w122.f5146q;
                                        P2.w.c(str42);
                                        P2.w.c(strK);
                                        String strConcat2 = "https://www.googleadservices.com/pagead/conversion/app/deeplink?id_type=adid&sdk_version=" + ("v119002." + w122.M0()) + "&rdid=" + str42 + "&bundleid=" + strK + "&retry=" + jG2;
                                        if (strK.equals(c0817r0.f12148w.I("debug.deferred.deeplink"))) {
                                        }
                                        if (!string.isEmpty()) {
                                        }
                                        url = new URL(strConcat2);
                                        if (url != null) {
                                        }
                                    }
                                }
                            } else {
                                C0817r0.k(z10);
                                z10.f11878y.b("Network is not available for Deferred Deep Link request. Skipping");
                            }
                            break;
                        } else {
                            activeNetworkInfo = null;
                            if (activeNetworkInfo == null) {
                                C0817r0.k(z10);
                                z10.f11878y.b("Network is not available for Deferred Deep Link request. Skipping");
                            }
                        }
                    }
                } else {
                    C0817r0.k(z10);
                    z10.D.b("ADID collection is disabled from Manifest. Skipping");
                }
                if (z) {
                    y03.f11849J.c(2000L);
                }
                break;
        }
    }
}
