package n7;

import android.content.Context;
import android.os.RemoteException;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.Nullable;
import androidx.annotation.VisibleForTesting;
import com.google.android.gms.internal.ads.ao;
import com.google.android.gms.internal.ads.mp;
import com.google.android.gms.internal.ads.oj;
import com.google.android.gms.internal.ads.uv;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;

/* JADX INFO: loaded from: classes2.dex */
public final class w2 {

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final g7.x f31075c;

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public g7.b f31077e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public g7.g[] f31078f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public g7.y f31079g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public String f31080h;

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

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

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

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final AtomicLong f31084l;

    @Nullable
    private a zzf;

    @Nullable
    private h7.d zzi;

    @Nullable
    private r0 zzj;

    @Nullable
    private g7.n zzp;

    public w2(ViewGroup viewGroup, AttributeSet attributeSet, boolean z10) {
        this(viewGroup, attributeSet, z10, e4.f30941a, null, 0);
    }

    public static f4 b(Context context, g7.g[] gVarArr, int i10) {
        for (g7.g gVar : gVarArr) {
            if (gVar.equals(g7.g.f26288p)) {
                return new f4("invalid", 0, 0, false, 0, 0, null, false, false, false, true, false, false, false, false);
            }
        }
        f4 f4Var = new f4(context, gVarArr);
        f4Var.f30955j = i10 == 1;
        return f4Var;
    }

    public final void a(g7.y yVar) {
        this.f31079g = yVar;
        try {
            r0 r0Var = this.zzj;
            if (r0Var != null) {
                r0Var.zzG(yVar == null ? null : new u3(yVar));
            }
        } catch (RemoteException e10) {
            q7.j.zzl("#007 Could not call remote method.", e10);
        }
    }

    public final void c() {
        try {
            r0 r0Var = this.zzj;
            if (r0Var != null) {
                r0Var.zzc();
            }
        } catch (RemoteException e10) {
            q7.j.zzl("#007 Could not call remote method.", e10);
        }
    }

    public final String d() {
        r0 r0Var;
        if (this.f31080h == null && (r0Var = this.zzj) != null) {
            try {
                this.f31080h = r0Var.c();
            } catch (RemoteException e10) {
                q7.j.zzl("#007 Could not call remote method.", e10);
            }
        }
        return this.f31080h;
    }

