华润售电云 v2.2.7版本的 MD5 值为:93c9468f6a7b82a4ae05a1eac91dbd03

以下内容为反编译后的 C0078b.java 源代码,内容仅作参考


package com.iflytek.thirdparty;

import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.v4.app.NotificationCompat;
import android.text.TextUtils;
import android.util.Log;
import com.iflytek.cloud.SpeechConstant;
import com.igexin.assist.sdk.AssistPushConsts;
import com.igexin.sdk.GTIntentService;
import com.igexin.sdk.PushConsts;
import io.dcloud.common.constant.AbsoluteConst;
import io.dcloud.common.util.JSUtil;
import io.dcloud.common.util.net.NetWork;
import io.dcloud.feature.ad.dcloud.ADSim;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.http.client.ClientProtocolException;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class C0078b {
    public static boolean a = false;
    private static int c = 1;
    private static boolean d = true;
    private static boolean e = false;
    private static boolean f = true;
    private static int g = 1;
    private static int h;
    private static String b = "lxd";
    private static final String i = "act" + b;
    private static final String j = "evn" + b;
    private static final String k = "esp" + b;
    private static final String l = NotificationCompat.CATEGORY_ERROR + b;
    private static final String m = NotificationCompat.CATEGORY_SYSTEM + b;
    private static String n = "";
    private static long o = 0;
    private static String p = "";
    private static Object q = new Object();
    private static Object r = new Object();
    private static Object s = new Object();
    private static boolean t = false;
    private static boolean u = false;
    private static String v = "";
    private static ExecutorService w = Executors.newSingleThreadExecutor();

    private static int a(Context context, String str, JSONObject jSONObject) {
        HttpURLConnection httpURLConnection;
        int i2 = 1;
        int i3 = 2;
        if (c != 1) {
            return 2;
        }
        C0079c.a("MobileAgentRun", "run into httppost :" + str + "####" + context.getClass().getName() + "###" + jSONObject.toString());
        HttpURLConnection httpURLConnection2 = null;
        int i4 = 0;
        try {
            try {
                C0079c.a("MobileAgentRun", jSONObject.toString());
                C0079c.a("MobileAgentRun", "post start");
                httpURLConnection = (HttpURLConnection) new URL(String.valueOf(str) + "&appkey=" + C0084h.h(context) + "&channel=" + URLEncoder.encode(C0084h.i(context), "UTF-8") + "&code=106").openConnection();
            } catch (Throwable th) {
                th = th;
            }
            try {
                try {
                    httpURLConnection.setReadTimeout(ADSim.INTISPLSH);
                    httpURLConnection.setDoOutput(true);
                    httpURLConnection.setDoInput(true);
                    httpURLConnection.setUseCaches(false);
                    httpURLConnection.setRequestMethod("POST");
                    byte[] a2 = C0083g.a().a(jSONObject.toString());
                    httpURLConnection.setRequestProperty("Content-length", new StringBuilder().append(a2.length).toString());
                    httpURLConnection.setRequestProperty(NetWork.CONTENT_TYPE, "application/octet-stream");
                    httpURLConnection.setRequestProperty("Charset", "UTF-8");
                    OutputStream outputStream = httpURLConnection.getOutputStream();
                    outputStream.write(a2);
                    outputStream.close();
                    i4 = httpURLConnection.getResponseCode();
                    C0079c.a("MobileAgentRun", "post end");
                    if (200 == i4) {
                        try {
                            C0079c.a("MobileAgent", "send success");
                        } catch (Exception e2) {
                            e = e2;
                            httpURLConnection2 = httpURLConnection;
                            C0079c.a("MobileAgentRun", e.toString());
                            e.printStackTrace();
                            if (httpURLConnection2 != null) {
                                httpURLConnection2.disconnect();
                            }
                            i3 = i2;
                            C0079c.a("MobileAgentHttpPost", "code:" + i4 + "status:  " + i3 + "  content: " + jSONObject.getString("logJsonAry"));
                            C0079c.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i3);
                            return i3;
                        }
                    } else {
                        i2 = 2;
                    }
                    if (httpURLConnection != null) {
                        httpURLConnection.disconnect();
                    }
                } catch (Exception e3) {
                    e = e3;
                    httpURLConnection2 = httpURLConnection;
                    i2 = 2;
                    C0079c.a("MobileAgentRun", e.toString());
                    e.printStackTrace();
                    if (httpURLConnection2 != null) {
                    }
                    i3 = i2;
                    C0079c.a("MobileAgentHttpPost", "code:" + i4 + "status:  " + i3 + "  content: " + jSONObject.getString("logJsonAry"));
                    C0079c.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i3);
                    return i3;
                }
            } catch (ClientProtocolException e4) {
                e = e4;
                httpURLConnection2 = httpURLConnection;
                C0079c.a("MobileAgentRun", e.toString());
                e.printStackTrace();
            } catch (IOException e5) {
                e = e5;
                httpURLConnection2 = httpURLConnection;
                C0079c.a("MobileAgentRun", e.toString());
                e.printStackTrace();
                if (httpURLConnection2 != null) {
                    httpURLConnection2.disconnect();
                }
                C0079c.a("MobileAgentHttpPost", "code:" + i4 + "status:  " + i3 + "  content: " + jSONObject.getString("logJsonAry"));
                C0079c.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i3);
                return i3;
            } catch (JSONException e6) {
                e = e6;
                httpURLConnection2 = httpURLConnection;
                C0079c.a("MobileAgentRun", e.toString());
                e.printStackTrace();
                i3 = 3;
            } catch (Throwable th2) {
                th = th2;
                httpURLConnection2 = httpURLConnection;
                if (httpURLConnection2 != null) {
                    httpURLConnection2.disconnect();
                }
                throw th;
            }
        } catch (IOException e7) {
            e = e7;
        } catch (JSONException e8) {
            e = e8;
        } catch (Exception e9) {
            e = e9;
        } catch (ClientProtocolException e10) {
            e = e10;
        }
        i3 = i2;
        try {
            C0079c.a("MobileAgentHttpPost", "code:" + i4 + "status:  " + i3 + "  content: " + jSONObject.getString("logJsonAry"));
        } catch (Exception unused) {
        }
        C0079c.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i3);
        return i3;
    }

    protected static SharedPreferences a(Context context) {
        return context.getSharedPreferences(String.valueOf(b) + "MoblieAgent_event_" + context.getPackageName(), 0);
    }

    private static String a(Context context, String str, SharedPreferences sharedPreferences) {
        n = "";
        String a2 = C0084h.a(context, str);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putString("appKey", str);
        edit.putString("sessionId", a2);
        edit.putLong("lastResumeTime", System.currentTimeMillis());
        edit.putString("activities", i(context, "onResume", null));
        long j2 = sharedPreferences.getLong("readFlowRev", 0L);
        long[] o2 = C0084h.o(context);
        edit.putLong("readFlowRev", o2[0]);
        long j3 = o2[0] - j2;
        if (j3 < 0) {
            j3 = 0;
        }
        edit.putLong("consumeFlowRev", j3);
        long j4 = sharedPreferences.getLong("readFlowSnd", 0L);
        edit.putLong("readFlowSnd", o2[1]);
        long j5 = o2[1] - j4;
        edit.putLong("consumeFlowSnd", j5 >= 0 ? j5 : 0L);
        edit.commit();
        p = a2;
        return a2;
    }

    private static void a(Context context, String str, long j2) {
        synchronized (q) {
            SharedPreferences c2 = c(context);
            int i2 = c2.getInt("uploadcount", 0);
            String str2 = String.valueOf(c2.getString("uploadList", "")) + str + "|";
            if (j2 > 10000) {
                j2 = 1;
            }
            c2.edit().putString("uploadList", str2).commit();
            c2.edit().putLong("uploadpopindex", j2).commit();
            if (str2.split("\\|").length > 30000) {
                String n2 = n(context);
                context.deleteFile(n2);
                j(context, n2);
            } else {
                c2.edit().putInt("uploadcount", i2 + 1).commit();
            }
        }
    }

    public static void a(Context context, String str, String str2) {
        if (c == 0) {
            Log.i("MobileAgent", "Du have not permission to collect data");
        } else if (str.contains("#")) {
            Log.w("MobileAgent", "the eventId contain illegal char");
        } else {
            h(context, str, str2);
        }
    }

    public static void a(Context context, boolean z) {
        if (z) {
            C0079c.a("MobileAgentRun", "run into pageact onresumep");
            h(context);
        } else {
            C0079c.a("MobileAgentRun", "run into pageact onpausep");
            i(context);
        }
        C0079c.a("MobileAgentRun", "run out pageact");
    }

    protected static boolean a(Context context, int i2) {
        int i3;
        String str;
        SharedPreferences k2 = k(context);
        if (i2 == 3) {
            i3 = k2.getInt("actionmonth", 0);
            str = "actionday";
        } else if (i2 == 2) {
            i3 = k2.getInt("eventmonth", 0);
            str = "eventday";
        } else {
            i3 = k2.getInt("sysmonth", 0);
            str = "sysday";
        }
        int i4 = k2.getInt(str, 0);
        Date date = new Date();
        return (Integer.valueOf(new SimpleDateFormat("M").format(date)).intValue() == i3 && Integer.valueOf(new SimpleDateFormat("dd").format(date)).intValue() == i4) ? false : true;
    }

    private static boolean a(Context context, SharedPreferences sharedPreferences) {
        SharedPreferences a2 = a(context);
        String string = a2.getString("eventlogs", "");
        if (string.equals("")) {
            return false;
        }
        String string2 = l(context).getString("sessionId", null);
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put(SpeechConstant.IST_SESSION_ID, string2);
            jSONObject.put("logJsonAry", string);
            if (a(context, jSONObject.toString(), 2)) {
                a2.edit().putString("eventlogs", "").commit();
                return true;
            }
            return true;
        } catch (JSONException e2) {
            e2.printStackTrace();
            return true;
        }
    }

    private static boolean a(Context context, SharedPreferences sharedPreferences, boolean z) {
        String string = sharedPreferences.getString("sessionId", "");
        String string2 = sharedPreferences.getString("activities", "");
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put(SpeechConstant.IST_SESSION_ID, string);
            jSONObject.put("logs", string2);
            if (z) {
                jSONObject.put("flowConsumpRev", sharedPreferences.getLong("consumeFlowRev", 0L));
                jSONObject.put("flowConsumpSnd", sharedPreferences.getLong("consumeFlowSnd", 0L));
            } else {
                jSONObject.put("flowConsumpRev", 0);
                jSONObject.put("flowConsumpSnd", 0);
            }
            if (a(context, jSONObject.toString(), 3)) {
                sharedPreferences.edit().putString("activities", "").commit();
                return true;
            }
            return true;
        } catch (JSONException e2) {
            e2.printStackTrace();
            return true;
        }
    }

    public static boolean a(Context context, String str) {
        int i2;
        String h2 = h(context, str);
        if (h2.equals("")) {
            b(context, 3);
            i(context, str);
            return true;
        }
        JSONObject d2 = d(context);
        try {
            try {
                d2.put(SpeechConstant.IST_SESSION_ID, new JSONObject(h2).get(SpeechConstant.IST_SESSION_ID));
            } catch (JSONException unused) {
                d2.put(SpeechConstant.IST_SESSION_ID, "");
            }
            d2.put("mac", C0084h.g(context));
            try {
                d2.put("deviceDetail", URLEncoder.encode(C0084h.a(), "UTF-8"));
            } catch (UnsupportedEncodingException unused2) {
                d2.put("deviceDetail", "");
            }
            try {
                d2.put("manufacturer", URLEncoder.encode(C0084h.b(), "UTF-8"));
            } catch (UnsupportedEncodingException unused3) {
                d2.put("manufacturer", "");
            }
            try {
                d2.put("phoneOs", URLEncoder.encode(C0084h.c(), "UTF-8"));
            } catch (UnsupportedEncodingException unused4) {
                d2.put("phoneOs", "");
            }
            try {
                d2.put("accessPoint", URLEncoder.encode(C0084h.l(context), "UTF-8"));
            } catch (UnsupportedEncodingException unused5) {
                d2.put("accessPoint", "");
            }
            try {
                d2.put("netWorkType", URLEncoder.encode(C0084h.p(context), "UTF-8"));
            } catch (UnsupportedEncodingException unused6) {
                d2.put("netWorkType", "");
            }
            d2.put("uuid", v);
            d2.put("deviceId", C0084h.a(context));
            d2.put("cpuRatioMax", C0084h.f());
            d2.put("cpuRatioCur", C0084h.g());
            d2.put("menoryRatio", C0084h.h());
            d2.put("logJsonAry", new JSONArray("[" + h2 + "]"));
            i2 = a(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:postactlog", d2);
        } catch (JSONException e2) {
            e2.printStackTrace();
            i2 = 3;
        }
        if (i2 == 1 || i2 == 3) {
            b(context, 3);
            i(context, str);
            Log.i("MobileAgent", "act log sd");
            return true;
        }
        return false;
    }

    private static synchronized boolean a(Context context, String str, int i2) {
        String str2;
        synchronized (C0078b.class) {
            try {
                if (i2 == 3) {
                    str2 = i;
                } else if (i2 == 2) {
                    str2 = j;
                } else if (i2 == 4) {
                    str2 = l;
                } else if (i2 == 1) {
                    str2 = m;
                } else if (i2 != 5) {
                    return false;
                } else {
                    str2 = k;
                }
                if (str.trim().equals("")) {
                    return false;
                }
                long m2 = m(context);
                long j2 = 1 + m2;
                String str3 = String.valueOf(str2) + m2;
                FileOutputStream fileOutputStream = null;
                try {
                    try {
                        fileOutputStream = context.openFileOutput(str3, 1);
                        a(context, str3, j2);
                        fileOutputStream.write(str.getBytes());
                        if (fileOutputStream != null) {
                            try {
                                fileOutputStream.close();
                            } catch (IOException e2) {
                                e = e2;
                                e.printStackTrace();
                                return true;
                            }
                        }
                    } catch (FileNotFoundException unused) {
                        Log.w("MobileAgentRun", "can not find log file");
                        if (fileOutputStream != null) {
                            try {
                                fileOutputStream.close();
                            } catch (IOException e3) {
                                e3.printStackTrace();
                            }
                        }
                        return false;
                    }
                } catch (IOException unused2) {
                    Log.w("MobileAgentRun", "file r/w execption");
                    if (fileOutputStream != null) {
                        try {
                            fileOutputStream.close();
                        } catch (IOException e4) {
                            e = e4;
                            e.printStackTrace();
                            return true;
                        }
                    }
                }
                return true;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    private static boolean a(SharedPreferences sharedPreferences) {
        return System.currentTimeMillis() - sharedPreferences.getLong("endTime", -1L) > GTIntentService.WAIT_TIME;
    }

    protected static SharedPreferences b(Context context) {
        return context.getSharedPreferences(String.valueOf(b) + "MoblieAgent_event_sp" + context.getPackageName(), 0);
    }

    protected static void b(Context context, int i2) {
        String str;
        Date date = new Date();
        int parseInt = Integer.parseInt(new SimpleDateFormat("dd").format(date));
        int parseInt2 = Integer.parseInt(new SimpleDateFormat("M").format(date));
        SharedPreferences.Editor edit = k(context).edit();
        if (i2 == 3) {
            edit.putInt("actionmonth", parseInt2);
            str = "actionday";
        } else if (i2 == 2) {
            edit.putInt("eventmonth", parseInt2);
            str = "eventday";
        } else {
            edit.putInt("sysmonth", parseInt2);
            str = "sysday";
        }
        edit.putInt(str, parseInt);
        edit.commit();
    }

    public static void b(Context context, String str, String str2) {
        synchronized (r) {
            String a2 = C0084h.a(str);
            String a3 = C0084h.a(str2);
            SharedPreferences a4 = a(context);
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append(a4.getString("eventlogs", ""));
            try {
                stringBuffer.append(URLEncoder.encode(a2, "UTF-8"));
                stringBuffer.append("|");
                stringBuffer.append(URLEncoder.encode(a3, "UTF-8"));
                stringBuffer.append("|");
                stringBuffer.append(1);
                stringBuffer.append("|");
                stringBuffer.append(System.currentTimeMillis());
                stringBuffer.append("\n");
                a4.edit().putString("eventlogs", stringBuffer.toString()).commit();
                a(context, (SharedPreferences) null);
            } catch (UnsupportedEncodingException unused) {
                C0079c.a("MobileAgentRun", "unsupport utf-8,can't onEvent()");
                return;
            }
        }
        b(context, false);
    }

    protected static void b(Context context, boolean z) {
        C0080d c0080d;
        if (c != 1) {
            return;
        }
        C0079c.a("MobileAgentRun", "run into strategy");
        f(context);
        boolean z2 = e;
        if (!z2 || (z2 && o(context))) {
            int i2 = g;
            if (i2 == 1) {
                c0080d = new C0080d(context, 6);
            } else if (i2 != 2) {
                if (i2 == 3 && a(context, 3)) {
                    c0080d = new C0080d(context, 6);
                }
            } else if (z) {
                new C0080d(context, 6).start();
                f = false;
            }
            c0080d.start();
        }
        f = false;
        C0079c.a("MobileAgentRun", "run out strategy");
    }

    private static boolean b(Context context, SharedPreferences sharedPreferences) {
        SharedPreferences b2 = b(context);
        String string = b2.getString("eventlogs", "");
        if (string.equals("")) {
            return false;
        }
        String string2 = l(context).getString("sessionId", null);
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put(SpeechConstant.IST_SESSION_ID, string2);
            jSONObject.put("logJsonAry", string);
            if (a(context, jSONObject.toString(), 5)) {
                b2.edit().putString("eventlogs", "").commit();
                return true;
            }
            return true;
        } catch (JSONException e2) {
            e2.printStackTrace();
            return true;
        }
    }

    public static boolean b(Context context, String str) {
        try {
            if (a(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:postsyslog", new JSONObject(h(context, str))) == 1) {
                i(context, str);
                return true;
            }
            return false;
        } catch (JSONException unused) {
            i(context, str);
            Log.i("MobileAgent", "SDK del a dirty data");
            return false;
        }
    }

    protected static SharedPreferences c(Context context) {
        return context.getSharedPreferences(String.valueOf(b) + "MoblieAgent_upload_" + context.getPackageName(), 0);
    }

    public static void c(Context context, String str, String str2) {
        synchronized (s) {
            String a2 = C0084h.a(str);
            String a3 = C0084h.a(str2);
            SharedPreferences b2 = b(context);
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append(b2.getString("eventlogs", ""));
            try {
                stringBuffer.append(URLEncoder.encode(a2, "UTF-8"));
                stringBuffer.append("|");
                stringBuffer.append(URLEncoder.encode(a3, "UTF-8"));
                stringBuffer.append("|");
                stringBuffer.append(1);
                stringBuffer.append("|");
                stringBuffer.append(System.currentTimeMillis());
                stringBuffer.append("\n");
                b2.edit().putString("eventlogs", stringBuffer.toString()).commit();
                if (g == 1 || stringBuffer.toString().getBytes().length > 10000) {
                    b(context, (SharedPreferences) null);
                }
            } catch (UnsupportedEncodingException unused) {
                C0079c.a("MobileAgent", "unsupport utf-8,can't onEvent()");
                return;
            }
        }
        b(context, false);
    }

    public static boolean c(Context context, String str) {
        String h2 = h(context, str);
        try {
            JSONObject jSONObject = new JSONObject(h2);
            jSONObject.put(PushConsts.KEY_SERVICE_PIT, 1);
            jSONObject.put("protocolVersion", "3.1.4");
            jSONObject.put("sdkVersion", "3.2.0.2");
            jSONObject.put("cid", C0084h.b(context));
            jSONObject.put("deviceId", C0084h.a(context));
            jSONObject.put("appKey", C0084h.h(context));
            jSONObject.put("packageName", C0084h.j(context));
            jSONObject.put("versionCode", C0084h.m(context));
            jSONObject.put("versionName", C0084h.n(context));
            jSONObject.put("sendTime", System.currentTimeMillis());
            int a2 = a(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:posterrlog", jSONObject);
            if (a2 != 1 && a2 != 3) {
                return false;
            }
            b(context, 3);
            i(context, str);
            Log.i("MobileAgent", "erLog sd");
            C0079c.a("MobileAgent", "send errlog success \n" + h2);
            return true;
        } catch (JSONException unused) {
            i(context, str);
            Log.i("MobileAgent", "SDK del a dirty data");
            return false;
        }
    }

    protected static JSONObject d(Context context) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put(PushConsts.KEY_SERVICE_PIT, 1);
            jSONObject.put("protocolVersion", "3.1.4");
            jSONObject.put("sdkVersion", "3.2.0.2");
            jSONObject.put("cid", C0084h.b(context));
            jSONObject.put("appKey", C0084h.h(context));
            jSONObject.put("packageName", context.getPackageName());
            jSONObject.put("versionCode", C0084h.m(context));
            jSONObject.put("versionName", C0084h.n(context));
            jSONObject.put("sendTime", System.currentTimeMillis());
            jSONObject.put("deviceId", C0084h.a(context));
            jSONObject.put(AbsoluteConst.XML_CHANNEL, C0084h.i(context));
        } catch (JSONException e2) {
            e2.printStackTrace();
        }
        return jSONObject;
    }

    protected static void d(Context context, String str) {
        k(context).edit().putString(str, "record").commit();
    }

    public static void d(Context context, String str, String str2) {
        if (t) {
            Log.i("MobileAgent", "already init");
            return;
        }
        try {
            if (!a) {
                a = !context.getSharedPreferences("MoblieAgent_debug", 0).getString("debug", "").equals("");
            }
        } catch (Exception unused) {
        }
        C0079c.a("MobileAgentAPI", "run in init[" + str + JSUtil.COMMA + str2 + "]");
        if (context == null) {
            Log.e("MobileAgent", "Exception occurent in joinDu ,context cann't be null");
        } else if (TextUtils.isEmpty(str) || C0084h.a(str, 50)) {
            Log.e("MobileAgent", "Exception occurent in joinDu ,appID cann't be null or empty");
        } else {
            if (TextUtils.isEmpty(str2)) {
                str2 = AssistPushConsts.PUSHMESSAGE_ACTION_MULTI_BRAND_RECEIVE_NONE;
            } else if (C0084h.a(str2, 100)) {
                str2 = str2.substring(0, 99);
                Log.e("MobileAgent", "Exception occurent in joinDu ,channelID cann't be null or empty");
            }
            SharedPreferences sharedPreferences = context.getSharedPreferences(String.valueOf(b) + "MoblieAgent_sys_config", 0);
            sharedPreferences.edit().putString("MOBILE_APPKEY", str).commit();
            sharedPreferences.edit().putString("MOBILE_CHANNEL", str2).commit();
            if (!e(context, "#lxapkmd5")) {
                new Thread(new RunnableC0082f(context)).start();
            }
            t = true;
            Log.i("MobileAgent", "finish init SUCCESS " + a);
        }
    }

    protected static void e(Context context) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put(PushConsts.KEY_SERVICE_PIT, 1);
            jSONObject.put("protocolVersion", "3.1.4");
            jSONObject.put("sdkVersion", "3.2.0.2");
            jSONObject.put("cid", C0084h.b(context));
            jSONObject.put("deviceId", C0084h.a(context));
            jSONObject.put("appKey", C0084h.h(context));
            jSONObject.put("packageName", context.getPackageName());
            jSONObject.put("versionCode", C0084h.m(context));
            jSONObject.put("versionName", C0084h.n(context));
            jSONObject.put("sendTime", System.currentTimeMillis());
            jSONObject.put("imsi", C0084h.c(context));
            jSONObject.put("mac", C0084h.g(context));
            jSONObject.put("deviceDetail", URLEncoder.encode(C0084h.a(), "UTF-8"));
            jSONObject.put("manufacturer", URLEncoder.encode(C0084h.b(), "UTF-8"));
            jSONObject.put("phoneOS", URLEncoder.encode(C0084h.c(), "UTF-8"));
            jSONObject.put("screenWidth", C0084h.d(context));
            jSONObject.put("screenHeight", C0084h.e(context));
            jSONObject.put("screenDensity", C0084h.f(context));
            jSONObject.put("carrierName", URLEncoder.encode(C0084h.k(context), "UTF-8"));
            jSONObject.put("accessPoint", C0084h.l(context));
            jSONObject.put("countryCode", C0084h.d());
            jSONObject.put("languageCode", C0084h.e());
            jSONObject.put(AbsoluteConst.XML_CHANNEL, URLEncoder.encode(C0084h.i(context), "UTF-8"));
            if (a(context, jSONObject.toString(), 1)) {
                b(context, 1);
            }
        } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
        } catch (JSONException e3) {
            e3.printStackTrace();
        }
    }

    protected static boolean e(Context context, String str) {
        return !k(context).getString(str, "").equals("");
    }

    public static boolean e(Context context, String str, String str2) {
        String str3;
        String h2 = str2 == null ? h(context, str) : str2;
        if (h2.equals("")) {
            if (str2 == null) {
                b(context, 3);
                i(context, str);
                return true;
            }
            return false;
        }
        try {
            JSONObject jSONObject = new JSONObject(h2);
            String b2 = C0084h.b(context);
            jSONObject.put(PushConsts.KEY_SERVICE_PIT, 1);
            jSONObject.put("protocolVersion", "3.1.4");
            jSONObject.put("sdkVersion", "3.2.0.2");
            jSONObject.put("cid", b2);
            jSONObject.put("appKey", C0084h.h(context));
            jSONObject.put("packageName", C0084h.j(context));
            jSONObject.put("versionCode", C0084h.m(context));
            jSONObject.put("versionName", C0084h.n(context));
            jSONObject.put("sendTime", System.currentTimeMillis());
            jSONObject.put("mac", C0084h.g(context));
            try {
                jSONObject.put("deviceDetail", URLEncoder.encode(C0084h.a(), "UTF-8"));
            } catch (UnsupportedEncodingException unused) {
                jSONObject.put("deviceDetail", "");
            }
            try {
                jSONObject.put("manufacturer", URLEncoder.encode(C0084h.b(), "UTF-8"));
            } catch (UnsupportedEncodingException unused2) {
                jSONObject.put("manufacturer", "");
            }
            try {
                jSONObject.put("phoneOs", URLEncoder.encode(C0084h.c(), "UTF-8"));
            } catch (UnsupportedEncodingException unused3) {
                jSONObject.put("phoneOs", "");
            }
            jSONObject.put("accessPoint", C0084h.l(context));
            jSONObject.put("deviceId", C0084h.a(context));
            try {
                jSONObject.put(AbsoluteConst.XML_CHANNEL, URLEncoder.encode(C0084h.i(context), "UTF-8"));
            } catch (UnsupportedEncodingException unused4) {
                jSONObject.put(AbsoluteConst.XML_CHANNEL, "");
            }
            int a2 = a(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:posteventlog", jSONObject);
            if (a2 != 1 && a2 != 3) {
                if (a2 == 2) {
                    Log.w("MobileAgent", "please check your network");
                }
                return false;
            }
            if (str2 == null) {
                b(context, 3);
                i(context, str);
                str3 = "evn log sd";
            } else {
                str3 = "evnrt log sd";
            }
            Log.i("MobileAgent", str3);
            return true;
        } catch (JSONException e2) {
            i(context, str);
            e2.printStackTrace();
            return true;
        }
    }

    protected static void f(Context context) {
        if (f) {
            if (g(context, "updateonlyonwifi").equals("1")) {
                e = true;
            } else {
                e = false;
            }
            String g2 = g(context, "updatedelay");
            if (!g2.equals(AssistPushConsts.PUSHMESSAGE_ACTION_MULTI_BRAND_RECEIVE_NONE)) {
                h = Integer.parseInt(g2) * 1000;
            }
            int parseInt = Integer.parseInt(g(context, "send_policy"));
            g = parseInt;
            if (parseInt == 0) {
                g = 1;
            }
        }
    }

    public static void f(Context context, String str) {
        if (str.trim().equals("")) {
            return;
        }
        try {
            JSONObject jSONObject = new JSONObject();
            JSONArray jSONArray = new JSONArray();
            JSONObject jSONObject2 = new JSONObject();
            jSONObject2.put("occurtime", System.currentTimeMillis());
            jSONObject2.put("errmsg", URLEncoder.encode(str, "UTF-8"));
            jSONArray.put(jSONObject2);
            jSONObject.put(SpeechConstant.IST_SESSION_ID, p);
            jSONObject.put("errjsonary", jSONArray);
            C0079c.a("MobileAgentRun", "errJso" + jSONObject.toString());
            a(context, jSONObject.toString(), 4);
        } catch (UnsupportedEncodingException unused) {
            C0079c.a("MobileAgentRun", "unsupport utf-8,lost catch Exception");
        } catch (JSONException unused2) {
            C0079c.a("MobileAgentRun", "json exception,lost catch Exception");
        }
    }

    protected static boolean f(Context context, String str, String str2) {
        String str3;
        String h2 = str2 == null ? h(context, str) : str2;
        if (h2.equals("")) {
            if (str2 == null) {
                b(context, 3);
                i(context, str);
                return true;
            }
            return false;
        }
        boolean contains = h2.contains("%23lxapkmd5");
        try {
            JSONObject jSONObject = new JSONObject(h2);
            String b2 = C0084h.b(context);
            jSONObject.put(PushConsts.KEY_SERVICE_PIT, 1);
            jSONObject.put("protocolVersion", "3.1.4");
            jSONObject.put("sdkVersion", "3.2.0.2");
            jSONObject.put("cid", b2);
            jSONObject.put("appKey", C0084h.h(context));
            jSONObject.put("packageName", C0084h.j(context));
            jSONObject.put("versionCode", C0084h.m(context));
            jSONObject.put("versionName", C0084h.n(context));
            jSONObject.put("sendTime", System.currentTimeMillis());
            jSONObject.put("mac", C0084h.g(context));
            try {
                jSONObject.put("deviceDetail", URLEncoder.encode(C0084h.a(), "UTF-8"));
            } catch (UnsupportedEncodingException unused) {
                jSONObject.put("deviceDetail", "");
            }
            try {
                jSONObject.put("manufacturer", URLEncoder.encode(C0084h.b(), "UTF-8"));
            } catch (UnsupportedEncodingException unused2) {
                jSONObject.put("manufacturer", "");
            }
            try {
                jSONObject.put("phoneOs", URLEncoder.encode(C0084h.c(), "UTF-8"));
            } catch (UnsupportedEncodingException unused3) {
                jSONObject.put("phoneOs", "");
            }
            jSONObject.put("accessPoint", C0084h.l(context));
            jSONObject.put("deviceId", C0084h.a(context));
            try {
                jSONObject.put(AbsoluteConst.XML_CHANNEL, URLEncoder.encode(C0084h.i(context), "UTF-8"));
            } catch (UnsupportedEncodingException unused4) {
                jSONObject.put(AbsoluteConst.XML_CHANNEL, "");
            }
            int a2 = a(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:specposteventlog", jSONObject);
            if (a2 != 1 && a2 != 3) {
                if (a2 == 2) {
                    Log.w("MobileAgent", "please check your network");
                }
                return false;
            }
            if (str2 == null) {
                b(context, 3);
                i(context, str);
                str3 = "evn log sd";
            } else {
                str3 = "evnrt log sd";
            }
            Log.i("MobileAgent", str3);
            if (contains && a2 == 1) {
                d(context, "#lxapkmd5");
            }
            return true;
        } catch (JSONException e2) {
            i(context, str);
            e2.printStackTrace();
            return true;
        }
    }

    private static String g(Context context, String str) {
        return k(context).getString(str, AssistPushConsts.PUSHMESSAGE_ACTION_MULTI_BRAND_RECEIVE_NONE);
    }

    public static synchronized void g(Context context) {
        synchronized (C0078b.class) {
            C0079c.a("MobileAgentRun", "run into uploadlist :" + context.getClass().getName());
            if (g == 2) {
                try {
                    Thread.sleep(h);
                } catch (InterruptedException e2) {
                    e2.printStackTrace();
                }
            }
            boolean z = true;
            System.currentTimeMillis();
            while (true) {
                String n2 = n(context);
                if (n2.equals("") || !z) {
                    break;
                }
                if (n2.substring(0, 6).equals(i)) {
                    z = a(context, n2);
                } else if (n2.substring(0, 6).equals(j)) {
                    z = e(context, n2, null);
                } else if (n2.substring(0, 6).equals(l)) {
                    z = c(context, n2);
                } else if (n2.substring(0, 6).equals(m)) {
                    z = b(context, n2);
                } else if (n2.substring(0, 6).equals(k)) {
                    z = f(context, n2, null);
                }
                if (z) {
                    try {
                        Thread.sleep(0L);
                    } catch (InterruptedException e3) {
                        e3.printStackTrace();
                    }
                }
                C0079c.a("MobileAgentRun", "finish a task : " + n2);
            }
            C0079c.a("MobileAgentRun", " finish uploadlist ");
            C0079c.a("MobileAgentRun", "run out uploadlist :" + context.getClass().getName());
        }
    }

    private static synchronized String h(Context context, String str) {
        String str2;
        int read;
        synchronized (C0078b.class) {
            str2 = "";
            FileInputStream fileInputStream = null;
            try {
                fileInputStream = context.openFileInput(str);
                byte[] bArr = new byte[ADSim.INTISPLSH];
                while (true) {
                    if (fileInputStream.read(bArr) == -1) {
                        break;
                    }
                    str2 = String.valueOf(str2) + new String(bArr, 0, read);
                }
                if (fileInputStream != null) {
                    try {
                        fileInputStream.close();
                    } catch (IOException e2) {
                        e = e2;
                        e.printStackTrace();
                        return str2;
                    }
                }
            } catch (FileNotFoundException e3) {
                e3.printStackTrace();
                if (fileInputStream != null) {
                    try {
                        fileInputStream.close();
                    } catch (IOException e4) {
                        e = e4;
                        e.printStackTrace();
                        return str2;
                    }
                }
            } catch (IOException e5) {
                e5.printStackTrace();
                if (fileInputStream != null) {
                    try {
                        fileInputStream.close();
                    } catch (IOException e6) {
                        e = e6;
                        e.printStackTrace();
                        return str2;
                    }
                }
            }
        }
        return str2;
    }

    private static void h(Context context) {
        C0079c.a("MobileAgentRun", "run into onresumep :" + context.getClass().getName());
        try {
            C0079c.a("page pro", "do resume start: " + context.getClass().getName());
            b(context, j(context));
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        C0079c.a("MobileAgentRun", "run out onresume :" + context.getClass().getName());
    }

    public static void h(Context context, String str, String str2) {
        C0079c.a("MobileAgentAPI", "run in onEvent [" + str + JSUtil.COMMA + str2 + "]");
        if (context == null) {
            Log.e("MobileAgent", "Exception occurent in onEvent ,context cann't be null");
            return;
        }
        if (TextUtils.isEmpty(str) || C0084h.a(str, 100)) {
            Log.e("MobileAgent", "Exception occurent in onEvent ,channelID cann't be empty or length more than 100");
        }
        if (C0084h.a(str2, 900)) {
            Log.e("MobileAgent", "Exception occurent in onEvent ,channelID cann't be empty or length more than 100");
        }
        new C0080d(context, 11, str, str2).start();
    }

    private static String i(Context context, String str, String str2) {
        long currentTimeMillis = System.currentTimeMillis();
        long j2 = 0;
        if (str.equals("onResume")) {
            o = currentTimeMillis;
        } else if (str.equals("onPause") && n.equals(context.getClass().getName())) {
            long j3 = currentTimeMillis - o;
            if (j3 > 12000000) {
                j2 = 300000;
            } else if (j3 >= 0) {
                j2 = j3;
            }
        }
        if (str2 == null) {
            str2 = "";
        }
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(str2);
        stringBuffer.append(str);
        stringBuffer.append("|");
        stringBuffer.append(context.getClass().getName());
        stringBuffer.append("|");
        stringBuffer.append(currentTimeMillis);
        stringBuffer.append("|");
        stringBuffer.append(j2);
        stringBuffer.append("|");
        stringBuffer.append(n);
        stringBuffer.append("\n");
        n = context.getClass().getName();
        return stringBuffer.toString();
    }

    private static void i(Context context) {
        C0079c.a("MobileAgentRun", "run into onpausep :" + context.getClass().getName());
        SharedPreferences l2 = l(context);
        String string = l2.getString("activities", null);
        SharedPreferences.Editor edit = l2.edit();
        edit.putLong("endTime", System.currentTimeMillis());
        edit.putString("activities", i(context, "onPause", string));
        edit.commit();
        C0079c.a("MobileAgentRun", "run out onpausep :" + context.getClass().getName());
    }

    private static void i(Context context, String str) {
        if (str != null) {
            context.deleteFile(str);
            j(context, str);
        }
    }

    private static void j(Context context, String str) {
        synchronized (q) {
            SharedPreferences c2 = c(context);
            c2.edit().putString("uploadList", c2.getString("uploadList", "").replace(String.valueOf(str) + "|", "")).commit();
        }
    }

    private static boolean j(Context context) {
        C0079c.a("MobileAgentRun", "run into sessionpolicy");
        String h2 = C0084h.h(context);
        SharedPreferences l2 = l(context);
        String string = l2.getString("sessionId", null);
        boolean z = false;
        if (a(l2)) {
            if (string != null) {
                a(context, l2, true);
                SharedPreferences.Editor edit = l2.edit();
                Long valueOf = Long.valueOf(l2.getLong("readFlowRev", 0L));
                Long valueOf2 = Long.valueOf(l2.getLong("readFlowSnd", 0L));
                edit.clear();
                edit.putLong("readFlowRev", valueOf.longValue()).commit();
                edit.putLong("readFlowSnd", valueOf2.longValue()).commit();
            }
            a(context, h2, l2);
            a(context, l2, false);
            if (a(context, 1)) {
                e(context);
            }
            z = true;
        } else {
            String string2 = l2.getString("activities", null);
            SharedPreferences.Editor edit2 = l2.edit();
            edit2.putString("activities", i(context, "onResume", string2));
            edit2.putLong("lastResumeTime", System.currentTimeMillis());
            edit2.commit();
            if (g == 1 || string2.getBytes().length > 10000) {
                a(context, l2, false);
            }
        }
        C0079c.a("MobileAgentRun", "run out sessionpolicy");
        return z;
    }

    private static SharedPreferences k(Context context) {
        return context.getSharedPreferences(String.valueOf(b) + "MoblieAgent_config_" + context.getPackageName(), 0);
    }

    private static SharedPreferences l(Context context) {
        return context.getSharedPreferences(String.valueOf(b) + "MoblieAgent_state_" + context.getPackageName(), 0);
    }

    private static synchronized long m(Context context) {
        long j2;
        synchronized (C0078b.class) {
            j2 = c(context).getLong("uploadpopindex", 0L);
        }
        return j2;
    }

    private static String n(Context context) {
        String substring;
        synchronized (q) {
            String string = c(context).getString("uploadList", "");
            substring = string.equals("") ? "" : string.substring(0, string.indexOf("|"));
        }
        return substring;
    }

    private static boolean o(Context context) {
        NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
        return activeNetworkInfo != null && activeNetworkInfo.getType() == 1;
    }
}