全民灭僵尸 v1.3.2版本的 MD5 值为:3e5a0825178a9706b17f30863f73a9f5

以下内容为反编译后的 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.util.DisplayMetrics;
import android.util.Log;
import android.view.WindowManager;
import com.appabc.island.IAPHandler;
import com.example.assetexam.ShellUtils;
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 org.apache.http.HttpHost;
import org.apache.http.ParseException;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpPost;
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 = "3.1.1";
    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 a;
    private static MMOnlineConfigureListener g;
    private static boolean b = true;
    private static boolean c = false;
    private static boolean d = true;
    private static int e = 1;
    private static int f = 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;
    private static boolean n = false;

    public static int HttpPostData(Context context, String str, JSONObject jSONObject) {
        try {
            try {
                String g2 = g.g(context);
                HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(String.valueOf(str) + "&appkey=" + g2 + "&channel=" + URLEncoder.encode(g.h(context), "UTF-8") + "&code=105").openConnection();
                httpURLConnection.setDoOutput(true);
                httpURLConnection.setDoInput(true);
                httpURLConnection.setUseCaches(false);
                httpURLConnection.setRequestMethod("POST");
                try {
                    jSONObject.toString();
                } catch (Exception e2) {
                }
                byte[] a2 = d.a().a(jSONObject.toString());
                httpURLConnection.setRequestProperty("Content-length", new StringBuilder().append(a2.length).toString());
                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(ShellUtils.COMMAND_LINE_END);
                }
            } catch (ClientProtocolException e3) {
                return 2;
            }
        } catch (IOException e4) {
            return 2;
        } catch (JSONException e5) {
            return 3;
        } catch (Exception e6) {
            e6.printStackTrace();
            return 2;
        }
    }

    protected static JSONObject createMessage(Context context) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("pid", 1);
            jSONObject.put("protocolVersion", "3.1.0");
            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.k(context));
            jSONObject.put("versionName", g.l(context));
            jSONObject.put("sendTime", System.currentTimeMillis());
            jSONObject.put("deviceId", g.a(context));
            jSONObject.put("channel", g.h(context));
        } catch (JSONException e2) {
            e2.printStackTrace();
        }
        return jSONObject;
    }

    private static String createSession(Context context, String str, SharedPreferences sharedPreferences) {
        h = "";
        String valueOf = String.valueOf(g.a(String.valueOf(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));
        long j2 = sharedPreferences.getLong("readFlowRev", 0L);
        long[] m2 = g.m(context);
        edit.putLong("readFlowRev", m2[0]);
        edit.putLong("consumeFlowRev", m2[0] - j2);
        long j3 = sharedPreferences.getLong("readFlowSnd", 0L);
        edit.putLong("readFlowSnd", m2[1]);
        edit.putLong("consumeFlowSnd", m2[1] - j3);
        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(String.valueOf(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 (j2 > 6000000) {
                j2 = 300000;
            }
        }
        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(h);
        stringBuffer.append(ShellUtils.COMMAND_LINE_END);
        h = context.getClass().getName();
        i = str;
        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);
        a = new JSONObject();
        try {
            a.put("sid", string2);
            a.put("logJsonAry", string);
            if (saveLog(context, a.toString(), 2)) {
                eventSharedPreferences.edit().putString("eventlogs", "").commit();
            }
        } catch (JSONException e2) {
            e2.printStackTrace();
        }
        return true;
    }

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

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

    private static synchronized long getPopIndex(Context context) {
        long j2;
        synchronized (MobileAgent.class) {
            j2 = getUploadListSharePreferences(context).getLong("uploadpopindex", 0L);
        }
        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);
        if (str.length() > 7) {
            Log.i("MobileAgent", "init: " + str.substring(6));
        }
        m = true;
    }

    protected 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) {
        c.a().a(context);
    }

    public 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.j(context));
        onEvent(context, com.tendcloud.tenddata.game.e.e, 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) {
            Log.e("MobileAgent", "onEvent context is null");
        } else if (str == null || str.equals("")) {
            Log.e("MobileAgent", "onEvent eventId is null or empty ");
        } else if (str2 == null || str2.equals("") || i2 <= 0) {
        } else {
            new k(context, 11, str, str2).start();
        }
    }

    public static void onEventP(Context context, String str, String str2) {
        if (!str.equals(com.tendcloud.tenddata.game.e.e)) {
            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(1);
                stringBuffer.append("|");
                stringBuffer.append(System.currentTimeMillis());
                stringBuffer.append(ShellUtils.COMMAND_LINE_END);
                eventSharedPreferences.edit().putString("eventlogs", stringBuffer.toString()).commit();
                if (e == 1 || stringBuffer.toString().getBytes().length > 10000) {
                    getLastEventData(context, null);
                    return;
                }
                return;
            } catch (UnsupportedEncodingException e2) {
                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(ShellUtils.COMMAND_LINE_END);
            JSONObject jSONObject = new JSONObject();
            a = jSONObject;
            jSONObject.put("sid", k);
            a.put("logJsonAry", stringBuffer2.toString());
            new k(context, a.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.j(context));
        stringBuffer.append("@@");
        stringBuffer.append(String.valueOf(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(ShellUtils.COMMAND_LINE_END);
            JSONObject jSONObject = new JSONObject();
            a = jSONObject;
            jSONObject.put("sid", k);
            a.put("logJsonAry", stringBuffer2.toString());
            new k(context, a.toString()).start();
        } catch (UnsupportedEncodingException e5) {
            e5.printStackTrace();
        } catch (JSONException e6) {
            e6.printStackTrace();
        }
    }

    private static void onEventSys(Context context, String str, String str2) {
        SharedPreferences eventSharedPreferences = getEventSharedPreferences(context);
        StringBuffer stringBuffer = new StringBuffer();
        stringBuffer.append(eventSharedPreferences.getString("eventlogs", ""));
        try {
            stringBuffer.append(URLEncoder.encode(str, "UTF-8"));
            stringBuffer.append("|");
            stringBuffer.append(URLEncoder.encode(str2, "UTF-8"));
            stringBuffer.append("|");
            stringBuffer.append(0);
            stringBuffer.append("|");
            stringBuffer.append(System.currentTimeMillis());
            stringBuffer.append(ShellUtils.COMMAND_LINE_END);
            eventSharedPreferences.edit().putString("eventlogs", stringBuffer.toString()).commit();
            if (e == 1 || stringBuffer.toString().getBytes().length > 10000) {
                getLastEventData(context, null);
            }
        } catch (UnsupportedEncodingException e2) {
        }
    }

    public static void onPause(Context context) {
        new k(context, 10).start();
    }

    private static void onPauseP(Context context) {
        if ("onPause".equals(i) && context.getClass().getName().equals(h)) {
            return;
        }
        String str = "do pausep start: " + context.getClass().getName();
        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();
        r0 = "do pauseP" + context.getClass().getName();
    }

    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 (b) {
                c.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 {
                new k(context, 9, str, str2).start();
            }
        } catch (Exception e2) {
            Log.e("MobileAgent", "Exception occurred in Mobclick.onResume(). ");
            e2.printStackTrace();
        }
    }

    private static void onResumeP(Context context, String str, String str2) {
        try {
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        if ("onResume".equals(i) && context.getClass().getName().equals(h)) {
            return;
        }
        String str3 = "do resume start: " + context.getClass().getName();
        strategy(context, sessionPolicy(context));
        r0 = "do resume:" + context.getClass().getName();
    }

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

    public static synchronized void pageAct(Context context, String str, String str2) {
        synchronized (MobileAgent.class) {
            if (str != null) {
                onResumeP(context, str, str2);
            } else {
                onPauseP(context);
            }
        }
    }

    private 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 boolean pushActLog(Context context, String str, String str2) {
        a = new JSONObject();
        try {
            a.put("sid", str2);
            a.put("logs", str);
            saveLog(context, a.toString(), 3);
            return true;
        } catch (JSONException e2) {
            e2.printStackTrace();
            return true;
        }
    }

    protected static void pushSysLog(Context context) {
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("pid", 1);
            jSONObject.put("protocolVersion", "3.1.0");
            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.k(context));
            jSONObject.put("versionName", g.l(context));
            jSONObject.put("sendTime", System.currentTimeMillis());
            jSONObject.put("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(g.i(context), "UTF-8"));
            jSONObject.put("accessPoint", g.j(context));
            jSONObject.put("countryCode", Locale.getDefault().getCountry());
            jSONObject.put("languageCode", Locale.getDefault().getLanguage());
            jSONObject.put("channel", URLEncoder.encode(g.h(context), "UTF-8"));
            if (saveLog(context, jSONObject.toString(), 1)) {
                recordDate(context, 1);
            }
        } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
        } catch (JSONException e3) {
            e3.printStackTrace();
        }
    }

    private static void pushUploadFileName(Context context, String str, long j2) {
        synchronized (l) {
            SharedPreferences uploadListSharePreferences = getUploadListSharePreferences(context);
            int i2 = uploadListSharePreferences.getInt("uploadcount", 0);
            String str2 = String.valueOf(uploadListSharePreferences.getString("uploadList", "")) + str + "|";
            if (j2 > 10000) {
                j2 = 1;
            }
            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("sid", k);
            jSONObject.put("errjsonary", jSONArray);
            saveLog(context, jSONObject.toString(), 4);
        } catch (UnsupportedEncodingException e2) {
        } catch (JSONException e3) {
        }
    }

    public static void requestParams(Context context) {
        HttpPost httpPost = new 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, m.a());
            HttpProtocolParams.setContentCharset(basicHttpParams, "utf-8");
            HttpProtocolParams.setHttpElementCharset(basicHttpParams, "utf-8");
            if (m.a(context).equals("cmwap")) {
                basicHttpParams.setParameter("http.route.default-proxy", new HttpHost("10.0.0.172", 80, (String) null));
            }
            DefaultHttpClient defaultHttpClient = new DefaultHttpClient(basicHttpParams);
            defaultHttpClient.setRedirectHandler(new l());
            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();
            if (jSONObject.length() <= 0 || g == null) {
                return;
            }
            g.onDataReceive(jSONObject);
        } catch (JSONException e2) {
            e2.printStackTrace();
        } catch (ParseException e3) {
            e3.printStackTrace();
        } catch (UnsupportedEncodingException e4) {
            e4.printStackTrace();
        } catch (IOException e5) {
            e5.printStackTrace();
        }
    }

    private static synchronized boolean saveLog(Context context, String str, int i2) {
        String str2;
        boolean z = false;
        synchronized (MobileAgent.class) {
            if (i2 == 3) {
                str2 = "act";
            } else if (i2 == 2) {
                str2 = "evn";
            } else if (i2 == 4) {
                str2 = "err";
            } else if (i2 == 1) {
                str2 = "sys";
            }
            if (!str.equals("")) {
                long popIndex = getPopIndex(context);
                long j2 = 1 + popIndex;
                String str3 = String.valueOf(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;
            }
        }
        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("sid", new JSONObject(logStr).get("sid"));
            createMessage.put("mac", g.f(context));
            try {
                createMessage.put("deviceDetail", URLEncoder.encode(g.b(Build.MODEL), "UTF-8"));
            } catch (UnsupportedEncodingException e2) {
                createMessage.put("deviceDetail", "");
            }
            try {
                createMessage.put("manufacturer", URLEncoder.encode(g.b(Build.MANUFACTURER), "UTF-8"));
            } catch (UnsupportedEncodingException e3) {
                createMessage.put("manufacturer", "");
            }
            try {
                createMessage.put("phoneOs", URLEncoder.encode(g.a(), "UTF-8"));
            } catch (UnsupportedEncodingException e4) {
                createMessage.put("phoneOs", "");
            }
            createMessage.put("accessPoint", g.j(context));
            createMessage.put("deviceId", g.a(context));
            createMessage.put("cpuRatioMax", g.b());
            createMessage.put("cpuRatioCur", g.c());
            createMessage.put("menoryRatio", g.d());
            createMessage.put("logJsonAry", new JSONArray("[" + logStr + "]"));
            i2 = HttpPostData(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:postactlog", createMessage);
        } catch (JSONException e5) {
            e5.printStackTrace();
            i2 = 3;
        }
        if (i2 != 1 && i2 != 3) {
            if (i2 == 2) {
            }
            return false;
        }
        recordDate(context, 3);
        deleteLog(context, str);
        Log.i("MobileAgent", "act log sd");
        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", "3.1.0");
            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.k(context));
            jSONObject.put("versionName", g.l(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);
            String str2 = "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", "3.1.0");
            jSONObject.put("sdkVersion", SDK_VERSION);
            jSONObject.put("cid", b2);
            jSONObject.put("appKey", g.g(context));
            jSONObject.put("packageName", context.getPackageName());
            jSONObject.put("versionCode", g.k(context));
            jSONObject.put("versionName", g.l(context));
            jSONObject.put("sendTime", System.currentTimeMillis());
            jSONObject.put("mac", g.f(context));
            try {
                jSONObject.put("deviceDetail", URLEncoder.encode(g.b(Build.MODEL), "UTF-8"));
            } catch (UnsupportedEncodingException e2) {
                jSONObject.put("deviceDetail", "");
            }
            try {
                jSONObject.put("manufacturer", URLEncoder.encode(g.b(Build.MANUFACTURER), "UTF-8"));
            } catch (UnsupportedEncodingException e3) {
                jSONObject.put("manufacturer", "");
            }
            try {
                jSONObject.put("phoneOs", URLEncoder.encode(g.a(), "UTF-8"));
            } catch (UnsupportedEncodingException e4) {
                jSONObject.put("phoneOs", "");
            }
            jSONObject.put("accessPoint", g.j(context));
            jSONObject.put("deviceId", g.a(context));
            jSONObject.put("deviceId", g.a(context));
            try {
                jSONObject.put("channel", URLEncoder.encode(g.h(context), "UTF-8"));
            } catch (UnsupportedEncodingException e5) {
                jSONObject.put("channel", "");
            }
            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", "evn log sd");
            return true;
        } catch (JSONException e6) {
            e6.printStackTrace();
            return true;
        }
    }

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

    public static boolean sendSystemMessage(Context context, String str) {
        try {
            if (HttpPostData(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:postsyslog", new JSONObject(getLogStr(context, str))) == 1) {
                deleteLog(context, str);
                Log.i("MobileAgent", "send syslog success");
                return true;
            }
        } catch (JSONException e2) {
            e2.printStackTrace();
        }
        return false;
    }

    private static boolean sessionPolicy(Context context) {
        String g2 = g.g(context);
        SharedPreferences stateSharedPreferences = getStateSharedPreferences(context);
        String string = stateSharedPreferences.getString("sessionId", null);
        if (!isSessionTimeOut(stateSharedPreferences)) {
            String string2 = stateSharedPreferences.getString("activities", null);
            SharedPreferences.Editor edit = stateSharedPreferences.edit();
            edit.putString("activities", getActivityStateStr(context, "onResume", string2));
            edit.putLong("lastResumeTime", System.currentTimeMillis());
            edit.commit();
            if (e == 1 || string2.getBytes().length > 10000) {
                getLastLaunchData(context, stateSharedPreferences, false);
            }
            return false;
        }
        if (string != null) {
            getLastEventData(context, stateSharedPreferences);
            getLastLaunchData(context, stateSharedPreferences, true);
            SharedPreferences.Editor edit2 = stateSharedPreferences.edit();
            Long valueOf = Long.valueOf(stateSharedPreferences.getLong("readFlowRev", 0L));
            Long valueOf2 = Long.valueOf(stateSharedPreferences.getLong("readFlowSnd", 0L));
            edit2.clear();
            edit2.putLong("readFlowRev", valueOf.longValue());
            edit2.putLong("readFlowSnd", valueOf2.longValue());
            edit2.commit();
        }
        createSession(context, g2, stateSharedPreferences);
        getLastLaunchData(context, stateSharedPreferences, false);
        if (isOnce(context, 1)) {
            pushSysLog(context);
            onEventSys(context, "#applist", g.n(context));
            return true;
        }
        return true;
    }

    public static void setAutoListenCrash(Boolean bool) {
        b = bool.booleanValue();
    }

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

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

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

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

    public static synchronized void uploadList(Context context) {
        String str;
        synchronized (MobileAgent.class) {
            if (e == 2) {
                try {
                    Thread.sleep(f);
                } catch (InterruptedException e2) {
                    e2.printStackTrace();
                }
            }
            long j2 = n ? 0L : g.m(context)[0] + g.m(context)[1];
            long currentTimeMillis = System.currentTimeMillis();
            boolean z = true;
            while (true) {
                String popUploadFileName = popUploadFileName(context);
                if (popUploadFileName.equals("") || !z) {
                    break;
                }
                if (popUploadFileName.substring(0, 3).equals("act")) {
                    z = sendActionMessage(context, popUploadFileName);
                } else if (popUploadFileName.substring(0, 3).equals("evn")) {
                    z = sendEventMessage(context, popUploadFileName, null);
                } else if (popUploadFileName.substring(0, 3).equals("err")) {
                    z = sendErrorMessage(context, popUploadFileName);
                } else if (popUploadFileName.substring(0, 3).equals("sys")) {
                    z = sendSystemMessage(context, popUploadFileName);
                }
                if (z) {
                    try {
                        Thread.sleep(0L);
                    } catch (InterruptedException e3) {
                        e3.printStackTrace();
                    }
                }
            }
            if (!n) {
                long currentTimeMillis2 = System.currentTimeMillis();
                float f2 = (float) ((g.m(context)[0] + g.m(context)[1]) - j2);
                StringBuffer stringBuffer = new StringBuffer();
                stringBuffer.append(k);
                stringBuffer.append("@@");
                stringBuffer.append(f2);
                stringBuffer.append("@@");
                stringBuffer.append((float) (currentTimeMillis2 - currentTimeMillis));
                stringBuffer.append("@@");
                NetworkInfo activeNetworkInfo = ((ConnectivityManager) context.getSystemService("connectivity")).getActiveNetworkInfo();
                if (activeNetworkInfo != null && activeNetworkInfo.getType() != 1) {
                    String extraInfo = activeNetworkInfo.getExtraInfo();
                    Log.i("MobileUtils", "net type:" + extraInfo);
                    if (extraInfo != null && (extraInfo.equals("cmwap") || extraInfo.equals("3gwap") || extraInfo.equals("uniwap"))) {
                        str = "10.0.0.172";
                        stringBuffer.append(str);
                        stringBuffer.append("@@");
                        stringBuffer.append("23");
                        onEventSys(context, "#netStatus", stringBuffer.toString());
                        n = true;
                    }
                }
                str = null;
                stringBuffer.append(str);
                stringBuffer.append("@@");
                stringBuffer.append("23");
                onEventSys(context, "#netStatus", stringBuffer.toString());
                n = true;
            }
        }
    }
}