package com.applovin.impl; import com.applovin.impl.sdk.utils.JsonUtils; import com.applovin.impl.sdk.utils.StringUtils; import com.applovin.sdk.AppLovinAdLoadListener; import java.util.Iterator; import org.json.JSONObject; /* loaded from: classes.dex */ public abstract class zm extends yl { private final AppLovinAdLoadListener h; private final a i; public zm(eq eqVar, AppLovinAdLoadListener appLovinAdLoadListener, com.applovin.impl.sdk.j jVar) { super("TaskProcessVastResponse", jVar); if (eqVar != null) { this.h = appLovinAdLoadListener; this.i = (a) eqVar; return; } throw new IllegalArgumentException("No context specified."); } public es b(String str) { try { return fs.a(str, this.a); } catch (Throwable th) { if (com.applovin.impl.sdk.n.a()) { this.c.a(this.b, "Failed to process VAST response", th); } a(fq.XML_PARSING); return null; } } public void c(String str) { if (str == null) { return; } Iterator it = StringUtils.getRegexMatches(StringUtils.match(str, (String) this.a.a(sj.n5)), 1).iterator(); while (it.hasNext()) { es b2 = b("" + it.next() + ""); if (b2 != null) { this.i.a(b2); } } } public void a(es esVar) { int d2 = this.i.d(); if (com.applovin.impl.sdk.n.a()) { this.c.a(this.b, "Finished parsing XML at depth " + d2); } this.i.a(esVar); if (mq.b(esVar)) { int intValue = ((Integer) this.a.a(sj.U4)).intValue(); if (d2 < intValue) { if (com.applovin.impl.sdk.n.a()) { this.c.a(this.b, "VAST response is wrapper. Resolving..."); } this.a.j0().a(new hn(this.i, this.h, this.a)); return; } if (com.applovin.impl.sdk.n.a()) { this.c.b(this.b, "Reached beyond max wrapper depth of " + intValue); } a(fq.WRAPPER_LIMIT_REACHED); return; } if (mq.a(esVar)) { if (com.applovin.impl.sdk.n.a()) { this.c.a(this.b, "VAST response is inline. Rendering ad..."); } this.a.j0().a(new cn(this.i, this.h, this.a)); return; } if (com.applovin.impl.sdk.n.a()) { this.c.b(this.b, "VAST response is an error"); } a(fq.NO_WRAPPER_RESPONSE); } public static zm a(JSONObject jSONObject, JSONObject jSONObject2, AppLovinAdLoadListener appLovinAdLoadListener, com.applovin.impl.sdk.j jVar) { return new c(new a(jSONObject, jSONObject2, jVar), appLovinAdLoadListener, jVar); } public static zm a(String str, JSONObject jSONObject, JSONObject jSONObject2, AppLovinAdLoadListener appLovinAdLoadListener, com.applovin.impl.sdk.j jVar) { return new b(str, new a(jSONObject, jSONObject2, jVar), appLovinAdLoadListener, jVar); } public static zm a(es esVar, eq eqVar, AppLovinAdLoadListener appLovinAdLoadListener, com.applovin.impl.sdk.j jVar) { return new d(esVar, eqVar, appLovinAdLoadListener, jVar); } public void a(fq fqVar) { if (com.applovin.impl.sdk.n.a()) { this.c.b(this.b, "Failed to process VAST response due to VAST error code " + fqVar); } mq.a(this.i, this.h, fqVar, -6, this.a); } public static final class c extends zm { private final JSONObject j; @Override // java.lang.Runnable public void run() { if (com.applovin.impl.sdk.n.a()) { this.c.a(this.b, "Processing SDK JSON response..."); } String string = JsonUtils.getString(this.j, "xml", null); if (!StringUtils.isValidString(string)) { if (com.applovin.impl.sdk.n.a()) { this.c.b(this.b, "No VAST response received."); } a(fq.NO_WRAPPER_RESPONSE); return; } if (string.length() >= ((Integer) this.a.a(sj.T4)).intValue()) { if (com.applovin.impl.sdk.n.a()) { this.c.b(this.b, "VAST response is over max length"); } a(fq.XML_PARSING); return; } es b = b(string); if (b != null) { a(b); return; } if (com.applovin.impl.sdk.n.a()) { this.c.b(this.b, "Unable to process XML: " + string); } c(string); a(fq.XML_PARSING); } public c(eq eqVar, AppLovinAdLoadListener appLovinAdLoadListener, com.applovin.impl.sdk.j jVar) { super(eqVar, appLovinAdLoadListener, jVar); this.j = eqVar.b(); } } public static final class b extends zm { private final String j; public b(String str, eq eqVar, AppLovinAdLoadListener appLovinAdLoadListener, com.applovin.impl.sdk.j jVar) { super(eqVar, appLovinAdLoadListener, jVar); this.j = str; } @Override // java.lang.Runnable public void run() { es b = b(this.j); if (b != null) { a(b); return; } if (com.applovin.impl.sdk.n.a()) { this.c.b(this.b, "Unable to process XML: " + this.j); } c(this.j); a(fq.XML_PARSING); } } public static final class d extends zm { private final es j; @Override // java.lang.Runnable public void run() { if (com.applovin.impl.sdk.n.a()) { this.c.a(this.b, "Processing VAST Wrapper response..."); } a(this.j); } public d(es esVar, eq eqVar, AppLovinAdLoadListener appLovinAdLoadListener, com.applovin.impl.sdk.j jVar) { super(eqVar, appLovinAdLoadListener, jVar); if (esVar == null) { throw new IllegalArgumentException("No response specified."); } if (eqVar == null) { throw new IllegalArgumentException("No context specified."); } if (appLovinAdLoadListener == null) { throw new IllegalArgumentException("No callback specified."); } this.j = esVar; } } public static final class a extends eq { public a(JSONObject jSONObject, JSONObject jSONObject2, com.applovin.impl.sdk.j jVar) { super(jSONObject, jSONObject2, jVar); } public void a(es esVar) { if (esVar != null) { this.b.add(esVar); return; } throw new IllegalArgumentException("No aggregated vast response specified"); } } }