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

import android.content.Context;
import android.content.IntentFilter;
import android.media.AudioDeviceInfo;
import android.media.AudioRouting;
import android.media.metrics.NetworkEvent;
import android.media.metrics.PlaybackErrorEvent;
import android.media.metrics.PlaybackMetrics;
import android.media.metrics.PlaybackStateEvent;
import android.media.metrics.TrackChangeEvent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Parcel;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.telephony.TelephonyManager;
import android.view.View;
import android.webkit.WebView;
import java.io.IOException;
import java.io.InputStream;
import java.util.AbstractCollection;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Timer;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

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

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

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

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

    public /* synthetic */ nw0(Object obj, Object obj2, int i10) {
        this.f14750a = i10;
        this.f14751b = obj;
        this.f14752c = obj2;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:241:0x05d1  */
    /* JADX WARN: Removed duplicated region for block: B:256:0x05fa  */
    /* JADX WARN: Removed duplicated region for block: B:257:0x05fc  */
    @Override // java.lang.Runnable
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void run() {
        px pxVar;
        np1 lp1Var;
        Throwable thA;
        int i10;
        long j10;
        boolean z10;
        long j11;
        int i11 = 2;
        boolean z11 = true;
        int i12 = 0;
        switch (this.f14750a) {
            case 0:
                wf1 wf1Var = (wf1) this.f14751b;
                ru ruVar = (ru) this.f14752c;
                Iterator it = wf1Var.f18038d.values().iterator();
                while (it.hasNext()) {
                    ((sf1) it.next()).b();
                }
                Timer timer = new Timer();
                timer.schedule(new vf1(wf1Var, ruVar, timer), 1000L);
                return;
            case 1:
                ((wf1) this.f14751b).zzd((View) this.f14752c, zzfsq.f19722a, "Ad overlay");
                return;
            case 2:
                kx0 kx0Var = (kx0) this.f14751b;
                x50 x50Var = (x50) this.f14752c;
                kx0Var.getClass();
                x50Var.q0();
                m60 m60VarZzh = x50Var.zzh();
                n7.u3 u3Var = kx0Var.f13421d.zza;
                if (u3Var != null && m60VarZzh != null) {
                    m60VarZzh.S2(u3Var);
                }
                if (!((Boolean) n7.y.f31093e.f31096c.b(ao.G1)).booleanValue() || x50Var.isAttachedToWindow()) {
                    return;
                }
                x50Var.onPause();
                x50Var.p0();
                return;
            case 3:
                IntentFilter intentFilter = new IntentFilter();
                intentFilter.addAction("android.net.conn.CONNECTIVITY_CHANGE");
                ((Context) this.f14752c).registerReceiver(new e.i0((jz0) this.f14751b), intentFilter);
                return;
            case 4:
                jz0 jz0Var = (jz0) ((e.i0) this.f14751b).f25225b;
                Context context = (Context) this.f14752c;
                jz0Var.getClass();
                ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
                if (connectivityManager == null) {
                    i11 = 0;
                } else {
                    try {
                        NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
                        if (activeNetworkInfo == null || !activeNetworkInfo.isConnected()) {
                            i11 = 1;
                        } else {
                            int type = activeNetworkInfo.getType();
                            if (type == 0) {
                                switch (activeNetworkInfo.getSubtype()) {
                                    case 1:
                                    case 2:
                                        i11 = 3;
                                        break;
                                    case 3:
                                    case 4:
                                    case 5:
                                    case 6:
                                    case 7:
                                    case 8:
                                    case 9:
                                    case 10:
                                    case 11:
                                    case 12:
                                    case 14:
                                    case 15:
                                    case 17:
                                        i11 = 4;
                                        break;
                                    case 13:
                                        i11 = 5;
                                        break;
                                    case 16:
                                    case 19:
                                    default:
                                        i11 = 6;
                                        break;
                                    case 18:
                                        break;
                                    case 20:
                                        if (Build.VERSION.SDK_INT >= 29) {
                                            i11 = 9;
                                            break;
                                        }
                                        break;
                                }
                            } else if (type != 1) {
                                if (type != 4 && type != 5) {
                                    if (type != 6) {
                                        i11 = type != 9 ? 8 : 7;
                                    }
                                }
                            }
                        }
                    } catch (SecurityException unused) {
                    }
                }
                if (Build.VERSION.SDK_INT < 31 || i11 != 5) {
                    jz0Var.c(i11);
                    return;
                }
                try {
                    TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService("phone");
                    telephonyManager.getClass();
                    vv0 vv0Var = new vv0(jz0Var);
                    telephonyManager.registerTelephonyCallback(jz0Var.f13040a, vv0Var);
                    telephonyManager.unregisterTelephonyCallback(vv0Var);
                    return;
                } catch (RuntimeException unused2) {
                    jz0Var.c(5);
                    return;
                }
            case 5:
                ((xe0) ((p11) ((oa1) this.f14751b).f14988f).f15234d.f17780d).q((n7.l2) this.f14752c);
                return;
            case 6:
                ((s81) ((oa1) this.f14751b).f14988f).f16355d.q((n7.l2) this.f14752c);
                return;
            case 7:
                ((x81) this.f14751b).f18358d.q((n7.l2) this.f14752c);
                return;
            case 8:
                ((qa1) ((oa1) this.f14751b).f14988f).f15667d.q((n7.l2) this.f14752c);
                return;
            case 9:
                ParcelFileDescriptor parcelFileDescriptor = (ParcelFileDescriptor) this.f14752c;
                InputStream inputStream = (InputStream) this.f14751b;
                try {
                    try {
                        ParcelFileDescriptor.AutoCloseOutputStream autoCloseOutputStream = new ParcelFileDescriptor.AutoCloseOutputStream(parcelFileDescriptor);
                        try {
                            hb.a.e(inputStream, autoCloseOutputStream, false);
                            autoCloseOutputStream.close();
                            inputStream.close();
                            return;
                        } finally {
                            try {
                                break;
                            } catch (Throwable th) {
                            }
                        }
                    } catch (IOException unused3) {
                        return;
                    }
                } finally {
                    if (inputStream != null) {
                        try {
                            break;
                        } catch (Throwable th2) {
                        }
                    }
                }
            case 10:
                zc1 zc1Var = ((xc1) this.f14751b).f18411e.f18809c;
                vc1 vc1Var = (vc1) this.f14752c;
                bd1 bd1Var = (bd1) zc1Var;
                bd1Var.getClass();
                bd1Var.H0(new ad1(vc1Var, 0));
                return;
            case 11:
                nd1 nd1Var = (nd1) this.f14751b;
                kd1 kd1Var = (kd1) this.f14752c;
                nd1Var.getClass();
                synchronized (nd1.f14560m) {
                    try {
                        if (!nd1Var.f14569i) {
                            nd1Var.f14569i = true;
                            if (nd1.a()) {
                                try {
                                    p7.r0 r0Var = m7.n.C.f30464c;
                                    nd1Var.f14564d = p7.r0.J(nd1Var.f14561a);
                                } catch (RemoteException | RuntimeException e10) {
                                    m7.n.C.f30469h.d("CuiMonitor.gettingAppIdFromManifest", e10);
                                }
                                e8.e eVar = e8.e.f25522b;
                                Context context2 = nd1Var.f14561a;
                                eVar.getClass();
                                nd1Var.f14565e = e8.e.a(context2);
                                tn tnVar = ao.Q9;
                                n7.y yVar = n7.y.f31093e;
                                int iIntValue = ((Integer) yVar.f31096c.b(tnVar)).intValue();
                                if (((Boolean) yVar.f31096c.b(ao.f8825dd)).booleanValue()) {
                                    long j12 = iIntValue;
                                    b30.f9362d.scheduleWithFixedDelay(nd1Var, j12, j12, TimeUnit.MILLISECONDS);
                                } else {
                                    long j13 = iIntValue;
                                    b30.f9362d.scheduleAtFixedRate(nd1Var, j13, j13, TimeUnit.MILLISECONDS);
                                }
                                tn tnVar2 = ao.W9;
                                if (((Boolean) yVar.f31096c.b(tnVar2)).booleanValue()) {
                                    e70 e70Var = nd1Var.f14568h;
                                    e70Var.getClass();
                                    if (((Boolean) yVar.f31096c.b(tnVar2)).booleanValue() && !e70Var.f10649b.getAndSet(true)) {
                                        e70Var.a();
                                    }
                                }
                                break;
                            }
                        }
                    } finally {
                    }
                }
                if (nd1.a() && kd1Var != null) {
                    synchronized (nd1.f14559l) {
                        try {
                            qd1 qd1Var = nd1Var.f14563c;
                            int iB = ((td1) qd1Var.f8617b).B();
                            tn tnVar3 = ao.R9;
                            n7.y yVar2 = n7.y.f31093e;
                            if (iB >= ((Integer) yVar2.f31096c.b(tnVar3)).intValue()) {
                                return;
                            }
                            od1 od1VarD = pd1.D();
                            int i13 = kd1Var.f13240m;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).Z(i13);
                            boolean z12 = kd1Var.f13229b;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).E(z12);
                            long j14 = kd1Var.f13228a;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).F(j14);
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).a0();
                            String str = nd1Var.f14562b.f32212a;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).H(str);
                            String str2 = nd1Var.f14564d;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).I(str2);
                            String str3 = Build.VERSION.RELEASE;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).J(str3);
                            int i14 = Build.VERSION.SDK_INT;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).K(i14);
                            int i15 = kd1Var.f13242o;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).B(i15);
                            int i16 = kd1Var.f13230c;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).M(i16);
                            long j15 = nd1Var.f14565e;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).N(j15);
                            int i17 = kd1Var.f13241n;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).C(i17);
                            String str4 = kd1Var.f13231d;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).O(str4);
                            String str5 = kd1Var.f13232e;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).P(str5);
                            String str6 = kd1Var.f13233f;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).Q(str6);
                            jq0 jq0VarB = nd1Var.f14566f.b(kd1Var.f13233f);
                            String string = (jq0VarB == null || (pxVar = jq0VarB.f12968b) == null) ? "" : pxVar.toString();
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).R(string);
                            String str7 = kd1Var.f13234g;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).S(str7);
                            zzfot zzfotVar = kd1Var.f13235h;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).W(zzfotVar);
                            String str8 = kd1Var.f13238k;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).V(str8);
                            String str9 = kd1Var.f13236i;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).T(str9);
                            String str10 = kd1Var.f13237j;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).U(str10);
                            long j16 = kd1Var.f13239l;
                            od1VarD.c();
                            ((pd1) od1VarD.f8617b).G(j16);
                            if (((Boolean) yVar2.f31096c.b(ao.V9)).booleanValue()) {
                                AbstractCollection abstractCollection = nd1Var.f14567g;
                                od1VarD.c();
                                ((pd1) od1VarD.f8617b).L(abstractCollection);
                            }
                            if (((Boolean) yVar2.f31096c.b(ao.W9)).booleanValue()) {
                                e70 e70Var2 = nd1Var.f14568h;
                                xc2 xc2VarZzd = e70Var2.zzd();
                                String strZzc = e70Var2.zzc();
                                if (xc2VarZzd != null) {
                                    od1VarD.c();
                                    ((pd1) od1VarD.f8617b).X(xc2VarZzd);
                                }
                                if (strZzc != null) {
                                    od1VarD.c();
                                    ((pd1) od1VarD.f8617b).Y(strZzc);
                                }
                            }
                            rd1 rd1VarB = sd1.B();
                            rd1VarB.c();
                            ((sd1) rd1VarB.f8617b).C((pd1) od1VarD.e());
                            qd1Var.c();
                            ((td1) qd1Var.f8617b).D((sd1) rd1VarB.e());
                            return;
                        } finally {
                        }
                    }
                }
                return;
            case 12:
                ((lf1) this.f14752c).b((n7.m2) this.f14751b);
                return;
            case 13:
                lf1 lf1Var = (lf1) this.f14752c;
                n7.l2 l2Var = (n7.l2) this.f14751b;
                synchronized (lf1Var) {
                    n7.z0 z0Var = lf1Var.zzh;
                    if (z0Var != null) {
                        try {
                            String str11 = lf1Var.f13668i;
                            n7.y0 y0Var = (n7.y0) z0Var;
                            Parcel parcelO = y0Var.O();
                            parcelO.writeString(str11);
                            aj.b(parcelO, l2Var);
                            y0Var.O0(3, parcelO);
                        } catch (RemoteException unused4) {
                            q7.j.d("Failed to call onAdFailedToPreload");
                            return;
                        }
                    }
                    break;
                }
                return;
            case 14:
                w80.o((WebView) this.f14751b, (String) this.f14752c);
                return;
            case 15:
                ((WebView) this.f14751b).destroy();
                return;
            case 16:
                ((w8.i) this.f14752c).setResult(ki1.a((Context) this.f14751b, "GLAS"));
                return;
            case 17:
                ao1 ao1Var = (ao1) this.f14751b;
                bi1 bi1Var = (bi1) this.f14752c;
                if (!ao1Var.f9204a.a(bi1Var)) {
                    throw new zzgjg(2);
                }
                ao1Var.f9209f.set("2.825731049.".concat(String.valueOf(bi1Var.f9546a.B())));
                return;
            case 18:
                IBinder iBinder = (IBinder) this.f14752c;
                int i18 = mp1.f14337a;
                if (iBinder == null) {
                    lp1Var = null;
                } else {
                    IInterface iInterfaceQueryLocalInterface = iBinder.queryLocalInterface("com.google.android.play.core.lmd.protocol.ILmdOverlayService");
                    lp1Var = iInterfaceQueryLocalInterface instanceof np1 ? (np1) iInterfaceQueryLocalInterface : new lp1(iBinder, "com.google.android.play.core.lmd.protocol.ILmdOverlayService", 0);
                }
                cq1 cq1Var = (cq1) this.f14751b;
                gq1 gq1Var = cq1Var.f10053a;
                gq1Var.d(lp1Var);
                gq1Var.f11838c.zza("linkToDeath", new Object[0]);
                try {
                    IInterface iInterfaceC = gq1Var.c();
                    iInterfaceC.getClass();
                    iInterfaceC.asBinder().linkToDeath(gq1Var.f11843h, 0);
                    break;
                } catch (RemoteException e11) {
                    cq1Var.f10053a.f11838c.zzd(e11, "linkToDeath failed", new Object[0]);
                }
                gq1 gq1Var2 = cq1Var.f10053a;
                gq1Var2.f11841f = false;
                synchronized (gq1Var2.f11840e) {
                    try {
                        Iterator it2 = gq1Var2.f11840e.iterator();
                        while (it2.hasNext()) {
                            ((Runnable) it2.next()).run();
                        }
                        gq1Var2.f11840e.clear();
                    } finally {
                    }
                    break;
                }
                return;
            case 19:
                ((mu1) this.f14751b).v((zzgub) this.f14752c);
                return;
            case 20:
                Future future = (Future) this.f14751b;
                boolean z13 = future instanceof pv1;
                Object obj = this.f14752c;
                if (z13 && (thA = ((pv1) future).a()) != null) {
                    ((zu1) obj).zza(thA);
                    return;
                }
                try {
                    ((zu1) obj).mo3zzb(ih1.A1(future));
                    return;
                } catch (ExecutionException e12) {
                    ((zu1) obj).zza(e12.getCause());
                    return;
                } catch (Throwable th3) {
                    ((zu1) obj).zza(th3);
                    return;
                }
            case 21:
                uh2 uh2Var = (uh2) this.f14751b;
                zh2 zh2Var = (zh2) this.f14752c;
                int i19 = uh2Var.D - zh2Var.f19286c;
                uh2Var.D = i19;
                if (zh2Var.f19287d) {
                    uh2Var.E = zh2Var.f19288e;
                    uh2Var.F = true;
                }
                if (i19 == 0) {
                    mk mkVar = zh2Var.f19285b.f18064a;
                    if (!uh2Var.W.f18064a.g() && mkVar.g()) {
                        uh2Var.X = -1;
                        uh2Var.Y = 0L;
                    }
                    if (!mkVar.g()) {
                        List listAsList = Arrays.asList(((cj2) mkVar).f9971h);
                        int size = listAsList.size();
                        ArrayList arrayList = uh2Var.f17271p;
                        ih1.b1(size == arrayList.size());
                        for (int i20 = 0; i20 < listAsList.size(); i20++) {
                            ((qh2) arrayList.get(i20)).f15746b = (mk) listAsList.get(i20);
                        }
                    }
                    if (uh2Var.F) {
                        boolean z14 = zh2Var.f19285b.f18064a.g() && uh2Var.W.f18064a.g();
                        boolean zEquals = zh2Var.f19285b.f18065b.equals(uh2Var.W.f18065b);
                        long j17 = zh2Var.f19285b.f18067d;
                        long j18 = uh2Var.W.f18080q;
                        if (z14 || (zEquals && j17 == j18)) {
                            z11 = false;
                        }
                        if (z11) {
                            int iZzs = uh2Var.zzs();
                            if (mkVar.g() || zh2Var.f19285b.f18065b.b()) {
                                j11 = zh2Var.f19285b.f18067d;
                            } else {
                                wi2 wi2Var = zh2Var.f19285b;
                                cp2 cp2Var = wi2Var.f18065b;
                                j11 = wi2Var.f18067d;
                                mkVar.n(cp2Var.f10025a, uh2Var.f17270o);
                            }
                            i10 = iZzs;
                            j10 = j11;
                        } else {
                            i10 = -1;
                            j10 = -9223372036854775807L;
                        }
                        z10 = z11;
                    } else {
                        i10 = -1;
                        j10 = -9223372036854775807L;
                        z10 = false;
                    }
                    uh2Var.F = false;
                    uh2Var.z(zh2Var.f19285b, 1, z10, uh2Var.E, j10, i10);
                    return;
                }
                return;
            case 22:
                ((ik2) this.f14751b).f12551d.reportNetworkEvent((NetworkEvent) this.f14752c);
                return;
            case 23:
                ((ik2) this.f14751b).f12551d.reportPlaybackStateEvent((PlaybackStateEvent) this.f14752c);
                return;
            case 24:
                ((ik2) this.f14751b).f12551d.reportTrackChangeEvent((TrackChangeEvent) this.f14752c);
                return;
            case 25:
                ((ik2) this.f14751b).f12551d.reportPlaybackMetrics((PlaybackMetrics) this.f14752c);
                return;
            case 26:
                ((ik2) this.f14751b).f12551d.reportPlaybackErrorEvent((PlaybackErrorEvent) this.f14752c);
                return;
            case 27:
                ((gl2) this.f14751b).b((tg2) this.f14752c);
                return;
            case 28:
                ((gl2) this.f14751b).u();
                return;
            default:
                rl2 rl2Var = (rl2) this.f14751b;
                AudioRouting audioRouting = (AudioRouting) this.f14752c;
                rl2Var.getClass();
                AudioDeviceInfo routedDevice = audioRouting.getRoutedDevice();
                if (routedDevice != null) {
                    rl2Var.f16164b.post(new pl2(rl2Var, routedDevice, i12));
                    return;
                }
                return;
        }
    }

    public final String toString() {
        switch (this.f14750a) {
            case 20:
                vu0 vu0Var = new vu0(nw0.class.getSimpleName(), 0);
                zu1 zu1Var = (zu1) this.f14752c;
                uz0 uz0Var = new uz0(10, (com.bytedance.sdk.component.adexpress.dynamic.dynamicview.b) null);
                ((uz0) vu0Var.f17780d).f17460b = uz0Var;
                vu0Var.f17780d = uz0Var;
                uz0Var.f17461c = zu1Var;
                return vu0Var.toString();
            default:
                return super.toString();
        }
    }

    public nw0(w80 w80Var, WebView webView, String str) {
        this.f14750a = 14;
        this.f14751b = webView;
        this.f14752c = str;
        Objects.requireNonNull(w80Var);
    }

    public nw0(lf1 lf1Var, n7.l2 l2Var) {
        this.f14750a = 13;
        this.f14751b = l2Var;
        this.f14752c = lf1Var;
    }

    public nw0(lf1 lf1Var, n7.m2 m2Var) {
        this.f14750a = 12;
        this.f14751b = m2Var;
        Objects.requireNonNull(lf1Var);
        this.f14752c = lf1Var;
    }

    public nw0(pg1 pg1Var) {
        this.f14750a = 15;
        Objects.requireNonNull(pg1Var);
        this.f14752c = pg1Var;
        this.f14751b = pg1Var.f15411e;
    }
}
