和通讯录 v4.2.0版本的 MD5 值为:f213fa766dccbfebde0dd8add5534518

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


package com.a.b;

import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.text.TextUtils;
import android.util.Log;
import com.baidu.location.LocationClientOption;
import com.cmcc.sso.sdk.auth.AuthnConstants;
import com.cmcc.sso.sdk.util.SsoSdkConstants;
import com.google.android.mms.pdu.EncodedStringValue;
import com.huawei.mcs.cloud.msg.base.mms.Telephony;
import com.huawei.tep.component.net.http.HttpConstant;
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 a {

    private static String f411b = "lxd";

    public static boolean f410a = 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 = 0;
    private static final String i = "act" + f411b;
    private static final String j = "evn" + f411b;
    private static final String k = "esp" + f411b;
    private static final String l = "err" + f411b;
    private static final String m = "sys" + f411b;
    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) {
        int i2;
        HttpURLConnection httpURLConnection;
        int i3 = 0;
        int i4 = 2;
        if (c != 1) {
            return 2;
        }
        b.a("MobileAgentRun", "run into httppost :" + str + "####" + context.getClass().getName() + "###" + jSONObject.toString());
        ?? r2 = 0;
        r2 = 0;
        r2 = 0;
        r2 = 0;
        r2 = 0;
        try {
            try {
                String str2 = String.valueOf(str) + "&appkey=" + g.h(context) + "&channel=" + URLEncoder.encode(g.i(context), EncodedStringValue.StringEncoding.UTF_8) + "&code=106";
                b.a("MobileAgentRun", jSONObject.toString());
                b.a("MobileAgentRun", "post start");
                httpURLConnection = (HttpURLConnection) new URL(str2).openConnection();
            } catch (Throwable th) {
                th = th;
            }
            try {
                try {
                    httpURLConnection.setReadTimeout(LocationClientOption.MIN_AUTO_NOTIFY_INTERVAL);
                    httpURLConnection.setDoOutput(true);
                    httpURLConnection.setDoInput(true);
                    httpURLConnection.setUseCaches(false);
                    httpURLConnection.setRequestMethod(HttpConstant.Method.POST);
                    byte[] a2 = f.a().a(jSONObject.toString());
                    httpURLConnection.setRequestProperty("Content-length", new StringBuilder().append(a2.length).toString());
                    httpURLConnection.setRequestProperty("Content-Type", "application/octet-stream");
                    httpURLConnection.setRequestProperty("Charset", EncodedStringValue.StringEncoding.UTF_8);
                    OutputStream outputStream = httpURLConnection.getOutputStream();
                    outputStream.write(a2);
                    outputStream.close();
                    i3 = httpURLConnection.getResponseCode();
                    b.a("MobileAgentRun", "post end");
                    r2 = 200;
                    if (200 == i3) {
                        try {
                            String str3 = "MobileAgent";
                            b.a("MobileAgent", "send success");
                            i4 = 1;
                            r2 = str3;
                        } catch (Exception e2) {
                            r2 = httpURLConnection;
                            e = e2;
                            i4 = 1;
                            b.a("MobileAgentRun", e.toString());
                            e.printStackTrace();
                            if (r2 != 0) {
                                r2.disconnect();
                                i2 = i4;
                                b.a("MobileAgentHttpPost", "code:" + i3 + "status:  " + i2 + "  content: " + jSONObject.getString("logJsonAry"));
                                b.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i2);
                                return i2;
                            }
                            i2 = i4;
                            b.a("MobileAgentHttpPost", "code:" + i3 + "status:  " + i2 + "  content: " + jSONObject.getString("logJsonAry"));
                            b.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i2);
                            return i2;
                        }
                    }
                    if (httpURLConnection != null) {
                        httpURLConnection.disconnect();
                    }
                } catch (Exception e3) {
                    r2 = httpURLConnection;
                    e = e3;
                }
            } catch (ClientProtocolException e4) {
                r2 = httpURLConnection;
                e = e4;
                b.a("MobileAgentRun", e.toString());
                e.printStackTrace();
                if (r2 != 0) {
                    r2.disconnect();
                    i2 = 2;
                    b.a("MobileAgentHttpPost", "code:" + i3 + "status:  " + i2 + "  content: " + jSONObject.getString("logJsonAry"));
                    b.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i2);
                    return i2;
                }
                i2 = i4;
                b.a("MobileAgentHttpPost", "code:" + i3 + "status:  " + i2 + "  content: " + jSONObject.getString("logJsonAry"));
                b.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i2);
                return i2;
            } catch (IOException e5) {
                r2 = httpURLConnection;
                e = e5;
                b.a("MobileAgentRun", e.toString());
                e.printStackTrace();
                if (r2 != 0) {
                    r2.disconnect();
                    i2 = 2;
                    b.a("MobileAgentHttpPost", "code:" + i3 + "status:  " + i2 + "  content: " + jSONObject.getString("logJsonAry"));
                    b.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i2);
                    return i2;
                }
                i2 = i4;
                b.a("MobileAgentHttpPost", "code:" + i3 + "status:  " + i2 + "  content: " + jSONObject.getString("logJsonAry"));
                b.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i2);
                return i2;
            } catch (JSONException e6) {
                r2 = httpURLConnection;
                e = e6;
                b.a("MobileAgentRun", e.toString());
                e.printStackTrace();
                i4 = 3;
                if (r2 != 0) {
                    r2.disconnect();
                    i2 = 3;
                    b.a("MobileAgentHttpPost", "code:" + i3 + "status:  " + i2 + "  content: " + jSONObject.getString("logJsonAry"));
                    b.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i2);
                    return i2;
                }
                i2 = i4;
                b.a("MobileAgentHttpPost", "code:" + i3 + "status:  " + i2 + "  content: " + jSONObject.getString("logJsonAry"));
                b.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i2);
                return i2;
            } catch (Throwable th2) {
                r2 = httpURLConnection;
                th = th2;
                if (r2 != 0) {
                    r2.disconnect();
                }
                throw th;
            }
        } catch (ClientProtocolException e7) {
            e = e7;
        } catch (IOException e8) {
            e = e8;
        } catch (JSONException e9) {
            e = e9;
        } catch (Exception e10) {
            e = e10;
        }
        i2 = i4;
        try {
            b.a("MobileAgentHttpPost", "code:" + i3 + "status:  " + i2 + "  content: " + jSONObject.getString("logJsonAry"));
        } catch (Exception e11) {
        }
        b.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i2);
        return i2;
    }

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

    private static String a(Context context, String str, SharedPreferences sharedPreferences) {
        n = "";
        String a2 = g.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 = g.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) {
            b.a("MobileAgentRun", "run into pageact onresumep");
            h(context);
        } else {
            b.a("MobileAgentRun", "run into pageact onpausep");
            i(context);
        }
        b.a("MobileAgentRun", "run out pageact");
    }

    protected static boolean a(Context context, int i2) {
        int i3;
        int i4;
        SharedPreferences k2 = k(context);
        if (i2 == 3) {
            i3 = k2.getInt("actionmonth", 0);
            i4 = k2.getInt("actionday", 0);
        } else if (i2 == 2) {
            i3 = k2.getInt("eventmonth", 0);
            i4 = k2.getInt("eventday", 0);
        } else {
            i3 = k2.getInt("sysmonth", 0);
            i4 = k2.getInt("sysday", 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("sid", string2);
            jSONObject.put("logJsonAry", string);
            if (a(context, jSONObject.toString(), 2)) {
                a2.edit().putString("eventlogs", "").commit();
            }
        } 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("sid", 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)) {
                return true;
            }
            sharedPreferences.edit().putString("activities", "").commit();
            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("sid", new JSONObject(h2).get("sid"));
            } catch (JSONException e2) {
                d2.put("sid", "");
            }
            d2.put(AuthnConstants.RESP_HEADER_KEY_MAC, g.g(context));
            try {
                d2.put("deviceDetail", URLEncoder.encode(g.a(), EncodedStringValue.StringEncoding.UTF_8));
            } catch (UnsupportedEncodingException e3) {
                d2.put("deviceDetail", "");
            }
            try {
                d2.put(SsoSdkConstants.VALUES_KEY_MANUFACTURER, URLEncoder.encode(g.b(), EncodedStringValue.StringEncoding.UTF_8));
            } catch (UnsupportedEncodingException e4) {
                d2.put(SsoSdkConstants.VALUES_KEY_MANUFACTURER, "");
            }
            try {
                d2.put("phoneOs", URLEncoder.encode(g.c(), EncodedStringValue.StringEncoding.UTF_8));
            } catch (UnsupportedEncodingException e5) {
                d2.put("phoneOs", "");
            }
            try {
                d2.put("accessPoint", URLEncoder.encode(g.l(context), EncodedStringValue.StringEncoding.UTF_8));
            } catch (UnsupportedEncodingException e6) {
                d2.put("accessPoint", "");
            }
            try {
                d2.put("netWorkType", URLEncoder.encode(g.p(context), EncodedStringValue.StringEncoding.UTF_8));
            } catch (UnsupportedEncodingException e7) {
                d2.put("netWorkType", "");
            }
            d2.put("uuid", v);
            d2.put("deviceId", g.a(context));
            d2.put("cpuRatioMax", g.f());
            d2.put("cpuRatioCur", g.g());
            d2.put("menoryRatio", g.h());
            d2.put("logJsonAry", new JSONArray("[" + h2 + "]"));
            i2 = a(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:postactlog", d2);
        } catch (JSONException e8) {
            e8.printStackTrace();
            i2 = 3;
        }
        if (i2 != 1 && i2 != 3) {
            if (i2 == 2) {
            }
            return false;
        }
        b(context, 3);
        i(context, str);
        Log.i("MobileAgent", "act log sd");
        return true;
    }

    private static synchronized boolean a(Context context, String str, int i2) {
        String str2;
        FileOutputStream fileOutputStream;
        boolean z = false;
        synchronized (a.class) {
            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) {
                str2 = k;
            }
            if (!str.trim().equals("")) {
                long m2 = m(context);
                long j2 = 1 + m2;
                String str3 = String.valueOf(str2) + m2;
                FileOutputStream fileOutputStream2 = null;
                try {
                    try {
                        try {
                            fileOutputStream2 = context.openFileOutput(str3, 1);
                        } catch (Throwable th) {
                            th = th;
                            if (fileOutputStream2 != null) {
                                try {
                                    fileOutputStream2.close();
                                } catch (IOException e2) {
                                    e2.printStackTrace();
                                }
                            }
                            throw th;
                        }
                    } catch (IOException e3) {
                        Log.w("MobileAgentRun", "file r/w execption");
                        if (0 != 0) {
                            try {
                                fileOutputStream2.close();
                            } catch (IOException e4) {
                                e4.printStackTrace();
                            }
                        }
                    }
                } catch (FileNotFoundException e5) {
                    fileOutputStream = null;
                }
                try {
                    a(context, str3, j2);
                    fileOutputStream2.write(str.getBytes());
                    if (fileOutputStream2 != null) {
                        try {
                            fileOutputStream2.close();
                        } catch (IOException e6) {
                            e6.printStackTrace();
                        }
                    }
                    z = true;
                } catch (FileNotFoundException e7) {
                    fileOutputStream = fileOutputStream2;
                    try {
                        Log.w("MobileAgentRun", "can not find log file");
                        if (fileOutputStream != null) {
                            try {
                                fileOutputStream.close();
                            } catch (IOException e8) {
                                e8.printStackTrace();
                            }
                        }
                        return z;
                    } catch (Throwable th2) {
                        th = th2;
                        fileOutputStream2 = fileOutputStream;
                        if (fileOutputStream2 != null) {
                        }
                        throw th;
                    }
                }
            }
        }
        return z;
    }

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

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

    protected static void b(Context context, int i2) {
        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);
            edit.putInt("actionday", parseInt);
        } else if (i2 == 2) {
            edit.putInt("eventmonth", parseInt2);
            edit.putInt("eventday", parseInt);
        } else {
            edit.putInt("sysmonth", parseInt2);
            edit.putInt("sysday", parseInt);
        }
        edit.commit();
    }

    public static void b(Context context, String str, String str2) {
        synchronized (r) {
            String a2 = g.a(str);
            String a3 = g.a(str2);
            SharedPreferences a4 = a(context);
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append(a4.getString("eventlogs", ""));
            try {
                stringBuffer.append(URLEncoder.encode(a2, EncodedStringValue.StringEncoding.UTF_8));
                stringBuffer.append("|");
                stringBuffer.append(URLEncoder.encode(a3, EncodedStringValue.StringEncoding.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 e2) {
                b.a("MobileAgentRun", "unsupport utf-8,can't onEvent()");
                return;
            }
        }
        b(context, false);
    }

    protected static void b(Context context, boolean z) {
        if (c != 1) {
            return;
        }
        b.a("MobileAgentRun", "run into strategy");
        f(context);
        if (!e || (e && o(context))) {
            switch (g) {
                case 1:
                    new c(context, 6).start();
                    break;
                case 2:
                    if (z) {
                        new c(context, 6).start();
                        f = false;
                        break;
                    }
                    break;
                case 3:
                    if (a(context, 3)) {
                        new c(context, 6).start();
                        break;
                    }
                    break;
            }
        }
        f = false;
        b.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("sid", string2);
            jSONObject.put("logJsonAry", string);
            if (a(context, jSONObject.toString(), 5)) {
                b2.edit().putString("eventlogs", "").commit();
            }
        } 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;
            }
        } catch (JSONException e2) {
            i(context, str);
            Log.i("MobileAgent", "SDK del a dirty data");
        }
        return false;
    }

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

    public static void c(Context context, String str, String str2) {
        synchronized (s) {
            String a2 = g.a(str);
            String a3 = g.a(str2);
            SharedPreferences b2 = b(context);
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append(b2.getString("eventlogs", ""));
            try {
                stringBuffer.append(URLEncoder.encode(a2, EncodedStringValue.StringEncoding.UTF_8));
                stringBuffer.append("|");
                stringBuffer.append(URLEncoder.encode(a3, EncodedStringValue.StringEncoding.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 e2) {
                b.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("pid", 1);
            jSONObject.put("protocolVersion", "3.1.4");
            jSONObject.put(SsoSdkConstants.VALUES_KEY_SDKVERSION, "3.2.0.2");
            jSONObject.put(Telephony.Mms.Part.CONTENT_ID, g.b(context));
            jSONObject.put("deviceId", g.a(context));
            jSONObject.put("appKey", g.h(context));
            jSONObject.put("packageName", g.j(context));
            jSONObject.put("versionCode", g.m(context));
            jSONObject.put("versionName", g.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) {
                if (a2 == 2) {
                }
                return false;
            }
            b(context, 3);
            i(context, str);
            Log.i("MobileAgent", "erLog sd");
            b.a("MobileAgent", "send errlog success \n" + h2);
            return true;
        } catch (JSONException e2) {
            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("pid", 1);
            jSONObject.put("protocolVersion", "3.1.4");
            jSONObject.put(SsoSdkConstants.VALUES_KEY_SDKVERSION, "3.2.0.2");
            jSONObject.put(Telephony.Mms.Part.CONTENT_ID, g.b(context));
            jSONObject.put("appKey", g.h(context));
            jSONObject.put("packageName", context.getPackageName());
            jSONObject.put("versionCode", g.m(context));
            jSONObject.put("versionName", g.n(context));
            jSONObject.put("sendTime", System.currentTimeMillis());
            jSONObject.put("deviceId", g.a(context));
            jSONObject.put("channel", g.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 (!f410a) {
                f410a = !context.getSharedPreferences("MoblieAgent_debug", 0).getString("debug", "").equals("");
            }
        } catch (Exception e2) {
        }
        b.a("MobileAgentAPI", "run in init[" + str + "," + str2 + "]");
        if (context == null) {
            Log.e("MobileAgent", "Exception occurent in joinDu ,context cann't be null");
            return;
        }
        if (TextUtils.isEmpty(str) || g.a(str, 50)) {
            Log.e("MobileAgent", "Exception occurent in joinDu ,appID cann't be null or empty");
            return;
        }
        if (TextUtils.isEmpty(str2)) {
            str2 = "0";
        } else if (g.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(f411b) + "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 e(context)).start();
        }
        t = true;
        Log.i("MobileAgent", "finish init SUCCESS " + f410a);
    }

    protected static void e(Context context) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("pid", 1);
            jSONObject.put("protocolVersion", "3.1.4");
            jSONObject.put(SsoSdkConstants.VALUES_KEY_SDKVERSION, "3.2.0.2");
            jSONObject.put(Telephony.Mms.Part.CONTENT_ID, g.b(context));
            jSONObject.put("deviceId", g.a(context));
            jSONObject.put("appKey", g.h(context));
            jSONObject.put("packageName", context.getPackageName());
            jSONObject.put("versionCode", g.m(context));
            jSONObject.put("versionName", g.n(context));
            jSONObject.put("sendTime", System.currentTimeMillis());
            jSONObject.put("imsi", g.c(context));
            jSONObject.put(AuthnConstants.RESP_HEADER_KEY_MAC, g.g(context));
            jSONObject.put("deviceDetail", URLEncoder.encode(g.a(), EncodedStringValue.StringEncoding.UTF_8));
            jSONObject.put(SsoSdkConstants.VALUES_KEY_MANUFACTURER, URLEncoder.encode(g.b(), EncodedStringValue.StringEncoding.UTF_8));
            jSONObject.put("phoneOS", URLEncoder.encode(g.c(), EncodedStringValue.StringEncoding.UTF_8));
            jSONObject.put("screenWidth", g.d(context));
            jSONObject.put("screenHeight", g.e(context));
            jSONObject.put("screenDensity", g.f(context));
            jSONObject.put("carrierName", URLEncoder.encode(g.k(context), EncodedStringValue.StringEncoding.UTF_8));
            jSONObject.put("accessPoint", g.l(context));
            jSONObject.put("countryCode", g.d());
            jSONObject.put("languageCode", g.e());
            jSONObject.put("channel", URLEncoder.encode(g.i(context), EncodedStringValue.StringEncoding.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 h2 = str2 == null ? h(context, str) : str2;
        if (h2.equals("")) {
            if (str2 != null) {
                return false;
            }
            b(context, 3);
            i(context, str);
            return true;
        }
        try {
            JSONObject jSONObject = new JSONObject(h2);
            String b2 = g.b(context);
            jSONObject.put("pid", 1);
            jSONObject.put("protocolVersion", "3.1.4");
            jSONObject.put(SsoSdkConstants.VALUES_KEY_SDKVERSION, "3.2.0.2");
            jSONObject.put(Telephony.Mms.Part.CONTENT_ID, b2);
            jSONObject.put("appKey", g.h(context));
            jSONObject.put("packageName", g.j(context));
            jSONObject.put("versionCode", g.m(context));
            jSONObject.put("versionName", g.n(context));
            jSONObject.put("sendTime", System.currentTimeMillis());
            jSONObject.put(AuthnConstants.RESP_HEADER_KEY_MAC, g.g(context));
            try {
                jSONObject.put("deviceDetail", URLEncoder.encode(g.a(), EncodedStringValue.StringEncoding.UTF_8));
            } catch (UnsupportedEncodingException e2) {
                jSONObject.put("deviceDetail", "");
            }
            try {
                jSONObject.put(SsoSdkConstants.VALUES_KEY_MANUFACTURER, URLEncoder.encode(g.b(), EncodedStringValue.StringEncoding.UTF_8));
            } catch (UnsupportedEncodingException e3) {
                jSONObject.put(SsoSdkConstants.VALUES_KEY_MANUFACTURER, "");
            }
            try {
                jSONObject.put("phoneOs", URLEncoder.encode(g.c(), EncodedStringValue.StringEncoding.UTF_8));
            } catch (UnsupportedEncodingException e4) {
                jSONObject.put("phoneOs", "");
            }
            jSONObject.put("accessPoint", g.l(context));
            jSONObject.put("deviceId", g.a(context));
            try {
                jSONObject.put("channel", URLEncoder.encode(g.i(context), EncodedStringValue.StringEncoding.UTF_8));
            } catch (UnsupportedEncodingException e5) {
                jSONObject.put("channel", "");
            }
            int a2 = a(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:posteventlog", jSONObject);
            if (a2 != 1 && a2 != 3) {
                if (a2 != 2) {
                    return false;
                }
                Log.w("MobileAgent", "please check your network");
                return false;
            }
            if (str2 == null) {
                b(context, 3);
                i(context, str);
                Log.i("MobileAgent", "evn log sd");
            } else {
                Log.i("MobileAgent", "evnrt log sd");
            }
            return true;
        } catch (JSONException e6) {
            i(context, str);
            e6.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("0")) {
                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, EncodedStringValue.StringEncoding.UTF_8));
            jSONArray.put(jSONObject2);
            jSONObject.put("sid", p);
            jSONObject.put("errjsonary", jSONArray);
            b.a("MobileAgentRun", "errJso" + jSONObject.toString());
            a(context, jSONObject.toString(), 4);
        } catch (UnsupportedEncodingException e2) {
            b.a("MobileAgentRun", "unsupport utf-8,lost catch Exception");
        } catch (JSONException e3) {
            b.a("MobileAgentRun", "json exception,lost catch Exception");
        }
    }

    protected static boolean f(Context context, String str, String str2) {
        String h2 = str2 == null ? h(context, str) : str2;
        if (h2.equals("")) {
            if (str2 != null) {
                return false;
            }
            b(context, 3);
            i(context, str);
            return true;
        }
        boolean z = h2.contains("%23lxapkmd5");
        try {
            JSONObject jSONObject = new JSONObject(h2);
            String b2 = g.b(context);
            jSONObject.put("pid", 1);
            jSONObject.put("protocolVersion", "3.1.4");
            jSONObject.put(SsoSdkConstants.VALUES_KEY_SDKVERSION, "3.2.0.2");
            jSONObject.put(Telephony.Mms.Part.CONTENT_ID, b2);
            jSONObject.put("appKey", g.h(context));
            jSONObject.put("packageName", g.j(context));
            jSONObject.put("versionCode", g.m(context));
            jSONObject.put("versionName", g.n(context));
            jSONObject.put("sendTime", System.currentTimeMillis());
            jSONObject.put(AuthnConstants.RESP_HEADER_KEY_MAC, g.g(context));
            try {
                jSONObject.put("deviceDetail", URLEncoder.encode(g.a(), EncodedStringValue.StringEncoding.UTF_8));
            } catch (UnsupportedEncodingException e2) {
                jSONObject.put("deviceDetail", "");
            }
            try {
                jSONObject.put(SsoSdkConstants.VALUES_KEY_MANUFACTURER, URLEncoder.encode(g.b(), EncodedStringValue.StringEncoding.UTF_8));
            } catch (UnsupportedEncodingException e3) {
                jSONObject.put(SsoSdkConstants.VALUES_KEY_MANUFACTURER, "");
            }
            try {
                jSONObject.put("phoneOs", URLEncoder.encode(g.c(), EncodedStringValue.StringEncoding.UTF_8));
            } catch (UnsupportedEncodingException e4) {
                jSONObject.put("phoneOs", "");
            }
            jSONObject.put("accessPoint", g.l(context));
            jSONObject.put("deviceId", g.a(context));
            try {
                jSONObject.put("channel", URLEncoder.encode(g.i(context), EncodedStringValue.StringEncoding.UTF_8));
            } catch (UnsupportedEncodingException e5) {
                jSONObject.put("channel", "");
            }
            int a2 = a(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:specposteventlog", jSONObject);
            if (a2 != 1 && a2 != 3) {
                if (a2 != 2) {
                    return false;
                }
                Log.w("MobileAgent", "please check your network");
                return false;
            }
            if (str2 == null) {
                b(context, 3);
                i(context, str);
                Log.i("MobileAgent", "evn log sd");
            } else {
                Log.i("MobileAgent", "evnrt log sd");
            }
            if (z && a2 == 1) {
                d(context, "#lxapkmd5");
            }
            return true;
        } catch (JSONException e6) {
            i(context, str);
            e6.printStackTrace();
            return true;
        }
    }

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

    public static synchronized void g(Context context) {
        synchronized (a.class) {
            b.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();
                    }
                }
                b.a("MobileAgentRun", "finish a task : " + n2);
            }
            b.a("MobileAgentRun", " finish uploadlist ");
            b.a("MobileAgentRun", "run out uploadlist :" + context.getClass().getName());
        }
    }

    private static synchronized String h(Context context, String str) {
        FileInputStream fileInputStream;
        IOException e2;
        String str2;
        FileNotFoundException e3;
        synchronized (a.class) {
            FileInputStream fileInputStream2 = null;
            try {
            } catch (Throwable th) {
                th = th;
            }
            try {
                fileInputStream = context.openFileInput(str);
                try {
                    byte[] bArr = new byte[LocationClientOption.MIN_AUTO_NOTIFY_INTERVAL];
                    str2 = "";
                    while (true) {
                        try {
                            int read = fileInputStream.read(bArr);
                            if (read == -1) {
                                break;
                            }
                            str2 = String.valueOf(str2) + new String(bArr, 0, read);
                        } catch (FileNotFoundException e4) {
                            e3 = e4;
                            e3.printStackTrace();
                            if (fileInputStream != null) {
                                try {
                                    fileInputStream.close();
                                } catch (IOException e5) {
                                    e5.printStackTrace();
                                }
                            }
                            return str2;
                        } catch (IOException e6) {
                            e2 = e6;
                            e2.printStackTrace();
                            if (fileInputStream != null) {
                                try {
                                    fileInputStream.close();
                                } catch (IOException e7) {
                                    e7.printStackTrace();
                                }
                            }
                            return str2;
                        }
                    }
                    if (fileInputStream != null) {
                        try {
                            fileInputStream.close();
                        } catch (IOException e8) {
                            e8.printStackTrace();
                        }
                    }
                } catch (FileNotFoundException e9) {
                    e3 = e9;
                    str2 = "";
                } catch (IOException e10) {
                    e2 = e10;
                    str2 = "";
                }
            } catch (FileNotFoundException e11) {
                fileInputStream = null;
                e3 = e11;
                str2 = "";
            } catch (IOException e12) {
                fileInputStream = null;
                e2 = e12;
                str2 = "";
            } catch (Throwable th2) {
                th = th2;
                if (0 != 0) {
                    try {
                        fileInputStream2.close();
                    } catch (IOException e13) {
                        e13.printStackTrace();
                    }
                }
                throw th;
            }
        }
        return str2;
    }

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

    public static void h(Context context, String str, String str2) {
        b.a("MobileAgentAPI", "run in onEvent [" + str + "," + str2 + "]");
        if (context == null) {
            Log.e("MobileAgent", "Exception occurent in onEvent ,context cann't be null");
            return;
        }
        if (TextUtils.isEmpty(str) || g.a(str, 100)) {
            Log.e("MobileAgent", "Exception occurent in onEvent ,channelID cann't be empty or length more than 100");
        }
        if (g.a(str2, com.chinamobile.contacts.im.mms2.d.g.CANCEL_BLACK)) {
            Log.e("MobileAgent", "Exception occurent in onEvent ,channelID cann't be empty or length more than 100");
        }
        new c(context, 11, str, str2).start();
    }

    private static String i(Context context, String str, String str2) {
        long j2 = 0;
        long currentTimeMillis = System.currentTimeMillis();
        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) {
        b.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();
        b.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) {
        boolean z = true;
        b.a("MobileAgentRun", "run into sessionpolicy");
        String h2 = g.h(context);
        SharedPreferences l2 = l(context);
        String string = l2.getString("sessionId", null);
        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);
            }
        } 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);
            }
            z = false;
        }
        b.a("MobileAgentRun", "run out sessionpolicy");
        return z;
    }

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

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

    private static synchronized long m(Context context) {
        long j2;
        synchronized (a.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;
    }
}