package c.t.m.g; import android.content.Context; import android.os.Handler; import android.os.Looper; import android.os.Message; import com.ali.auth.third.login.LoginConstants; import com.alipay.sdk.util.f; import com.tencent.imsdk.v2.V2TIMOfflinePushInfo; import com.xingin.xhs.v2.album.entities.AlbumBean; import java.io.File; import java.util.ArrayList; import java.util.List; import org.json.JSONArray; import org.json.JSONObject; /* compiled from: TML */ public class eq { /* renamed from: a reason: collision with root package name */ public Context f10109a; /* renamed from: b reason: collision with root package name */ public a f10110b; /* renamed from: c reason: collision with root package name */ private String f10111c = "CheckUpdate"; /* renamed from: d reason: collision with root package name */ private boolean f10112d = true; /* renamed from: e reason: collision with root package name */ private ev f10113e; /* renamed from: f reason: collision with root package name */ private boolean f10114f = false; /* compiled from: TML */ public class a extends Handler { public a(Looper looper) { super(looper); } private void a(Message message) { if (message.what == 10006) { removeCallbacksAndMessages(null); eq eqVar = eq.this; eqVar.b((eq) eqVar.f10112d); eq.this.a(); eo.a().d(); } } public void handleMessage(Message message) { try { a(message); } catch (Throwable th3) { if (ey.f10154a) { ey.a(eq.this.f10111c, th3); } } } } public eq(Context context) { this.f10109a = context; this.f10113e = new ev(context); this.f10110b = new a(eo.a(context).c()); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void b(boolean z14) { if (!z14) { boolean b14 = b(); eo a14 = eo.a(this.f10109a); a14.a("MCUS", "t:" + b14 + ",i:" + z14); if (!b14) { if (ey.f10154a) { String str = this.f10111c; ey.b(str, "runCheck t:" + b14 + ",i:" + z14); return; } return; } } if (ey.f10154a) { ey.a(this.f10111c, "begin to sendrequest download desc"); } String b15 = fj.b(this.f10109a, "SP_TMLSDK_MODULE_INFO", V2TIMOfflinePushInfo.IOS_OFFLINE_PUSH_DEFAULT_SOUND); eo a15 = eo.a(this.f10109a); a15.a("MCUS", "load desc," + b15); List<ew> a16 = fj.a(b15); if (ey.f10154a) { String str2 = this.f10111c; ey.a(str2, "local comp infos = " + b15); } if (a16 != null && !a16.isEmpty()) { List<ew> a17 = a(a16); if (ey.f10154a) { ey.a(this.f10111c, " sendrequest download desc result"); } fj.a(this.f10109a, "SP_last_check_TMLSDK_update_time", Long.valueOf(System.currentTimeMillis())); if (a17 != null) { this.f10113e.a(a17, a16); } } } public void a(boolean z14) { this.f10112d = z14; this.f10110b.sendEmptyMessageDelayed(10006, 1000); } /* access modifiers changed from: private */ /* access modifiers changed from: public */ private void a() { if (!this.f10114f) { this.f10114f = true; String str = "loaddir,"; File[] listFiles = fj.a(this.f10109a, "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()) + f.f18324b; } } eo.a().a("MCUS", str); } } private List<ew> a(String str, List<ew> list) { String b14 = fb.b(str, fj.a("m_update_pwd", ff.f10193m)); if (ey.f10154a) { String str2 = this.f10111c; ey.a(str2, "decryAes256 the response is : " + b14); } String b15 = b(b14, list); if (ey.f10154a) { String str3 = this.f10111c; ey.a(str3, "parseJson is " + b15); } eo a14 = eo.a(this.f10109a); a14.a("MCUS", "updateModules," + b15); if (b15 == null) { if (ey.f10154a) { String str4 = this.f10111c; ey.a(str4, "parseJson is " + b15); } return null; } List<ew> a15 = fj.a(b15); if (a15 == null || a15.isEmpty()) { if (ey.f10154a) { ey.a(this.f10111c, "update desc complist is empty"); } return null; } if (ey.f10154a) { String a16 = fj.a(a15); String str5 = this.f10111c; ey.a(str5, "need update module string : " + a16); } String b16 = fj.b(this.f10109a, "SP_bad_TMLSDK_info", "preference_default"); if (ey.f10154a) { String str6 = this.f10111c; ey.a(str6, "badDexInfoStr : " + b16); } List<ew> a17 = fj.a(b16); if (!b16.equals("preference_default") && !a17.isEmpty()) { ArrayList<ew> a18 = fj.a(a15, a17); if (ey.f10154a) { String str7 = this.f10111c; ey.a(str7, "the num update dex in bad dex is " + a18.size()); } if (a18.size() > 0) { eo.a(this.f10109a).a("MCUS", "updateModules is bad,donot update"); return null; } } if (ey.f10154a) { String str8 = this.f10111c; ey.b(str8, "update desc prepared, prepare download," + b15); } return a15; } private String b(String str, List<ew> list) { try { JSONObject jSONObject = new JSONObject(str); String string = jSONObject.getString("status"); eo.a(this.f10109a).a("MCUS", "statucode," + string + "," + str); if (string.equals("-3")) { if (ey.f10154a) { ey.a(this.f10111c, "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.f10154a) { ey.a(this.f10111c, "need to update dex from server !!"); } String str2 = ""; JSONArray jSONArray = jSONObject.getJSONArray("compList"); for (int i10 = 0; i10 < jSONArray.length(); i10++) { JSONObject jSONObject2 = jSONArray.getJSONObject(i10); int i14 = jSONObject2.getInt("compId"); String string2 = jSONObject2.getString("compVer"); String string3 = jSONObject2.getString("md5"); long j14 = jSONObject2.getLong("size"); String string4 = jSONObject2.getString("compName"); if (!a(i14, string3, j14, string4, list)) { String str3 = i14 + "," + string2 + "," + string4 + "," + j14 + "," + string3 + ",;"; if (!str2.contains(str3)) { str2 = str2 + str3; } else if (!ey.f10154a) { return null; } else { ey.b(this.f10111c, "server response error,current comp is repeat from server,donot update," + str3); return null; } } else if (ey.f10154a) { ey.b(this.f10111c, "current comp from server is already new,so donot need to update:" + i14 + "," + string2 + "," + string4 + "," + j14 + "," + string3); } } return str2; } else if (string.equals(AlbumBean.ID_ALBUM_ALL)) { if (!ey.f10154a) { return null; } ey.a(this.f10111c, "sever parse json error,pelase check!"); return null; } else if (string.equals(AlbumBean.ID_VIDEO_ALL)) { if (!ey.f10154a) { return null; } ey.a(this.f10111c, "the params in json is error,please check!"); return null; } else if (string.equals("-4")) { if (!ey.f10154a) { return null; } ey.a(this.f10111c, "server has not config this version !!!"); return null; } else if (!string.equals("-5") || !ey.f10154a) { return null; } else { ey.a(this.f10111c, "server unkown error!!!"); return null; } } catch (Exception e14) { if (ey.f10154a) { ey.a(this.f10111c, e14); } String exc = e14.toString(); if (exc != null && exc.contains("\n")) { exc.replaceAll("\n", ","); } eo.a(this.f10109a).a("MCUS", "parser exp:" + exc); return null; } } private boolean a(int i10, String str, long j14, String str2, List<ew> list) { try { for (ew ewVar : list) { if (i10 == ewVar.f10136a && j14 == ewVar.f10139d && ewVar.f10138c.contains(str2) && ewVar.f10140e.equals(str)) { return true; } } return false; } catch (Exception e14) { if (!ey.f10154a) { return false; } ey.a(this.f10111c, e14); return false; } } private List<ew> a(List<ew> list) { String b14 = b(list); if (b14 == null) { if (ey.f10154a) { ey.a(this.f10111c, "download desc file postjsondata is null !!!"); } return null; } if (ey.f10154a) { String str = this.f10111c; ey.a(str, "desc file request postjson " + b14); } byte[] bytes = b14.getBytes(); if (bytes != null) { int i10 = 0; while (true) { int i14 = i10 + 1; if (i10 >= 3) { break; } if (ey.f10154a) { String str2 = this.f10111c; ey.a(str2, "desc file request times is " + i14); } byte[] a14 = fc.a("https://cc.map.qq.com?desc_c", bytes); if (a14 != null) { String str3 = new String(a14); if (ey.f10154a) { String str4 = this.f10111c; ey.a(str4, "download dex desc file: " + str3); } return a(str3, list); } eo a15 = eo.a(this.f10109a); a15.a("MCUS", "response failed,try:" + i14); i10 = i14; } } return null; } private String b(List<ew> list) { JSONObject jSONObject = new JSONObject(); try { jSONObject.put("projName", "TMLSDK"); jSONObject.put("appkey", fj.a(this.f10109a)); jSONObject.put("appversion", fj.b(this.f10109a)); jSONObject.put("imei", fj.c(this.f10109a)); jSONObject.put("coverSDKver", ff.f10187g); jSONObject.put("model", fj.b() + LoginConstants.UNDER_LINE + 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.f10136a); jSONObject2.put("compVer", ewVar.f10137b); jSONObject2.put("size", ewVar.f10139d); jSONObject2.put("md5", ewVar.f10140e); jSONArray.put(jSONObject2); } } jSONObject.put("compList", jSONArray); String jSONObject3 = jSONObject.toString(); eo a14 = eo.a(this.f10109a); a14.a("MCUS", "req:" + jSONObject3); if (ey.f10154a) { String str = this.f10111c; ey.a(str, "download desc file PostJsonData : " + jSONObject3); } return fb.a(jSONObject3, fj.a("m_update_pwd", ff.f10193m)); } catch (Exception e14) { String exc = e14.toString(); if (exc != null && exc.contains("\n")) { exc.replaceAll("\n", ","); } eo a15 = eo.a(this.f10109a); a15.a("MCUS", "reqDerror:" + exc); if (!ey.f10154a) { return null; } ey.a(this.f10111c, e14); return null; } } private boolean b() { long currentTimeMillis = System.currentTimeMillis() - fj.b(this.f10109a, "SP_last_check_TMLSDK_update_time", (Long) 0L).longValue(); if (ey.f10154a) { String str = this.f10111c; ey.a(str, "check time period is " + currentTimeMillis + "," + (currentTimeMillis / 3600000) + "days"); } return currentTimeMillis > 0; } }