package com.ironsource; import android.content.Context; import com.ironsource.mediationsdk.logger.IronLog; import com.ironsource.sdk.utils.IronSourceStorageUtils; import com.ironsource.sdk.utils.Logger; import com.ironsource.v8; import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes2.dex */ public class pf implements u2 { private static final String b = "pf"; private static pf c; private final Map a = Collections.synchronizedMap(new HashMap()); public class a implements Runnable { final /* synthetic */ of a; final /* synthetic */ Context b; final /* synthetic */ String c; public a(of ofVar, Context context, String str) { this.a = ofVar; this.b = context; this.c = str; } @Override // java.lang.Runnable public void run() { pf.this.a.put(this.c, new jf(this.a, this.b)); } } private hf a(JSONObject jSONObject) { try { JSONObject jSONObject2 = new JSONObject(jSONObject.getString(v8.h.O)); String obj = jSONObject2.get("height").toString(); String obj2 = jSONObject2.get("width").toString(); return new hf(Integer.parseInt(obj2), Integer.parseInt(obj), jSONObject2.get("label").toString()); } catch (Exception e) { i9.d().a(e); return new hf(); } } public static synchronized pf a() { pf pfVar; synchronized (pf.class) { try { if (c == null) { c = new pf(); } pfVar = c; } catch (Throwable th) { throw th; } } return pfVar; } private hf b(JSONObject jSONObject) { hf hfVar = new hf(); try { return a(jSONObject); } catch (Exception e) { i9.d().a(e); IronLog.INTERNAL.error(e.toString()); return hfVar; } } private boolean d(JSONObject jSONObject) { return jSONObject.optBoolean(v8.h.s0); } @Override // com.ironsource.u2 public hg a(String str) { if (str.isEmpty() || !this.a.containsKey(str)) { return null; } return this.a.get(str); } public void a(kf kfVar, JSONObject jSONObject, Context context, String str, String str2) throws Exception { String string = jSONObject.getString("adViewId"); if (string.isEmpty()) { Logger.i(b, "loadWithUrl fail - adViewId is empty"); throw new Exception("adViewId is empty"); } hf b2 = b(jSONObject); if (this.a.containsKey(string)) { Logger.i(b, "sendMessageToAd fail - collection already contain adViewId"); throw new Exception("collection already contain adViewId"); } of ofVar = new of(kfVar, context, string, b2); ofVar.e(IronSourceStorageUtils.getNetworkStorageDir(context)); ofVar.b(jSONObject, str, str2); if (d(jSONObject)) { ve.a.d(new a(ofVar, context, string)); } else { this.a.put(string, ofVar); } } public void a(JSONObject jSONObject, String str, String str2) throws Exception { String string = jSONObject.getString("adViewId"); if (string.isEmpty()) { Logger.i(b, "removeAdView fail - adViewId is empty"); throw new Exception("adViewId is empty"); } if (!this.a.containsKey(string)) { Logger.i(b, "removeAdView fail - collection does not contain adViewId"); throw new Exception("collection does not contain adViewId"); } hg hgVar = this.a.get(string); if (hgVar != null) { hgVar.a(jSONObject, str, str2); } } public void b(JSONObject jSONObject, String str, String str2) throws Exception { String string = jSONObject.getString("adViewId"); if (string.isEmpty()) { Logger.i(b, "performWebViewAction fail - adViewId is empty"); throw new Exception("adViewId is empty"); } if (!this.a.containsKey(string)) { Logger.i(b, "performWebViewAction fail - collection does not contain adViewId"); throw new Exception("collection does not contain adViewId"); } hg hgVar = this.a.get(string); String string2 = jSONObject.getString(v8.h.v0); if (hgVar != null) { hgVar.a(string2, str, str2); } } public String c(JSONObject jSONObject) throws JSONException { return (jSONObject == null || !jSONObject.has("adViewId")) ? (jSONObject == null || !jSONObject.has("params")) ? "" : new JSONObject(jSONObject.getString("params")).getString("adViewId") : jSONObject.getString("adViewId"); } public void c(JSONObject jSONObject, String str, String str2) throws Exception { String string = jSONObject.getString("adViewId"); if (string.isEmpty()) { Logger.i(b, "removeAdView fail - adViewId is empty"); throw new Exception("adViewId is empty"); } if (!this.a.containsKey(string)) { Logger.i(b, "removeAdView fail - collection does not contain adViewId"); throw new Exception("collection does not contain adViewId"); } hg hgVar = this.a.get(string); this.a.remove(string); if (hgVar != null) { hgVar.a(str, str2); } } public void d(JSONObject jSONObject, String str, String str2) throws Exception { String string = new JSONObject(jSONObject.getString("params")).getString("adViewId"); if (string.isEmpty()) { Logger.i(b, "sendMessageToAd fail - adViewId is empty"); throw new Exception("adViewId is empty"); } if (!this.a.containsKey(string)) { Logger.i(b, "sendMessageToAd fail - collection does not contain adViewId"); throw new Exception("collection does not contain adViewId"); } hg hgVar = this.a.get(string); if (hgVar != null) { hgVar.c(jSONObject, str, str2); } } }