package c.t.m.g; import android.content.Context; import android.os.Handler; import android.os.Looper; import android.os.Message; import java.io.File; import java.util.ArrayList; import java.util.List; import logo.i; import org.json.JSONArray; import org.json.JSONObject; /* compiled from: TML */ public class eq { public Context a; public a b; /* renamed from: c reason: collision with root package name */ private String f150c = "CheckUpdate"; private boolean d = true; private ev e; private boolean f = false; public eq(Context context) { this.a = context; this.e = new ev(context); this.b = new a(eo.a(context).c()); } public void a(boolean z) { this.d = z; this.b.sendEmptyMessageDelayed(10006, 1000); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void b(boolean z) { if (!z) { boolean b2 = b(); eo a2 = eo.a(this.a); a2.a("MCUS", "t:" + b2 + ",i:" + z); if (!b2) { if (ey.a) { String str = this.f150c; ey.b(str, "runCheck t:" + b2 + ",i:" + z); return; } return; } } if (ey.a) { ey.a(this.f150c, "begin to sendrequest download desc"); } String b3 = fj.b(this.a, "SP_TMLSDK_MODULE_INFO", "default"); eo a3 = eo.a(this.a); a3.a("MCUS", "load desc," + b3); List<ew> a4 = fj.a(b3); if (ey.a) { String str2 = this.f150c; ey.a(str2, "local comp infos = " + b3); } if (a4 != null && !a4.isEmpty()) { List<ew> a5 = a(a4); if (ey.a) { ey.a(this.f150c, " sendrequest download desc result"); } fj.a(this.a, "SP_last_check_TMLSDK_update_time", Long.valueOf(System.currentTimeMillis())); if (a5 != null) { this.e.a(a5, a4); } } } /* compiled from: TML */ class a extends Handler { public a(Looper looper) { super(looper); } public void handleMessage(Message message) { try { a(message); } catch (Throwable th) { if (ey.a) { ey.a(eq.this.f150c, th); } } } private void a(Message message) { if (message.what == 10006) { removeCallbacksAndMessages(null); eq eqVar = eq.this; eqVar.b((eq) eqVar.d); eq.this.a(); eo.a().d(); } } } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void a() { if (!this.f) { this.f = true; String str = "loaddir,"; File[] listFiles = fj.a(this.a, "TMLSDK_hp").listFiles(); if (listFiles != null && listFiles.length > 0) { for (File file : listFiles) { str = str + (file.isFile() ? "" + "f," + file.getName() + "," + file.length() + "," + file.canRead() + "," + file.canWrite() : "" + "d," + file.getName()) + ";"; } } eo.a().a("MCUS", str); } } private List<ew> a(String str, List<ew> list) { String b2 = fb.b(str, fj.a("m_update_pwd", ff.m)); if (ey.a) { String str2 = this.f150c; ey.a(str2, "decryAes256 the response is : " + b2); } String b3 = b(b2, list); if (ey.a) { String str3 = this.f150c; ey.a(str3, "parseJson is " + b3); } eo a2 = eo.a(this.a); a2.a("MCUS", "updateModules," + b3); if (b3 == null) { if (ey.a) { String str4 = this.f150c; ey.a(str4, "parseJson is " + b3); } return null; } List<ew> a3 = fj.a(b3); if (a3 == null || a3.isEmpty()) { if (ey.a) { ey.a(this.f150c, "update desc complist is empty"); } return null; } if (ey.a) { String a4 = fj.a(a3); String str5 = this.f150c; ey.a(str5, "need update module string : " + a4); } String b4 = fj.b(this.a, "SP_bad_TMLSDK_info", "preference_default"); if (ey.a) { String str6 = this.f150c; ey.a(str6, "badDexInfoStr : " + b4); } List<ew> a5 = fj.a(b4); if (!b4.equals("preference_default") && !a5.isEmpty()) { ArrayList<ew> a6 = fj.a(a3, a5); if (ey.a) { String str7 = this.f150c; ey.a(str7, "the num update dex in bad dex is " + a6.size()); } if (a6.size() > 0) { eo.a(this.a).a("MCUS", "updateModules is bad,donot update"); return null; } } if (ey.a) { String str8 = this.f150c; ey.b(str8, "update desc prepared, prepare download," + b3); } return a3; } private String b(String str, List<ew> list) { try { JSONObject jSONObject = new JSONObject(str); String string = jSONObject.getString("status"); eo.a(this.a).a("MCUS", "statucode," + string + "," + str); if (string.equals("-3")) { if (ey.a) { ey.a(this.f150c, "local dex version is the same to the lasted version in server,not need to update!!"); } return null; } else if (string.equals("0")) { if (ey.a) { ey.a(this.f150c, "need to update dex from server !!"); } String str2 = ""; int i = 0; for (JSONArray jSONArray = jSONObject.getJSONArray("compList"); i < jSONArray.length(); jSONArray = jSONArray) { JSONObject jSONObject2 = jSONArray.getJSONObject(i); int i2 = jSONObject2.getInt("compId"); String string2 = jSONObject2.getString("compVer"); String string3 = jSONObject2.getString("md5"); long j = jSONObject2.getLong("size"); String string4 = jSONObject2.getString("compName"); if (!a(i2, string3, j, string4, list)) { String str3 = i2 + "," + string2 + "," + string4 + "," + j + "," + string3 + ",;"; if (!str2.contains(str3)) { str2 = str2 + str3; } else if (!ey.a) { return null; } else { ey.b(this.f150c, "server response error,current comp is repeat from server,donot update," + str3); return null; } } else if (ey.a) { ey.b(this.f150c, "current comp from server is already new,so donot need to update:" + i2 + "," + string2 + "," + string4 + "," + j + "," + string3); } i++; } return str2; } else if (string.equals("-1")) { if (!ey.a) { return null; } ey.a(this.f150c, "sever parse json error,pelase check!"); return null; } else if (string.equals("-2")) { if (!ey.a) { return null; } ey.a(this.f150c, "the params in json is error,please check!"); return null; } else if (string.equals("-4")) { if (!ey.a) { return null; } ey.a(this.f150c, "server has not config this version !!!"); return null; } else if (!string.equals("-5") || !ey.a) { return null; } else { ey.a(this.f150c, "server unkown error!!!"); return null; } } catch (Exception e2) { if (ey.a) { ey.a(this.f150c, e2); } String exc = e2.toString(); if (exc != null && exc.contains("\n")) { exc.replaceAll("\n", ","); } eo.a(this.a).a("MCUS", "parser exp:" + exc); return null; } } private boolean a(int i, String str, long j, String str2, List<ew> list) { try { for (ew ewVar : list) { if (i == ewVar.a && j == ewVar.d && ewVar.f154c.contains(str2) && ewVar.e.equals(str)) { return true; } } return false; } catch (Exception e2) { if (!ey.a) { return false; } ey.a(this.f150c, e2); return false; } } private List<ew> a(List<ew> list) { String b2 = b(list); if (b2 == null) { if (ey.a) { ey.a(this.f150c, "download desc file postjsondata is null !!!"); } return null; } if (ey.a) { String str = this.f150c; ey.a(str, "desc file request postjson " + b2); } byte[] bytes = b2.getBytes(); if (bytes != null) { int i = 0; while (true) { int i2 = i + 1; if (i >= 3) { break; } if (ey.a) { String str2 = this.f150c; ey.a(str2, "desc file request times is " + i2); } byte[] a2 = fc.a("https://cc.map.qq.com?desc_c", bytes); if (a2 != null) { String str3 = new String(a2); if (ey.a) { String str4 = this.f150c; ey.a(str4, "download dex desc file: " + str3); } return a(str3, list); } eo a3 = eo.a(this.a); a3.a("MCUS", "response failed,try:" + i2); i = i2; } } return null; } private String b(List<ew> list) { JSONObject jSONObject = new JSONObject(); try { jSONObject.put("projName", "TMLSDK"); jSONObject.put("appkey", fj.a(this.a)); jSONObject.put("appversion", fj.b(this.a)); jSONObject.put(i.b.p, fj.c(this.a)); jSONObject.put("coverSDKver", ff.g); jSONObject.put(i.b.T, fj.b() + "_" + fj.a()); jSONObject.put("APILevel", fj.c()); JSONArray jSONArray = new JSONArray(); for (ew ewVar : list) { if (ewVar != null) { JSONObject jSONObject2 = new JSONObject(); jSONObject2.put("compId", ewVar.a); jSONObject2.put("compVer", ewVar.b); jSONObject2.put("size", ewVar.d); jSONObject2.put("md5", ewVar.e); jSONArray.put(jSONObject2); } } jSONObject.put("compList", jSONArray); String jSONObject3 = jSONObject.toString(); eo a2 = eo.a(this.a); a2.a("MCUS", "req:" + jSONObject3); if (ey.a) { String str = this.f150c; ey.a(str, "download desc file PostJsonData : " + jSONObject3); } return fb.a(jSONObject3, fj.a("m_update_pwd", ff.m)); } catch (Exception e2) { String exc = e2.toString(); if (exc != null && exc.contains("\n")) { exc.replaceAll("\n", ","); } eo a3 = eo.a(this.a); a3.a("MCUS", "reqDerror:" + exc); if (!ey.a) { return null; } ey.a(this.f150c, e2); return null; } } private boolean b() { long currentTimeMillis = System.currentTimeMillis() - fj.b(this.a, "SP_last_check_TMLSDK_update_time", (Long) 0L).longValue(); if (ey.a) { String str = this.f150c; ey.a(str, "check time period is " + currentTimeMillis + "," + (currentTimeMillis / 3600000) + "days"); } return currentTimeMillis > 0; } }