京东到家.apk(点击下载) / a.java


package performance.jd.jdreportperformance.a.b;

import android.text.TextUtils;
import com.jingdong.sdk.jdhttpdns.config.HttpDnsConfig;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Pattern;
import main.homenew.parser.StyleConstant;
import org.json.JSONArray;
import org.json.JSONObject;
import performance.jd.jdreportperformance.b.b;
import performance.jd.jdreportperformance.c.b;
import performance.jd.jdreportperformance.d.c;
import performance.jd.jdreportperformance.minterface.InitInformation;

/* compiled from: CommonUtil */
public class a {
    public static String a() {
        return "" + String.format(Locale.CHINESE, "%.6f", Double.valueOf((((double) System.currentTimeMillis()) + 0.0d) / 1000.0d));
    }

    private static boolean a(String str) {
        return Pattern.compile("[0-9]*").matcher(str.trim()).matches();
    }

    public static Long a(String str, long j) {
        long j2;
        if (a(str)) {
            try {
                j2 = Long.parseLong(str);
            } catch (Exception e) {
                e.printStackTrace();
                j2 = j;
            }
            if (j2 >= 0) {
                j = j2;
            }
        }
        return Long.valueOf(j);
    }

    public static JSONObject a(HashMap<String, String> hashMap) {
        if (hashMap == null || hashMap.isEmpty()) {
            return null;
        }
        try {
            JSONObject jSONObject = new JSONObject();
            for (Map.Entry<String, String> entry : hashMap.entrySet()) {
                if (entry != null && !TextUtils.isEmpty(entry.getKey())) {
                    try {
                        jSONObject.put(entry.getKey(), entry.getValue() + "");
                    } catch (Exception unused) {
                    }
                }
            }
            return jSONObject;
        } catch (Throwable unused2) {
            return null;
        }
    }

    public static boolean b() {
        String a = a((JSONArray) null);
        String c2 = c();
        boolean z = !TextUtils.isEmpty(c2);
        return a(a, z ? a(c2, "/app_monitor/v2/getRule") : "https://perf.m.jd.com/app_monitor/v2/getRule", "https://perf.m.jd.com/app_monitor/v2/getRule", z);
    }

    private static String c() {
        InitInformation.IPerformanceController b = b.a().b();
        if (b == null) {
            return "";
        }
        String queryIpByHost = b.queryIpByHost("perf.m.jd.com");
        StringBuilder sb = new StringBuilder();
        sb.append("httpdns ip: ");
        sb.append(TextUtils.isEmpty(queryIpByHost) ? StyleConstant.EMPTY : queryIpByHost);
        b.a("CommonUtil", sb.toString());
        if (TextUtils.isEmpty(queryIpByHost) || queryIpByHost.contains("[") || !queryIpByHost.contains(":")) {
            return queryIpByHost;
        }
        return "[" + queryIpByHost + "]";
    }

    private static String a(String str, String str2) {
        return HttpDnsConfig.SCHEMA_HTTPS + str + str2;
    }

    public static boolean a(List<HashMap<String, String>> list) {
        String c2 = c(list);
        String c3 = c();
        boolean z = !TextUtils.isEmpty(c3);
        return a(c2, z ? a(c3, "/app_monitor/v2/report") : "https://perf.m.jd.com/app_monitor/v2/report", "https://perf.m.jd.com/app_monitor/v2/report", z);
    }

    public static boolean b(List<performance.jd.jdreportperformance.d.b> list) {
        String d = d(list);
        String c2 = c();
        boolean z = !TextUtils.isEmpty(c2);
        return a(d, z ? a(c2, "/app_monitor/v2/report") : "https://perf.m.jd.com/app_monitor/v2/report", "https://perf.m.jd.com/app_monitor/v2/report", z);
    }

    private static String c(List<HashMap<String, String>> list) {
        JSONArray jSONArray = new JSONArray();
        for (HashMap<String, String> hashMap : list) {
            JSONObject a = a(hashMap);
            if (a != null) {
                try {
                    jSONArray.put(a);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return a(jSONArray);
    }

    private static String d(List<performance.jd.jdreportperformance.d.b> list) {
        JSONArray jSONArray = new JSONArray();
        for (performance.jd.jdreportperformance.d.b bVar : list) {
            if (bVar != null) {
                try {
                    jSONArray.put(new JSONObject(bVar.a()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
        return a(jSONArray);
    }

    private static String a(JSONArray jSONArray) {
        String str = "";
        JSONObject b = performance.jd.jdreportperformance.d.a.a().b();
        if (jSONArray != null) {
            try {
                b.put("data", jSONArray);
            } catch (Throwable th) {
                th.printStackTrace();
            }
        }
        str = b.toString();
        if (TextUtils.isEmpty(str)) {
            return "";
        }
        try {
            return performance.jd.jdreportperformance.a.a.a.a(performance.jd.jdreportperformance.a.a.a.b(str.getBytes()));
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    private static boolean a(String str, String str2, String str3, boolean z) {
        boolean z2;
        if (TextUtils.isEmpty(str)) {
            b.a("CommonUtil", "data after assemble is null or empty");
            return false;
        }
        b.a("CommonUtil", "http url: " + str2);
        performance.jd.jdreportperformance.b.b bVar = new performance.jd.jdreportperformance.b.b();
        bVar.a(str2);
        bVar.a(str.getBytes());
        b.a a = bVar.a();
        if (a != null && a.a == 0) {
            if (a.f3221c == 200) {
                String a2 = a.a();
                StringBuilder sb = new StringBuilder();
                sb.append("response strategy: ");
                sb.append(TextUtils.isEmpty(a2) ? "" : a2);
                b.b("CommonUtil", sb.toString());
                z2 = c.a().a(a2);
                if (!z2) {
                    StringBuilder sb2 = new StringBuilder();
                    sb2.append("update strategy failed, strategy: ");
                    if (TextUtils.isEmpty(a2)) {
                        a2 = "null";
                    }
                    sb2.append(a2);
                    b.a("CommonUtil", sb2.toString());
                }
                b.a("CommonUtil", "postStatus: " + z2);
                return (!z2 || !z) ? z2 : a(str, str3, str3, false);
            }
            b.b("CommonUtil", "response code error: " + a.f3221c);
        }
        z2 = false;
        b.a("CommonUtil", "postStatus: " + z2);
        if (!z2) {
        }
    }
}