package com.ironsource.sdk; import android.app.Activity; import android.content.Context; import android.text.TextUtils; import com.ironsource.fn; import com.ironsource.i9; import com.ironsource.mi; import com.ironsource.pb; import com.ironsource.qi; import com.ironsource.rf; import com.ironsource.sdk.controller.e; import com.ironsource.sdk.utils.Logger; import com.ironsource.sdk.utils.SDKUtils; import com.ironsource.wi; import com.ironsource.xf; import com.ironsource.yf; import com.ironsource.zi; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Map; import org.json.JSONObject; /* loaded from: classes4.dex */ public class IronSourceNetwork { static final String a = "IronSourceNetwork"; private static wi b; private static List c = new ArrayList(); private static zi d; private static synchronized void a() throws Exception { synchronized (IronSourceNetwork.class) { if (b == null) { throw new NullPointerException("Call initSDK first"); } } } private static void a(Context context, JSONObject jSONObject, String str, String str2, Map map) throws Exception { if (jSONObject != null) { pb a2 = yf.a(jSONObject); if (a2.a()) { xf.a(a2, yf.a(context, str, str2, map)); } } } public static synchronized void addInitListener(fn fnVar) { synchronized (IronSourceNetwork.class) { zi ziVar = d; if (ziVar == null) { c.add(fnVar); } else if (ziVar.b()) { fnVar.onSuccess(); } else { fnVar.onFail(d.a()); } } } public static synchronized void destroyAd(mi miVar) throws Exception { synchronized (IronSourceNetwork.class) { a(); b.b(miVar); } } public static synchronized e getControllerManager() { e a2; synchronized (IronSourceNetwork.class) { a2 = b.a(); } return a2; } public static String getVersion() { return SDKUtils.getSDKVersion(); } public static synchronized void initSDK(Context context, String str, String str2, Map map) { synchronized (IronSourceNetwork.class) { if (TextUtils.isEmpty(str)) { Logger.e(a, "applicationKey is NULL"); return; } if (b == null) { SDKUtils.setInitSDKParams(map); try { a(context, SDKUtils.getNetworkConfiguration().optJSONObject("events"), str2, str, map); } catch (Exception e) { i9.d().a(e); Logger.e(a, "Failed to init event tracker: " + e.getMessage()); } b = qi.a(context, str, str2); } } } public static synchronized boolean isAdAvailableForInstance(mi miVar) { synchronized (IronSourceNetwork.class) { wi wiVar = b; if (wiVar == null) { return false; } return wiVar.a(miVar); } } public static synchronized void loadAd(mi miVar, Map map) throws Exception { synchronized (IronSourceNetwork.class) { a(); b.a(miVar, map); } } public static synchronized void loadAdView(Activity activity, mi miVar, Map map) throws Exception { synchronized (IronSourceNetwork.class) { a(); b.b(activity, miVar, map); } } public static void onPause(Activity activity) { wi wiVar = b; if (wiVar == null) { return; } wiVar.onPause(activity); } public static void onResume(Activity activity) { wi wiVar = b; if (wiVar == null) { return; } wiVar.onResume(activity); } public static synchronized void release(Activity activity) { synchronized (IronSourceNetwork.class) { wi wiVar = b; if (wiVar == null) { return; } wiVar.a(activity); } } public static synchronized void showAd(Activity activity, mi miVar, Map map) throws Exception { synchronized (IronSourceNetwork.class) { a(); b.a(activity, miVar, map); } } public static synchronized void updateInitFailed(rf rfVar) { synchronized (IronSourceNetwork.class) { try { d = new zi(rfVar); Iterator it = c.iterator(); while (it.hasNext()) { it.next().onFail(rfVar); } c.clear(); } catch (Throwable th) { throw th; } } } public static synchronized void updateInitSucceeded() { synchronized (IronSourceNetwork.class) { try { d = new zi(); Iterator it = c.iterator(); while (it.hasNext()) { it.next().onSuccess(); } c.clear(); } catch (Throwable th) { throw th; } } } }