package com.ironsource; import android.content.Context; import android.graphics.Rect; import android.text.TextUtils; import android.view.View; import android.widget.FrameLayout; import com.ironsource.environment.ContextProvider; import com.ironsource.g2; import com.ironsource.h7; import com.ironsource.mediationsdk.AdapterUtils; import com.ironsource.mediationsdk.ISBannerSize; import com.ironsource.mediationsdk.IronSource; import com.ironsource.mediationsdk.IronSourceBannerLayout; import com.ironsource.mediationsdk.IronSourceSegment; import com.ironsource.mediationsdk.LoadWhileShowSupportState; import com.ironsource.mediationsdk.adunit.adapter.internal.AdapterBaseInterface; import com.ironsource.mediationsdk.adunit.adapter.internal.AdapterSettingsInterface; import com.ironsource.mediationsdk.adunit.adapter.internal.BaseAdAdapter; import com.ironsource.mediationsdk.adunit.adapter.internal.listener.AdapterAdViewListener; import com.ironsource.mediationsdk.adunit.adapter.utility.AdData; import com.ironsource.mediationsdk.logger.IronLog; import com.ironsource.mediationsdk.logger.IronSourceError; import com.ironsource.mediationsdk.model.NetworkSettings; import com.ironsource.mediationsdk.model.Placement; import com.ironsource.mediationsdk.utils.IronSourceConstants; import java.util.List; import java.util.Map; import java.util.concurrent.atomic.AtomicBoolean; import org.json.JSONObject; /* loaded from: classes2.dex */ public class z5 extends h7 implements o1, y5 { private u6 K; private boolean L; private IronSourceBannerLayout M; private View N; private k7 O; private FrameLayout.LayoutParams P; private final AtomicBoolean Q; private final AtomicBoolean R; public class a implements v7 { final /* synthetic */ k7 a; public a(k7 k7Var) { this.a = k7Var; } @Override // com.ironsource.v7 public void a() { ((d6) this.a).Q(); } } public class b implements v7 { final /* synthetic */ k7 a; public b(k7 k7Var) { this.a = k7Var; } @Override // com.ironsource.v7 public void a() { ((d6) this.a).Q(); z5 z5Var = z5.this; z5Var.s.j.j(z5Var.n()); z5.this.Q.set(false); z5.this.W(); IronLog.INTERNAL.verbose("start binding timer after impression, expected interval = " + z5.this.o.i().b() + ", current timestamp = " + System.currentTimeMillis()); z5.this.O().h(); } } public static /* synthetic */ class c { static final /* synthetic */ int[] a; static { int[] iArr = new int[g2.a.values().length]; a = iArr; try { iArr[g2.a.MANUAL_WITH_AUTOMATIC_RELOAD.ordinal()] = 1; } catch (NoSuchFieldError unused) { } try { a[g2.a.MANUAL_WITH_LOAD_ON_SHOW.ordinal()] = 2; } catch (NoSuchFieldError unused2) { } } } public z5(List list, n6 n6Var, String str, lj ljVar, IronSourceSegment ironSourceSegment) { super(new a6(str, list, n6Var), ljVar, ironSourceSegment); this.L = false; this.Q = new AtomicBoolean(true); this.R = new AtomicBoolean(false); this.K = N(); } private void M() { int i = c.a[this.q.b().a().ordinal()]; if (i == 1) { P().a(); } else { if (i != 2) { return; } P().l(); P().m(); O().a(); O().b(); } } private u6 N() { return new u6(this.o.i(), this.o.h(), this); } /* JADX INFO: Access modifiers changed from: private */ public u6 O() { return this.K; } private a7 P() { return (a7) this.q; } private ISBannerSize Q() { IronSourceBannerLayout ironSourceBannerLayout = this.M; if (ironSourceBannerLayout == null || ironSourceBannerLayout.getSize() == null) { return null; } return this.M.getSize().isSmart() ? AdapterUtils.isLargeScreen(ContextProvider.getInstance().getApplicationContext()) ? com.ironsource.mediationsdk.l.a() : ISBannerSize.BANNER : this.M.getSize(); } private boolean S() { IronLog.INTERNAL.verbose(b(this.N + ", " + this.P + ", " + this.O)); return (this.N == null || this.P == null || this.O == null) ? false : true; } private void U() { int i = c.a[this.q.b().a().ordinal()]; if (i == 1) { P().k(); } else { if (i != 2) { return; } P().r(); } } private void V() { int i = c.a[this.q.b().a().ordinal()]; if (i == 1) { P().k(); } else { if (i != 2) { return; } P().q(); } } /* JADX INFO: Access modifiers changed from: private */ public void W() { this.O = null; this.N = null; this.P = null; } private void b(k7 k7Var, View view, FrameLayout.LayoutParams layoutParams) { ((d6) k7Var).R(); com.ironsource.mediationsdk.l.a(this.M, view, layoutParams, new a(k7Var)); } private void c(k7 k7Var, View view, FrameLayout.LayoutParams layoutParams) { if (a(h7.f.READY_TO_SHOW, h7.f.SHOWING)) { this.R.set(false); O().e(); ((d6) k7Var).R(); com.ironsource.mediationsdk.l.a(this.M, view, layoutParams, new b(k7Var)); return; } IronLog.INTERNAL.verbose("wrong state = " + this.p); } public boolean R() { IronLog ironLog; String str; if (!this.M.isShown()) { ironLog = IronLog.INTERNAL; str = "banner or one of its parents are INVISIBLE or GONE"; } else { if (this.M.hasWindowFocus()) { boolean globalVisibleRect = this.M.getGlobalVisibleRect(new Rect()); IronLog.INTERNAL.verbose("visible = " + globalVisibleRect); return globalVisibleRect; } ironLog = IronLog.INTERNAL; str = "banner has no window focus"; } ironLog.verbose(str); return false; } public void T() { IronSourceBannerLayout ironSourceBannerLayout = this.M; if (ironSourceBannerLayout != null) { a(ironSourceBannerLayout); } } @Override // com.ironsource.h7 public LoadWhileShowSupportState a(NetworkSettings networkSettings, AdapterBaseInterface adapterBaseInterface) { return ((AdapterSettingsInterface) adapterBaseInterface).getBannerLoadWhileShowSupportedState(networkSettings); } @Override // com.ironsource.h7 public AdData a(NetworkSettings networkSettings, String str) { return AdData.createAdDataForNetworkAdapter(b(networkSettings), this.o.b(), str, this.M); } @Override // com.ironsource.h7, com.ironsource.w1 public Map a(u1 u1Var) { Map a2 = super.a(u1Var); if (b(this.M)) { com.ironsource.mediationsdk.l.a(a2, this.M.getSize()); } if (this.i != null) { a2.put("placement", n()); } return a2; } @Override // com.ironsource.h7, com.ironsource.xk public void a() { boolean z; IronLog ironLog = IronLog.INTERNAL; ironLog.verbose(i()); try { if (this.M == null) { ironLog.error("mIronSourceBanner is null"); this.s.g.b(IronSourceError.ERROR_BN_RELOAD_SKIP_BANNER_LAYOUT_IS_NULL); return; } if (!R()) { if (this.o.i().a() == g2.a.MANUAL_WITH_AUTOMATIC_RELOAD) { ironLog.verbose("banner is not visible, reload skipped"); this.s.g.b(IronSourceError.ERROR_BN_RELOAD_SKIP_INVISIBLE); } U(); return; } synchronized (this.x) { try { if (a(h7.f.SHOWING, h7.f.READY_TO_LOAD)) { ironLog.verbose("start reload"); z = true; this.L = true; } else { ironLog.error("wrong state = " + this.p); z = false; } } finally { } } if (z) { a(this.M, this.i); } } catch (Throwable th) { i9.d().a(th); this.s.k.c(th.getMessage()); } } @Override // com.ironsource.h7 public void a(int i, String str, boolean z) { if (!v()) { super.a(i, str, z); return; } if (!z) { this.s.g.b(ta.a(this.n), i, str); com.ironsource.mediationsdk.n.a().b(this.o.b(), new IronSourceError(i, str)); } if (v()) { a(h7.f.SHOWING); V(); } } @Override // com.ironsource.h7 public void a(Context context, com.ironsource.mediationsdk.i iVar, l4 l4Var) { if (this.c == null) { IronLog.INTERNAL.error(b("mAuctionHandler is null")); } else { iVar.a(Q()); this.c.a(context, iVar, l4Var); } } @Override // com.ironsource.m2 public void a(k7 k7Var) { IronLog.INTERNAL.verbose(b(k7Var.k())); this.t.f(k7Var.f()); } @Override // com.ironsource.o1 public void a(k7 k7Var, View view, FrameLayout.LayoutParams layoutParams) { IronLog.INTERNAL.verbose("mState = " + this.p); super.e(k7Var); if (this.o.i().a() == g2.a.MANUAL_WITH_AUTOMATIC_RELOAD) { if (!a(h7.f.READY_TO_SHOW, h7.f.SHOWING)) { return; } this.a.a(k7Var); this.a.b(k7Var); b(k7Var, view, layoutParams); P().k(); } else { if (!P().o()) { return; } this.a.b(k7Var); if (this.Q.get()) { c(k7Var, view, layoutParams); } else { this.O = k7Var; this.N = view; this.P = layoutParams; } } this.t.c(k7Var.f()); } public void a(IronSourceBannerLayout ironSourceBannerLayout) { try { if (!b(ironSourceBannerLayout)) { Object[] objArr = new Object[1]; objArr[0] = ironSourceBannerLayout == null ? "banner is null" : "banner is destroyed"; String format = String.format("can't destroy banner - %s", objArr); IronLog.API.error("destroy banner failed - errorMessage = " + format); return; } IronLog.INTERNAL.verbose("destroying banner"); M(); d6 d6Var = (d6) this.a.d(); if (d6Var != null) { this.s.g.a(d6Var.r() != null ? d6Var.r().intValue() : this.C.a(this.o.b())); d6Var.P(); this.a.a(null); this.a.b(null); } com.ironsource.mediationsdk.l.a(ironSourceBannerLayout); this.M = null; this.i = null; this.L = false; if (P().o()) { this.Q.set(true); this.R.set(false); W(); } a(h7.f.READY_TO_LOAD); } catch (Throwable th) { i9.d().a(th); String str = "destroyBanner - exception = " + th.getLocalizedMessage() + " state = " + this.p; IronLog.INTERNAL.error(b(str)); x1 x1Var = this.s; if (x1Var != null) { x1Var.k.f(str); } } } public void a(IronSourceBannerLayout ironSourceBannerLayout, Placement placement) { String format; IronLog.INTERNAL.verbose("placement = " + placement); int i = 510; if (!b(ironSourceBannerLayout)) { Object[] objArr = new Object[1]; objArr[0] = ironSourceBannerLayout == null ? "banner is null" : "banner is destroyed"; format = String.format("can't load banner - %s", objArr); } else if (placement == null || TextUtils.isEmpty(placement.getPlacementName())) { Object[] objArr2 = new Object[1]; objArr2[0] = placement == null ? "placement is null" : "placement name is empty"; format = String.format("can't load banner - %s", objArr2); i = t1.b(this.o.b()); } else if (this.E.b(ContextProvider.getInstance().getApplicationContext(), placement, this.o.b())) { format = String.format("placement %s is capped", placement.getPlacementName()); i = t1.f(this.o.b()); } else { format = null; } if (!TextUtils.isEmpty(format)) { IronLog.API.error(b(format)); a(i, format, false); } else { com.ironsource.mediationsdk.l.b(ironSourceBannerLayout); this.M = ironSourceBannerLayout; this.i = placement; A(); } } @Override // com.ironsource.h7 /* renamed from: b, reason: merged with bridge method [inline-methods] */ public d6 a(NetworkSettings networkSettings, BaseAdAdapter baseAdAdapter, int i, String str, f5 f5Var) { return new d6(this, new i1(IronSource.AD_UNIT.BANNER, this.o.p(), i, this.g, str, this.e, this.f, networkSettings, this.o.o()), baseAdAdapter, this.M, this.i, v(), f5Var, this); } @Override // com.ironsource.h7 public JSONObject b(NetworkSettings networkSettings) { return networkSettings.getBannerSettings(); } @Override // com.ironsource.h7, com.ironsource.j2 public void b(k7 k7Var) { super.b(k7Var); if (P().o()) { if (!this.R.compareAndSet(false, true)) { IronLog.INTERNAL.verbose("Impression already recorded as receive, it can occur from network onAdOpened or from impression timeout timer - loading next ad already in progress"); } else { O().b(); U(); } } } public boolean b(IronSourceBannerLayout ironSourceBannerLayout) { return (ironSourceBannerLayout == null || ironSourceBannerLayout.isDestroyed()) ? false : true; } @Override // com.ironsource.m2 public void c(k7 k7Var) { IronLog.INTERNAL.verbose(b(k7Var.k())); this.t.e(k7Var.f()); } @Override // com.ironsource.m2 public void d(k7 k7Var) { IronLog.INTERNAL.verbose(b(k7Var.k())); this.t.b(k7Var.f()); } @Override // com.ironsource.y5 public void e() { if (!R()) { IronLog.INTERNAL.verbose("banner is not visible, binding skipped"); O().h(); this.s.g.b(IronSourceError.ERROR_BN_BINDING_SKIP_INVISIBLE); } else { if (!S()) { IronLog.INTERNAL.verbose("Cannot bind banner view after interval, the next ad is not ready yet"); this.Q.set(true); return; } IronLog.INTERNAL.verbose("done binding timer, binding view now, current timestamp = " + System.currentTimeMillis()); c(this.O, this.N, this.P); } } @Override // com.ironsource.y5 public void f() { if (!R()) { IronLog.INTERNAL.verbose("banner is not visible, starting the impression timeout timer again"); O().e(); } else if (this.R.compareAndSet(false, true)) { IronLog.INTERNAL.verbose("banner impression timeout reached, reloading banner manually"); U(); this.s.k.b("banner impression timeout reached, reloading banner manually"); } } @Override // com.ironsource.h7 public e2 g() { return new v6(); } @Override // com.ironsource.h7 public void g(k7 k7Var) { } @Override // com.ironsource.h7 public i2 h() { return new a7(this.o.i(), this); } @Override // com.ironsource.h7 public void h(k7 k7Var) { } @Override // com.ironsource.h7 public String l() { return "BN"; } @Override // com.ironsource.h7 public String o() { return IronSourceConstants.OPW_BN_MANAGER_NAME; } @Override // com.ironsource.h7 public boolean v() { return this.L; } }