package com.applovin.impl.mediation; import android.content.Context; import android.os.SystemClock; import com.applovin.impl.fm; import com.applovin.impl.gc; import com.applovin.impl.ge; import com.applovin.impl.lm; import com.applovin.impl.mediation.ads.a; import com.applovin.impl.mediation.d; import com.applovin.impl.sdk.j; import com.applovin.impl.sdk.n; import com.applovin.impl.sdk.utils.CollectionUtils; import com.applovin.impl.sdk.utils.StringUtils; import com.applovin.impl.sj; import com.applovin.impl.tm; import com.applovin.impl.ve; import com.applovin.impl.yl; import com.applovin.impl.yp; import com.applovin.mediation.MaxAd; import com.applovin.mediation.MaxAdFormat; import com.applovin.mediation.MaxError; import com.applovin.sdk.AppLovinSdkUtils; import com.mbridge.msdk.mbsignalcommon.commonwebview.ToolBar; import java.lang.ref.WeakReference; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import org.json.JSONArray; /* loaded from: classes2.dex */ public class d { private final j a; private final Map b = new HashMap(4); private final Object c = new Object(); private final Map d = new HashMap(4); private final Object e = new Object(); private final Map f = new HashMap(); private final Object g = new Object(); public class a implements fm.b { final /* synthetic */ long a; final /* synthetic */ Map b; final /* synthetic */ String c; final /* synthetic */ MaxAdFormat d; final /* synthetic */ Map e; final /* synthetic */ Map f; final /* synthetic */ Context g; final /* synthetic */ a.InterfaceC0026a h; public a(long j, Map map, String str, MaxAdFormat maxAdFormat, Map map2, Map map3, Context context, a.InterfaceC0026a interfaceC0026a) { this.a = j; this.b = map; this.c = str; this.d = maxAdFormat; this.e = map2; this.f = map3; this.g = context; this.h = interfaceC0026a; } @Override // com.applovin.impl.fm.b public void a(JSONArray jSONArray) { this.b.put("sct_ms", Long.valueOf(SystemClock.elapsedRealtime() - this.a)); this.b.put("calfc", Integer.valueOf(d.this.b(this.c))); lm lmVar = new lm(this.c, this.d, this.e, this.f, this.b, jSONArray, this.g, d.this.a, this.h); if (((Boolean) d.this.a.a(ve.T7)).booleanValue()) { d.this.a.j0().a((yl) lmVar, tm.b.MEDIATION); } else { d.this.a.j0().a(lmVar); } } } public enum b { PUBLISHER_INITIATED("publisher_initiated"), SEQUENTIAL_OR_PRECACHE("sequential_or_precache"), REFRESH(ToolBar.REFRESH), EXPONENTIAL_RETRY("exponential_retry"), EXPIRED("expired"), NATIVE_AD_PLACER("native_ad_placer"); private final String a; b(String str) { this.a = str; } public String b() { return this.a; } } public static class c implements a.InterfaceC0026a { private final j a; private final WeakReference b; private final d c; private final C0027d d; private final MaxAdFormat f; private final Map g; private final Map h; private final Map i; private final int j; private long k; private long l; public /* synthetic */ c(Map map, Map map2, Map map3, C0027d c0027d, MaxAdFormat maxAdFormat, long j, long j2, d dVar, j jVar, Context context, a aVar) { this(map, map2, map3, c0027d, maxAdFormat, j, j2, dVar, jVar, context); } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void a(int i, String str) { this.h.put("retry_delay_sec", Integer.valueOf(i)); this.h.put("retry_attempt", Integer.valueOf(this.d.d)); Context context = (Context) this.b.get(); if (context == null) { context = j.l(); } Context context2 = context; this.i.put("art", b.EXPONENTIAL_RETRY.b()); this.i.put("era", Integer.valueOf(this.d.d)); this.l = System.currentTimeMillis(); this.c.a(str, this.f, this.g, this.h, this.i, context2, this); } @Override // com.applovin.mediation.MaxAdListener public void onAdClicked(MaxAd maxAd) { } @Override // com.applovin.mediation.MaxAdListener public void onAdDisplayFailed(MaxAd maxAd, MaxError maxError) { } @Override // com.applovin.mediation.MaxAdListener public void onAdDisplayed(MaxAd maxAd) { } @Override // com.applovin.mediation.MaxAdListener public void onAdHidden(MaxAd maxAd) { throw new IllegalStateException("Wrong callback invoked for ad: " + maxAd); } @Override // com.applovin.mediation.MaxAdListener public void onAdLoadFailed(final String str, MaxError maxError) { this.c.c(str); if (((Boolean) this.a.a(ve.H7)).booleanValue() && this.d.c.get()) { this.a.J(); if (n.a()) { this.a.J().a("MediationAdLoadManager", "Ad failed to load but its load state was destroyed"); return; } return; } long elapsedRealtime = SystemClock.elapsedRealtime() - this.k; MaxAdWaterfallInfoImpl maxAdWaterfallInfoImpl = (MaxAdWaterfallInfoImpl) maxError.getWaterfall(); if (maxAdWaterfallInfoImpl != null) { this.a.Q().processWaterfallInfoPostback(str, this.f, maxAdWaterfallInfoImpl, maxError, this.l, elapsedRealtime); } boolean z = maxError.getCode() == -5603 && yp.c(this.a) && ((Boolean) this.a.a(sj.s6)).booleanValue(); if (this.a.a(ve.G7, this.f) && this.d.d < this.j && !z) { C0027d.f(this.d); final int pow = (int) Math.pow(2.0d, this.d.d); AppLovinSdkUtils.runOnUiThreadDelayed(new Runnable() { // from class: com.applovin.impl.mediation.d$c$$ExternalSyntheticLambda0 @Override // java.lang.Runnable public final void run() { d.c.this.a(pow, str); } }, TimeUnit.SECONDS.toMillis(pow)); return; } this.d.d = 0; this.d.b.set(false); if (this.d.e != null) { MaxErrorImpl maxErrorImpl = (MaxErrorImpl) maxError; maxErrorImpl.setLoadTag(this.d.a); maxErrorImpl.setRequestLatencyMillis(elapsedRealtime); gc.a(this.d.e, str, maxError); this.d.e = null; } } @Override // com.applovin.mediation.MaxAdListener public void onAdLoaded(MaxAd maxAd) { if (((Boolean) this.a.a(ve.H7)).booleanValue() && this.d.c.get()) { this.a.J(); if (n.a()) { this.a.J().a("MediationAdLoadManager", "Ad loaded but its load state was destroyed"); } this.a.Q().destroyAd(maxAd); return; } ge geVar = (ge) maxAd; geVar.i(this.d.a); geVar.a(SystemClock.elapsedRealtime() - this.k); MaxAdWaterfallInfoImpl maxAdWaterfallInfoImpl = (MaxAdWaterfallInfoImpl) geVar.getWaterfall(); if (maxAdWaterfallInfoImpl != null) { this.a.Q().processWaterfallInfoPostback(geVar.getAdUnitId(), this.f, maxAdWaterfallInfoImpl, null, this.l, geVar.getRequestLatencyMillis()); } this.c.a(maxAd.getAdUnitId()); this.d.d = 0; if (this.d.e == null) { this.c.a(geVar); this.d.b.set(false); return; } geVar.A().c().a(this.d.e); this.d.e.onAdLoaded(geVar); if (geVar.Q().endsWith("load")) { this.d.e.onAdRevenuePaid(geVar); } this.d.e = null; if ((!this.a.c(ve.E7).contains(maxAd.getAdUnitId()) && !this.a.a(ve.D7, maxAd.getFormat())) || this.a.l0().c() || this.a.l0().d()) { this.d.b.set(false); return; } Context context = (Context) this.b.get(); if (context == null) { context = j.l(); } Context context2 = context; this.k = SystemClock.elapsedRealtime(); this.l = System.currentTimeMillis(); this.i.put("art", b.SEQUENTIAL_OR_PRECACHE.b()); this.c.a(maxAd.getAdUnitId(), maxAd.getFormat(), this.g, this.h, this.i, context2, this); } @Override // com.applovin.mediation.MaxAdRequestListener public void onAdRequestStarted(String str) { } @Override // com.applovin.mediation.MaxAdRevenueListener public void onAdRevenuePaid(MaxAd maxAd) { } private c(Map map, Map map2, Map map3, C0027d c0027d, MaxAdFormat maxAdFormat, long j, long j2, d dVar, j jVar, Context context) { this.a = jVar; this.b = new WeakReference(context); this.c = dVar; this.d = c0027d; this.f = maxAdFormat; this.h = map2; this.g = map; this.i = map3; this.k = j; this.l = j2; if (CollectionUtils.getBoolean(map2, "disable_auto_retries")) { this.j = -1; } else if (maxAdFormat.isAdViewAd() && CollectionUtils.getBoolean(map2, "auto_refresh_stopped")) { this.j = Math.min(2, ((Integer) jVar.a(ve.F7)).intValue()); } else { this.j = ((Integer) jVar.a(ve.F7)).intValue(); } } } /* renamed from: com.applovin.impl.mediation.d$d, reason: collision with other inner class name */ public static class C0027d { private final String a; private final AtomicBoolean b; private final AtomicBoolean c; private int d; private volatile a.InterfaceC0026a e; public /* synthetic */ C0027d(String str, a aVar) { this(str); } public static /* synthetic */ int f(C0027d c0027d) { int i = c0027d.d; c0027d.d = i + 1; return i; } private C0027d(String str) { this.b = new AtomicBoolean(); this.c = new AtomicBoolean(); this.a = str; } } public d(j jVar) { this.a = jVar; } private String b(String str, String str2) { String str3; StringBuilder sb = new StringBuilder(); sb.append(str); if (str2 != null) { str3 = "-" + str2; } else { str3 = ""; } sb.append(str3); return sb.toString(); } public void c(String str, String str2) { synchronized (this.c) { String b2 = b(str, str2); a(str, str2).c.set(true); this.b.remove(b2); } } public boolean d(String str) { boolean z; synchronized (this.e) { z = this.d.get(str) != null; } return z; } public int b(String str) { int intValue; synchronized (this.g) { try { Integer num = (Integer) this.f.get(str); intValue = num != null ? num.intValue() : 0; } catch (Throwable th) { throw th; } } return intValue; } public void c(String str) { synchronized (this.g) { try { this.a.J(); if (n.a()) { this.a.J().a("MediationAdLoadManager", "Incrementing ad load failures count for ad unit ID: " + str); } Integer num = (Integer) this.f.get(str); if (num == null) { num = 0; } this.f.put(str, Integer.valueOf(num.intValue() + 1)); } catch (Throwable th) { throw th; } } } private ge e(String str) { ge geVar; synchronized (this.e) { geVar = (ge) this.d.get(str); this.d.remove(str); } return geVar; } /* JADX INFO: Access modifiers changed from: private */ public void a(ge geVar) { synchronized (this.e) { try { if (this.d.containsKey(geVar.getAdUnitId())) { n.h("AppLovinSdk", "Ad in cache already: " + geVar.getAdUnitId()); } this.d.put(geVar.getAdUnitId(), geVar); } catch (Throwable th) { throw th; } } } public void a(String str, String str2, MaxAdFormat maxAdFormat, b bVar, Map map, Map map2, Context context, a.InterfaceC0026a interfaceC0026a) { ge e = (this.a.l0().d() || yp.f(j.l())) ? null : e(str); if (e != null) { e.i(str2); e.A().c().a(interfaceC0026a); interfaceC0026a.onAdLoaded(e); if (e.Q().endsWith("load")) { interfaceC0026a.onAdRevenuePaid(e); } } C0027d a2 = a(str, str2); if (!a2.b.compareAndSet(false, true)) { if (a2.e != null && a2.e != interfaceC0026a) { n.j("MediationAdLoadManager", "Attempting to load ad for same ad unit id (" + str + ") while another ad load is already in progress!"); } a2.e = interfaceC0026a; return; } if (e == null) { a2.e = interfaceC0026a; } Map synchronizedMap = Collections.synchronizedMap(new HashMap()); synchronizedMap.put("art", bVar.b()); if (StringUtils.isValidString(str2)) { synchronizedMap.put("alt", str2); } a(str, maxAdFormat, map, map2, synchronizedMap, context, new c(map, map2, synchronizedMap, a2, maxAdFormat, SystemClock.elapsedRealtime(), System.currentTimeMillis(), this, this.a, context, null)); } /* JADX INFO: Access modifiers changed from: private */ public void a(String str, MaxAdFormat maxAdFormat, Map map, Map map2, Map map3, Context context, a.InterfaceC0026a interfaceC0026a) { this.a.j0().a((yl) new fm(str, maxAdFormat, map, context, this.a, new a(SystemClock.elapsedRealtime(), map3, str, maxAdFormat, map, map2, context, interfaceC0026a)), tm.b.MEDIATION); } private C0027d a(String str, String str2) { C0027d c0027d; synchronized (this.c) { try { String b2 = b(str, str2); c0027d = (C0027d) this.b.get(b2); if (c0027d == null) { c0027d = new C0027d(str2, null); this.b.put(b2, c0027d); } } catch (Throwable th) { throw th; } } return c0027d; } /* JADX INFO: Access modifiers changed from: private */ public void a(String str) { synchronized (this.g) { try { this.a.J(); if (n.a()) { this.a.J().a("MediationAdLoadManager", "Clearing ad load failures count for ad unit ID: " + str); } this.f.remove(str); } catch (Throwable th) { throw th; } } } }