    /* JADX WARN: Removed duplicated region for block: B:37:0x00d7 A[Catch: RemoteException -> 0x00d5, TRY_LEAVE, TryCatch #1 {RemoteException -> 0x00d5, blocks: (B:28:0x00a2, B:30:0x00a8, B:32:0x00b6, B:34:0x00c8, B:37:0x00d7), top: B:53:0x00a2, outer: #0 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void e(u2 u2Var) {
        try {
            long jCurrentTimeMillis = System.currentTimeMillis();
            r0 r0Var = this.zzj;
            ViewGroup viewGroup = this.f31081i;
            if (r0Var == null) {
                if (this.f31078f == null || this.f31080h == null) {
                    throw new IllegalStateException("The ad size and ad unit ID must be set before loadAd is called.");
                }
                Context context = viewGroup.getContext();
                f4 f4VarB = b(context, this.f31078f, this.f31082j);
                int i10 = 0;
                r0 r0Var2 = "search_v2".equals(f4VarB.f30946a) ? (r0) new k(x.f31085g.f31087b, context, f4VarB, this.f31080h).a(context, false) : (r0) new i(x.f31085g.f31087b, context, f4VarB, this.f31080h, this.f31073a).a(context, false);
                this.zzj = r0Var2;
                r0Var2.zzdR(new t3(this.f31076d));
                a aVar = this.zzf;
                if (aVar != null) {
                    this.zzj.zzy(new v(aVar));
                }
                h7.d dVar = this.zzi;
                if (dVar != null) {
                    this.zzj.zzi(new oj(dVar));
                }
                g7.y yVar = this.f31079g;
                if (yVar != null) {
                    this.zzj.zzG(new u3(yVar));
                }
                this.zzj.j2(new o3(null));
                this.zzj.K1(this.f31083k);
                r0 r0Var3 = this.zzj;
                if (r0Var3 != null) {
                    try {
                        k8.a aVarZzb = r0Var3.zzb();
                        if (aVarZzb != null) {
                            if (((Boolean) mp.f14330f.j()).booleanValue()) {
                                if (((Boolean) y.f31093e.f31096c.b(ao.f9089tc)).booleanValue()) {
                                    q7.e.f32222b.post(new l.l(this, aVarZzb, 17, i10));
                                } else {
                                    viewGroup.addView((View) k8.b.O(aVarZzb));
                                }
                            }
                        }
                    } catch (RemoteException e10) {
                        q7.j.zzl("#007 Could not call remote method.", e10);
                    }
                }
            }
            u2Var.f31062n = jCurrentTimeMillis;
            r0 r0Var4 = this.zzj;
            r0Var4.getClass();
            AtomicLong atomicLong = this.f31084l;
            if (atomicLong.get() != 0) {
                r0Var4.d0(atomicLong.get());
            }
            e4 e4Var = this.f31074b;
            Context context2 = viewGroup.getContext();
            e4Var.getClass();
            r0Var4.z(e4.a(context2, u2Var));
        } catch (RemoteException e11) {
            q7.j.zzl("#007 Could not call remote method.", e11);
        }
    }

    public final void f() {
        try {
            r0 r0Var = this.zzj;
            if (r0Var != null) {
                r0Var.zzf();
            }
        } catch (RemoteException e10) {
            q7.j.zzl("#007 Could not call remote method.", e10);
        }
    }

    public final void g() {
        try {
            r0 r0Var = this.zzj;
            if (r0Var != null) {
                r0Var.zzg();
            }
        } catch (RemoteException e10) {
            q7.j.zzl("#007 Could not call remote method.", e10);
        }
    }

    public final void h(g7.g... gVarArr) {
        ViewGroup viewGroup = this.f31081i;
        this.f31078f = gVarArr;
        try {
            r0 r0Var = this.zzj;
            if (r0Var != null) {
                r0Var.c2(b(viewGroup.getContext(), this.f31078f, this.f31082j));
            }
        } catch (RemoteException e10) {
            q7.j.zzl("#007 Could not call remote method.", e10);
        }
        viewGroup.requestLayout();
    }

    public final void i(boolean z10) {
        this.f31083k = z10;
        try {
            r0 r0Var = this.zzj;
            if (r0Var != null) {
                r0Var.K1(z10);
            }
        } catch (RemoteException e10) {
            q7.j.zzl("#007 Could not call remote method.", e10);
        }
    }

    public final long j() {
        AtomicLong atomicLong = this.f31084l;
        if (atomicLong.get() != 0) {
            return atomicLong.get();
        }
        try {
            r0 r0Var = this.zzj;
            if (r0Var != null) {
                atomicLong.set(r0Var.x());
                return atomicLong.get();
            }
        } catch (RemoteException e10) {
            q7.j.zzl("#007 Could not call remote method.", e10);
        }
        return 0L;
    }

    public final void k(long j10) {
        this.f31084l.set(j10);
        try {
            r0 r0Var = this.zzj;
            if (r0Var != null) {
                r0Var.d0(j10);
            }
        } catch (RemoteException e10) {
            q7.j.zzl("#007 Could not call remote method.", e10);
        }
    }

    @Nullable
    public final g7.g zzc() {
        f4 f4VarZzn;
        try {
            r0 r0Var = this.zzj;
            if (r0Var != null && (f4VarZzn = r0Var.zzn()) != null) {
                return new g7.g(f4VarZzn.f30950e, f4VarZzn.f30947b, f4VarZzn.f30946a);
            }
        } catch (RemoteException e10) {
            q7.j.zzl("#007 Could not call remote method.", e10);
        }
        g7.g[] gVarArr = this.f31078f;
        if (gVarArr != null) {
            return gVarArr[0];
        }
        return null;
    }

    @Nullable
    public final h7.d zzf() {
        return this.zzi;
    }

    public final void zzl(@Nullable a aVar) {
        try {
            this.zzf = aVar;
            r0 r0Var = this.zzj;
            if (r0Var != null) {
                r0Var.zzy(aVar != null ? new v(aVar) : null);
            }
        } catch (RemoteException e10) {
            q7.j.zzl("#007 Could not call remote method.", e10);
        }
    }

    public final void zzp(@Nullable h7.d dVar) {
        try {
            this.zzi = dVar;
            r0 r0Var = this.zzj;
            if (r0Var != null) {
                r0Var.zzi(dVar != null ? new oj(dVar) : null);
            }
        } catch (RemoteException e10) {
            q7.j.zzl("#007 Could not call remote method.", e10);
        }
    }

    @Nullable
    public final g7.u zzt() {
        m2 m2VarZzt = null;
        try {
            r0 r0Var = this.zzj;
            if (r0Var != null) {
                m2VarZzt = r0Var.zzt();
            }
        } catch (RemoteException e10) {
            q7.j.zzl("#007 Could not call remote method.", e10);
        }
        return g7.u.zzb(m2VarZzt);
    }

    public final void zzu(@Nullable g7.n nVar) {
        try {
            r0 r0Var = this.zzj;
            if (r0Var != null) {
                r0Var.j2(new o3(nVar));
            }
        } catch (RemoteException e10) {
            q7.j.zzl("#007 Could not call remote method.", e10);
        }
    }

    @Nullable
    public final g7.n zzx() {
        return null;
    }

    @Nullable
    public final p2 zzz() {
        r0 r0Var = this.zzj;
        if (r0Var != null) {
            try {
                return r0Var.zzF();
            } catch (RemoteException e10) {
                q7.j.zzl("#007 Could not call remote method.", e10);
            }
        }
        return null;
    }

    @VisibleForTesting
    public w2(ViewGroup viewGroup, @Nullable AttributeSet attributeSet, boolean z10, e4 e4Var, @Nullable r0 r0Var, int i10) {
        f4 f4Var;
        this.f31073a = new uv();
        this.f31075c = new g7.x();
        this.f31076d = new v2(this);
        this.f31084l = new AtomicLong();
        this.f31081i = viewGroup;
        this.f31074b = e4Var;
        this.zzj = null;
        new AtomicBoolean(false);
        this.f31082j = i10;
        if (attributeSet != null) {
            Context context = viewGroup.getContext();
            try {
                com.google.android.gms.internal.atv_ads_framework.d1 d1Var = new com.google.android.gms.internal.atv_ads_framework.d1(context, attributeSet);
                if (!z10 && ((g7.g[]) d1Var.f19914b).length != 1) {
                    throw new IllegalArgumentException("The adSizes XML attribute is only allowed on PublisherAdViews.");
                }
                this.f31078f = (g7.g[]) d1Var.f19914b;
                this.f31080h = (String) d1Var.f19915c;
                if (viewGroup.isInEditMode()) {
                    q7.e eVar = x.f31085g.f31086a;
                    g7.g gVar = this.f31078f[0];
                    if (gVar.equals(g7.g.f26288p)) {
                        f4Var = new f4("invalid", 0, 0, false, 0, 0, null, false, false, false, true, false, false, false, false);
                    } else {
                        f4 f4Var2 = new f4(context, gVar);
                        f4Var2.f30955j = i10 == 1;
                        f4Var = f4Var2;
                    }
                    eVar.zzc(viewGroup, f4Var, "Ads by Google");
                }
            } catch (IllegalArgumentException e10) {
                x.f31085g.f31086a.zzb(viewGroup, new f4(context, g7.g.f26280h), e10.getMessage(), e10.getMessage());
            }
        }
    }
}
