和通讯录 v3.9.6版本的 MD5 值为:669178e2ee1b2311daf378bd20c6bbe1
以下内容为反编译后的 MobileAgent.java 源代码,内容仅作参考
package com.chinaMobile;
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.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 MobileAgent {
public static final String SDK_VERSION = "3.2.0";
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";
public static boolean f1217a = false;
private static boolean f1218b = true;
private static boolean c = false;
private static boolean d = true;
private static int e = 1;
private static int f = 0;
private static String g = "";
private static long h = 0;
private static String i = "";
private static Object j = new Object();
private static Object k = new Object();
private static Object l = new Object();
private static boolean m = false;
private static boolean n = false;
private static ExecutorService o = Executors.newSingleThreadExecutor();
public static int HttpPostData(Context context, String str, JSONObject jSONObject) {
int i2;
int i3;
HttpURLConnection httpURLConnection;
int i4 = 0;
int i5 = 2;
f.a("MobileAgentRun", "run into httppost :" + str + "####" + context.getClass().getName() + "###" + jSONObject.toString());
?? r1 = 0;
HttpURLConnection httpURLConnection2 = null;
HttpURLConnection httpURLConnection3 = null;
HttpURLConnection httpURLConnection4 = null;
HttpURLConnection httpURLConnection5 = null;
try {
try {
String str2 = String.valueOf(str) + "&appkey=" + g.i(context) + "&channel=" + URLEncoder.encode(g.j(context), EncodedStringValue.StringEncoding.UTF_8) + "&code=106";
f.a("MobileAgentRun", jSONObject.toString());
f.a("MobileAgentRun", "post start");
httpURLConnection = (HttpURLConnection) new URL(str2).openConnection();
} catch (Throwable th) {
th = th;
}
} catch (ClientProtocolException e2) {
e = e2;
} catch (IOException e3) {
e = e3;
} catch (JSONException e4) {
e = e4;
} catch (Exception e5) {
e = e5;
i2 = 0;
i3 = 2;
}
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 = 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", EncodedStringValue.StringEncoding.UTF_8);
OutputStream outputStream = httpURLConnection.getOutputStream();
outputStream.write(a2);
outputStream.close();
i4 = httpURLConnection.getResponseCode();
f.a("MobileAgentRun", "post end");
if (200 == i4) {
try {
f.a("MobileAgent", "send success");
i5 = 1;
} catch (Exception e6) {
httpURLConnection5 = httpURLConnection;
e = e6;
i2 = i4;
i3 = 1;
f.a("MobileAgentRun", e.toString());
e.printStackTrace();
if (httpURLConnection5 != null) {
httpURLConnection5.disconnect();
i5 = i3;
i4 = i2;
} else {
i5 = i3;
i4 = i2;
}
r1 = "code:" + i4 + "status: " + i5 + " content: " + jSONObject.getString("logJsonAry");
f.a("MobileAgentHttpPost", r1);
f.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i5);
return i5;
}
}
if (httpURLConnection != null) {
httpURLConnection.disconnect();
}
} catch (Exception e7) {
i2 = i4;
i3 = 2;
e = e7;
httpURLConnection5 = httpURLConnection;
}
} catch (ClientProtocolException e8) {
httpURLConnection2 = httpURLConnection;
e = e8;
f.a("MobileAgentRun", e.toString());
e.printStackTrace();
if (httpURLConnection2 != null) {
httpURLConnection2.disconnect();
}
r1 = "code:" + i4 + "status: " + i5 + " content: " + jSONObject.getString("logJsonAry");
f.a("MobileAgentHttpPost", r1);
f.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i5);
return i5;
} catch (IOException e9) {
httpURLConnection3 = httpURLConnection;
e = e9;
f.a("MobileAgentRun", e.toString());
e.printStackTrace();
if (httpURLConnection3 != null) {
httpURLConnection3.disconnect();
}
r1 = "code:" + i4 + "status: " + i5 + " content: " + jSONObject.getString("logJsonAry");
f.a("MobileAgentHttpPost", r1);
f.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i5);
return i5;
} catch (JSONException e10) {
httpURLConnection4 = httpURLConnection;
e = e10;
f.a("MobileAgentRun", e.toString());
e.printStackTrace();
i5 = 3;
if (httpURLConnection4 != null) {
httpURLConnection4.disconnect();
}
r1 = "code:" + i4 + "status: " + i5 + " content: " + jSONObject.getString("logJsonAry");
f.a("MobileAgentHttpPost", r1);
f.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i5);
return i5;
} catch (Throwable th2) {
r1 = httpURLConnection;
th = th2;
if (r1 != 0) {
r1.disconnect();
}
throw th;
}
r1 = "code:" + i4 + "status: " + i5 + " content: " + jSONObject.getString("logJsonAry");
f.a("MobileAgentHttpPost", r1);
f.a("MobileAgentRun", "run out httppost :" + context.getClass().getName() + " resultcode:" + i5);
return i5;
}
protected static JSONObject createMessage(Context context) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("pid", 1);
jSONObject.put("protocolVersion", "3.1.4");
jSONObject.put(SsoSdkConstants.VALUES_KEY_SDKVERSION, SDK_VERSION);
jSONObject.put(Telephony.Mms.Part.CONTENT_ID, g.b(context));
jSONObject.put("appKey", g.i(context));
jSONObject.put("packageName", context.getPackageName());
jSONObject.put("versionCode", g.n(context));
jSONObject.put("versionName", g.o(context));
jSONObject.put("sendTime", System.currentTimeMillis());
jSONObject.put("deviceId", g.a(context));
jSONObject.put("channel", g.j(context));
} catch (JSONException e2) {
e2.printStackTrace();
}
return jSONObject;
}
private static String createSession(Context context, String str, SharedPreferences sharedPreferences) {
g = "";
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", getActivityStateStr(context, "onResume", null));
long j2 = sharedPreferences.getLong("readFlowRev", 0L);
long[] p = g.p(context);
edit.putLong("readFlowRev", p[0]);
long j3 = p[0] - j2;
if (j3 < 0) {
j3 = 0;
}
edit.putLong("consumeFlowRev", j3);
long j4 = sharedPreferences.getLong("readFlowSnd", 0L);
edit.putLong("readFlowSnd", p[1]);
long j5 = p[1] - j4;
edit.putLong("consumeFlowSnd", j5 >= 0 ? j5 : 0L);
edit.commit();
i = a2;
return a2;
}
private static void delPopUpload(Context context, String str) {
synchronized (j) {
SharedPreferences uploadListSharePreferences = getUploadListSharePreferences(context);
uploadListSharePreferences.edit().putString("uploadList", uploadListSharePreferences.getString("uploadList", "").replace(String.valueOf(str) + "|", "")).commit();
}
}
private static void deleteLog(Context context, String str) {
if (str != null) {
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")) {
h = currentTimeMillis;
} else if (str.equals("onPause") && g.equals(context.getClass().getName())) {
long j3 = currentTimeMillis - h;
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(g);
stringBuffer.append("\n");
g = context.getClass().getName();
return stringBuffer.toString();
}
private 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);
}
protected static SharedPreferences getEventSpSharedPreferences(Context context) {
return context.getSharedPreferences("MoblieAgent_event_sp" + 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);
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("sid", string2);
jSONObject.put("logJsonAry", string);
if (saveLog(context, jSONObject.toString(), 2)) {
eventSharedPreferences.edit().putString("eventlogs", "").commit();
}
} catch (JSONException e2) {
e2.printStackTrace();
}
return true;
}
private static boolean getLastEventSpData(Context context, SharedPreferences sharedPreferences) {
SharedPreferences eventSpSharedPreferences = getEventSpSharedPreferences(context);
String string = eventSpSharedPreferences.getString("eventlogs", "");
if (string.equals("")) {
return false;
}
String string2 = getStateSharedPreferences(context).getString("sessionId", null);
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("sid", string2);
jSONObject.put("logJsonAry", string);
if (saveLog(context, jSONObject.toString(), 5)) {
eventSpSharedPreferences.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", "");
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 (!saveLog(context, jSONObject.toString(), 3)) {
return true;
}
sharedPreferences.edit().putString("activities", "").commit();
return true;
} catch (JSONException e2) {
e2.printStackTrace();
return true;
}
}
private static synchronized String getLogStr(Context context, String str) {
FileInputStream fileInputStream;
IOException e2;
String str2;
FileNotFoundException e3;
synchronized (MobileAgent.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 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) {
Log.i("MobileAgent", "already init");
return;
}
try {
f1217a = !context.getSharedPreferences("MoblieAgent_debug", 0).getString("debug", "").equals("");
} catch (Exception e2) {
}
f.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("MoblieAgent_sys_config", 0);
sharedPreferences.edit().putString("MOBILE_APPKEY", str).commit();
sharedPreferences.edit().putString("MOBILE_CHANNEL", str2).commit();
m = true;
Log.i("MobileAgent", "finish init SUCCESS " + f1217a);
}
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;
}
protected static boolean isRecordEvent(Context context, String str) {
return !getConfigPreferences(context).getString(str, "").equals("");
}
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;
}
private static void joinDu(Context context, String str, String str2) {
if (n) {
Log.i("MobileAgent", "already init");
return;
}
try {
f1217a = !context.getSharedPreferences("MoblieAgent_debug", 0).getString("debug", "").equals("");
} catch (Exception e2) {
}
f.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("MoblieAgent_sys_config", 0);
sharedPreferences.edit().putString("MOBILE_APPKEY", str).commit();
sharedPreferences.edit().putString("MOBILE_CHANNEL", str2).commit();
onResume(context);
onPause(context);
n = true;
Log.i("MobileAgent", "finish init SUCCESS " + f1217a);
}
public static void listenCrash(Context context) {
if (context == null) {
Log.e("MobileAgent", "Exception occurent in listenCrash ,context cann't be null");
}
b.a().a(context);
}
public static void listenUser(Context context, String str, String str2) {
if (context == null) {
Log.e("MobileAgent", "Exception occurent in listenUser() ,context cann't be null");
return;
}
if (TextUtils.isEmpty(str) || g.a(str, 100)) {
Log.e("MobileAgent", "Exception occurent in listenUser() ,channelID cann't be empty or length more than 100");
}
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.j(context), EncodedStringValue.StringEncoding.UTF_8));
} catch (Exception e2) {
stringBuffer.append("");
}
stringBuffer.append("@@");
stringBuffer.append(g.c(context));
stringBuffer.append("@@");
stringBuffer.append(g.a());
stringBuffer.append("@@");
try {
stringBuffer.append(URLEncoder.encode(g.c(), EncodedStringValue.StringEncoding.UTF_8));
} catch (UnsupportedEncodingException e3) {
stringBuffer.append("");
}
stringBuffer.append("@@");
stringBuffer.append(g.h(context));
stringBuffer.append("@@");
stringBuffer.append(g.m(context));
onEvent(context, "userID", stringBuffer.toString());
}
public static void onErr(Context context, String str) {
new k(context, str).start();
}
public static void onErrP(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", i);
jSONObject.put("errjsonary", jSONArray);
f.a("MobileAgentRun", "errJso" + jSONObject.toString());
saveLog(context, jSONObject.toString(), 4);
} catch (UnsupportedEncodingException e2) {
f.a("MobileAgentRun", "unsupport utf-8,lost catch Exception");
} catch (JSONException e3) {
f.a("MobileAgentRun", "json exception,lost catch Exception");
}
}
public static void onEvent(Context context, String str) {
onEvent(context, str, str);
}
public static void onEvent(Context context, String str, String str2) {
if (str.contains("#")) {
Log.w("MobileAgent", "the eventId contain illegal char");
} else {
onEventBase(context, str, str2);
}
}
private static void onEventBase(Context context, String str, String str2) {
f.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 k(context, 11, str, str2).start();
}
public static void onEventP(Context context, String str, String str2) {
synchronized (k) {
String a2 = g.a(str);
String a3 = g.a(str2);
SharedPreferences eventSharedPreferences = getEventSharedPreferences(context);
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(eventSharedPreferences.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");
eventSharedPreferences.edit().putString("eventlogs", stringBuffer.toString()).commit();
getLastEventData(context, null);
} catch (UnsupportedEncodingException e2) {
f.a("MobileAgentRun", "unsupport utf-8,can't onEvent()");
return;
}
}
strategy(context, false);
}
public static void onEventRT(Context context, String str, String str2) {
f.a("MobileAgentAPI", "run in onEventRT [" + str + "," + str2 + "]");
if (context == null) {
Log.e("MobileAgent", "Exception occurent in onEventRt() ,context cann't be null");
return;
}
if (TextUtils.isEmpty(str) || g.a(str, 100)) {
Log.e("MobileAgent", "Exception occurent in onEventRt() ,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 onEventRt() ,channelID cann't be empty or length more than 900");
}
new Thread(new j(context, str2, str)).start();
}
private static void onEventSp(Context context, String str, String str2, int i2) {
new k(context, 13, str, str2).start();
}
public static void onEventSpP(Context context, String str, String str2) {
synchronized (l) {
String a2 = g.a(str);
String a3 = g.a(str2);
SharedPreferences eventSpSharedPreferences = getEventSpSharedPreferences(context);
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(eventSpSharedPreferences.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");
eventSpSharedPreferences.edit().putString("eventlogs", stringBuffer.toString()).commit();
if (e == 1 || stringBuffer.toString().getBytes().length > 10000) {
getLastEventSpData(context, null);
}
} catch (UnsupportedEncodingException e2) {
f.a("MobileAgent", "unsupport utf-8,can't onEvent()");
return;
}
}
strategy(context, false);
}
public static void onPause(Context context) {
String str = "";
try {
str = context.getClass().getName();
} catch (Exception e2) {
f.a("MobileAgentAPI", e2.getMessage());
}
f.a("MobileAgentAPI", "run into onpause " + str);
if (context == null) {
Log.e("MobileAgent", "Exception occurent in onPause ,context cann't be null");
} else {
o.execute(new k(context, 10));
f.a("MobileAgentAPI", "run out onpause " + str);
}
}
private static void onPauseP(Context context) {
f.a("MobileAgentRun", "run into onpausep :" + 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();
f.a("MobileAgentRun", "run out onpausep :" + context.getClass().getName());
}
public static void onResume(Context context) {
String str = "";
try {
str = context.getClass().getName();
} catch (Exception e2) {
f.a("MobileAgentAPI", e2.getMessage());
}
f.a("MobileAgentAPI", "run into onresume " + str);
try {
} catch (Exception e3) {
Log.e("MobileAgent", "Exception occurred in MobileAgent.onResume(). ");
f.a("MobileAgentRun", e3.toString());
}
if (context == null) {
Log.e("MobileAgent", "Exception occurent in onResume ,context cann't be null");
return;
}
o.execute(new k(context, 9, null, null));
if (f1218b) {
listenCrash(context);
}
f.a("MobileAgentAPI", "run out onresume " + str);
}
private static void onResumeP(Context context) {
f.a("MobileAgentRun", "run into onresumep :" + context.getClass().getName());
try {
f.a("page pro", "do resume start: " + context.getClass().getName());
strategy(context, sessionPolicy(context));
} catch (Exception e2) {
e2.printStackTrace();
}
f.a("MobileAgentRun", "run out onresume :" + context.getClass().getName());
}
public static void openFeedbackDialog(Context context) {
if (context == null) {
Log.e("MobileAgent", "Exception occurent in openFeedbackDialog() ,context cann't be null");
} else {
new m(context).show();
}
}
public static void pageAct(Context context, boolean z) {
if (z) {
f.a("MobileAgentRun", "run into pageact onresumep");
onResumeP(context);
} else {
f.a("MobileAgentRun", "run into pageact onpausep");
onPauseP(context);
}
f.a("MobileAgentRun", "run out pageact");
}
private static String popUploadFileName(Context context) {
String substring;
synchronized (j) {
String string = getUploadListSharePreferences(context).getString("uploadList", "");
substring = string.equals("") ? "" : string.substring(0, string.indexOf("|"));
}
return substring;
}
protected static void pushSysLog(Context context) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("pid", 1);
jSONObject.put("protocolVersion", "3.1.4");
jSONObject.put(SsoSdkConstants.VALUES_KEY_SDKVERSION, SDK_VERSION);
jSONObject.put(Telephony.Mms.Part.CONTENT_ID, g.b(context));
jSONObject.put("deviceId", g.a(context));
jSONObject.put("appKey", g.i(context));
jSONObject.put("packageName", context.getPackageName());
jSONObject.put("versionCode", g.n(context));
jSONObject.put("versionName", g.o(context));
jSONObject.put("sendTime", System.currentTimeMillis());
jSONObject.put("imsi", g.c(context));
jSONObject.put("mac", g.h(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.l(context), EncodedStringValue.StringEncoding.UTF_8));
jSONObject.put("accessPoint", g.m(context));
jSONObject.put("countryCode", g.d());
jSONObject.put("languageCode", g.e());
jSONObject.put("channel", URLEncoder.encode(g.j(context), EncodedStringValue.StringEncoding.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 (j) {
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 > 500) {
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();
}
protected static void recordEvent(Context context, String str) {
getConfigPreferences(context).edit().putString(str, "record").commit();
}
private static synchronized boolean saveLog(Context context, String str, int i2) {
String str2;
FileOutputStream fileOutputStream;
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";
} else if (i2 == 5) {
str2 = "esp";
}
if (!str.trim().equals("")) {
long popIndex = getPopIndex(context);
long j2 = 1 + popIndex;
String str3 = String.valueOf(str2) + popIndex;
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 {
pushUploadFileName(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;
}
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 {
try {
createMessage.put("sid", new JSONObject(logStr).get("sid"));
} catch (JSONException e2) {
createMessage.put("sid", "");
}
createMessage.put("mac", g.h(context));
try {
createMessage.put("deviceDetail", URLEncoder.encode(g.a(), EncodedStringValue.StringEncoding.UTF_8));
} catch (UnsupportedEncodingException e3) {
createMessage.put("deviceDetail", "");
}
try {
createMessage.put(SsoSdkConstants.VALUES_KEY_MANUFACTURER, URLEncoder.encode(g.b(), EncodedStringValue.StringEncoding.UTF_8));
} catch (UnsupportedEncodingException e4) {
createMessage.put(SsoSdkConstants.VALUES_KEY_MANUFACTURER, "");
}
try {
createMessage.put("phoneOs", URLEncoder.encode(g.c(), EncodedStringValue.StringEncoding.UTF_8));
} catch (UnsupportedEncodingException e5) {
createMessage.put("phoneOs", "");
}
try {
createMessage.put("accessPoint", URLEncoder.encode(g.m(context), EncodedStringValue.StringEncoding.UTF_8));
} catch (UnsupportedEncodingException e6) {
createMessage.put("accessPoint", "");
}
try {
createMessage.put("netWorkType", URLEncoder.encode(g.q(context), EncodedStringValue.StringEncoding.UTF_8));
} catch (UnsupportedEncodingException e7) {
createMessage.put("netWorkType", "");
}
createMessage.put("deviceId", g.a(context));
createMessage.put("cpuRatioMax", g.f());
createMessage.put("cpuRatioCur", g.g());
createMessage.put("menoryRatio", g.h());
createMessage.put("logJsonAry", new JSONArray("[" + logStr + "]"));
i2 = HttpPostData(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:postactlog", createMessage);
} catch (JSONException e8) {
e8.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) {
String logStr = getLogStr(context, str);
try {
JSONObject jSONObject = new JSONObject(logStr);
jSONObject.put("pid", 1);
jSONObject.put("protocolVersion", "3.1.4");
jSONObject.put(SsoSdkConstants.VALUES_KEY_SDKVERSION, SDK_VERSION);
jSONObject.put(Telephony.Mms.Part.CONTENT_ID, g.b(context));
jSONObject.put("deviceId", g.a(context));
jSONObject.put("appKey", g.i(context));
jSONObject.put("packageName", g.k(context));
jSONObject.put("versionCode", g.n(context));
jSONObject.put("versionName", g.o(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", "erLog sd");
f.a("MobileAgent", "send errlog success \n" + logStr);
return true;
} catch (JSONException e2) {
deleteLog(context, str);
Log.i("MobileAgent", "SDK del a dirty data");
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) {
return false;
}
recordDate(context, 3);
deleteLog(context, str);
return true;
}
try {
JSONObject jSONObject = new JSONObject(logStr);
String b2 = g.b(context);
jSONObject.put("pid", 1);
jSONObject.put("protocolVersion", "3.1.4");
jSONObject.put(SsoSdkConstants.VALUES_KEY_SDKVERSION, SDK_VERSION);
jSONObject.put(Telephony.Mms.Part.CONTENT_ID, b2);
jSONObject.put("appKey", g.i(context));
jSONObject.put("packageName", g.k(context));
jSONObject.put("versionCode", g.n(context));
jSONObject.put("versionName", g.o(context));
jSONObject.put("sendTime", System.currentTimeMillis());
jSONObject.put("mac", g.h(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.m(context));
jSONObject.put("deviceId", g.a(context));
try {
jSONObject.put("channel", URLEncoder.encode(g.j(context), EncodedStringValue.StringEncoding.UTF_8));
} catch (UnsupportedEncodingException e5) {
jSONObject.put("channel", "");
}
int HttpPostData = HttpPostData(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:posteventlog", jSONObject);
if (HttpPostData != 1 && HttpPostData != 3) {
if (HttpPostData != 2) {
return false;
}
Log.w("MobileAgent", "please check your network");
return false;
}
if (str2 == null) {
recordDate(context, 3);
deleteLog(context, str);
Log.i("MobileAgent", "evn log sd");
} else {
Log.i("MobileAgent", "evnrt log sd");
}
return true;
} catch (JSONException e6) {
deleteLog(context, str);
e6.printStackTrace();
return true;
}
}
protected static boolean sendEventSpMessage(Context context, String str, String str2) {
String logStr = str2 == null ? getLogStr(context, str) : str2;
if (logStr.equals("")) {
if (str2 != null) {
return false;
}
recordDate(context, 3);
deleteLog(context, str);
return true;
}
try {
JSONObject jSONObject = new JSONObject(logStr);
String b2 = g.b(context);
jSONObject.put("pid", 1);
jSONObject.put("protocolVersion", "3.1.4");
jSONObject.put(SsoSdkConstants.VALUES_KEY_SDKVERSION, SDK_VERSION);
jSONObject.put(Telephony.Mms.Part.CONTENT_ID, b2);
jSONObject.put("appKey", g.i(context));
jSONObject.put("packageName", g.k(context));
jSONObject.put("versionCode", g.n(context));
jSONObject.put("versionName", g.o(context));
jSONObject.put("sendTime", System.currentTimeMillis());
jSONObject.put("mac", g.h(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.m(context));
jSONObject.put("deviceId", g.a(context));
try {
jSONObject.put("channel", URLEncoder.encode(g.j(context), EncodedStringValue.StringEncoding.UTF_8));
} catch (UnsupportedEncodingException e5) {
jSONObject.put("channel", "");
}
int HttpPostData = HttpPostData(context, "http://da.mmarket.com/mmsdk/mmsdk?func=mmsdk:specposteventlog", jSONObject);
if (HttpPostData != 1 && HttpPostData != 3) {
if (HttpPostData != 2) {
return false;
}
Log.w("MobileAgent", "please check your network");
return false;
}
if (str2 == null) {
recordDate(context, 3);
deleteLog(context, str);
Log.i("MobileAgent", "evn log sd");
} else {
Log.i("MobileAgent", "evnrt log sd");
}
return true;
} catch (JSONException e6) {
deleteLog(context, str);
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);
return true;
}
} catch (JSONException e2) {
deleteLog(context, str);
Log.i("MobileAgent", "SDK del a dirty data");
}
return false;
}
private static boolean sessionPolicy(Context context) {
boolean z = true;
f.a("MobileAgentRun", "run into sessionpolicy");
String i2 = g.i(context);
SharedPreferences stateSharedPreferences = getStateSharedPreferences(context);
String string = stateSharedPreferences.getString("sessionId", null);
if (isSessionTimeOut(stateSharedPreferences)) {
if (string != null) {
getLastLaunchData(context, stateSharedPreferences, true);
SharedPreferences.Editor edit = stateSharedPreferences.edit();
Long valueOf = Long.valueOf(stateSharedPreferences.getLong("readFlowRev", 0L));
Long valueOf2 = Long.valueOf(stateSharedPreferences.getLong("readFlowSnd", 0L));
edit.clear();
edit.putLong("readFlowRev", valueOf.longValue()).commit();
edit.putLong("readFlowSnd", valueOf2.longValue()).commit();
}
createSession(context, i2, stateSharedPreferences);
getLastLaunchData(context, stateSharedPreferences, false);
if (isOnce(context, 1)) {
pushSysLog(context);
}
} else {
String string2 = stateSharedPreferences.getString("activities", null);
SharedPreferences.Editor edit2 = stateSharedPreferences.edit();
edit2.putString("activities", getActivityStateStr(context, "onResume", string2));
edit2.putLong("lastResumeTime", System.currentTimeMillis());
edit2.commit();
if (e == 1 || string2.getBytes().length > 10000) {
getLastLaunchData(context, stateSharedPreferences, false);
}
z = false;
}
f.a("MobileAgentRun", "run out sessionpolicy");
return z;
}
public static void setAutoListenCrash(Boolean bool) {
f1218b = bool.booleanValue();
}
protected static void strategy(Context context, boolean z) {
f.a("MobileAgentRun", "run into strategy");
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;
f.a("MobileAgentRun", "run out strategy");
}
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 synchronized void uploadList(Context context) {
synchronized (MobileAgent.class) {
f.a("MobileAgentRun", "run into uploadlist :" + context.getClass().getName());
if (e == 2) {
try {
Thread.sleep(f);
} catch (InterruptedException e2) {
e2.printStackTrace();
}
}
boolean z = true;
System.currentTimeMillis();
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);
} else if (popUploadFileName.substring(0, 3).equals("esp")) {
z = sendEventSpMessage(context, popUploadFileName, null);
}
if (z) {
try {
Thread.sleep(0L);
} catch (InterruptedException e3) {
e3.printStackTrace();
}
}
f.a("MobileAgentRun", "finish a task : " + popUploadFileName);
}
f.a("MobileAgentRun", " finish uploadlist ");
f.a("MobileAgentRun", "run out uploadlist :" + context.getClass().getName());
}
}
}