package com.tencent.open.utils; import android.content.Context; import android.os.Build; import android.os.Bundle; import android.os.SystemClock; import com.tencent.open.SocialConstants; import java.io.BufferedReader; import java.io.FileNotFoundException; 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 */ /* loaded from: classes.dex */ public class e { private static Map a = Collections.synchronizedMap(new HashMap()); private static String b = null; private Context c; private String d; private JSONObject e = null; private long f = 0; private int g = 0; private boolean h = true; private e(Context context, String str) { this.c = null; this.d = null; this.c = context.getApplicationContext(); this.d = str; a(); b(); } private void b() { if (this.g != 0) { d("update thread is running, return"); return; } this.g = 1; final Bundle bundle = new Bundle(); bundle.putString(SocialConstants.PARAM_APP_ID, this.d); bundle.putString("appid_for_getting_config", this.d); bundle.putString("status_os", Build.VERSION.RELEASE); bundle.putString("status_machine", Build.MODEL); bundle.putString("status_version", Build.VERSION.SDK); bundle.putString("sdkv", "3.3.0.lite"); bundle.putString("sdkp", "a"); new Thread() { // from class: com.tencent.open.utils.e.1 @Override // java.lang.Thread, java.lang.Runnable public void run() { try { e.this.a(i.d(HttpUtils.openUrl2(e.this.c, "http://cgi.connect.qq.com/qqconnectopen/openapi/policy_conf", "GET", bundle).a)); } catch (Exception e) { e.printStackTrace(); } e.this.g = 0; } }.start(); } private String c(String str) { InputStream open; String str2; String str3 = ""; try { try { if (this.d != null) { str2 = str + "." + this.d; } else { str2 = str; } open = this.c.openFileInput(str2); } catch (FileNotFoundException unused) { open = this.c.getAssets().open(str); } BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(open, Charset.forName("UTF-8"))); StringBuffer stringBuffer = new StringBuffer(); while (true) { try { try { try { String readLine = bufferedReader.readLine(); if (readLine == null) { break; } stringBuffer.append(readLine); } catch (Throwable th) { try { open.close(); bufferedReader.close(); } catch (IOException e) { e.printStackTrace(); } throw th; } } catch (IOException e2) { e2.printStackTrace(); open.close(); bufferedReader.close(); } } catch (IOException e3) { e3.printStackTrace(); } } str3 = stringBuffer.toString(); open.close(); bufferedReader.close(); return str3; } catch (IOException e4) { e4.printStackTrace(); return ""; } } private void d(String str) { if (this.h) { com.tencent.open.a.f.a("openSDK_LOG.OpenConfig", str + "; appid: " + this.d); } } public static e a(Context context, String str) { e eVar; synchronized (a) { com.tencent.open.a.f.a("openSDK_LOG.OpenConfig", "getInstance begin"); if (str != null) { b = str; } if (str == null) { str = b != null ? b : "0"; } eVar = a.get(str); if (eVar == null) { eVar = new e(context, str); a.put(str, eVar); } com.tencent.open.a.f.a("openSDK_LOG.OpenConfig", "getInstance end"); } return eVar; } public boolean b(String str) { d("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.c.openFileOutput(str, 0), Charset.forName("UTF-8")); outputStreamWriter.write(str2); outputStreamWriter.flush(); outputStreamWriter.close(); } catch (IOException e) { e.printStackTrace(); } } private void c() { int optInt = this.e.optInt("Common_frequency"); if (optInt == 0) { optInt = 1; } if (SystemClock.elapsedRealtime() - this.f >= optInt * 3600000) { b(); } } /* JADX INFO: Access modifiers changed from: private */ public 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("get " + str); c(); return this.e.optInt(str); } }