package com.umeng.cconfig; import android.content.ContentValues; import android.content.Context; import android.content.SharedPreferences; import android.content.res.XmlResourceParser; import android.database.sqlite.SQLiteDatabaseCorruptException; import android.text.TextUtils; import com.mbridge.msdk.foundation.entity.DomainCampaignEx; import com.mbridge.msdk.foundation.same.report.e; import com.umeng.analytics.pro.e; import com.umeng.cconfig.b.c; import com.umeng.cconfig.b.d; import com.umeng.cconfig.c.b; import com.umeng.cconfig.listener.OnConfigStatusChangedListener; import com.umeng.commonsdk.statistics.common.MLog; import com.umeng.commonsdk.statistics.common.ULog; import com.umeng.commonsdk.statistics.idtracking.ImprintHandler; import com.umeng.commonsdk.statistics.internal.UMImprintChangeCallback; import com.umeng.commonsdk.utils.UMUtils; import java.io.IOException; import java.nio.CharBuffer; import java.util.HashMap; import java.util.Map; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; import java.util.regex.Pattern; import org.json.JSONArray; import org.json.JSONObject; import org.xmlpull.v1.XmlPullParserException; public class UMRemoteConfig { public static final Pattern a = Pattern.compile("^[a-zA-Z_][a-zA-Z0-9_]{1,255}"); public static boolean b = true; private static Context c = null; private static Map<String, c> d = new HashMap(); private static Map<String, c> e = new HashMap(); private static Map<String, String> f = new HashMap(); private int g; private RemoteConfigSettings h; private OnConfigStatusChangedListener i; private final ReadWriteLock j; /* access modifiers changed from: package-private */ public static class a { private static final UMRemoteConfig a = new UMRemoteConfig((byte) 0); } private UMRemoteConfig() { this.j = new ReentrantReadWriteLock(true); } /* synthetic */ UMRemoteConfig(byte b2) { this(); } /* JADX WARNING: Code restructure failed: missing block: B:20:0x006d, code lost: if (com.umeng.cconfig.UMRemoteConfig.f.size() <= 1000) goto L_0x006f; */ /* JADX WARNING: Missing exception handler attribute for start block: B:35:0x009e */ private void a(Context context, int i2) { if (context != null && i2 > 0) { try { this.j.writeLock().lock(); XmlResourceParser xml = context.getResources().getXml(i2); String str = null; String str2 = null; String str3 = null; for (int eventType = xml.getEventType(); eventType != 1; eventType = xml.next()) { if (eventType == 2) { str = xml.getName(); } else if (eventType == 3) { if (!(!"entry".equals(xml.getName()) || str2 == null || str3 == null)) { if (a.matcher(str2.trim()).matches()) { f.put(str2, str3); c cVar = new c(); cVar.a = str2; cVar.b = str3; e.put(str2, cVar); str2 = null; str3 = null; } } str = null; } else if (eventType == 4) { if ("key".equals(str)) { str2 = xml.getText(); } else if (DomainCampaignEx.LOOPBACK_VALUE.equals(str)) { str3 = xml.getText(); } } } try { this.j.writeLock().unlock(); } catch (Exception unused) { ULog.e("jessie", "[xmlLoad] xml load fail"); } } catch (XmlPullParserException unused2) { ULog.e("jessie", "[xmlLoad] xml load fail"); this.j.writeLock().unlock(); } catch (IOException unknown) { try { ULog.e("jessie", "[xmlLoad] xml load fail"); } finally { this.j.writeLock().unlock(); } } } } /* JADX WARNING: Code restructure failed: missing block: B:33:0x00ab, code lost: r15 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:35:?, code lost: com.umeng.commonsdk.statistics.common.ULog.e("jessie", "[active] new config active false"); */ /* JADX WARNING: Code restructure failed: missing block: B:36:0x00b5, code lost: r14.j.writeLock().unlock(); */ /* JADX WARNING: Code restructure failed: missing block: B:37:0x00be, code lost: throw r15; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:34:0x00ad */ private void a(d dVar) { if (dVar != null) { String str = dVar.b; this.j.writeLock().lock(); if (!TextUtils.isEmpty(str)) { JSONArray jSONArray = new JSONArray(str); int length = jSONArray.length(); for (int i2 = 0; i2 < length; i2++) { JSONObject jSONObject = new JSONObject(jSONArray.getString(i2)); String str2 = ""; try { c cVar = new c(); if (jSONObject.has("k")) { str2 = jSONObject.getString("k"); cVar.a = str2; } if (jSONObject.has("v")) { cVar.b = jSONObject.getString("v"); } if (jSONObject.has(e.a)) { cVar.c = jSONObject.getString(e.a); } if (jSONObject.has("g")) { cVar.d = jSONObject.getString("g"); } if (!TextUtils.isEmpty(str2)) { e.put(jSONObject.getString("k"), cVar); } } catch (Exception unused) { ULog.e("jessie", "[active] new config active false"); } } } d.clear(); d.putAll(e); e.clear(); ULog.i("jessie", "[active] new config active success i"); } else { try { this.j.writeLock().lock(); d.clear(); d.putAll(e); e.clear(); ULog.i("[active] new config active success ii"); } catch (Exception unused2) { } catch (Throwable th) { this.j.writeLock().unlock(); throw th; } } this.j.writeLock().unlock(); } public static UMRemoteConfig getInstance() { return a.a; } public static String getVersion() { return "1.0.1"; } public void activeFetchConfig() { if (!b) { MLog.d("ucc", "remote config disable"); return; } Context context = c; if (context == null) { MLog.d("ucc", "UMRemoteConfig did not init"); } else if (!UMUtils.isMainProgress(context)) { MLog.d("ucc", "can not be called in child process"); } else { try { new com.umeng.cconfig.d.a(c).run(); } catch (Exception unused) { } } } public String getConfigValue(String str) { String str2 = null; if (!b) { MLog.d("ucc", "remote config disable"); return null; } Context context = c; if (context == null) { MLog.d("ucc", "UMRemoteConfig did not init"); return null; } else if (!UMUtils.isMainProgress(context)) { MLog.d("ucc", "can not be called in child process"); return null; } else { try { this.j.readLock().lock(); c cVar = d.get(str); if (cVar != null) { str2 = cVar.b; if (!TextUtils.isEmpty(cVar.d)) { JSONArray a2 = com.umeng.cconfig.b.e.a(cVar, c); ULog.d("jessie", "[ablog] ablog params : " + a2.toString()); if (a2 != null) { com.umeng.cconfig.c.c.a(new b("https://pslog.umeng.com/ablog", a2)); } } } } catch (Exception unused) { } catch (Throwable th) { this.j.readLock().unlock(); throw th; } this.j.readLock().unlock(); return str2; } } /* JADX WARNING: Code restructure failed: missing block: B:68:0x013c, code lost: r10 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:69:0x013d, code lost: r9.j.writeLock().unlock(); */ /* JADX WARNING: Code restructure failed: missing block: B:70:0x0146, code lost: throw r10; */ /* JADX WARNING: Code restructure failed: missing block: B:81:0x0185, code lost: r10 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:82:0x0186, code lost: r9.j.writeLock().unlock(); */ /* JADX WARNING: Code restructure failed: missing block: B:83:0x018f, code lost: throw r10; */ /* JADX WARNING: Exception block dominator not found, dom blocks: [B:4:0x0014, B:60:0x0110] */ /* JADX WARNING: Exception block dominator not found, dom blocks: [B:4:0x0014, B:73:0x014a] */ /* JADX WARNING: Missing exception handler attribute for start block: B:30:0x00ae */ /* JADX WARNING: Removed duplicated region for block: B:52:? A[ExcHandler: Exception (unused java.lang.Exception), SYNTHETIC, Splitter:B:4:0x0014] */ public void handlerMessage(int i2, Object obj, String str) { OnConfigStatusChangedListener onConfigStatusChangedListener; SharedPreferences a2; com.umeng.cconfig.a.b a3; if (i2 == 1) { String str2 = (String) obj; if (!TextUtils.isEmpty(str2)) { try { this.j.writeLock().lock(); JSONObject jSONObject = new JSONObject(str2); String str3 = ""; String string = jSONObject.has("cc") ? jSONObject.getString("cc") : str3; if (jSONObject.has("ts")) { str3 = jSONObject.getString("ts"); } if (!TextUtils.isEmpty(string) && !TextUtils.isEmpty(str3)) { a3 = com.umeng.cconfig.a.b.a(c); try { a3.a(); ContentValues contentValues = new ContentValues(); contentValues.put("__ts", str3); contentValues.put(e.d.a.d, string); contentValues.put("__a", "0"); ULog.i("jessie", "[DbManager] insert timeStamp: " + str3 + " content: " + string + " active: " + "0"); a3.a.insert("__cc", null, contentValues); a3.a.setTransactionSuccessful(); try { if (a3.a != null) { a3.a.endTransaction(); } } catch (Throwable unused) { } } catch (SQLiteDatabaseCorruptException unknown) { try { ULog.i("jessie", "[DbManager] insert failed"); if (a3.a != null) { a3.a.endTransaction(); } } catch (Throwable unused2) { } } catch (Throwable unused3) { if (a3.a != null) { a3.a.endTransaction(); } } a3.b(); com.umeng.cconfig.a.b.a(c).d(); MLog.i("ucc", "get new config success"); RemoteConfigSettings remoteConfigSettings = this.h; if (remoteConfigSettings != null) { if (!remoteConfigSettings.isAutoUpdateModeEnabled()) { OnConfigStatusChangedListener onConfigStatusChangedListener2 = this.i; if (onConfigStatusChangedListener2 != null) { onConfigStatusChangedListener2.onFetchComplete(); } } else { activeFetchConfig(); } } } } catch (Exception unused4) { } catch (Throwable th) { this.j.writeLock().unlock(); throw th; } } else { return; } } else if (i2 == 2) { this.j.writeLock().lock(); if (TextUtils.isEmpty((String) obj) && !TextUtils.isEmpty(str) && (a2 = com.umeng.cconfig.a.c.a(c)) != null) { SharedPreferences.Editor edit = a2.edit(); edit.putString("abtest_sp_last_request_data", str); edit.commit(); } } else if (i2 == 3) { this.j.writeLock().lock(); if (((Boolean) obj).booleanValue()) { a(c, this.g); a(com.umeng.cconfig.a.b.a(c).c()); MLog.i("ucc", "active new config success"); if (!(this.h == null || (onConfigStatusChangedListener = this.i) == null)) { onConfigStatusChangedListener.onActiveComplete(); } } } else { return; } this.j.writeLock().unlock(); return; a3.b(); throw th; } public void init(Context context) { try { if (!b) { MLog.d("ucc", "remote config disable"); } else if (context != null) { if (c == null) { c = context.getApplicationContext(); } if (!UMUtils.isMainProgress(context)) { MLog.d("ucc", "can not be called in child process"); } else if (this.h == null) { MLog.d("ucc", "please set RemoteConfigSettings using UMRemoteConfig.getInstance().setConfigSettings"); } else { a(c, this.g); a(com.umeng.cconfig.a.b.a(c).c()); ImprintHandler.getImprintService(c).registImprintCallback("ucc", new UMImprintChangeCallback() { /* class com.umeng.cconfig.UMRemoteConfig.AnonymousClass1 */ /* JADX DEBUG: Multi-variable search result rejected for r9v3, resolved type: java.nio.CharBuffer */ /* JADX WARN: Multi-variable type inference failed */ @Override // com.umeng.commonsdk.statistics.internal.UMImprintChangeCallback public final void onImprintValueChanged(String str, String str2) { SharedPreferences a2; try { if ("ucc".equals(str)) { ULog.i("jessie", "[imprint] key: " + str + " value: " + str2); String[] split = str2.split("@"); CharBuffer charBuffer = split[3]; if (!TextUtils.isEmpty(charBuffer) && "1".equals(charBuffer)) { String str3 = split[0]; if (!TextUtils.isEmpty(str3) && (a2 = com.umeng.cconfig.a.c.a(UMRemoteConfig.c)) != null) { String string = a2.getString("cconfig_sp_last_request_time", ""); if (!TextUtils.isEmpty(string)) { if (str3.equals(string)) { ULog.i("jessie", "[imprint] newTimeStamp.equals(oldTimeStamp)"); return; } } SharedPreferences.Editor edit = a2.edit(); edit.putString("cconfig_sp_last_request_time", str3); edit.commit(); JSONObject a3 = com.umeng.cconfig.b.e.a(UMRemoteConfig.c); if (a3 != null) { try { ULog.i("jessie", "[imprint] send request. body: " + a3.toString()); com.umeng.cconfig.c.c.a(new b("https://ucc.umeng.com/v1/fetch", a3)); } catch (Exception unused) { } } } } } } catch (Exception unused2) { ULog.e("jessie", "[imprint] fail"); } } }); } } } catch (Throwable unused) { } } public synchronized void setConfigSettings(RemoteConfigSettings remoteConfigSettings) { if (!b) { MLog.d("ucc", "remote config disable"); return; } if (remoteConfigSettings != null) { this.h = remoteConfigSettings; } } public synchronized void setDefaults(int i2) { if (!b) { MLog.d("ucc", "remote config disable"); return; } this.g = i2; } public synchronized void setOnNewConfigfecthed(OnConfigStatusChangedListener onConfigStatusChangedListener) { if (!b) { MLog.d("ucc", "remote config disable"); return; } if (onConfigStatusChangedListener != null) { this.i = onConfigStatusChangedListener; } } }