package com.applovin.impl; import android.content.Context; import android.content.SharedPreferences; import com.applovin.impl.sdk.utils.CollectionUtils; import com.applovin.impl.sdk.utils.JsonUtils; import com.applovin.mediation.MaxAdFormat; import csdk.gluads.Consts; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.json.JSONException; import org.json.JSONObject; /* loaded from: classes.dex */ public class tj { protected final com.applovin.impl.sdk.j a; protected final Context b; protected final SharedPreferences c; private final Map d = new HashMap(); private final Object e = new Object(); public tj(com.applovin.impl.sdk.j jVar) { this.a = jVar; Context l = com.applovin.impl.sdk.j.l(); this.b = l; this.c = l.getSharedPreferences("com.applovin.sdk.1", 0); try { Class.forName(sj.class.getName()); Class.forName(ve.class.getName()); } catch (Throwable unused) { } d(); } public List c(sj sjVar) { return CollectionUtils.explode((String) a(sjVar)); } public List b(sj sjVar) { ArrayList arrayList = new ArrayList(6); Iterator it = c(sjVar).iterator(); while (it.hasNext()) { arrayList.add(MaxAdFormat.formatFromString((String) it.next())); } return arrayList; } private String b() { return "com.applovin.sdk." + yp.d(this.a.b0()) + Consts.STRING_PERIOD; } public void e() { String b = b(); synchronized (this.e) { try { SharedPreferences.Editor edit = this.c.edit(); for (sj sjVar : sj.c()) { Object obj = this.d.get(sjVar.b()); if (obj != null) { this.a.a(b + sjVar.b(), obj, edit); } } edit.apply(); } catch (Throwable th) { throw th; } } } public void d() { String b = b(); synchronized (this.e) { try { for (sj sjVar : sj.c()) { try { Object a = this.a.a(b + sjVar.b(), null, sjVar.a().getClass(), this.c); if (a != null) { this.d.put(sjVar.b(), a); } } catch (Throwable th) { com.applovin.impl.sdk.n.c("SettingsManager", "Unable to load \"" + sjVar.b() + "\"", th); this.a.E().a("SettingsManager", "initSettings", th); } } } catch (Throwable th2) { throw th2; } } } public void a() { synchronized (this.e) { this.d.clear(); } this.a.a(this.c); } public Object a(sj sjVar) { if (sjVar != null) { synchronized (this.e) { try { Object obj = this.d.get(sjVar.b()); if (obj == null) { return sjVar.a(); } return sjVar.a(obj); } catch (Throwable th) { throw th; } } } throw new IllegalArgumentException("No setting type specified"); } public boolean c() { return this.a.g0().isVerboseLoggingEnabled() || ((Boolean) a(sj.l)).booleanValue(); } private static Object a(String str, JSONObject jSONObject, Object obj) { if (obj instanceof Boolean) { return Boolean.valueOf(jSONObject.getBoolean(str)); } if (obj instanceof Float) { return Float.valueOf((float) jSONObject.getDouble(str)); } if (obj instanceof Double) { return Double.valueOf(jSONObject.getDouble(str)); } if (obj instanceof Integer) { return Integer.valueOf(jSONObject.getInt(str)); } if (obj instanceof Long) { return Long.valueOf(jSONObject.getLong(str)); } if (obj instanceof String) { return jSONObject.getString(str); } throw new RuntimeException("SDK Error: unknown value type: " + obj.getClass()); } public void a(JSONObject jSONObject) { synchronized (this.e) { try { boolean booleanValue = JsonUtils.getBoolean(jSONObject, sj.B.b(), Boolean.FALSE).booleanValue(); HashMap hashMap = booleanValue ? new HashMap() : null; Iterator keys = jSONObject.keys(); while (keys.hasNext()) { String next = keys.next(); if (next != null && next.length() > 0) { try { sj a = a(next, (sj) null); if (a != null) { Object a2 = booleanValue ? a(a) : null; Object a3 = a(next, jSONObject, a.a()); this.d.put(a.b(), a3); if (a == sj.J5) { this.d.put(sj.K5.b(), Long.valueOf(System.currentTimeMillis())); } if (booleanValue && !a3.equals(a2)) { hashMap.put(a, a2); } } } catch (JSONException e) { com.applovin.impl.sdk.n.c("SettingsManager", "Unable to parse JSON settingsValues array", e); this.a.E().a("SettingsManager", "loadSettingsException", e); } catch (Throwable th) { com.applovin.impl.sdk.n.c("SettingsManager", "Unable to convert setting object ", th); this.a.E().a("SettingsManager", "loadSettingsThrowable", th); } } } if (booleanValue && hashMap.size() > 0) { qc qcVar = new qc(); qcVar.a("========== UPDATED SETTINGS =========="); for (sj sjVar : hashMap.keySet()) { qcVar.a(sjVar.b(), a(sjVar) + " (" + hashMap.get(sjVar) + ")"); } qcVar.a("========== END =========="); this.a.J(); if (com.applovin.impl.sdk.n.a()) { this.a.J().a("SettingsManager", qcVar.toString()); } } } catch (Throwable th2) { throw th2; } } } public sj a(String str, sj sjVar) { synchronized (this.e) { try { for (sj sjVar2 : sj.c()) { if (sjVar2.b().equals(str)) { return sjVar2; } } return sjVar; } catch (Throwable th) { throw th; } } } public void a(sj sjVar, Object obj) { if (sjVar == null) { throw new IllegalArgumentException("No setting type specified"); } if (obj != null) { synchronized (this.e) { this.d.put(sjVar.b(), obj); } return; } throw new IllegalArgumentException("No new value specified"); } }