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

import android.content.Context;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Pair;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;
import androidx.annotation.Nullable;
import java.util.HashSet;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executor;
import java.util.concurrent.ScheduledExecutorService;

/* JADX INFO: loaded from: classes2.dex */
public final class x81 implements m11 {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Context f18355a;

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

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final FrameLayout f18360f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final bh0 f18361g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final nd1 f18362h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final si0 f18363i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final hb1 f18364j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public boolean f18365k;

    @Nullable
    private qo zzg;

    @Nullable
    private com.google.common.util.concurrent.w zzl;

    @Nullable
    private n7.l2 zzn;

    @Nullable
    private l11 zzo;

    public x81(Context context, Executor executor, n7.f4 f4Var, h70 h70Var, d11 d11Var, f11 f11Var, hb1 hb1Var, si0 si0Var) {
        this.f18355a = context;
        this.f18356b = executor;
        this.f18357c = h70Var;
        this.f18358d = d11Var;
        this.f18359e = f11Var;
        this.f18364j = hb1Var;
        a80 a80Var = (a80) h70Var;
        this.f18361g = new bh0((ScheduledExecutorService) a80Var.f8529e.zzb(), (i8.c) a80Var.f8533g.zzb(), (cr0) a80Var.f8543l.zzb());
        this.f18362h = h70Var.c();
        this.f18360f = new FrameLayout(context);
        this.f18363i = si0Var;
        hb1Var.f12105b = f4Var;
        this.f18365k = true;
        this.zzn = null;
        this.zzo = null;
    }

