得物.apk(点击下载) / eq.java


package c.t.m.g;

import a0.b;
import a30.h;
import a40.f;
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 org.json.JSONArray;
import org.json.JSONObject;

/* compiled from: TML */
public class eq {

    /* renamed from: a  reason: collision with root package name */
    public Context f2207a;
    public a b;

    /* renamed from: c  reason: collision with root package name */
    private String f2208c = "CheckUpdate";
    private boolean d = true;
    private ev e;
    private boolean f;

    /* 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.d);
                eq.this.b.sendEmptyMessageDelayed(10006, 60000);
                eq.this.a();
                eo.a().d();
            }
        }

        public void handleMessage(Message message) {
            try {
                a(message);
            } catch (Throwable th2) {
                if (ey.f2232a) {
                    ey.a(eq.this.f2208c, th2);
                }
            }
        }
    }

    public eq(Context context) {
        this.f2207a = context;
        this.e = new ev(context);
        this.b = new a(eo.a(context).c());
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void b(boolean z) {
        if (!z) {
            boolean b2 = b();
            eo a5 = eo.a(this.f2207a);
            a5.a("MCUS", "t:" + b2 + ",i:" + z);
            if (!b2) {
                if (ey.f2232a) {
                    String str = this.f2208c;
                    ey.b(str, "runCheck t:" + b2 + ",i:" + z);
                    return;
                }
                return;
            }
        }
        if (ey.f2232a) {
            ey.a(this.f2208c, "begin to sendrequest download desc");
        }
        String b5 = fk.b(this.f2207a, "SP_TMLSDK_MODULE_INFO", "default");
        eo a12 = eo.a(this.f2207a);
        a12.a("MCUS", "load desc," + b5);
        List<ew> a13 = fk.a(b5);
        if (ey.f2232a) {
            h.m("local comp infos = ", b5, this.f2208c);
        }
        if (a13 != null && !a13.isEmpty()) {
            List<ew> a14 = a(a13);
            if (ey.f2232a) {
                ey.a(this.f2208c, " sendrequest download desc result");
            }
            fk.a(this.f2207a, "SP_last_check_TMLSDK_update_time", Long.valueOf(System.currentTimeMillis()));
            if (a14 != null) {
                this.e.a(a14, a13);
            }
        }
    }

    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 a() {
        String str;
        if (!this.f) {
            this.f = true;
            String str2 = "loaddir,";
            File[] listFiles = fk.a(this.f2207a, "TMLSDK_hp").listFiles();
            if (listFiles != null && listFiles.length > 0) {
                for (File file : listFiles) {
                    if (file.isFile()) {
                        StringBuilder j = f.j("", "f,");
                        j.append(file.getName());
                        j.append(",");
                        j.append(file.length());
                        j.append(",");
                        j.append(file.canRead());
                        j.append(",");
                        j.append(file.canWrite());
                        str = j.toString();
                    } else {
                        StringBuilder j12 = f.j("", "d,");
                        j12.append(file.getName());
                        str = j12.toString();
                    }
                    str2 = a01.a.g(str2, str, ";");
                }
            }
            eo.a().a("MCUS", str2);
        }
    }

    private List<ew> a(String str, List<ew> list) {
        String b2 = fb.b(str, fk.a("m_update_pwd", fg.m));
        if (ey.f2232a) {
            h.m("decryAes256 the response is : ", b2, this.f2208c);
        }
        String b5 = b(b2, list);
        if (ey.f2232a) {
            h.m("parseJson is ", b5, this.f2208c);
        }
        eo a5 = eo.a(this.f2207a);
        a5.a("MCUS", "updateModules," + b5);
        if (b5 == null) {
            if (ey.f2232a) {
                h.m("parseJson is ", b5, this.f2208c);
            }
            return null;
        }
        List<ew> a12 = fk.a(b5);
        if (a12 == null || a12.isEmpty()) {
            if (ey.f2232a) {
                ey.a(this.f2208c, "update desc complist is empty");
            }
            return null;
        }
        if (ey.f2232a) {
            h.m("need update module string : ", fk.a(a12), this.f2208c);
        }
        String b12 = fk.b(this.f2207a, "SP_bad_TMLSDK_info", "preference_default");
        if (ey.f2232a) {
            h.m("badDexInfoStr : ", b12, this.f2208c);
        }
        List<ew> a13 = fk.a(b12);
        if (!b12.equals("preference_default") && !a13.isEmpty()) {
            ArrayList<ew> a14 = fk.a(a12, a13);
            if (ey.f2232a) {
                String str2 = this.f2208c;
                StringBuilder h12 = a.f.h("the num update dex in bad dex is ");
                h12.append(a14.size());
                ey.a(str2, h12.toString());
            }
            if (a14.size() > 0) {
                eo.a(this.f2207a).a("MCUS", "updateModules is bad,donot update");
                return null;
            }
        }
        if (ey.f2232a) {
            String str3 = this.f2208c;
            ey.b(str3, "update desc prepared, prepare download," + b5);
        }
        return a12;
    }

    private String b(String str, List<ew> list) {
        try {
            JSONObject jSONObject = new JSONObject(str);
            String string = jSONObject.getString("status");
            eo.a(this.f2207a).a("MCUS", "statucode," + string + "," + str);
            if (string.equals("-3")) {
                if (ey.f2232a) {
                    ey.a(this.f2208c, "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.f2232a) {
                    ey.a(this.f2208c, "need to update dex from server !!");
                }
                String str2 = "";
                JSONArray jSONArray = jSONObject.getJSONArray("compList");
                for (int i = 0; i < jSONArray.length(); i++) {
                    JSONObject jSONObject2 = jSONArray.getJSONObject(i);
                    int i3 = 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(i3, string3, j, string4, list)) {
                        String str3 = i3 + "," + string2 + "," + string4 + "," + j + "," + string3 + ",;";
                        if (!str2.contains(str3)) {
                            str2 = str2 + str3;
                        } else if (!ey.f2232a) {
                            return null;
                        } else {
                            ey.b(this.f2208c, "server response error,current comp is repeat from server,donot update," + str3);
                            return null;
                        }
                    } else if (ey.f2232a) {
                        ey.b(this.f2208c, "current comp from server is already new,so donot need to update:" + i3 + "," + string2 + "," + string4 + "," + j + "," + string3);
                    }
                }
                return str2;
            } else if (string.equals("-1")) {
                if (!ey.f2232a) {
                    return null;
                }
                ey.a(this.f2208c, "sever parse json error,pelase check!");
                return null;
            } else if (string.equals("-2")) {
                if (!ey.f2232a) {
                    return null;
                }
                ey.a(this.f2208c, "the params in json is error,please check!");
                return null;
            } else if (string.equals("-4")) {
                if (!ey.f2232a) {
                    return null;
                }
                ey.a(this.f2208c, "server has not config this version !!!");
                return null;
            } else if (!string.equals("-5") || !ey.f2232a) {
                return null;
            } else {
                ey.a(this.f2208c, "server unkown error!!!");
                return null;
            }
        } catch (Exception e6) {
            if (ey.f2232a) {
                ey.a(this.f2208c, e6);
            }
            String exc = e6.toString();
            if (exc != null && exc.contains("\n")) {
                exc.replaceAll("\n", ",");
            }
            eo.a(this.f2207a).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.f2223a && j == ewVar.d && ewVar.f2224c.contains(str2) && ewVar.e.equals(str)) {
                    return true;
                }
            }
            return false;
        } catch (Exception e6) {
            if (!ey.f2232a) {
                return false;
            }
            ey.a(this.f2208c, e6);
            return false;
        }
    }

    private List<ew> a(List<ew> list) {
        String b2 = b(list);
        if (b2 == null) {
            if (ey.f2232a) {
                ey.a(this.f2208c, "download desc file postjsondata is null !!!");
            }
            return null;
        }
        if (ey.f2232a) {
            h.m("desc file request postjson ", b2, this.f2208c);
        }
        byte[] bytes = b2.getBytes();
        if (bytes != null) {
            int i = 0;
            while (true) {
                int i3 = i + 1;
                if (i >= 3) {
                    break;
                }
                if (ey.f2232a) {
                    String str = this.f2208c;
                    ey.a(str, "desc file request times is " + i3);
                }
                byte[] a5 = fd.a("https://cc.map.qq.com?desc_c", bytes);
                if (a5 != null) {
                    String str2 = new String(a5);
                    if (ey.f2232a) {
                        h.m("download dex desc file: ", str2, this.f2208c);
                    }
                    return a(str2, list);
                }
                eo a12 = eo.a(this.f2207a);
                a12.a("MCUS", "response failed,try:" + i3);
                i = i3;
            }
        }
        return null;
    }

    private String b(List<ew> list) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("projName", "TMLSDK");
            jSONObject.put("appkey", fk.a(this.f2207a));
            jSONObject.put("appversion", fk.b(this.f2207a));
            jSONObject.put("imei", fk.c(this.f2207a));
            jSONObject.put("coverSDKver", fg.f2247g);
            jSONObject.put("model", fk.b() + "_" + fk.a());
            jSONObject.put("APILevel", fk.c());
            JSONArray jSONArray = new JSONArray();
            for (ew ewVar : list) {
                if (ewVar != null) {
                    JSONObject jSONObject2 = new JSONObject();
                    jSONObject2.put("compId", ewVar.f2223a);
                    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 a5 = eo.a(this.f2207a);
            a5.a("MCUS", "req:" + jSONObject3);
            if (ey.f2232a) {
                String str = this.f2208c;
                ey.a(str, "download desc file PostJsonData : " + jSONObject3);
            }
            return fb.a(jSONObject3, fk.a("m_update_pwd", fg.m));
        } catch (Exception e6) {
            String exc = e6.toString();
            if (exc != null && exc.contains("\n")) {
                exc.replaceAll("\n", ",");
            }
            eo a12 = eo.a(this.f2207a);
            a12.a("MCUS", "reqDerror:" + exc);
            if (!ey.f2232a) {
                return null;
            }
            ey.a(this.f2208c, e6);
            return null;
        }
    }

    private boolean b() {
        long currentTimeMillis = System.currentTimeMillis() - fk.b(this.f2207a, "SP_last_check_TMLSDK_update_time", (Long) 0L).longValue();
        if (ey.f2232a) {
            String str = this.f2208c;
            StringBuilder g3 = b.g("check time period is ", currentTimeMillis, ",");
            g3.append(currentTimeMillis / 3600000);
            g3.append("days");
            ey.a(str, g3.toString());
        }
        return currentTimeMillis > 0;
    }
}