package com.applovin.impl; import android.content.Context; import com.applovin.impl.mediation.MaxErrorImpl; import com.applovin.impl.mediation.ads.a; import com.applovin.impl.sdk.o; import com.applovin.impl.sdk.utils.CollectionUtils; import com.applovin.impl.sdk.utils.JsonUtils; import com.applovin.impl.sdk.utils.StringUtils; import com.applovin.impl.tm; import com.applovin.impl.vi; import com.applovin.impl.xe; import com.applovin.mediation.MaxAdFormat; import com.applovin.mediation.MaxError; import com.applovin.mediation.adapter.MaxAdapterError; import com.applovin.sdk.AppLovinWebViewActivity; import java.util.Collection; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.concurrent.TimeUnit; import org.json.JSONArray; import org.json.JSONObject; /* loaded from: classes.dex */ public class lm extends yl { private final String h; private final MaxAdFormat i; private final Map j; private final Map k; private final Map l; private final JSONArray m; private final Context n; private final a.InterfaceC0026a o; @Override // java.lang.Runnable public void run() { if (com.applovin.impl.sdk.n.a()) { this.c.a(this.b, "Fetching next ad for " + this.i.getLabel() + " ad unit " + this.h); } pb.a(); if (((Boolean) this.a.a(sj.h4)).booleanValue() && yp.j() && com.applovin.impl.sdk.n.a()) { this.c.a(this.b, "User is connected to a VPN"); } this.a.E().a(la.r, this.i, this.h, (MaxError) null); if (((Boolean) this.a.a(sj.Q4)).booleanValue()) { ye R = this.a.R(); we weVar = we.c; R.a(weVar, xe.a(this.h)); R.a(weVar, xe.a(this.i)); } yp.a(this.a, this.b); da D = this.a.D(); D.c(ca.s); ca caVar = ca.g; if (D.b(caVar) == 0) { D.b(caVar, System.currentTimeMillis()); } try { JSONObject g = g(); HashMap hashMap = new HashMap(); if (!((Boolean) this.a.a(sj.D5)).booleanValue() && !((Boolean) this.a.a(sj.B5)).booleanValue()) { hashMap.put("rid", UUID.randomUUID().toString()); } if (!((Boolean) this.a.a(sj.o5)).booleanValue()) { hashMap.put(AppLovinWebViewActivity.INTENT_EXTRA_KEY_SDK_KEY, this.a.b0()); } if (this.a.l0().c()) { hashMap.put("test_mode", "1"); } List b = this.a.l0().b(); String str = this.a.g0().getExtraParameters().get("fan"); if (b != null && !b.isEmpty()) { String join = String.join(",", b); hashMap.put("filter_ad_network", join); if (!this.a.l0().c()) { hashMap.put("fhkZsVqYC7", "1"); } if (this.a.l0().d()) { hashMap.put("force_ad_network", join); } } else if (StringUtils.isValidString(str)) { hashMap.put("filter_ad_network", str); } a(D); a aVar = new a(com.applovin.impl.sdk.network.a.a(this.a).c("POST").a(h()).b(f()).a(e()).b(hashMap).a(g).b(((Boolean) this.a.a(ve.c8)).booleanValue()).a((Object) new JSONObject()).c(((Long) this.a.a(ve.U6)).intValue()).a(((Integer) this.a.a(sj.o3)).intValue()).b(((Long) this.a.a(ve.T6)).intValue()).a(vi.a.a(((Integer) this.a.a(sj.u5)).intValue())).f(true).a(), this.a); aVar.c(ve.R6); aVar.b(ve.S6); this.a.j0().a(aVar); } catch (Throwable th) { if (com.applovin.impl.sdk.n.a()) { this.c.a(this.b, "Unable to fetch ad for Ad Unit ID: " + this.h, th); } a("", 0, th.getMessage()); } } public lm(String str, MaxAdFormat maxAdFormat, Map map, Map map2, Map map3, JSONArray jSONArray, Context context, com.applovin.impl.sdk.j jVar, a.InterfaceC0026a interfaceC0026a) { super("TaskFetchMediatedAd", jVar, str); this.h = str; this.i = maxAdFormat; this.j = map; this.k = map2; this.l = map3; this.m = jSONArray; this.n = context; this.o = interfaceC0026a; } public class a extends dn { public a(com.applovin.impl.sdk.network.a aVar, com.applovin.impl.sdk.j jVar) { super(aVar, jVar); } @Override // com.applovin.impl.dn, com.applovin.impl.d4.e public void a(String str, int i, String str2, JSONObject jSONObject) { lm.this.a(str, i, str2); this.a.E().a("fetchMediatedAd", str, i, CollectionUtils.hashMap("error_message", str2)); } @Override // com.applovin.impl.dn, com.applovin.impl.d4.e public void a(String str, JSONObject jSONObject, int i) { if (i != 200) { lm.this.a(str, i, null); return; } JsonUtils.putLong(jSONObject, "ad_fetch_latency_millis", this.m.a()); JsonUtils.putLong(jSONObject, "ad_fetch_response_size", this.m.b()); HashMap hashMap = new HashMap(6); CollectionUtils.putStringIfValid("url", StringUtils.getHost(str), hashMap); CollectionUtils.putStringIfValid("code", String.valueOf(i), hashMap); CollectionUtils.putStringIfValid("ad_unit_id", lm.this.h, hashMap); CollectionUtils.putStringIfValid("ad_format", lm.this.i.getLabel(), hashMap); CollectionUtils.putStringIfValid("latency_ms", String.valueOf(this.m.a()), hashMap); CollectionUtils.putStringIfValid("response_size", String.valueOf(this.m.b()), hashMap); this.a.E().a(la.s, (Map) hashMap); lm.this.b(jSONObject); } } private String f() { return qe.b(this.a); } private String e() { return qe.a(this.a); } /* JADX INFO: Access modifiers changed from: private */ public void b(JSONObject jSONObject) { try { e4.c(jSONObject, this.a); e4.b(jSONObject, this.a); e4.a(jSONObject, this.a); qe.f(jSONObject, this.a); qe.d(jSONObject, this.a); qe.e(jSONObject, this.a); qe.g(jSONObject, this.a); u0.b(this.a); MaxAdFormat formatFromString = MaxAdFormat.formatFromString(JsonUtils.getString(jSONObject, "ad_format", null)); if (this.i == formatFromString) { a(jSONObject); return; } String label = formatFromString != null ? formatFromString.getLabel() : "UNKNOWN"; String str = "Incorrect format (" + label + ") loaded for (" + this.i.getLabel() + ") ad. Please verify if the ad unit ID (" + this.h + ") is assigned to the correct ad format."; if (yp.a(this.i, formatFromString)) { com.applovin.impl.sdk.n.j(this.b, str); a(jSONObject); return; } q6.a(str, new Object[0]); com.applovin.impl.sdk.n.h(this.b, str); this.o.onAdLoadFailed(this.h, new MaxAdapterError(MaxAdapterError.INVALID_CONFIGURATION, 0, str)); HashMap hashMap = CollectionUtils.hashMap("ad_unit_id", this.h); CollectionUtils.putStringIfValid("name", this.i.getLabel(), hashMap); CollectionUtils.putStringIfValid("details", label, hashMap); this.a.E().a(la.L, "incompatible_ad_format", (Map) hashMap); } catch (Throwable th) { if (com.applovin.impl.sdk.n.a()) { this.c.a(this.b, "Unable to process mediated ad response for ad unit " + this.h, th); } throw new RuntimeException("Unable to process ad: " + th); } } private JSONObject g() { Map a2 = this.a.y().a(null, false, true); a2.putAll(this.l); JSONObject jSONObject = new JSONObject(a2); e(jSONObject); h(jSONObject); f(jSONObject); c(jSONObject); g(jSONObject); d(jSONObject); return jSONObject; } private void a(JSONObject jSONObject) { yl xmVar; if (this.a.a(ve.P7, this.i)) { xmVar = new wm(this.h, this.i, this.j, jSONObject, this.n, this.a, this.o); } else { xmVar = new xm(this.h, this.i, this.j, jSONObject, this.n, this.a, this.o); } yl ylVar = xmVar; long j = JsonUtils.getLong(jSONObject, "process_waterfall_delay_ms", -1L); if (j > 0) { this.a.j0().a(ylVar, tm.b.MEDIATION, j, true); } else { this.a.j0().a(ylVar); } } private void h(JSONObject jSONObject) { JSONArray jSONArray = this.m; if (jSONArray != null) { jSONObject.put("signal_data", jSONArray); } } private Map h() { HashMap hashMap = new HashMap(2); hashMap.put("AppLovin-Ad-Unit-Id", this.h); hashMap.put("AppLovin-Ad-Format", this.i.getLabel()); CollectionUtils.putObjectToStringIfValid("AppLovin-Retry-Attempt", this.k.get("retry_attempt"), hashMap); CollectionUtils.putObjectToStringIfValid("AppLovin-Retry-Delay-Sec", this.k.get("retry_delay_sec"), hashMap); return hashMap; } private void c(JSONObject jSONObject) { JSONObject andResetCustomPostBodyData = this.a.Q().getAndResetCustomPostBodyData(); if (andResetCustomPostBodyData == null || !yp.f(com.applovin.impl.sdk.j.l())) { return; } JsonUtils.putAll(jSONObject, andResetCustomPostBodyData); } private void d(JSONObject jSONObject) { if (((Boolean) this.a.a(sj.Q4)).booleanValue()) { ye R = this.a.R(); JSONObject jSONObject2 = new JSONObject(); JSONObject jSONObject3 = new JSONObject(); we weVar = we.c; JsonUtils.putAll(jSONObject3, (Map) R.a(weVar, xe.a.AD_UNIT_ID)); JsonUtils.putJSONObject(jSONObject2, "arpau", jSONObject3); JSONObject jSONObject4 = new JSONObject(); JsonUtils.putAll(jSONObject4, (Map) R.a(weVar, xe.a.AD_FORMAT)); JsonUtils.putJSONObject(jSONObject2, "arpaf", jSONObject4); JSONObject jSONObject5 = new JSONObject(); JsonUtils.putAll(jSONObject5, (Map) R.a(we.d, xe.a.AD)); JsonUtils.putJSONObject(jSONObject2, "ttdasipa_ms", jSONObject5); JsonUtils.putJSONObject(jSONObject, "mediation_stats", jSONObject2); } } private void f(JSONObject jSONObject) { try { JSONObject jSONObject2 = new JSONObject(); jSONObject2.put("disabled", new JSONArray(this.a.M().a())); jSONObject2.put("installed", af.a(this.a)); jSONObject2.put("initialized", this.a.L().b()); jSONObject2.put("initialized_classnames", new JSONArray((Collection) this.a.L().a())); jSONObject2.put("loaded_classnames", new JSONArray(this.a.M().c())); jSONObject2.put("failed_classnames", new JSONArray(this.a.M().b())); jSONObject.put("adapters_info", jSONObject2); } catch (Exception e) { if (com.applovin.impl.sdk.n.a()) { this.c.a(this.b, "Failed to populate adapter classNames", e); } throw new RuntimeException("Failed to populate classNames: " + e); } } private void e(JSONObject jSONObject) { JSONObject jSONObject2 = new JSONObject(); jSONObject2.put("ad_unit_id", this.h); jSONObject2.put("ad_format", this.i.getLabel()); Map map = CollectionUtils.map(this.k); com.applovin.impl.sdk.o T = this.a.T(); CollectionUtils.putStringIfValid("previous_request_id", T.b(this.h), map); CollectionUtils.putStringIfValid("previous_loaded_request_id", T.a(this.h), map); o.a c = T.c(this.h); if (c != null) { if (Boolean.parseBoolean(this.a.g0().getExtraParameters().get("esc"))) { map.put("previous_winning_network", "APPLOVIN_NETWORK"); map.put("previous_winning_network_name", "AppLovin"); } else { map.put("previous_winning_network", c.a()); map.put("previous_winning_network_name", c.c()); CollectionUtils.putStringIfValid("second_previous_winning_network", c.d(), map); CollectionUtils.putStringIfValid("second_previous_winning_network_name", c.e(), map); } } jSONObject2.put("extra_parameters", CollectionUtils.toJson(map)); jSONObject.put("ad_info", jSONObject2); } private void a(da daVar) { ca caVar = ca.g; long b = daVar.b(caVar); long currentTimeMillis = System.currentTimeMillis(); if (currentTimeMillis - b > TimeUnit.MINUTES.toMillis(((Integer) this.a.a(sj.K3)).intValue())) { daVar.b(caVar, currentTimeMillis); daVar.a(ca.h); daVar.a(ca.i); } } /* JADX INFO: Access modifiers changed from: private */ public void a(String str, int i, String str2) { MaxErrorImpl maxErrorImpl; if (com.applovin.impl.sdk.n.a()) { this.c.b(this.b, "Unable to fetch ad for ad unit " + this.h + ": server returned " + i); } if (i == -800) { this.a.D().c(ca.t); } if (i == -1009) { maxErrorImpl = new MaxErrorImpl(-1009, str2); } else if (i == -1001) { maxErrorImpl = new MaxErrorImpl(-1001, str2); } else if (StringUtils.isValidString(str2)) { maxErrorImpl = new MaxErrorImpl(-1000, str2); } else { maxErrorImpl = new MaxErrorImpl(-1); } HashMap hashMap = new HashMap(5); CollectionUtils.putStringIfValid("url", StringUtils.getHost(str), hashMap); CollectionUtils.putStringIfValid("code", String.valueOf(i), hashMap); CollectionUtils.putStringIfValid("error_message", str2, hashMap); CollectionUtils.putStringIfValid("ad_unit_id", this.h, hashMap); CollectionUtils.putStringIfValid("ad_format", this.i.getLabel(), hashMap); this.a.E().a(la.t, (Map) hashMap); gc.a(this.o, this.h, maxErrorImpl); } private void g(JSONObject jSONObject) { JsonUtils.putObject(jSONObject, "sdk_extra_parameters", new JSONObject(this.a.g0().getExtraParameters())); } }