package com.ironsource; import android.text.TextUtils; import com.ironsource.environment.ContextProvider; import com.ironsource.gs; import com.ironsource.j2; import com.ironsource.lg; import com.ironsource.mediationsdk.IronSource; import com.ironsource.mediationsdk.adunit.adapter.internal.AdapterAdFullScreenInterface; import com.ironsource.mediationsdk.adunit.adapter.internal.BaseAdAdapter; import com.ironsource.mediationsdk.adunit.adapter.internal.listener.AdapterAdListener; import com.ironsource.mediationsdk.adunit.adapter.listener.NetworkInitializationListener; import com.ironsource.mediationsdk.adunit.adapter.utility.AdData; import com.ironsource.mediationsdk.adunit.adapter.utility.AdInfo; import com.ironsource.mediationsdk.adunit.adapter.utility.AdapterErrorType; 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.ErrorBuilder; import com.ironsource.mediationsdk.utils.IronSourceConstants; import com.ironsource.x1; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import org.json.JSONObject; /* loaded from: classes2.dex */ public abstract class k7 implements NetworkInitializationListener, gs.a, w1, AdapterAdListener, lg.b { protected i1 a; protected Listener b; protected BaseAdAdapter c; protected x1 d; protected h e; protected Placement g; protected v2 h; protected JSONObject i; protected String j; protected AdData k; protected Long l; protected ta m; private final f5 o; private final ko p; private AtomicBoolean f = new AtomicBoolean(false); private gs n = new gs(TimeUnit.SECONDS.toMillis(s())); protected final Object q = new Object(); public class a extends yp { public a() { } @Override // com.ironsource.yp public void a() { k7.this.L(); } } public class b extends yp { public b() { } @Override // com.ironsource.yp public void a() { k7.this.K(); } } public class c extends yp { final /* synthetic */ int a; final /* synthetic */ String b; public c(int i, String str) { this.a = i; this.b = str; } @Override // com.ironsource.yp public void a() { k7.this.a(this.a, this.b); } } public class d extends yp { public d() { } @Override // com.ironsource.yp public void a() { k7.this.I(); } } public class e extends yp { final /* synthetic */ AdapterErrorType a; final /* synthetic */ int b; final /* synthetic */ String c; public e(AdapterErrorType adapterErrorType, int i, String str) { this.a = adapterErrorType; this.b = i; this.c = str; } @Override // com.ironsource.yp public void a() { k7.this.a(this.a, this.b, this.c); } } public class f extends yp { public f() { } @Override // com.ironsource.yp public void a() { k7.this.J(); } } public class g extends yp { public g() { } @Override // com.ironsource.yp public void a() { k7.this.H(); } } public enum h { NONE, INIT_IN_PROGRESS, READY_TO_LOAD, LOADING, LOADED, SHOWING, FAILED } /* JADX WARN: Multi-variable type inference failed */ public k7(ko koVar, i1 i1Var, BaseAdAdapter baseAdAdapter, v2 v2Var, f5 f5Var, Listener listener) { this.a = i1Var; this.b = listener; this.d = new x1(i1Var.a(), x1.b.PROVIDER, this); this.h = v2Var; this.i = v2Var.c(); this.c = baseAdAdapter; this.o = f5Var; this.p = koVar; a(h.NONE); } private boolean D() { return this.e == h.INIT_IN_PROGRESS; } private void F() { IronLog.INTERNAL.verbose(d()); a(h.LOADING); a(false); try { this.n.a((gs.a) this); G(); } catch (Throwable th) { i9.d().a(th); String str = "unexpected error while calling adapter.loadAd() - " + th.getMessage() + " - state = " + this.e; IronLog.INTERNAL.error(a(str)); x1 x1Var = this.d; if (x1Var != null) { x1Var.k.f(str); } onAdLoadFailed(AdapterErrorType.ADAPTER_ERROR_TYPE_INTERNAL, 510, str); } } /* JADX INFO: Access modifiers changed from: private */ public void H() { IronLog.INTERNAL.verbose(d()); x1 x1Var = this.d; if (x1Var != null) { x1Var.j.a(j()); } this.b.f(this); } /* JADX INFO: Access modifiers changed from: private */ public void I() { boolean z; IronLog ironLog = IronLog.INTERNAL; ironLog.verbose(d()); gs gsVar = this.n; if (gsVar != null) { gsVar.e(); } synchronized (this.q) { try { h hVar = this.e; z = false; if (hVar == h.LOADING) { long a2 = ta.a(this.m); ironLog.verbose(a("Load duration = " + a2)); if (this.d != null) { if (v()) { this.d.g.a(a2); } else { this.d.g.a(a2, false); } } a(h.LOADED); z = O(); } else if (hVar != h.FAILED) { ironLog.error(a(String.format("unexpected load success for %s, state - %s", k(), this.e))); String format = String.format("unexpected load success, state - %s", this.e); if (this.d != null) { if (v()) { this.d.k.q(format); } else { this.d.k.n(format); } } } } catch (Throwable th) { throw th; } } if (z) { this.b.e(this); } } /* JADX INFO: Access modifiers changed from: private */ public void J() { IronLog.INTERNAL.verbose(d()); a(h.SHOWING); x1 x1Var = this.d; if (x1Var != null) { x1Var.j.g(j()); } this.b.b(this); } /* JADX INFO: Access modifiers changed from: private */ public void K() { IronLog ironLog = IronLog.INTERNAL; ironLog.verbose(d()); if (D()) { gs gsVar = this.n; if (gsVar != null) { gsVar.e(); } a(h.READY_TO_LOAD); F(); return; } if (this.e == h.FAILED) { return; } ironLog.error(a(String.format("unexpected init success for %s, state - %s", k(), this.e))); if (this.d != null) { this.d.k.l(String.format("unexpected init success, state - %s", this.e)); } } /* JADX INFO: Access modifiers changed from: private */ public void L() { long a2 = ta.a(this.m); IronLog ironLog = IronLog.INTERNAL; ironLog.verbose(a("Load duration = " + a2 + ", state = " + this.e + ", isBidder = " + w())); synchronized (this.q) { try { if (!z()) { ironLog.error(a(String.format("unexpected timeout for %s, state - %s, error - %s", k(), this.e, 1025))); if (this.d != null) { this.d.k.s(String.format("unexpected timeout, state - %s, error - %s", this.e, 1025)); } } else { a(h.FAILED); x1 x1Var = this.d; if (x1Var != null) { x1Var.g.a(a2, 1025); this.d.g.a(a2, 1025, "time out"); } this.b.a(ErrorBuilder.buildLoadFailedError("time out"), this); } } catch (Throwable th) { throw th; } } } /* JADX INFO: Access modifiers changed from: private */ public void a(int i, String str) { IronLog ironLog = IronLog.INTERNAL; ironLog.verbose(a("error = " + i + ", " + str)); if (D()) { gs gsVar = this.n; if (gsVar != null) { gsVar.e(); } a(h.FAILED); a(AdapterErrorType.ADAPTER_ERROR_TYPE_INTERNAL, i, str, ta.a(this.m)); this.b.a(new IronSourceError(i, str), this); return; } if (this.e == h.FAILED) { return; } ironLog.error(a(String.format("unexpected init failed for %s, state - %s, error - %s, %s", k(), this.e, Integer.valueOf(i), str))); if (this.d != null) { this.d.k.k(String.format("unexpected init failed, state - %s, error - %s, %s", this.e, Integer.valueOf(i), str)); } } /* JADX INFO: Access modifiers changed from: private */ public void a(AdapterErrorType adapterErrorType, int i, String str) { long a2 = ta.a(this.m); IronLog ironLog = IronLog.INTERNAL; ironLog.verbose(a("Load duration = " + a2 + ", error = " + i + ", " + str)); gs gsVar = this.n; if (gsVar != null) { gsVar.e(); } synchronized (this.q) { h hVar = this.e; if (hVar == h.LOADING) { a(adapterErrorType, i, str, a2); a(h.FAILED); this.b.a(new IronSourceError(i, str), this); return; } if (hVar == h.FAILED) { a(adapterErrorType, i, str, a2); return; } if (hVar == h.LOADED && adapterErrorType == AdapterErrorType.ADAPTER_ERROR_TYPE_AD_EXPIRED) { this.l = Long.valueOf(System.currentTimeMillis()); ironLog.error(a(String.format("ad expired for %s, state = %s", this.h.f(), this.e))); x1 x1Var = this.d; if (x1Var != null) { x1Var.k.a(String.format("ad expired, state = %s", this.e)); } return; } ironLog.error(a(String.format("unexpected load failed for %s, state - %s, error - %s, %s", k(), this.e, Integer.valueOf(i), str))); String format = String.format("unexpected load failed, state - %s, error - %s, %s", this.e, Integer.valueOf(i), str); if (this.d != null) { if (v()) { this.d.k.p(format); } else if (this.a.a() != IronSource.AD_UNIT.REWARDED_VIDEO || this.e != h.SHOWING) { this.d.k.m(format); } } } } private void a(AdapterErrorType adapterErrorType, int i, String str, long j) { if (this.d != null) { if (adapterErrorType == AdapterErrorType.ADAPTER_ERROR_TYPE_NO_FILL) { if (v()) { this.d.g.c(j, i); return; } else { this.d.g.b(j, i); return; } } if (TextUtils.isEmpty(str)) { this.d.g.a(j, i); } else if (v()) { this.d.g.b(j, i, str); } else { this.d.g.a(j, i, str); } } } private boolean b(u1 u1Var) { return new ArrayList(Arrays.asList(u1.LOAD_AD, u1.LOAD_AD_SUCCESS, u1.LOAD_AD_FAILED, u1.LOAD_AD_FAILED_WITH_REASON, u1.LOAD_AD_NO_FILL, u1.RELOAD_AD, u1.RELOAD_AD_SUCCESS, u1.RELOAD_AD_FAILED_WITH_REASON, u1.RELOAD_AD_NO_FILL, u1.DESTROY_AD, u1.AD_PRESENT_SCREEN, u1.AD_DISMISS_SCREEN, u1.AD_LEFT_APPLICATION, u1.AD_OPENED, u1.AD_CLOSED, u1.SHOW_AD, u1.SHOW_AD_FAILED, u1.AD_CLICKED, u1.AD_REWARDED)).contains(u1Var); } private int o() { return 1; } private int s() { f5 f5Var = this.o; if (f5Var == null) { return this.a.f(); } Integer e2 = f5Var.e(); int f2 = (e2 == null || e2.intValue() <= 0) ? this.a.f() : e2.intValue(); IronLog.INTERNAL.verbose(a("Load timeout for " + this.o.c() + " - " + f2 + " seconds")); return f2; } public AtomicBoolean A() { return this.f; } public boolean B() { return y(); } public boolean C() { return this.e == h.SHOWING; } /* JADX WARN: Type inference failed for: r1v16, types: [com.ironsource.mediationsdk.adunit.adapter.internal.AdapterBaseInterface] */ public void E() { IronLog ironLog = IronLog.INTERNAL; ironLog.verbose(d()); f5 i = i(); String j = i.j(); Map a2 = hj.a(i.a()); a2.put("adUnit", this.a.a()); b(j); try { boolean z = false; if (v()) { this.d.g.a(); } else { this.d.g.a(false); } this.l = null; this.m = new ta(); this.k = a(j, a2); synchronized (this.q) { if (this.e != h.NONE) { z = true; } else { a(h.INIT_IN_PROGRESS); } } if (z) { String str = "loadAd - incorrect state while loading, state = " + this.e; ironLog.error(a(str)); this.d.k.f(str); onInitFailed(t1.c(this.a.a()), str); return; } this.n.a((gs.a) this); ?? networkAdapter = this.c.getNetworkAdapter(); if (networkAdapter != 0) { networkAdapter.init(this.k, ContextProvider.getInstance().getApplicationContext(), this); return; } String str2 = "loadAd - network adapter not available " + k(); ironLog.error(a(str2)); onInitFailed(t1.c(this.a.a()), str2); } catch (Throwable th) { i9.d().a(th); String str3 = "loadAd - exception = " + th.getLocalizedMessage(); IronLog.INTERNAL.error(a(str3)); x1 x1Var = this.d; if (x1Var != null) { x1Var.k.f(str3); } onInitFailed(t1.c(this.a.a()), str3); } } public void G() { Object obj = this.c; if (obj instanceof AdapterAdFullScreenInterface) { ((AdapterAdFullScreenInterface) obj).loadAd(this.k, ContextProvider.getInstance().getCurrentActiveActivity(), this); } else { IronLog.INTERNAL.error(a("adapter not instance of AdapterAdFullScreenInterface")); } } public void M() { synchronized (this) { BaseAdAdapter baseAdAdapter = this.c; if (baseAdAdapter != null) { try { baseAdAdapter.releaseMemory(); this.c = null; } catch (Exception e2) { i9.d().a(e2); String str = "Exception while calling adapter.releaseMemory() from " + this.h.f() + " - " + e2.getMessage() + " - state = " + this.e; IronLog.INTERNAL.error(a(str)); x1 x1Var = this.d; if (x1Var != null) { x1Var.k.f(str); } } } x1 x1Var2 = this.d; if (x1Var2 != null) { x1Var2.f(); this.d = null; } gs gsVar = this.n; if (gsVar != null) { gsVar.d(); this.n = null; } } } public void N() { IronLog.INTERNAL.verbose(d()); x1 x1Var = this.d; if (x1Var != null) { x1Var.j.a(); } } public boolean O() { return true; } public AdData a(String str, Map map) { return new AdData(str, q(), a(map)); } public String a(String str) { String str2 = this.a.a().name() + " - " + k() + " - state = " + this.e; if (TextUtils.isEmpty(str)) { return str2; } return str2 + " - " + str; } /* JADX WARN: Type inference failed for: r2v16, types: [com.ironsource.mediationsdk.adunit.adapter.internal.AdapterBaseInterface] */ /* JADX WARN: Type inference failed for: r2v17, types: [com.ironsource.mediationsdk.adunit.adapter.internal.AdapterBaseInterface] */ public Map a(u1 u1Var) { HashMap hashMap = new HashMap(); try { BaseAdAdapter baseAdAdapter = this.c; hashMap.put(IronSourceConstants.EVENTS_PROVIDER_ADAPTER_VERSION, baseAdAdapter != null ? baseAdAdapter.getNetworkAdapter().getAdapterVersion() : ""); BaseAdAdapter baseAdAdapter2 = this.c; hashMap.put(IronSourceConstants.EVENTS_PROVIDER_SDK_VERSION, baseAdAdapter2 != null ? baseAdAdapter2.getNetworkAdapter().getNetworkSDKVersion() : ""); } catch (Exception e2) { i9.d().a(e2); IronLog.INTERNAL.error(a("could not get adapter version for event data" + k())); } hashMap.put("spId", this.h.i()); hashMap.put(IronSourceConstants.EVENTS_PROVIDER, this.h.a()); hashMap.put("instanceType", Integer.valueOf(l())); hashMap.put(IronSourceConstants.EVENTS_PROGRAMMATIC, Integer.valueOf(o())); if (!TextUtils.isEmpty(this.j)) { hashMap.put("dynamicDemandSource", this.j); } hashMap.put("sessionDepth", r()); if (this.a.e() != null && this.a.e().length() > 0) { hashMap.put("genericParams", this.a.e()); } if (!TextUtils.isEmpty(this.a.c())) { hashMap.put("auctionId", this.a.c()); } if (b(u1Var)) { hashMap.put(IronSourceConstants.AUCTION_TRIALS, Integer.valueOf(this.a.d())); if (!TextUtils.isEmpty(this.a.b())) { hashMap.put(IronSourceConstants.AUCTION_FALLBACK, this.a.b()); } } if (!TextUtils.isEmpty(this.a.g().getCustomNetwork())) { hashMap.put(IronSourceConstants.EVENTS_CUSTOM_NETWORK_FIELD, this.a.g().getCustomNetwork()); } return hashMap; } public Map a(Map map) { if (map == null) { map = new HashMap<>(); } map.put("userId", this.a.i()); return map; } @Override // com.ironsource.gs.a public void a() { if (this.p.c()) { this.p.a(new a()); } else { L(); } } public void a(h hVar) { IronLog.INTERNAL.verbose(d()); this.e = hVar; } public void a(boolean z) { this.f.set(z); } @Override // com.ironsource.lg.b public int b() { return this.h.e(); } public void b(String str) { this.j = com.ironsource.mediationsdk.d.b().c(str); } @Override // com.ironsource.lg.b public String c() { return this.h.f(); } public String d() { return a((String) null); } public Long e() { return this.l; } public AdInfo f() { return new AdInfo(this.o.a(j())); } public IronSource.AD_UNIT g() { return this.a.a(); } public String h() { return this.a.c(); } public f5 i() { return this.o; } public String j() { Placement placement = this.g; return placement == null ? "" : placement.getPlacementName(); } public String k() { return String.format("%s %s", c(), Integer.valueOf(hashCode())); } public int l() { return this.h.d(); } public String m() { return this.h.h().isMultipleInstances() ? this.h.h().getProviderTypeForReflection() : this.h.f(); } public String n() { return this.h.g(); } @Override // com.ironsource.mediationsdk.adunit.adapter.internal.listener.AdapterAdListener public void onAdClicked() { if (this.p.c()) { this.p.a(new g()); } else { H(); } } @Override // com.ironsource.mediationsdk.adunit.adapter.internal.listener.AdapterAdListener public void onAdLoadFailed(AdapterErrorType adapterErrorType, int i, String str) { if (this.p.c()) { this.p.a(new e(adapterErrorType, i, str)); } else { a(adapterErrorType, i, str); } } @Override // com.ironsource.mediationsdk.adunit.adapter.internal.listener.AdapterAdListener public void onAdLoadSuccess() { if (this.p.c()) { this.p.a(new d()); } else { I(); } } public void onAdOpened() { if (this.p.c()) { this.p.a(new f()); } else { J(); } } @Override // com.ironsource.mediationsdk.adunit.adapter.listener.NetworkInitializationListener public void onInitFailed(int i, String str) { if (this.p.c()) { this.p.a(new c(i, str)); } else { a(i, str); } } @Override // com.ironsource.mediationsdk.adunit.adapter.listener.NetworkInitializationListener public void onInitSuccess() { if (this.p.c()) { this.p.a(new b()); } else { K(); } } public NetworkSettings p() { return this.a.g(); } public Map q() { HashMap hashMap = new HashMap(); hashMap.putAll(hj.a(this.i)); return hashMap; } public Integer r() { i1 i1Var = this.a; if (i1Var != null) { return Integer.valueOf(i1Var.h()); } return null; } public h t() { return this.e; } public ko u() { return this.p; } public boolean v() { return false; } public boolean w() { return this.h.j(); } public boolean x() { return this.e == h.FAILED; } public boolean y() { return this.e == h.LOADED; } public boolean z() { h hVar = this.e; return hVar == h.INIT_IN_PROGRESS || hVar == h.LOADING; } }