package com.tencent.open.utils; import android.content.Context; import android.os.Build; import android.os.SystemClock; import com.tencent.open.a.f; import com.tencent.open.a.g; import com.tencent.open.log.SLog; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.nio.charset.Charset; import java.util.Collections; import java.util.HashMap; import java.util.Map; import org.json.JSONException; import org.json.JSONObject; /* compiled from: ProGuard */ public class i { /* renamed from: a reason: collision with root package name */ private static Map<String, i> f29430a = Collections.synchronizedMap(new HashMap()); private static String b = null; /* renamed from: c reason: collision with root package name */ private Context f29431c; private String d; private JSONObject e; private long f; /* renamed from: g reason: collision with root package name */ private int f29432g; /* renamed from: h reason: collision with root package name */ private boolean f29433h = true; private i(Context context, String str) { this.f29431c = context.getApplicationContext(); this.d = str; a(); b(); } private void b() { if (this.f29432g != 0) { d("update thread is running, return"); return; } this.f29432g = 1; final HashMap hashMap = new HashMap(); hashMap.put("appid", this.d); hashMap.put("status_os", Build.VERSION.RELEASE); hashMap.put("status_machine", f.a().c(g.a())); hashMap.put("status_version", Build.VERSION.SDK); hashMap.put("sdkv", "3.5.13.lite"); hashMap.put("sdkp", "a"); l.a(new Runnable() { /* class com.tencent.open.utils.i.AnonymousClass1 */ public void run() { try { g a5 = f.a().a("https://cgi.connect.qq.com/qqconnectopen/openapi/policy_conf", hashMap); String a12 = a5.a(); SLog.i("openSDK_LOG.OpenConfig", "update: get config statusCode " + a5.d()); i.this.a((i) m.d(a12)); } catch (Exception e) { SLog.e("openSDK_LOG.OpenConfig", "get config error ", e); } i.this.f29432g = 0; } }); } /* JADX WARNING: Can't wrap try/catch for region: R(2:7|8) */ /* JADX WARNING: Code restructure failed: missing block: B:30:0x0077, code lost: r5 = move-exception; */ /* JADX WARNING: Code restructure failed: missing block: B:31:0x0078, code lost: r5.printStackTrace(); */ /* JADX WARNING: Code restructure failed: missing block: B:32:0x007b, code lost: return r0; */ /* JADX WARNING: Code restructure failed: missing block: B:8:?, code lost: r5 = r4.f29431c.getAssets().open(r5); */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Missing exception handler attribute for start block: B:7:0x0025 */ private String c(String str) { String str2; String str3 = ""; if (this.d != null) { str2 = str + "." + this.d; } else { str2 = str; } InputStream inputStream = this.f29431c.openFileInput(str2); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream, Charset.forName("UTF-8"))); StringBuffer stringBuffer = new StringBuffer(); while (true) { try { String readLine = bufferedReader.readLine(); if (readLine == null) { break; } stringBuffer.append(readLine); } catch (IOException e6) { e6.printStackTrace(); inputStream.close(); bufferedReader.close(); } catch (Throwable th2) { try { inputStream.close(); bufferedReader.close(); } catch (IOException e12) { e12.printStackTrace(); } throw th2; } } str3 = stringBuffer.toString(); try { inputStream.close(); bufferedReader.close(); } catch (IOException e13) { e13.printStackTrace(); } return str3; } private void d(String str) { if (this.f29433h) { StringBuilder j = a40.f.j(str, "; appid: "); j.append(this.d); SLog.v("openSDK_LOG.OpenConfig", j.toString()); } } public static i a(Context context, String str) { i iVar; synchronized (f29430a) { SLog.v("openSDK_LOG.OpenConfig", "getInstance begin"); if (str != null) { b = str; } if (str == null) { str = b; if (str == null) { str = "0"; } } iVar = f29430a.get(str); if (iVar == null) { iVar = new i(context, str); f29430a.put(str, iVar); } SLog.v("openSDK_LOG.OpenConfig", "getInstance end"); } return iVar; } public boolean b(String str) { d(a40.f.g("get ", str)); c(); Object opt = this.e.opt(str); if (opt == null) { return false; } if (opt instanceof Integer) { return !opt.equals(0); } if (opt instanceof Boolean) { return ((Boolean) opt).booleanValue(); } return false; } private void a() { try { this.e = new JSONObject(c("com.tencent.open.config.json")); } catch (JSONException unused) { this.e = new JSONObject(); } } private void a(String str, String str2) { try { if (this.d != null) { str = str + "." + this.d; } OutputStreamWriter outputStreamWriter = new OutputStreamWriter(this.f29431c.openFileOutput(str, 0), Charset.forName("UTF-8")); outputStreamWriter.write(str2); outputStreamWriter.flush(); outputStreamWriter.close(); } catch (IOException e6) { e6.printStackTrace(); } } private void c() { int optInt = this.e.optInt("Common_frequency"); if (optInt == 0) { optInt = 1; } if (SystemClock.elapsedRealtime() - this.f >= ((long) (optInt * 3600000))) { b(); } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void a(JSONObject jSONObject) { d("cgi back, do update"); this.e = jSONObject; a("com.tencent.open.config.json", jSONObject.toString()); this.f = SystemClock.elapsedRealtime(); } public int a(String str) { d(a40.f.g("get ", str)); c(); return this.e.optInt(str); } }