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

import android.os.RemoteException;
import com.google.android.gms.internal.ads.a61;
import com.google.android.gms.internal.ads.oi2;
import java.io.IOException;
import java.io.Serializable;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

/* JADX INFO: loaded from: classes2.dex */
public final class u2 implements Runnable {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final String f21926b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Serializable f21927c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Object f21928d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final Object f21929e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final /* synthetic */ o0.i f21930f;

    public u2(g2 g2Var, AtomicReference atomicReference, String str, String str2) {
        this.f21925a = 1;
        this.f21927c = atomicReference;
        this.f21926b = null;
        this.f21928d = str;
        this.f21929e = str2;
        this.f21930f = g2Var;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:57:0x0138  */
    /* JADX WARN: Removed duplicated region for block: B:61:0x0151  */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:16:0x0072 -> B:67:0x007d). Please report as a decompilation issue!!! */
    @Override // java.lang.Runnable
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void run() throws Throwable {
        IOException iOException;
        int responseCode;
        HttpURLConnection httpURLConnection;
        Map<String, List<String>> headerFields;
        int i10 = this.f21925a;
        Object obj = this.f21929e;
        Object obj2 = this.f21928d;
        o0.i iVar = this.f21930f;
        Object obj3 = this.f21927c;
        switch (i10) {
            case 0:
                j1 j1Var = ((m1) ((t2) iVar).f31277a).f21758j;
                m1.d(j1Var);
                j1Var.L();
                IOException iOException2 = null;
                boolean z10 = false;
                boolean z11 = false;
                boolean z12 = false;
                try {
                    try {
                        URL url = (URL) obj3;
                        try {
                            synchronized (com.google.android.gms.internal.measurement.s0.class) {
                                break;
                            }
                            URLConnection uRLConnectionOpenConnection = url.openConnection();
                            if (!(uRLConnectionOpenConnection instanceof HttpURLConnection)) {
                                throw new IOException("Failed to obtain HTTP connection");
                            }
                            httpURLConnection = (HttpURLConnection) uRLConnectionOpenConnection;
                            httpURLConnection.setDefaultUseCaches(false);
                            httpURLConnection.setConnectTimeout(60000);
                            httpURLConnection.setReadTimeout(61000);
                            httpURLConnection.setInstanceFollowRedirects(false);
                            httpURLConnection.setDoInput(true);
                            try {
                                responseCode = httpURLConnection.getResponseCode();
                                try {
                                    headerFields = httpURLConnection.getHeaderFields();
                                } catch (IOException e10) {
                                    iOException = e10;
                                    headerFields = null;
                                    if (httpURLConnection != null) {
                                        httpURLConnection.disconnect();
                                    }
                                    ((t2) this.f21930f).zzl().I(new oi2(this, responseCode, iOException, (byte[]) (z12 ? 1 : 0), (Map) headerFields));
                                    return;
                                } catch (Throwable th) {
                                    th = th;
                                    headerFields = null;
                                    if (httpURLConnection != null) {
                                    }
                                    ((t2) this.f21930f).zzl().I(new oi2(this, responseCode, (IOException) (z11 ? 1 : 0), (byte[]) (z10 ? 1 : 0), (Map) headerFields));
                                    throw th;
                                }
                            } catch (IOException e11) {
                                iOException = e11;
                                responseCode = 0;
                            } catch (Throwable th2) {
                                th = th2;
                                responseCode = 0;
                            }
                            try {
                                byte[] bArrA = t2.A(httpURLConnection);
                                httpURLConnection.disconnect();
                                ((t2) this.f21930f).zzl().I(new oi2(this, responseCode, iOException2, bArrA, headerFields));
                                return;
                            } catch (IOException e12) {
                                iOException = e12;
                                if (httpURLConnection != null) {
                                }
                                ((t2) this.f21930f).zzl().I(new oi2(this, responseCode, iOException, (byte[]) (z12 ? 1 : 0), (Map) headerFields));
                                return;
                            } catch (Throwable th3) {
                                th = th3;
                                if (httpURLConnection != null) {
                                }
                                ((t2) this.f21930f).zzl().I(new oi2(this, responseCode, (IOException) (z11 ? 1 : 0), (byte[]) (z10 ? 1 : 0), (Map) headerFields));
                                throw th;
                            }
                        } catch (Throwable th4) {
                            th = th4;
                            responseCode = 0;
                            httpURLConnection = null;
                            headerFields = null;
                            if (httpURLConnection != null) {
                                httpURLConnection.disconnect();
                            }
                            ((t2) this.f21930f).zzl().I(new oi2(this, responseCode, (IOException) (z11 ? 1 : 0), (byte[]) (z10 ? 1 : 0), (Map) headerFields));
                            throw th;
                        }
                    } catch (IOException e13) {
                        iOException = e13;
                        responseCode = 0;
                        httpURLConnection = null;
                        headerFields = null;
                    }
                } catch (Throwable th5) {
                    th = th5;
                }
                break;
            case 1:
                a3 a3VarL = ((m1) ((g2) iVar).f31277a).l();
                a3VarL.w();
                a3VarL.D();
                a3VarL.I(new a61(a3VarL, (AtomicReference) obj3, (String) obj2, (String) obj, a3VarL.S(false)));
                return;
            default:
                String strV = this.f21926b;
                ArrayList arrayList = new ArrayList();
                try {
                    h0 h0Var = ((a3) iVar).f21472d;
                    if (h0Var == null) {
                        ((a3) iVar).zzj().f21834f.a(strV, (String) obj3, "Failed to get conditional properties; not connected to service");
                    } else {
                        com.google.android.gms.common.internal.w.checkNotNull((d4) obj2);
                        arrayList = n4.q0(h0Var.zza(strV, (String) obj3, (d4) obj2));
                        ((a3) iVar).R();
                        iVar = (a3) iVar;
                        n4 n4VarV = iVar.v();
                        com.google.android.gms.internal.measurement.x0 x0Var = (com.google.android.gms.internal.measurement.x0) obj;
                        n4VarV.T(x0Var, arrayList);
                        strV = n4VarV;
                        obj = x0Var;
                        obj3 = obj3;
                    }
                } catch (RemoteException e14) {
                    Object obj4 = (String) obj3;
                    ((a3) iVar).zzj().f21834f.d("Failed to get conditional properties; remote exception", strV, obj4, e14);
                } finally {
                    ((a3) iVar).v().T((com.google.android.gms.internal.measurement.x0) obj, arrayList);
                }
                return;
        }
    }

    public u2(t2 t2Var, String str, URL url, p1 p1Var) {
        this.f21925a = 0;
        this.f21930f = t2Var;
        com.google.android.gms.common.internal.w.checkNotEmpty(str);
        com.google.android.gms.common.internal.w.checkNotNull(url);
        com.google.android.gms.common.internal.w.checkNotNull(p1Var);
        this.f21927c = url;
        this.f21928d = p1Var;
        this.f21926b = str;
        this.f21929e = null;
    }

    public u2(a3 a3Var, String str, String str2, d4 d4Var, com.google.android.gms.internal.measurement.x0 x0Var) {
        this.f21925a = 2;
        this.f21926b = str;
        this.f21927c = str2;
        this.f21928d = d4Var;
        this.f21929e = x0Var;
        this.f21930f = a3Var;
    }
}
