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

import com.google.ads.interactivemedia.pal.NonceLoaderException;
import com.google.ads.interactivemedia.pal.zzat;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.GeneralSecurityException;

/* JADX INFO: loaded from: classes2.dex */
public final class t2 extends x2 {
    public static m5 d() throws Throwable {
        HttpURLConnection httpURLConnection;
        HttpURLConnection httpURLConnection2 = null;
        try {
            try {
                httpURLConnection = (HttpURLConnection) new URL("https://imasdk.googleapis.com/pal/key/public.json").openConnection();
            } catch (Throwable th) {
                th = th;
            }
        } catch (IOException e10) {
            e = e10;
        } catch (GeneralSecurityException e11) {
            e = e11;
        }
        try {
            try {
                httpURLConnection.setConnectTimeout(zzat.zzb);
                httpURLConnection.setReadTimeout(zzat.zzc);
                httpURLConnection.setDoInput(true);
                httpURLConnection.setUseCaches(false);
                httpURLConnection.connect();
                if (httpURLConnection.getResponseCode() != 200) {
                    httpURLConnection.getResponseCode();
                    throw NonceLoaderException.zzb(202);
                }
                InputStream inputStream = httpURLConnection.getInputStream();
                try {
                    m5 m5VarB = m5.b(new e7(inputStream));
                    if (inputStream != null) {
                        inputStream.close();
                    }
                    httpURLConnection.disconnect();
                    return m5VarB;
                } catch (Throwable th2) {
                    if (inputStream != null) {
                        try {
                            inputStream.close();
                        } catch (Throwable th3) {
                            try {
                                Throwable.class.getDeclaredMethod("addSuppressed", Throwable.class).invoke(th2, th3);
                            } catch (Exception unused) {
                            }
                        }
                    }
                    throw th2;
                }
            } catch (Throwable th4) {
                th = th4;
                httpURLConnection2 = httpURLConnection;
                if (httpURLConnection2 != null) {
                    httpURLConnection2.disconnect();
                }
                throw th;
            }
        } catch (IOException | GeneralSecurityException e12) {
            e = e12;
            e.toString();
            throw new NonceLoaderException(203, e);
        }
    }

    @Override // com.google.android.gms.internal.pal.x2
    public final zzil a() throws NonceLoaderException {
        try {
            o8.a();
            return new zziq(new s2((d7) d().d()));
        } catch (GeneralSecurityException e10) {
            throw new NonceLoaderException(201, e10);
        }
    }
}
