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

import android.content.Context;
import android.os.Handler;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Looper;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.LinearLayout;
import android.widget.TableRow;
import android.widget.TextView;
import androidx.media3.exoplayer.hls.playlist.HlsMediaPlaylist;
import androidx.media3.exoplayer.rtsp.RtspHeaders;
import java.io.ByteArrayInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public final class w80 implements t2, vb2, co0, uq1, j2, l5, b8, q7.l, f30, hv, g7.o, rc1, kc0, w8.b {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final w80 f17909a = new w80();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final /* synthetic */ w80 f17910b = new w80();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final w80 f17911c = new w80();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final w80 f17912d = new w80();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final w80 f17913e = new w80();

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final /* synthetic */ w80 f17914f = new w80();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static final /* synthetic */ w80 f17915g = new w80();

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public static final /* synthetic */ w80 f17916h = new w80();

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public static final /* synthetic */ w80 f17917i = new w80();

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public static final /* synthetic */ w80 f17918j = new w80();

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public static final /* synthetic */ w80 f17919k = new w80();

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public static final /* synthetic */ w80 f17920l = new w80();

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public static final /* synthetic */ w80 f17921m = new w80();
    public static final /* synthetic */ w80 Q = new w80();
    public static final /* synthetic */ w80 R = new w80();
    public static final /* synthetic */ w80 S = new w80();

    public static xc e(gc gcVar, Map map) throws Throwable {
        HashMap map2 = new HashMap();
        map2.putAll(map);
        map2.putAll(gcVar.f());
        URL url = new URL(gcVar.f11697c);
        HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
        httpURLConnection.setInstanceFollowRedirects(HttpURLConnection.getFollowRedirects());
        int i10 = gcVar.f11704j.f33652b;
        httpURLConnection.setConnectTimeout(i10);
        httpURLConnection.setReadTimeout(i10);
        boolean z10 = false;
        httpURLConnection.setUseCaches(false);
        httpURLConnection.setDoInput(true);
        url.getProtocol();
        try {
            for (String str : map2.keySet()) {
                httpURLConnection.setRequestProperty(str, (String) map2.get(str));
            }
            if (gcVar.f11696b != 0) {
                httpURLConnection.setRequestMethod(HlsMediaPlaylist.Interstitial.CUE_TRIGGER_POST);
                byte[] bArrG = gcVar.g();
                if (bArrG != null) {
                    httpURLConnection.setDoOutput(true);
                    if (!httpURLConnection.getRequestProperties().containsKey(RtspHeaders.CONTENT_TYPE)) {
                        httpURLConnection.setRequestProperty(RtspHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded; charset=UTF-8");
                    }
                    DataOutputStream dataOutputStream = new DataOutputStream(httpURLConnection.getOutputStream());
                    dataOutputStream.write(bArrG);
                    dataOutputStream.close();
                }
            } else {
                httpURLConnection.setRequestMethod("GET");
            }
            int responseCode = httpURLConnection.getResponseCode();
            if (responseCode == -1) {
                throw new IOException("Could not retrieve response code from HttpUrlConnection.");
            }
            if ((responseCode >= 100 && responseCode < 200) || responseCode == 204 || responseCode == 304) {
                xc xcVar = new xc(responseCode, g(httpURLConnection.getHeaderFields()), -1, null);
                httpURLConnection.disconnect();
                return xcVar;
            }
            try {
                return new xc(responseCode, g(httpURLConnection.getHeaderFields()), httpURLConnection.getContentLength(), new yc(httpURLConnection));
            } catch (Throwable th) {
                th = th;
                z10 = true;
                if (!z10) {
                    httpURLConnection.disconnect();
                }
                throw th;
            }
        } catch (Throwable th2) {
            th = th2;
        }
    }

    public static ArrayList g(Map map) {
        ArrayList arrayList = new ArrayList(map.size());
        for (Map.Entry entry : map.entrySet()) {
            if (entry.getKey() != null) {
                Iterator it = ((List) entry.getValue()).iterator();
                while (it.hasNext()) {
                    arrayList.add(new cc((String) entry.getKey(), (String) it.next()));
                }
            }
        }
        return arrayList;
    }

    public static TextView i(Context context, String str, int i10, int i11, float f10, String str2) {
        TextView textView = new TextView(context);
        textView.setTag(str2);
        j(textView, -2, -2);
        ViewGroup.LayoutParams layoutParams = textView.getLayoutParams();
        if (layoutParams == null) {
            layoutParams = new TableRow.LayoutParams();
        }
        ViewGroup.MarginLayoutParams marginLayoutParams = new ViewGroup.MarginLayoutParams(layoutParams);
        marginLayoutParams.bottomMargin = (int) TypedValue.applyDimension(1, f10, textView.getResources().getDisplayMetrics());
        textView.setLayoutParams(marginLayoutParams);
        textView.setTextAppearance(context, i10);
        textView.setTextColor(i11);
        textView.setText(str);
        return textView;
    }

    public static void j(View view, int i10, int i11) {
        ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
        if (layoutParams == null) {
            layoutParams = new TableRow.LayoutParams();
        }
        LinearLayout.LayoutParams layoutParams2 = new LinearLayout.LayoutParams(layoutParams);
        layoutParams2.height = i10;
        layoutParams2.width = i11;
        view.setLayoutParams(layoutParams2);
    }

    public static /* bridge */ nc2 k(Object obj) {
        cb2 cb2Var = (cb2) obj;
        nc2 nc2Var = cb2Var.zzt;
        if (nc2Var != nc2.f14529f) {
            return nc2Var;
        }
        nc2 nc2VarA = nc2.a();
        cb2Var.zzt = nc2VarA;
        return nc2VarA;
    }

    public static void l(Object obj, Object obj2) {
        ((cb2) obj).zzt = (nc2) obj2;
    }

    public static void n(Object obj) {
        nc2 nc2Var = ((cb2) obj).zzt;
        if (nc2Var.f14534e) {
            nc2Var.f14534e = false;
        }
    }

    public static final void o(WebView webView, String str) {
        if (webView == null || TextUtils.isEmpty(str)) {
            return;
        }
        try {
            try {
                webView.evaluateJavascript(str, null);
            } catch (IllegalStateException unused) {
                StringBuilder sb = new StringBuilder(String.valueOf(str).length() + 12);
                sb.append("javascript: ");
                sb.append(str);
                webView.loadUrl(sb.toString());
            }
        } catch (Exception e10) {
            e10.getMessage();
            qf1.f15728a.booleanValue();
        }
    }

    public static boolean p(int i10, na2 na2Var, Object obj) throws zzicg {
        int i11 = na2Var.f14511b;
        int i12 = i11 >>> 3;
        int i13 = i11 & 7;
        ma2 ma2Var = na2Var.f14510a;
        if (i13 == 0) {
            na2Var.q(0);
            ((nc2) obj).d(i12 << 3, Long.valueOf(ma2Var.o()));
            return true;
        }
        if (i13 == 1) {
            na2Var.q(1);
            ((nc2) obj).d((i12 << 3) | 1, Long.valueOf(ma2Var.q()));
            return true;
        }
        if (i13 == 2) {
            ((nc2) obj).d((i12 << 3) | 2, na2Var.y());
            return true;
        }
        if (i13 != 3) {
            if (i13 == 4) {
                if (i10 != 0) {
                    return false;
                }
                throw new zzicg("Protocol message end-group tag did not match expected tag.");
            }
            if (i13 != 5) {
                throw new zzicf();
            }
            na2Var.q(5);
            ((nc2) obj).d(5 | (i12 << 3), Integer.valueOf(ma2Var.r()));
            return true;
        }
        nc2 nc2VarA = nc2.a();
        int i14 = i12 << 3;
        int i15 = i10 + 1;
        if (i15 >= 100) {
            throw new zzicg("Protocol message had too many levels of nesting.  May be malicious.  Use setRecursionLimit() to increase the recursion depth limit.");
        }
        while (na2Var.x() != Integer.MAX_VALUE && p(i15, na2Var, nc2VarA)) {
        }
        if ((i14 | 4) != na2Var.f14511b) {
            throw new zzicg("Protocol message end-group tag did not match expected tag.");
        }
        if (nc2VarA.f14534e) {
            nc2VarA.f14534e = false;
        }
        ((nc2) obj).d(i14 | 3, nc2VarA);
        return true;
    }

    @Override // com.google.android.gms.internal.ads.b8
    public long a(p2 p2Var) {
        return -1L;
    }

    @Override // com.google.android.gms.internal.ads.hv
    public /* synthetic */ Object b(JSONObject jSONObject) {
        return new ByteArrayInputStream(jSONObject.toString().getBytes(StandardCharsets.UTF_8));
    }

    @Override // com.google.android.gms.internal.ads.b8
    public void c(long j10) {
    }

    @Override // g7.o
    public /* synthetic */ void d() {
    }

    @Override // q7.l
    public Object f(IBinder iBinder) {
        IBinder iBinder2 = iBinder;
        int i10 = fj.f11258a;
        if (iBinder2 == null) {
            return null;
        }
        IInterface iInterfaceQueryLocalInterface = iBinder2.queryLocalInterface("com.google.android.gms.ads.clearcut.IClearcut");
        return iInterfaceQueryLocalInterface instanceof hj ? (hj) iInterfaceQueryLocalInterface : new ej(iBinder2, "com.google.android.gms.ads.clearcut.IClearcut", 0);
    }

    public void m(WebView webView, String str, Object... objArr) {
        if (webView == null) {
            qf1.f15728a.booleanValue();
            return;
        }
        StringBuilder sb = new StringBuilder(128);
        sb.append("if(window.omidBridge!==undefined){omidBridge.");
        sb.append(str);
        sb.append("(");
        for (Object obj : objArr) {
            if (obj == null) {
                sb.append("null");
            } else if (obj instanceof String) {
                String string = obj.toString();
                if (string.startsWith("{")) {
                    sb.append(string);
                } else {
                    sb.append('\"');
                    sb.append(string);
                    sb.append('\"');
                }
            } else {
                sb.append(obj);
            }
            sb.append(",");
        }
        sb.setLength(sb.length() - 1);
        sb.append(")}");
        String string2 = sb.toString();
        Handler handler = webView.getHandler();
        if (handler == null) {
            handler = new Handler(Looper.getMainLooper());
        }
        if (Looper.myLooper() == handler.getLooper()) {
            o(webView, string2);
        } else {
            handler.post(new nw0(this, webView, string2));
        }
    }

    @Override // w8.b
    public /* synthetic */ Object then(w8.h hVar) {
        return new Boolean(hVar.j());
    }

    @Override // com.google.android.gms.internal.ads.uq1
    public /* synthetic */ n7.p2 zza() {
        return null;
    }

    @Override // com.google.android.gms.internal.ads.vb2
    public boolean zzb(Class cls) {
        return cb2.class.isAssignableFrom(cls);
    }

    @Override // com.google.android.gms.internal.ads.b8
    public k3 zzc() {
        return new w2(-9223372036854775807L, 0L);
    }

    @Override // com.google.android.gms.internal.ads.f30
    /* JADX INFO: renamed from: zza, reason: collision with other method in class */
    public /* synthetic */ void mo5zza() {
    }

    @Override // com.google.android.gms.internal.ads.vb2
    public tb2 zzc(Class cls) {
        if (!cb2.class.isAssignableFrom(cls)) {
            throw new IllegalArgumentException("Unsupported message type: ".concat(cls.getName()));
        }
        try {
            return (tb2) cb2.u(cls.asSubclass(cb2.class)).x(zzibq.f19863c, null);
        } catch (Exception e10) {
            throw new RuntimeException("Unable to get message info for ".concat(cls.getName()), e10);
        }
    }

    @Override // com.google.android.gms.internal.ads.co0
    /* JADX INFO: renamed from: zza */
    public /* synthetic */ void mo2zza(Object obj) {
        ((ExecutorService) obj).shutdown();
    }

    @Override // com.google.android.gms.internal.ads.uq1
    public /* synthetic */ Object zza() {
        int i10 = x0.f18280a;
        try {
            return Class.forName("androidx.media3.effect.DefaultVideoFrameProcessor$Factory$Builder");
        } catch (Exception e10) {
            throw new IllegalStateException(e10);
        }
    }

    @Override // com.google.android.gms.internal.ads.rc1
    public /* synthetic */ Object zza(Object obj) {
        JSONObject jSONObject = (JSONObject) obj;
        p7.l0.g("Ad request signals:");
        p7.l0.g(jSONObject.toString(2));
        return jSONObject;
    }

    @Override // com.google.android.gms.internal.ads.uq1
    public /* synthetic */ Constructor zza() {
        int[] iArr = l2.f13471b;
        return Class.forName("androidx.media3.decoder.midi.MidiExtractor").asSubclass(o2.class).getConstructor(new Class[0]);
    }

    @Override // com.google.android.gms.internal.ads.t2, com.google.android.gms.internal.ads.ow0
    /* JADX INFO: renamed from: zza, reason: collision with other method in class */
    public o2[] mo6zza() {
        int i10 = n50.W;
        return new o2[]{new j7(), new g6(), new d7(i8.f12406t, 32, null, null, zzgwa.f19786e, null)};
    }
}
