package com.applovin.impl.mediation; import android.text.TextUtils; import com.applovin.impl.ge; import com.applovin.impl.pe; import com.applovin.impl.sdk.j; import com.applovin.impl.sdk.n; import com.applovin.impl.sdk.utils.JsonUtils; import com.applovin.mediation.MaxAdFormat; import com.applovin.mediation.adapter.MaxAdapter; import com.applovin.mediation.adapters.MediationAdapterBase; import com.applovin.sdk.AppLovinSdk; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.util.Map; import java.util.Set; import org.json.JSONObject; /* loaded from: classes2.dex */ public class f { private final j b; private final n c; private final Map a = Collections.synchronizedMap(new HashMap(16)); private final Object d = new Object(); private final Map e = new HashMap(); private final Set f = new HashSet(); private final Object g = new Object(); private final Set h = new HashSet(); public f(j jVar) { if (jVar == null) { throw new IllegalArgumentException("No sdk specified"); } this.b = jVar; this.c = jVar.J(); } public Collection b() { Set unmodifiableSet; synchronized (this.d) { unmodifiableSet = Collections.unmodifiableSet(this.f); } return unmodifiableSet; } public Collection c() { Set unmodifiableSet; synchronized (this.d) { try { HashSet hashSet = new HashSet(this.e.size()); Iterator it = this.e.values().iterator(); while (it.hasNext()) { hashSet.add(((Class) it.next()).getName()); } unmodifiableSet = Collections.unmodifiableSet(hashSet); } catch (Throwable th) { throw th; } } return unmodifiableSet; } public void a(String str, String str2, ge geVar) { synchronized (this.g) { try { this.b.J(); if (n.a()) { this.b.J().b("MediationAdapterManager", "Adding " + str + " to list of disabled adapters."); } this.h.add(new a(str, str2, geVar, this.b)); } catch (Throwable th) { throw th; } } } public static class a { private final String a; private final String b; private final MaxAdFormat c; private final JSONObject d; public JSONObject a() { return this.d; } public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } a aVar = (a) obj; if (!this.a.equals(aVar.a) || !this.b.equals(aVar.b)) { return false; } MaxAdFormat maxAdFormat = this.c; MaxAdFormat maxAdFormat2 = aVar.c; return maxAdFormat == null ? maxAdFormat2 == null : maxAdFormat.equals(maxAdFormat2); } public int hashCode() { int hashCode = ((this.a.hashCode() * 31) + this.b.hashCode()) * 31; MaxAdFormat maxAdFormat = this.c; return hashCode + (maxAdFormat != null ? maxAdFormat.hashCode() : 0); } public String toString() { return "DisabledAdapterInfo{className='" + this.a + "', operationTag='" + this.b + "', format=" + this.c + '}'; } public a(String str, String str2, ge geVar, j jVar) { this.a = str; this.b = str2; JSONObject jSONObject = new JSONObject(); this.d = jSONObject; JsonUtils.putString(jSONObject, "class", str); JsonUtils.putString(jSONObject, "operation", str2); if (geVar == null) { this.c = null; } else { this.c = geVar.getFormat(); JsonUtils.putString(jSONObject, "format", geVar.getFormat().getLabel()); } } } public g a(pe peVar) { return a(peVar, false); } public g a(pe peVar, boolean z) { Class a2; g gVar; if (peVar != null) { String c = peVar.c(); String b = peVar.b(); if (TextUtils.isEmpty(c)) { if (n.a()) { this.c.b("MediationAdapterManager", "No adapter name provided for " + b + ", not loading the adapter "); } return null; } if (TextUtils.isEmpty(b)) { if (n.a()) { this.c.b("MediationAdapterManager", "Unable to find default className for '" + c + "'"); } return null; } if (z && (gVar = (g) this.a.get(b)) != null) { return gVar; } synchronized (this.d) { try { if (!this.f.contains(b)) { if (this.e.containsKey(b)) { a2 = (Class) this.e.get(b); } else { a2 = a(b); if (a2 == null) { if (n.a()) { this.c.k("MediationAdapterManager", "Adapter " + c + " could not be loaded, class " + b + " not found"); } this.f.add(b); return null; } } g a3 = a(peVar, a2, z); if (a3 != null) { if (n.a()) { this.c.a("MediationAdapterManager", "Loaded " + c); } this.e.put(b, a2); if (z) { this.a.put(peVar.b(), a3); } return a3; } if (n.a()) { this.c.b("MediationAdapterManager", "Failed to load " + c); } this.f.add(b); return null; } if (n.a()) { this.c.a("MediationAdapterManager", "Not attempting to load " + c + " due to prior errors"); } return null; } catch (Throwable th) { throw th; } } } throw new IllegalArgumentException("No adapter spec specified"); } private g a(pe peVar, Class cls, boolean z) { try { return new g(peVar, (MediationAdapterBase) cls.getConstructor(AppLovinSdk.class).newInstance(this.b.s0()), z, this.b); } catch (Throwable th) { n.c("MediationAdapterManager", "Failed to load adapter: " + peVar, th); return null; } } public Collection a() { ArrayList arrayList; synchronized (this.g) { try { arrayList = new ArrayList(this.h.size()); Iterator it = this.h.iterator(); while (it.hasNext()) { arrayList.add(((a) it.next()).a()); } } catch (Throwable th) { throw th; } } return arrayList; } private Class a(String str) { try { Class cls = Class.forName(str); if (MaxAdapter.class.isAssignableFrom(cls)) { return cls.asSubclass(MaxAdapter.class); } n.h("MediationAdapterManager", str + " error: not an instance of '" + MaxAdapter.class.getName() + "'."); return null; } catch (Throwable unused) { return null; } } }