亲朋打僵尸 v1.0版本的 MD5 值为:027c73d6bc1ac0a24f96eaed77a689a4

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


package com.chinaMobile;

import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Looper;
import android.telephony.TelephonyManager;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;
import com.alipay.android.AlixDefine;
import cz.msebera.android.httpclient.client.methods.HttpPost;
import cz.msebera.android.httpclient.conn.params.ConnRoutePNames;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
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.Iterator;
import java.util.Locale;
import java.util.Random;
import mm.purchasesdk.PurchaseCode;
import org.apache.http.HttpHost;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.params.HttpClientParams;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class MobileAgent {
    public static final String SDK_VERSION = "1.0.4";
    public static final String USER_STATUS_ACTIVATE = "activate";
    public static final String USER_STATUS_CUSTOM = "custom";
    public static final String USER_STATUS_LOGIN = "login";
    public static final String USER_STATUS_REGIST = "regist";
    public static final String USER_STATUS_START = "start";
    private static JSONObject c;
    private static MMOnlineConfigureListener g;
    private static boolean d = true;
    private static boolean e = false;
    private static boolean f = true;
    static int a = -1;
    static int b = 0;
    private static String h = "";
    private static String i = "";
    private static long j = 0;
    private static String k = "";
    private static Object l = new Object();
    private static boolean m = false;

    public static int HttpPostData(Context context, String str, JSONObject jSONObject) {
        try {
            String g2 = g.g(context);
            HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(str + "&appkey=" + g2 + "&channel=" + URLEncoder.encode(g.h(context), "UTF-8") + "&code=" + PurchaseCode.AUTH_OK).openConnection();
            httpURLConnection.setDoOutput(true);
            httpURLConnection.setDoInput(true);
            httpURLConnection.setUseCaches(false);
            httpURLConnection.setRequestMethod(HttpPost.METHOD_NAME);
            byte[] a2 = d.a().a(jSONObject.toString());
            httpURLConnection.setRequestProperty("Content-length", "" + a2.length);
            httpURLConnection.setRequestProperty("Content-Type", "application/octet-stream");
            httpURLConnection.setRequestProperty("Charset", "UTF-8");
            OutputStream outputStream = httpURLConnection.getOutputStream();
            outputStream.write(a2);
            outputStream.close();
            if (200 != httpURLConnection.getResponseCode()) {
                return 2;
            }
            StringBuffer stringBuffer = new StringBuffer();
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream(), "utf-8"));
            while (true) {
                String readLine = bufferedReader.readLine();
                if (readLine == null) {
                    bufferedReader.close();
                    new JSONObject(stringBuffer.toString()).getInt("resultcode");
                    return 1;
                }
                stringBuffer.append(readLine).append("\n");
            }
        } catch (ClientProtocolException e2) {
            return 2;
        } catch (IOException e3) {
            return 2;
        } catch (JSONException e4) {
            return 3;
        } catch (Exception e5) {
            e5.printStackTrace();
            return 2;
        }
    }

    protected static JSONObject createMessage(Context context) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("pid", 1);
            jSONObject.put("protocolVersion", SDK_VERSION);
            jSONObject.put("sdkVersion", SDK_VERSION);
            jSONObject.put("cid", g.b(context));
            jSONObject.put("appKey", g.g(context));
            jSONObject.put("packageName", context.getPackageName());
            jSONObject.put("versionCode", g.j(context));
            jSONObject.put("versionName", g.k(context));
            jSONObject.put("sendTime", System.currentTimeMillis());
            jSONObject.put("deviceId", g.a(context));
        } catch (JSONException e2) {
            e2.printStackTrace();
        }
        return jSONObject;
    }

    private static String createSession(Context context, String str, SharedPreferences sharedPreferences) {
        String valueOf = String.valueOf(g.a(System.currentTimeMillis() + str + g.a(context) + g.f(context) + new Random().nextInt(10)).toCharArray(), 8, 16);
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putString("appKey", str);
        edit.putString("sessionId", valueOf);
        edit.putLong("lastResumeTime", System.currentTimeMillis());
        edit.putString("activities", getActivityStateStr(context, "onResume", null));
        edit.commit();
        k = valueOf;
        return valueOf;
    }

    private static String createSessionBody(Context context, String str, SharedPreferences sharedPreferences) {
        SharedPreferences.Editor edit = sharedPreferences.edit();
        edit.putString("appKey", str);
        edit.putString("sessionId", k);
        edit.putLong("lastResumeTime", System.currentTimeMillis());
        edit.putString("activities", "");
        edit.commit();
        return k;
    }

    private static void delPopUpload(Context context, String str) {
        synchronized (l) {
            SharedPreferences uploadListSharePreferences = getUploadListSharePreferences(context);
            uploadListSharePreferences.edit().putString("uploadList", uploadListSharePreferences.getString("uploadList", "").replace(str + "|", "")).commit();
        }
    }

    private static void deleteLog(Context context, String str) {
        context.deleteFile(str);
        delPopUpload(context, str);
    }

    private static String getActivityStateStr(Context context, String str, String str2) {
        long j2 = 0;
        long currentTimeMillis = System.currentTimeMillis();
        if (str.equals("onResume")) {
            j = currentTimeMillis;
        } else if (str.equals("onPause") && h.equals(context.getClass().getName())) {
            j2 = currentTimeMillis - j;
        }
        if (str2 == null) {
            str2 = "";
        }
        h = context.getClass().getName();
        i = str;
        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("\n");
        return stringBuffer.toString();
    }

    public static String getConfigParams(Context context, String str) {
        return getConfigPreferences(context).getString(str, "0");
    }

    private static SharedPreferences getConfigPreferences(Context context) {
        return context.getSharedPreferences("MoblieAgent_config_" + context.getPackageName(), 0);
    }

    protected static SharedPreferences getEventSharedPreferences(Context context) {
        return context.getSharedPreferences("MoblieAgent_event_" + context.getPackageName(), 0);
    }

    private static boolean getLastEventData(Context context, SharedPreferences sharedPreferences) {
        SharedPreferences eventSharedPreferences = getEventSharedPreferences(context);
        String string = eventSharedPreferences.getString("eventlogs", "");
        if (string.equals("")) {
            return false;
        }
        String string2 = getStateSharedPreferences(context).getString("sessionId", null);
        c = new JSONObject();
        try {
            c.put(AlixDefine.SID, string2);
            c.put("logJsonAry", string);
            if (saveLog(context, c.toString(), 2)) {
                eventSharedPreferences.edit().putString("eventlogs", "").commit();
            }
        } catch (JSONException e2) {
            e2.printStackTrace();
        }
        return true;
    }

    private static boolean getLastLaunchData(Context context, SharedPreferences sharedPreferences) {
        String string = sharedPreferences.getString("sessionId", null);
        String string2 = sharedPreferences.getString("activities", null);
        c = new JSONObject();
        try {
            c.put(AlixDefine.SID, string);
            c.put("logs", string2);
            if (saveLog(context, c.toString(), 3)) {
                sharedPreferences.edit().putString("activities", "").commit();
                return true;
            }
            return true;
        } catch (JSONException e2) {
            e2.printStackTrace();
            return true;
        }
    }

    private static String getLogStr(Context context, String str) {
        String str2;
        int read;
        synchronized (MobileAgent.class) {
            str2 = "";
            try {
                FileInputStream openFileInput = context.openFileInput(str);
                byte[] bArr = new byte[10000];
                while (true) {
                    if (openFileInput.read(bArr) == -1) {
                        break;
                    }
                    str2 = str2 + new String(bArr, 0, read);
                }
                openFileInput.close();
            } catch (FileNotFoundException e2) {
                str2 = "";
            } catch (IOException e3) {
            } catch (Throwable th) {
                try {
                    throw th;
                } finally {
                }
            }
        }
        return str2;
    }

    private static long getPopIndex(Context context) {
        long j2;
        synchronized (MobileAgent.class) {
            try {
                j2 = getUploadListSharePreferences(context).getLong("uploadpopindex", 0L);
            } catch (Throwable th) {
                throw th;
            }
        }
        return j2;
    }

    private static SharedPreferences getStateSharedPreferences(Context context) {
        return context.getSharedPreferences("MoblieAgent_state_" + context.getPackageName(), 0);
    }

    protected static SharedPreferences getUploadListSharePreferences(Context context) {
        return context.getSharedPreferences("MoblieAgent_upload_" + context.getPackageName(), 0);
    }

    public static void init(Context context, String str, String str2) {
        if (m) {
            return;
        }
        SharedPreferences sharedPreferences = context.getSharedPreferences("MoblieAgent_sys_config", 0);
        sharedPreferences.edit().putString("MOBILE_APPKEY", str).commit();
        sharedPreferences.edit().putString("MOBILE_CHANNEL", str2).commit();
        onResume(context);
        m = true;
    }

    public static boolean isOnce(Context context, int i2) {
        int i3;
        int i4;
        SharedPreferences configPreferences = getConfigPreferences(context);
        if (i2 == 3) {
            i3 = configPreferences.getInt("actionmonth", 0);
            i4 = configPreferences.getInt("actionday", 0);
        } else if (i2 == 2) {
            i3 = configPreferences.getInt("eventmonth", 0);
            i4 = configPreferences.getInt("eventday", 0);
        } else {
            i3 = configPreferences.getInt("sysmonth", 0);
            i4 = configPreferences.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 isSessionTimeOut(SharedPreferences sharedPreferences) {
        return System.currentTimeMillis() - sharedPreferences.getLong("endTime", -1L) > 30000;
    }

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

    public static void listenCrash(Context context) {
        b.a().a(context);
    }

    private static void listenUser(Context context, String str, String str2) {
        StringBuffer stringBuffer = new StringBuffer();
        if (str == null || str.equals("")) {
            stringBuffer.append("guest");
        } else {
            stringBuffer.append(str);
        }
        stringBuffer.append("@@");
        if (str2 == null) {
            stringBuffer.append("other");
        } else {
            stringBuffer.append(str2);
        }
        stringBuffer.append("@@");
        try {
            stringBuffer.append(URLEncoder.encode(g.h(context), "UTF-8"));
        } catch (UnsupportedEncodingException e2) {
            stringBuffer.append("");
        }
        stringBuffer.append("@@");
        stringBuffer.append(g.c(context));
        stringBuffer.append("@@");
        stringBuffer.append(g.b(Build.MODEL));
        stringBuffer.append("@@");
        try {
            stringBuffer.append(URLEncoder.encode(g.a(), "UTF-8"));
        } catch (UnsupportedEncodingException e3) {
            stringBuffer.append("");
        }
        stringBuffer.append("@@");
        stringBuffer.append(g.f(context));
        stringBuffer.append("@@");
        stringBuffer.append(g.i(context));
        onEvent(context, "userID", stringBuffer.toString());
    }

    public static void onEvent(Context context, String str) {
        onEvent(context, str, str, 1);
    }

    public static void onEvent(Context context, String str, int i2) {
        onEvent(context, str, str, i2);
    }

    public static void onEvent(Context context, String str, String str2) {
        onEvent(context, str, str2, 1);
    }

    public static void onEvent(Context context, String str, String str2, int i2) {
        if (context == null || str == null || str.equals("") || str2 == null || str2.equals("") || i2 <= 0) {
            return;
        }
        if (!str.equals("userID")) {
            String b2 = g.b(str);
            String b3 = g.b(str2);
            SharedPreferences eventSharedPreferences = getEventSharedPreferences(context);
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append(eventSharedPreferences.getString("eventlogs", ""));
            try {
                stringBuffer.append(URLEncoder.encode(b2, "UTF-8"));
                stringBuffer.append("|");
                stringBuffer.append(URLEncoder.encode(b3, "UTF-8"));
                stringBuffer.append("|");
                stringBuffer.append(i2);
                stringBuffer.append("|");
                stringBuffer.append(System.currentTimeMillis());
                stringBuffer.append("\n");
                eventSharedPreferences.edit().putString("eventlogs", stringBuffer.toString()).commit();
                if (stringBuffer.toString().getBytes().length > 10000) {
                    getLastEventData(context, null);
                    return;
                }
                return;
            } catch (UnsupportedEncodingException e2) {
                Log.i("MobileAgent", "unsupport utf-8,can't onEvent()");
                return;
            }
        }
        StringBuffer stringBuffer2 = new StringBuffer();
        try {
            stringBuffer2.append(URLEncoder.encode(str, "UTF-8"));
            stringBuffer2.append("|");
            stringBuffer2.append(URLEncoder.encode(str2, "UTF-8"));
            stringBuffer2.append("|");
            stringBuffer2.append(0);
            stringBuffer2.append("|");
            stringBuffer2.append(System.currentTimeMillis());
            stringBuffer2.append("\n");
            JSONObject jSONObject = new JSONObject();
            c = jSONObject;
            jSONObject.put(AlixDefine.SID, k);
            c.put("logJsonAry", stringBuffer2.toString());
            Log.i("MobileAgent", "send event_act .....");
            new l(context, c.toString()).start();
        } catch (UnsupportedEncodingException e3) {
            e3.printStackTrace();
        } catch (JSONException e4) {
            e4.printStackTrace();
        }
    }

    public static void onEventRT(Context context, String str, String str2) {
        StringBuffer stringBuffer = new StringBuffer();
        try {
            stringBuffer.append(URLEncoder.encode(g.h(context), "UTF-8"));
        } catch (UnsupportedEncodingException e2) {
            stringBuffer.append("");
        }
        stringBuffer.append("@@");
        stringBuffer.append(g.c(context));
        stringBuffer.append("@@");
        stringBuffer.append(g.b(Build.MANUFACTURER));
        stringBuffer.append("@@");
        stringBuffer.append(g.b(Build.MODEL));
        stringBuffer.append("@@");
        try {
            stringBuffer.append(URLEncoder.encode(g.a(), "UTF-8"));
        } catch (UnsupportedEncodingException e3) {
            stringBuffer.append("");
        }
        stringBuffer.append("@@");
        stringBuffer.append(g.f(context));
        stringBuffer.append("@@");
        stringBuffer.append(g.i(context));
        stringBuffer.append("@@");
        stringBuffer.append(g.d(context) + "*" + g.e(context));
        stringBuffer.append("@@");
        try {
            stringBuffer.append(URLEncoder.encode(str2, "UTF-8"));
        } catch (UnsupportedEncodingException e4) {
            stringBuffer.append("");
        }
        StringBuffer stringBuffer2 = new StringBuffer();
        try {
            stringBuffer2.append(URLEncoder.encode(str, "UTF-8"));
            stringBuffer2.append("|");
            stringBuffer2.append(URLEncoder.encode(stringBuffer.toString(), "UTF-8"));
            stringBuffer2.append("|");
            stringBuffer2.append(0);
            stringBuffer2.append("|");
            stringBuffer2.append(System.currentTimeMillis());
            stringBuffer2.append("\n");
            JSONObject jSONObject = new JSONObject();
            c = jSONObject;
            jSONObject.put(AlixDefine.SID, k);
            c.put("logJsonAry", stringBuffer2.toString());
            Log.i("MobileAgent", "send event_rt .....");
            new l(context, c.toString()).start();
        } catch (UnsupportedEncodingException e5) {
            e5.printStackTrace();
        } catch (JSONException e6) {
            e6.printStackTrace();
        }
    }

    public static void onPause(Context context) {
        if ("onPause".equals(i) && context.getClass().getName().equals(h)) {
            return;
        }
        SharedPreferences stateSharedPreferences = getStateSharedPreferences(context);
        String string = stateSharedPreferences.getString("activities", null);
        SharedPreferences.Editor edit = stateSharedPreferences.edit();
        edit.putLong("endTime", System.currentTimeMillis());
        edit.putString("activities", getActivityStateStr(context, "onPause", string));
        edit.commit();
    }

    public static void onResume(Context context) {
        onResume(context, g.g(context), g.h(context));
    }

    private static void onResume(Context context, String str, String str2) {
        try {
            if ("onResume".equals(i) && context.getClass().getName().equals(h)) {
                return;
            }
            if (d) {
                b.a().a(context);
            }
            if (context == null) {
                Log.e("MobileAgent", "unexpected null context");
            } else if (str == null || str.length() == 0) {
                Log.e("MobileAgent", "unexpected empty appkey");
            } else {
                strategy(context, sessionPolicy(context));
            }
        } catch (Exception e2) {
            Log.e("MobileAgent", "Exception occurred in Mobclick.onResume(). ");
            e2.printStackTrace();
        }
    }

    public static void openFeedbackDialog(Context context) {
        new q(context).show();
    }

    public static String popUploadFileName(Context context) {
        String substring;
        synchronized (l) {
            String string = getUploadListSharePreferences(context).getString("uploadList", "");
            substring = string.equals("") ? "" : string.substring(0, string.indexOf("|"));
        }
        return substring;
    }

    private static void pushUploadFileName(Context context, String str, long j2) {
        synchronized (l) {
            SharedPreferences uploadListSharePreferences = getUploadListSharePreferences(context);
            int i2 = uploadListSharePreferences.getInt("uploadcount", 0);
            String str2 = uploadListSharePreferences.getString("uploadList", "") + str + "|";
            uploadListSharePreferences.edit().putString("uploadList", str2).commit();
            uploadListSharePreferences.edit().putLong("uploadpopindex", j2).commit();
            if (str2.split("\\|").length > 200) {
                String popUploadFileName = popUploadFileName(context);
                context.deleteFile(popUploadFileName);
                delPopUpload(context, popUploadFileName);
            } else {
                uploadListSharePreferences.edit().putInt("uploadcount", i2 + 1).commit();
            }
        }
    }

    protected static void recordDate(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 = getConfigPreferences(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 recordErr(Context context, String str) {
        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(AlixDefine.SID, k);
            jSONObject.put("errjsonary", jSONArray);
            saveLog(context, jSONObject.toString(), 4);
        } catch (UnsupportedEncodingException e2) {
        } catch (JSONException e3) {
        }
    }

    public static void requestParams(Context context) {
        org.apache.http.client.methods.HttpPost httpPost = new org.apache.http.client.methods.HttpPost("http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:getappparameter&appkey=" + g.g(context));
        try {
            BasicHttpParams basicHttpParams = new BasicHttpParams();
            HttpClientParams.setRedirecting(basicHttpParams, true);
            HttpProtocolParams.setUserAgent(basicHttpParams, n.a());
            HttpProtocolParams.setContentCharset(basicHttpParams, "utf-8");
            HttpProtocolParams.setHttpElementCharset(basicHttpParams, "utf-8");
            if (n.a(context).equals("cmwap")) {
                basicHttpParams.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost("10.0.0.172", 80, (String) null));
            }
            DefaultHttpClient defaultHttpClient = new DefaultHttpClient(basicHttpParams);
            defaultHttpClient.setRedirectHandler(new m());
            JSONObject jSONObject = new JSONObject(EntityUtils.toString(defaultHttpClient.execute(httpPost).getEntity()));
            SharedPreferences.Editor edit = getConfigPreferences(context).edit();
            Iterator<String> keys = jSONObject.keys();
            while (keys.hasNext()) {
                String next = keys.next();
                edit.putString(next, jSONObject.getString(next));
            }
            edit.commit();
            Looper.prepare();
            if (jSONObject.length() > 0) {
                g.onDataReceive(jSONObject);
            }
            Looper.loop();
        } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
        } catch (IOException e3) {
            e3.printStackTrace();
        } catch (JSONException e4) {
            e4.printStackTrace();
        } catch (ParseException e5) {
            e5.printStackTrace();
        }
    }

    private static boolean saveLog(Context context, String str, int i2) {
        String str2;
        boolean z = false;
        synchronized (MobileAgent.class) {
            try {
                if (i2 == 3) {
                    str2 = "act";
                } else if (i2 == 2) {
                    str2 = "evn";
                } else if (i2 == 4) {
                    str2 = "err";
                }
                if (!str.equals("")) {
                    long popIndex = getPopIndex(context);
                    long j2 = 1 + popIndex;
                    String str3 = str2 + popIndex;
                    try {
                        FileOutputStream openFileOutput = context.openFileOutput(str3, 1);
                        pushUploadFileName(context, str3, j2);
                        openFileOutput.write(str.getBytes());
                        openFileOutput.close();
                    } catch (FileNotFoundException e2) {
                    } catch (IOException e3) {
                    }
                    z = true;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        return z;
    }

    public static boolean sendActionMessage(Context context, String str) {
        int i2;
        String logStr = getLogStr(context, str);
        if (logStr.equals("")) {
            recordDate(context, 3);
            deleteLog(context, str);
            return true;
        }
        JSONObject createMessage = createMessage(context);
        try {
            createMessage.put(AlixDefine.SID, new JSONObject(logStr).get(AlixDefine.SID));
            createMessage.put("logJsonAry", new JSONArray("[" + logStr + "]"));
            i2 = HttpPostData(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:postactlog", createMessage);
        } catch (JSONException e2) {
            e2.printStackTrace();
            i2 = 3;
        }
        if (i2 != 1 && i2 != 3) {
            if (i2 == 2) {
            }
            return false;
        }
        recordDate(context, 3);
        deleteLog(context, str);
        Log.i("MobileAgent", "send actlog success:" + str + " size:" + createMessage.toString().getBytes().length);
        return true;
    }

    public static boolean sendErrorMessage(Context context, String str) {
        try {
            JSONObject jSONObject = new JSONObject(getLogStr(context, str));
            jSONObject.put("pid", 1);
            jSONObject.put("protocolVersion", SDK_VERSION);
            jSONObject.put("sdkVersion", SDK_VERSION);
            jSONObject.put("cid", g.b(context));
            jSONObject.put("deviceId", g.a(context));
            jSONObject.put("appKey", g.g(context));
            jSONObject.put("packageName", context.getPackageName());
            jSONObject.put("versionCode", g.j(context));
            jSONObject.put("versionName", g.k(context));
            jSONObject.put("sendTime", System.currentTimeMillis());
            int HttpPostData = HttpPostData(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:posterrlog", jSONObject);
            if (HttpPostData != 1 && HttpPostData != 3) {
                if (HttpPostData == 2) {
                }
                return false;
            }
            recordDate(context, 3);
            deleteLog(context, str);
            Log.i("MobileAgent", "send errlog success" + str);
            return true;
        } catch (JSONException e2) {
            e2.printStackTrace();
            return false;
        }
    }

    public static boolean sendEventMessage(Context context, String str, String str2) {
        String logStr = str2 == null ? getLogStr(context, str) : str2;
        if (logStr.equals("")) {
            if (str2 == null) {
                recordDate(context, 3);
                deleteLog(context, str);
                return true;
            }
            return false;
        }
        try {
            JSONObject jSONObject = new JSONObject(logStr);
            String b2 = g.b(context);
            jSONObject.put("pid", 1);
            jSONObject.put("protocolVersion", SDK_VERSION);
            jSONObject.put("sdkVersion", SDK_VERSION);
            jSONObject.put("cid", b2);
            jSONObject.put("appKey", g.g(context));
            jSONObject.put("packageName", context.getPackageName());
            jSONObject.put("versionCode", g.j(context));
            jSONObject.put("versionName", g.k(context));
            jSONObject.put("sendTime", System.currentTimeMillis());
            jSONObject.put("deviceId", g.a(context));
            int HttpPostData = HttpPostData(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:posteventlog", jSONObject);
            if (str2 != null || (HttpPostData != 1 && HttpPostData != 3)) {
                return HttpPostData == 2 ? false : false;
            }
            recordDate(context, 3);
            deleteLog(context, str);
            Log.i("MobileAgent", "send eventlog success" + str + " size:" + jSONObject.toString().getBytes().length);
            return true;
        } catch (JSONException e2) {
            e2.printStackTrace();
            return true;
        }
    }

    public static void sendFeedbackMessage(Context context, String str, String str2, String str3) {
        new Thread(new k(context, str3, str, str2)).start();
    }

    public static void sendSystemMessage(Context context) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("pid", 1);
            jSONObject.put("protocolVersion", SDK_VERSION);
            jSONObject.put("sdkVersion", SDK_VERSION);
            jSONObject.put("cid", g.b(context));
            jSONObject.put("deviceId", g.a(context));
            jSONObject.put("appKey", g.g(context));
            jSONObject.put("packageName", context.getPackageName());
            jSONObject.put("versionCode", g.j(context));
            jSONObject.put("versionName", g.k(context));
            jSONObject.put("sendTime", System.currentTimeMillis());
            jSONObject.put(AlixDefine.IMSI, g.c(context));
            jSONObject.put("mac", g.f(context));
            jSONObject.put("deviceDetail", URLEncoder.encode(g.b(Build.MODEL), "UTF-8"));
            jSONObject.put("manufacturer", URLEncoder.encode(g.b(Build.MANUFACTURER), "UTF-8"));
            jSONObject.put("phoneOS", URLEncoder.encode(g.a(), "UTF-8"));
            jSONObject.put("screenWidth", g.d(context));
            jSONObject.put("screenHeight", g.e(context));
            DisplayMetrics displayMetrics = new DisplayMetrics();
            ((WindowManager) context.getSystemService("window")).getDefaultDisplay().getMetrics(displayMetrics);
            jSONObject.put("screenDensity", displayMetrics.densityDpi);
            jSONObject.put("carrierName", URLEncoder.encode(((TelephonyManager) context.getSystemService("phone")).getNetworkOperatorName(), "UTF-8"));
            jSONObject.put("accessPoint", g.i(context));
            jSONObject.put("countryCode", Locale.getDefault().getCountry());
            jSONObject.put("languageCode", Locale.getDefault().getLanguage());
            jSONObject.put("channel", URLEncoder.encode(g.h(context), "UTF-8"));
        } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
        } catch (JSONException e3) {
            e3.printStackTrace();
            return;
        }
        if (HttpPostData(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:postsyslog", jSONObject) == 1) {
            recordDate(context, 1);
            Log.i("MobileAgent", "send syslog success");
        }
    }

    private static boolean sessionPolicy(Context context) {
        boolean z;
        synchronized (MobileAgent.class) {
            try {
                String g2 = g.g(context);
                SharedPreferences stateSharedPreferences = getStateSharedPreferences(context);
                String string = stateSharedPreferences.getString("sessionId", null);
                if (isSessionTimeOut(stateSharedPreferences)) {
                    if (string != null) {
                        getLastEventData(context, stateSharedPreferences);
                        getLastLaunchData(context, stateSharedPreferences);
                        SharedPreferences.Editor edit = stateSharedPreferences.edit();
                        edit.clear();
                        edit.commit();
                    }
                    createSession(context, g2, stateSharedPreferences);
                    getLastLaunchData(context, stateSharedPreferences);
                    createSessionBody(context, g2, stateSharedPreferences);
                    z = true;
                } else {
                    String string2 = stateSharedPreferences.getString("activities", null);
                    if (string2.getBytes().length > 10000) {
                        getLastLaunchData(context, stateSharedPreferences);
                        string2 = "";
                    }
                    SharedPreferences.Editor edit2 = stateSharedPreferences.edit();
                    edit2.putString("activities", getActivityStateStr(context, "onResume", string2));
                    edit2.putLong("lastResumeTime", System.currentTimeMillis());
                    edit2.commit();
                    z = false;
                }
            } finally {
            }
        }
        return z;
    }

    public static void setDontListenCrash() {
        d = false;
    }

    public static void setUpdateOnlineConfigListen(MMOnlineConfigureListener mMOnlineConfigureListener) {
        g = mMOnlineConfigureListener;
    }

    protected static void strategy(Context context, boolean z) {
        syncParams(context);
        if (!e || (e && isWiFi(context))) {
            switch (a) {
                case 1:
                    if (z) {
                        new l(context, 6).start();
                        break;
                    }
                    break;
                case 2:
                    if (f) {
                        new l(context, 6).start();
                        f = false;
                        break;
                    }
                    break;
                case 3:
                    if (isOnce(context, 3)) {
                        new l(context, 6).start();
                        break;
                    }
                    break;
            }
        }
        f = false;
    }

    protected static void syncParams(Context context) {
        if (f) {
            if (getConfigParams(context, "updateonlyonwifi").equals(com.alipay.sdk.cons.a.e)) {
                e = true;
            } else {
                e = false;
            }
            String configParams = getConfigParams(context, "updatedelay");
            if (!configParams.equals("0")) {
                b = Integer.parseInt(configParams) * 1000;
            }
            int parseInt = Integer.parseInt(getConfigParams(context, "send_policy"));
            a = parseInt;
            if (parseInt == 0) {
                a = 1;
            }
        }
    }

    public static void updateOnlineConfig(Context context) {
        new l(context, 8).start();
    }

    public static void uploadList(Context context) {
        new Thread(new i(context)).start();
    }
}