    public final void a() {
        synchronized (this) {
            try {
                com.google.common.util.concurrent.w wVar = this.zzl;
                if (wVar != null && wVar.isDone()) {
                    try {
                        eb0 eb0Var = (eb0) this.zzl.get();
                        this.zzl = null;
                        FrameLayout frameLayout = this.f18360f;
                        frameLayout.removeAllViews();
                        eb0Var.getClass();
                        ViewParent parent = ((gb0) eb0Var).f11686l.getParent();
                        if (parent instanceof ViewGroup) {
                            oe0 oe0Var = eb0Var.f14060e;
                            String str = oe0Var != null ? oe0Var.f15040a : "";
                            StringBuilder sb = new StringBuilder(String.valueOf(str).length() + 78);
                            sb.append("Banner view provided from ");
                            sb.append(str);
                            sb.append(" already has a parent view. Removing its old parent.");
                            q7.j.d(sb.toString());
                            ((ViewGroup) parent).removeView(((gb0) eb0Var).f11686l);
                        }
                        tn tnVar = ao.f8952l9;
                        n7.y yVar = n7.y.f31093e;
                        if (((Boolean) yVar.f31096c.b(tnVar)).booleanValue()) {
                            dh0 dh0Var = eb0Var.f14061f.f12523a;
                            d11 d11Var = this.f18358d;
                            Object obj = dh0Var.f10402b;
                            ((ii0) obj).f12524b = d11Var;
                            ((ii0) obj).f12525c = this.f18359e;
                        }
                        frameLayout.addView(((gb0) eb0Var).f11686l);
                        l11 l11Var = this.zzo;
                        if (l11Var != null) {
                            l11Var.mo3zzb(eb0Var);
                        }
                        if (((Boolean) yVar.f31096c.b(tnVar)).booleanValue()) {
                            Executor executor = this.f18356b;
                            d11 d11Var2 = this.f18358d;
                            Objects.requireNonNull(d11Var2);
                            executor.execute(new z80(d11Var2, 28));
                        }
                        if (((gb0) eb0Var).f14056a.f10746b.f10364b.f19183d >= 0) {
                            this.f18365k = false;
                            bh0 bh0Var = this.f18361g;
                            bh0Var.J0(((gb0) eb0Var).f14056a.f10746b.f10364b.f19183d);
                            bh0Var.K0(eb0Var.e());
                        } else {
                            this.f18365k = true;
                            this.f18361g.J0(eb0Var.e());
                        }
                    } catch (InterruptedException | ExecutionException unused) {
                        d();
                        p7.l0.h();
                        this.f18365k = true;
                        this.f18361g.zzc();
                    }
                } else if (this.zzl != null) {
                    p7.l0.g("Show timer went off but there is an ongoing ad request.");
                    this.f18365k = true;
                } else {
                    p7.l0.g("No ad request was in progress or an ad was cached when show timer went off. Hence requesting a new ad.");
                    this.f18365k = true;
                    this.f18361g.zzc();
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void b(qo qoVar) {
        this.zzg = qoVar;
    }

    public final /* synthetic */ void c(n7.l2 l2Var) {
        this.zzn = l2Var;
    }

    public final void d() {
        this.zzl = null;
        n7.l2 l2Var = this.zzn;
        this.zzn = null;
        if (((Boolean) n7.y.f31093e.f31096c.b(ao.f8952l9)).booleanValue() && l2Var != null) {
            this.f18356b.execute(new nw0(this, l2Var, 7));
        }
        l11 l11Var = this.zzo;
        if (l11Var != null) {
            l11Var.zza();
        }
    }

    @Override // com.google.android.gms.internal.ads.m11
    public final boolean zza(n7.a4 a4Var, String str, @Nullable k11 k11Var, l11 l11Var) throws RemoteException {
        g80 g80VarZzh;
        Executor executor = this.f18356b;
        if (str == null) {
            q7.j.b("Ad unit ID should not be null for banner ad.");
            executor.execute(new z80(this, 27));
            return false;
        }
        boolean zZzb = zzb();
        hb1 hb1Var = this.f18364j;
        if (!zZzb) {
            tn tnVar = ao.Q2;
            n7.y yVar = n7.y.f31093e;
            if (((Boolean) yVar.f31096c.b(tnVar)).booleanValue()) {
                n7.x.a();
            }
            tn tnVar2 = ao.f8856fa;
            yn ynVar = yVar.f31096c;
            boolean zBooleanValue = ((Boolean) ynVar.b(tnVar2)).booleanValue();
            h70 h70Var = this.f18357c;
            if (zBooleanValue && a4Var.f30898f) {
                ((ps0) ((a80) h70Var).D.zzb()).b(true);
            }
            String strA = zzdxh.DYNAMITE_ENTER.a();
            m7.n.C.f30472k.getClass();
            Bundle bundleA = ni.a(new Pair(zzdxh.PUBLIC_API_CALL.a(), Long.valueOf(a4Var.Z)), new Pair(strA, Long.valueOf(System.currentTimeMillis())));
            hb1Var.f12106c = str;
            hb1Var.f12104a = a4Var;
            hb1Var.f12118o = bundleA;
            ib1 ib1VarA = hb1Var.a();
            int I = ni.I(ib1VarA);
            Context context = this.f18355a;
            id1 id1VarF = id1.f(context, I, 3, a4Var);
            boolean zBooleanValue2 = ((Boolean) up.f17364e.j()).booleanValue();
            d11 d11Var = this.f18358d;
            md1 md1Var = null;
            if (!zBooleanValue2 || !hb1Var.f12105b.f30956k) {
                boolean zBooleanValue3 = ((Boolean) ynVar.b(ao.f8952l9)).booleanValue();
                FrameLayout frameLayout = this.f18360f;
                si0 si0Var = this.f18363i;
                bh0 bh0Var = this.f18361g;
                if (zBooleanValue3) {
                    f80 f80Var = new f80(((a80) h70Var).f8525c);
                    fe0 fe0Var = new fe0();
                    fe0Var.f11184a = context;
                    fe0Var.f11185b = ib1VarA;
                    f80Var.f11100e = new ge0(fe0Var);
                    cj0 cj0Var = new cj0();
                    cj0Var.d(d11Var, executor);
                    cj0Var.b(d11Var, executor);
                    f80Var.f11099d = new dj0(cj0Var);
                    f80Var.f11101f = new xz0(this.zzg);
                    f80Var.f11105j = new ml0(um0.f17325c, null);
                    f80Var.f11102g = new dc0(bh0Var, si0Var);
                    f80Var.f11104i = new bb0(frameLayout);
                    g80VarZzh = f80Var.zzh();
                } else {
                    f80 f80Var2 = new f80(((a80) h70Var).f8525c);
                    fe0 fe0Var2 = new fe0();
                    fe0Var2.f11184a = context;
                    fe0Var2.f11185b = ib1VarA;
                    f80Var2.f11100e = new ge0(fe0Var2);
                    cj0 cj0Var2 = new cj0();
                    cj0Var2.d(d11Var, executor);
                    ak0 ak0Var = new ak0(d11Var, executor);
                    HashSet hashSet = cj0Var2.f9950c;
                    hashSet.add(ak0Var);
                    hashSet.add(new ak0(this.f18359e, executor));
                    cj0Var2.c(d11Var, executor);
                    cj0Var2.f9953f.add(new ak0(d11Var, executor));
                    cj0Var2.f9952e.add(new ak0(d11Var, executor));
                    cj0Var2.f9955h.add(new ak0(d11Var, executor));
                    cj0Var2.a(d11Var, executor);
                    cj0Var2.b(d11Var, executor);
                    cj0Var2.f9960m.add(new ak0(d11Var, executor));
                    f80Var2.f11099d = new dj0(cj0Var2);
                    f80Var2.f11101f = new xz0(this.zzg);
                    f80Var2.f11105j = new ml0(um0.f17325c, null);
                    f80Var2.f11102g = new dc0(bh0Var, si0Var);
                    f80Var2.f11104i = new bb0(frameLayout);
                    g80VarZzh = f80Var2.zzh();
                }
                if (((Boolean) ip.f12589c.j()).booleanValue()) {
                    md1Var = (md1) g80VarZzh.f11581l0.zzb();
                    md1Var.i(3);
                    md1Var.c(a4Var.S);
                    md1Var.d(a4Var.f30905m);
                }
                this.zzo = l11Var;
                dd0 dd0Var = (dd0) g80VarZzh.D0.zzb();
                vc1 vc1VarC = dd0Var.c(dd0Var.b());
                this.zzl = vc1VarC;
                ih1.z1(vc1VarC, new eb(this, md1Var, id1VarF, g80VarZzh), executor);
                return true;
            }
            if (d11Var != null) {
                d11Var.q(sb1.zzd(7, null, null));
            }
        } else if (!hb1Var.f12115l) {
            this.f18365k = true;
        }
        return false;
    }

    @Override // com.google.android.gms.internal.ads.m11
    public final boolean zzb() {
        com.google.common.util.concurrent.w wVar = this.zzl;
        return (wVar == null || wVar.isDone()) ? false : true;
    }
}
