package c.t.m.g; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; import android.os.Handler; import android.text.TextUtils; import java.util.HashMap; import java.util.Iterator; import java.util.TimerTask; import org.json.JSONException; import org.json.JSONObject; import p4.f; /* compiled from: TML */ public class p extends ax { private static volatile p d; private static Context e; /* renamed from: c reason: collision with root package name */ private volatile boolean f2285c = true; private volatile aq f = aq.f1960a; /* renamed from: g reason: collision with root package name */ private Handler f2286g; private p() { Context context = e; if (context == null || context.getApplicationContext() == null) { throw new IllegalStateException("Please invoke initial(context,...) first when app started!"); } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void h() { long j; try { int b = q.a().b("cc_version"); if (b == -1) { j = 10800000; } else { j = i(); } bt.a("TxCC", "schedule : locVer[" + b + "],delayTime[" + j + "]"); a(j); } catch (Throwable th2) { bt.a("TxCC", "startSchedule error.", th2); } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private long i() { long c5 = q.a().c("cc_req_interval"); if (c5 > 86400000) { c5 = 86400000; } if (c5 < 1800000) { return 1800000; } return c5; } @Override // c.t.m.g.ax public String b() { return "TxCC"; } public static void a(HashMap<String, String> hashMap) { q.a(hashMap); } public static synchronized p c() { p pVar; synchronized (p.class) { if (d == null) { synchronized (p.class) { if (d == null) { d = new p(); } } } pVar = d; } return pVar; } @Override // c.t.m.g.ax public int d() { this.f2286g = new Handler(bn.a("th_loc_task_t_consume").getLooper()); a(5000); return 0; } public static void a(Context context, String str, String str2) { if (context == null || context.getApplicationContext() == null) { throw new NullPointerException("context cannot be null!"); } Context applicationContext = context.getApplicationContext(); e = applicationContext; be.a(applicationContext); r.a(str); q.a(str, str2); AnonymousClass1 r12 = new Thread("th_loc_tmp") { /* class c.t.m.g.p.AnonymousClass1 */ public void run() { try { p.c(); r.a(); q.a(); } catch (Throwable unused) { } } }; int i = f.b; r12.setName(f.a(r12.getName(), "c.t.m.g.p")); r12.start(); } public static void a(String str) { q.a(str); } @Override // c.t.m.g.ax public void a() { try { q.a().c(); bt.a("TxCC", "shutdown:pull immediately"); bp.b(this.f2286g); a(0); bn.a("th_loc_task_t_consume", 100L); this.f2286g = null; } catch (Throwable th2) { bt.a("TxCC", "shutdown error.", th2); } } /* compiled from: TML */ public class a extends TimerTask { private final JSONObject b; /* renamed from: c reason: collision with root package name */ private q f2288c; private r d; public a() { this.b = new JSONObject(); this.f2288c = null; this.d = null; this.f2288c = q.a(); this.d = r.a(); } private void a() { boolean f = p.this.f(); if (f) { try { this.d.c(); } catch (Throwable th2) { this.f2288c.b(); if (f) { this.d.d(); } throw th2; } } JSONObject b2 = b(); if (b2 != this.b) { int parseInt = Integer.parseInt(b2.optString("status", "-5")); bt.a("CC_Task", "status:" + parseInt); if (parseInt == 0) { if (b2.has("version")) { a(b2); } } ca.a(this.d.b(), "last_pull_time", (Object) String.valueOf(System.currentTimeMillis())); Thread.sleep(1000); bt.a("CC_Task", "---> finish update xml"); } this.f2288c.b(); if (!f) { return; } this.d.d(); } private JSONObject b() { if (p.this.f == null) { return this.b; } String str = "https://cc.map.qq.com/?get_c3"; if (!p.this.f2285c) { str = str.replace("https:", "http:"); } bt.a("CC_Task", "cc_url:" + str); try { JSONObject jSONObject = new JSONObject(); jSONObject.put("cc_version", this.f2288c.e("cc_version")); jSONObject.put("m_module", q.f2289a); jSONObject.put("m_channel", q.b); jSONObject.put("m_version", q.f2290c); String b2 = cb.b(); if (by.a(b2) || "0123456789ABCDEF".equals(b2)) { b2 = cb.d(); } jSONObject.put("imei", b2); String a5 = bj.a("cc"); String a12 = bj.a(jSONObject.toString(), a5); bt.a("CC_Task", "req:" + a12); Bundle a13 = p.this.f.a(str, a12.getBytes(), null); String string = a13.getString("msg_suc", ""); if (TextUtils.isEmpty(string)) { String string2 = a13.getString("msg_fail", ""); bt.a("CC_Task", "net work error! res = [" + string2 + "]"); return this.b; } bt.a("CC_Task", "res:" + string); String jSONObject2 = this.b.toString(); if (jSONObject2.equals(string)) { bt.a("CC_Task", "network or server error,response empty json"); } else { bt.a("CC_Task", "start dec"); jSONObject2 = bj.b(string, a5); bt.a("CC_Task", "end dec, " + jSONObject2); } return TextUtils.isEmpty(jSONObject2) ? this.b : new JSONObject(jSONObject2); } catch (Throwable th2) { bt.a("CC_Task", "req cc error.", th2); return this.b; } } public void run() { try { if (Math.abs(System.currentTimeMillis() - this.f2288c.c("last_pull_time")) >= p.this.i()) { a(); } else { bt.a("CC_Task", "skip pull"); } if (p.this.f()) { p.this.h(); } } catch (Throwable th2) { bt.a("CC_Task", "timer task error.", th2); } } private void a(JSONObject jSONObject) throws JSONException { int i; SharedPreferences b2 = this.d.b(); if (b2 != null) { int b5 = this.f2288c.b("cc_version"); try { i = Integer.parseInt(jSONObject.optString("version", this.f2288c.e("cc_version"))); } catch (Throwable unused) { i = b5; } bt.a("CC_Task", "locVer:" + b5 + ",serVer:" + i); if (i != b5) { bt.a("CC_Task", "locVer != serVer, clear sp."); b2.edit().clear().apply(); JSONObject optJSONObject = jSONObject.optJSONObject("data"); if (optJSONObject == null) { optJSONObject = this.b; } SharedPreferences.Editor edit = b2.edit(); Iterator<String> keys = optJSONObject.keys(); while (keys.hasNext()) { String next = keys.next(); a(edit, next, next, optJSONObject); } edit.putString("cc_version", String.valueOf(i)); edit.putString("app_version", q.f2290c); try { long parseLong = Long.parseLong(optJSONObject.optString("cc_req_interval", this.f2288c.e("cc_req_interval"))); if (parseLong < 1800000) { parseLong = 1800000; } else if (parseLong > 86400000) { parseLong = 86400000; } edit.putString("cc_req_interval", String.valueOf(parseLong)); } catch (Throwable unused2) { } edit.apply(); } } } private void a(SharedPreferences.Editor editor, String str, String str2, JSONObject jSONObject) { try { String e = this.f2288c.e(str); if (e != null) { editor.putString(str, jSONObject.optString(str2, e)); } } catch (Exception e6) { bt.a("CC_Task", "update sp error.", e6); } } } private void a(long j) { Handler handler = this.f2286g; a aVar = new a(); if (j < 0) { j = 0; } bp.a(handler, aVar, j); } }