智能工厂.apk(点击下载) / c.java


package cn.jiguang.al;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ApplicationInfo;
import android.text.TextUtils;
import cn.jiguang.ao.d;
import cn.jiguang.ao.f;
import cn.jiguang.ao.h;
import cn.jiguang.dy.b;
import cn.jiguang.internal.JConstants;
import java.io.File;
import org.json.JSONArray;
import org.json.JSONObject;

public class c {
    private static final String a = "https://ce3e75d5.jpush.cn/wi/cjc4sa";
    private static c b;

    /* access modifiers changed from: package-private */
    public class a implements Runnable {
        private int b;
        private String c;
        private Context d;
        private b.a e;

        public a(Context context, int i, String str, b.a aVar) {
            this.d = context;
            this.b = i;
            this.c = str;
            this.e = aVar;
        }

        public void run() {
            try {
                if (TextUtils.isEmpty(this.c)) {
                    this.c = c.a;
                }
                if (f.c() && !TextUtils.isEmpty(f.e())) {
                    this.c = f.e();
                }
                File a2 = c.this.a((c) this.d, (Context) this.b, (int) this.c);
                if (a2 == null) {
                    cn.jiguang.an.b.b("UPM", "pluginFile is null");
                }
                if (this.e == null || this.e.a(a2)) {
                    c.this.a((c) this.d, (Context) this.b, (int) System.currentTimeMillis());
                }
            } catch (Throwable th) {
                cn.jiguang.an.b.e("UPM", "UpdateAction failed:" + th.getMessage());
            }
        }
    }

    private c() {
    }

    public static c a() {
        if (b == null) {
            synchronized (c.class) {
                if (b == null) {
                    b = new c();
                }
            }
        }
        return b;
    }

    /* JADX WARNING: Removed duplicated region for block: B:15:0x00ae  */
    /* JADX WARNING: Removed duplicated region for block: B:17:0x00b6  */
    private File a(Context context, int i, int i2, String str) {
        JSONObject jSONObject;
        String str2;
        int i3;
        cn.jiguang.am.a aVar;
        cn.jiguang.dy.c cVar;
        File a2;
        String str3;
        String str4;
        Throwable th;
        File file = null;
        try {
            JSONObject jSONObject2 = new JSONObject(str);
            int i4 = jSONObject2.getInt("code");
            if (i4 != 0) {
                cn.jiguang.an.b.f("UPM", "dealUif ERR:" + i4);
                cn.jiguang.an.b.f("UPM", "dealUif ERR:" + jSONObject2.getString("message"));
                cn.jiguang.dy.c.a().a(context, i, i2, cn.jiguang.am.a.g, 2, jSONObject2.getString("message"));
                return null;
            }
            jSONObject = jSONObject2.getJSONArray("data").optJSONObject(0);
            if (jSONObject == null) {
                try {
                    cn.jiguang.dy.c.a().a(context, i, i2, cn.jiguang.am.a.g, 2, "reponseData is empty");
                } catch (Throwable th2) {
                    th = th2;
                }
            }
            if (jSONObject != null) {
                cn.jiguang.an.b.f("UPM", "dealUif ERR");
                return null;
            }
            cn.jiguang.am.c a3 = cn.jiguang.am.c.a(jSONObject);
            if (a3 != null) {
                int i5 = a3.q;
                cn.jiguang.dy.c.a().a(context, a3.y);
                cn.jiguang.dy.c.a().b(context, a3.z);
                if (i5 == 2) {
                    str3 = "UPM";
                    str4 = "l is newest.";
                } else if (i5 == 1) {
                    str3 = "UPM";
                    str4 = "p not exist.";
                } else {
                    if (i5 == 3) {
                        c(context, i);
                        a.a(context, i, "", false);
                    } else if (i5 != 0) {
                        cn.jiguang.an.b.e("UPM", "p status is :" + i5);
                    } else if (a(a3, context)) {
                        cn.jiguang.dy.c.a().a(context, i, i2, cn.jiguang.am.a.f, 0, null);
                        cn.jiguang.dy.c.a().a(context, i, i2, cn.jiguang.am.a.h, 0, null);
                        if (TextUtils.isEmpty(a3.r)) {
                            cn.jiguang.an.b.b("UPM", "p:" + i + " du is empty");
                            cn.jiguang.dy.c.a().a(context, i, i2, cn.jiguang.am.a.f, 2, "p:" + i + " du is empty");
                            cn.jiguang.dy.c.a().a(context, i, i2, cn.jiguang.am.a.h, 2, "p:" + i + " du is empty");
                            return null;
                        }
                        a2 = a(context, a3);
                        if (a2 == null || !a2.exists()) {
                            cn.jiguang.dy.c.a().a(context, i, i2, cn.jiguang.am.a.f, 2, "update plugin failed");
                        }
                        file = a2;
                    }
                    if (i5 <= 3 || i5 < 0) {
                        cVar = cn.jiguang.dy.c.a();
                        aVar = cn.jiguang.am.a.g;
                        i3 = 2;
                        str2 = "unknown status " + i5;
                    } else {
                        cVar = cn.jiguang.dy.c.a();
                        aVar = cn.jiguang.am.a.g;
                        i3 = 1;
                        str2 = null;
                    }
                }
                cn.jiguang.an.b.b(str3, str4);
                a2 = a.a(context, a3, true);
                file = a2;
                if (i5 <= 3) {
                }
                cVar = cn.jiguang.dy.c.a();
                aVar = cn.jiguang.am.a.g;
                i3 = 2;
                str2 = "unknown status " + i5;
            } else {
                cn.jiguang.an.b.b("UPM", "dUif error:" + str);
                cVar = cn.jiguang.dy.c.a();
                aVar = cn.jiguang.am.a.g;
                i3 = 2;
                str2 = "parsePluginInfo failed";
            }
            cVar.a(context, i, i2, aVar, i3, str2);
            return file;
        } catch (Throwable th3) {
            th = th3;
            jSONObject = null;
            cn.jiguang.an.b.f("UPM", "dealUif e:" + th);
            cn.jiguang.dy.c.a().a(context, i, i2, cn.jiguang.am.a.g, 2, th.getMessage());
            if (jSONObject != null) {
            }
        }
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private File a(Context context, int i, String str) {
        StringBuilder sb;
        String str2;
        int i2;
        Throwable th;
        String str3;
        StringBuilder sb2;
        try {
            cn.jiguang.an.b.b("UPM", "u p:" + i + ",url:" + str);
            int a2 = a(context, i);
            try {
                JSONObject jSONObject = new JSONObject();
                jSONObject.put(cn.jiguang.dy.a.h, i);
                jSONObject.put(cn.jiguang.dy.a.i, a2);
                String a3 = a.a(i, 4);
                if (!TextUtils.isEmpty(a3)) {
                    try {
                        jSONObject.put(cn.jiguang.dy.a.j, Integer.parseInt(a3));
                        cn.jiguang.dy.c.a().a(context, i, a2, cn.jiguang.am.a.g, 0, null);
                        JSONArray jSONArray = new JSONArray();
                        jSONArray.put(jSONObject);
                        long a4 = f.a(context);
                        String a5 = h.a(context);
                        String b2 = h.b(context);
                        String str4 = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionName;
                        ApplicationInfo applicationInfo = context.getApplicationInfo();
                        String str5 = "";
                        if (applicationInfo != null) {
                            str5 = context.getPackageManager().getApplicationLabel(applicationInfo).toString();
                        }
                        Object a6 = cn.jiguang.ao.a.a(context);
                        if (a6 == null) {
                            a6 = null;
                        }
                        JSONObject jSONObject2 = new JSONObject();
                        jSONObject2.put(cn.jiguang.dy.a.k, jSONArray);
                        jSONObject2.put(cn.jiguang.dy.a.a, System.currentTimeMillis());
                        String str6 = cn.jiguang.dy.a.b;
                        if (a5 == null) {
                            a5 = "";
                        }
                        jSONObject2.put(str6, a5);
                        jSONObject2.put(cn.jiguang.dy.a.c, a4);
                        String str7 = cn.jiguang.dy.a.d;
                        if (b2 == null) {
                            b2 = "";
                        }
                        jSONObject2.put(str7, b2);
                        String str8 = cn.jiguang.dy.a.e;
                        if (str4 == null) {
                            str4 = "";
                        }
                        jSONObject2.put(str8, str4);
                        jSONObject2.put(cn.jiguang.dy.a.f, str5);
                        jSONObject2.put(cn.jiguang.dy.a.g, context.getPackageName());
                        String str9 = cn.jiguang.dy.a.l;
                        if (a6 == null) {
                            a6 = "";
                        }
                        jSONObject2.put(str9, a6);
                        cn.jiguang.an.b.b("UPM", "u:" + str);
                        cn.jiguang.an.b.b("UPM", "request p :" + jSONObject2.toString());
                        String a7 = a(str, jSONObject2.toString());
                        cn.jiguang.an.b.b("UPM", "request http response:" + a7);
                        if (!TextUtils.isEmpty(a7)) {
                            try {
                                File a8 = a(context, i, a2, a7);
                                cn.jiguang.an.b.b("UPM", "pI:" + i + " u finish");
                                return a8;
                            } catch (Throwable th2) {
                                th = th2;
                                i2 = a2;
                                try {
                                    cn.jiguang.an.b.f("UPM", "sU error:" + th.getMessage());
                                    cn.jiguang.dy.c.a().a(context, i, i2, cn.jiguang.am.a.g, 2, th.getMessage());
                                    str2 = "UPM";
                                    sb = new StringBuilder();
                                    sb.append("pI:");
                                    sb.append(i);
                                    sb.append(" u finish");
                                    cn.jiguang.an.b.b(str2, sb.toString());
                                    return null;
                                } catch (Throwable th3) {
                                    cn.jiguang.an.b.b("UPM", "pI:" + i + " u finish");
                                    throw th3;
                                }
                            }
                        } else {
                            cn.jiguang.dy.c.a().a(context, i, a2, cn.jiguang.am.a.g, 2, "config response is empty");
                            str2 = "UPM";
                            sb = new StringBuilder();
                            sb.append("pI:");
                            sb.append(i);
                            sb.append(" u finish");
                            cn.jiguang.an.b.b(str2, sb.toString());
                            return null;
                        }
                    } catch (Throwable th4) {
                        cn.jiguang.an.b.e("UPM", "put l_version error, " + th4.getMessage());
                        str3 = "UPM";
                        sb2 = new StringBuilder();
                    }
                } else {
                    cn.jiguang.an.b.b("UPM", "get l_version is null");
                    str3 = "UPM";
                    sb2 = new StringBuilder();
                    sb2.append("pI:");
                    sb2.append(i);
                    sb2.append(" u finish");
                    cn.jiguang.an.b.b(str3, sb2.toString());
                    return null;
                }
            } catch (Throwable th5) {
                th = th5;
                i2 = a2;
                cn.jiguang.an.b.f("UPM", "sU error:" + th.getMessage());
                cn.jiguang.dy.c.a().a(context, i, i2, cn.jiguang.am.a.g, 2, th.getMessage());
                str2 = "UPM";
                sb = new StringBuilder();
                sb.append("pI:");
                sb.append(i);
                sb.append(" u finish");
                cn.jiguang.an.b.b(str2, sb.toString());
                return null;
            }
        } catch (Throwable th6) {
            th = th6;
            i2 = -1;
            cn.jiguang.an.b.f("UPM", "sU error:" + th.getMessage());
            cn.jiguang.dy.c.a().a(context, i, i2, cn.jiguang.am.a.g, 2, th.getMessage());
            str2 = "UPM";
            sb = new StringBuilder();
            sb.append("pI:");
            sb.append(i);
            sb.append(" u finish");
            cn.jiguang.an.b.b(str2, sb.toString());
            return null;
        }
    }

    /* JADX WARNING: Removed duplicated region for block: B:17:0x011d A[ORIG_RETURN, RETURN, SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:18:? A[RETURN, SYNTHETIC] */
    private File a(Context context, cn.jiguang.am.c cVar) {
        String str;
        int i;
        cn.jiguang.am.a aVar;
        int i2;
        cn.jiguang.dy.c cVar2;
        int a2 = a(context, cVar.m);
        File a3 = b.a(context, cVar.s, cVar.m, cVar.o);
        if (d.b(cVar.r, 10000, a3.getAbsolutePath()) != null) {
            cn.jiguang.an.b.b("UPM", "d p :" + cVar.r + " p:" + a3);
            cn.jiguang.dy.c.a().a(context, cVar.m, a2, cn.jiguang.am.a.h, 1, null);
            cn.jiguang.dy.c.a().a(context, cVar.m, a2, cn.jiguang.am.a.i, 0, null);
            String a4 = cn.jiguang.ao.c.a(a3.getAbsolutePath());
            if (TextUtils.isEmpty(a4) || !a4.equalsIgnoreCase(cVar.s)) {
                cn.jiguang.an.b.b("UPM", "d p m not m, will d: file m:" + a4 + ",config m:" + cVar.s);
                cn.jiguang.dy.c.a().a(context, cVar.m, a2, cn.jiguang.am.a.i, 2, "check plugin file md5 failed");
                a3.delete();
                if (!a3.exists()) {
                    return a3;
                }
                return null;
            }
            File a5 = a.a(context, cVar.m);
            a.a(context, cVar.m, cVar.x, true);
            if (a5 != null && a5.exists()) {
                cn.jiguang.an.b.b("UPM", "delete old file:" + a5.getAbsolutePath());
                a5.delete();
            }
            cn.jiguang.an.b.b("UPM", "d p val succ");
            cVar2 = cn.jiguang.dy.c.a();
            i2 = cVar.m;
            aVar = cn.jiguang.am.a.i;
            i = 1;
            str = null;
        } else {
            cn.jiguang.an.b.e("UPM", "d p :" + cVar.r + " fail.");
            cVar2 = cn.jiguang.dy.c.a();
            i2 = cVar.m;
            aVar = cn.jiguang.am.a.h;
            i = 2;
            str = "down load plugin fail.";
        }
        cVar2.a(context, i2, a2, aVar, i, str);
        if (!a3.exists()) {
        }
    }

    private String a(String str, String str2) {
        return d.a(str, 10000, str2);
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void a(Context context, int i, long j) {
        try {
            SharedPreferences.Editor edit = context.getSharedPreferences("cn.jiguang.prefs", 0).edit();
            edit.putLong("plugin_update_time_" + i, j).apply();
        } catch (Throwable unused) {
        }
    }

    private void a(File file) {
        if (file != null && file.exists()) {
            file.delete();
        }
    }

    private boolean a(cn.jiguang.am.c cVar, Context context) {
        cn.jiguang.an.b.b("UPM", "c nU l p...");
        File a2 = a.a(context, cVar, true);
        cn.jiguang.an.b.b("UPM", "pII:" + a2);
        if (a2 == null) {
            return true;
        }
        a.a(context, cVar.m, cVar.x, false);
        cn.jiguang.an.b.b("UPM", "p has exist, p is:" + a2.getAbsolutePath());
        return false;
    }

    private boolean b(Context context, int i) {
        boolean z = false;
        SharedPreferences sharedPreferences = context.getSharedPreferences("cn.jiguang.prefs", 0);
        long j = sharedPreferences.getLong("plugin_update_time_" + i, 0);
        long j2 = sharedPreferences.getLong("plugin_update_interval_" + i, JConstants.DAY);
        if (j <= 0 || System.currentTimeMillis() > j2 + j) {
            z = true;
        }
        if (!z) {
            cn.jiguang.an.b.b("UPM", "no need update, last is " + cn.jiguang.ao.b.a(j));
        }
        return z;
    }

    private void c(Context context, int i) {
        a(a.a(context, i));
    }

    public int a(Context context, int i) {
        cn.jiguang.am.c b2 = a.b(context, i);
        if (a.a(context, i) != null) {
            return b2.o;
        }
        try {
            return Integer.parseInt(a.a(i, 4));
        } catch (Throwable unused) {
            return -1;
        }
    }

    public void a(Context context, int i, String str, b.a aVar) {
        if (b(context, i)) {
            f.a(context, JConstants.SDK_TYPE, 76, null, null, new a(context, i, str, aVar));
        }
    }
}