TIM v2.3.1版本的 MD5 值为:d6957e3ee7ce901ccc491cefdea0da8c
以下内容为反编译后的 DataReport.java 源代码,内容仅作参考
package com.tencent.proxyinner.report;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Message;
import android.util.Log;
import com.tencent.mobileqq.troop.utils.TroopBarUtils;
import com.tencent.proxyinner.log.ODLog;
import com.tencent.txproxy.Constants;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
public class DataReport {
private static final int MSG_BOOT_COMPLETE = 1;
private static final int MSG_DOWNLOAD_COMPLETE = 3;
private static final int MSG_DOWNLOAD_START = 2;
private static final String REPORT_URL = "http://tiantian.qq.com/cgi-bin/love/report?type=1";
private static final String TAG = "ODSDK|DataReport";
public static final int TYPE_FIRST_DOWNLOAD = 1;
public static final int TYPE_FORCE_DOWNLOAD = 3;
public static final int TYPE_NORMAL_DOWNLOAD = 2;
public static DataReport sInstance = null;
private int mSourceChannelId;
private int mSourceFromId;
private String mSourceVersion;
private Handler reportThreadHandler;
private HandlerThread reportThread = null;
long bootTimeStart = 0;
long downloadTimeStart = 0;
private boolean mReportHost = false;
private int mVasType = 1;
private long mHostID = 0;
private List<Event> mEventList = new ArrayList();
private Handler mHandler = new Handler() {
@Override
public void handleMessage(Message msg2) {
Bundle bundle = msg2.getData();
for (Event e : DataReport.this.mEventList) {
if (msg2.what == 1) {
e.onDataReport("boot", bundle);
} else if (msg2.what == 2) {
e.onDataReport("download_start", bundle);
} else if (msg2.what == 3) {
e.onDataReport("download_complete", bundle);
}
}
}
};
public interface Event {
void onDataReport(String str, Bundle bundle);
}
private DataReport() {
}
public static DataReport getInstance() {
if (sInstance == null) {
synchronized (DataReport.class) {
if (sInstance == null) {
sInstance = new DataReport();
}
}
}
return sInstance;
}
public void init() {
}
public void addListener(Event listener) {
if (listener != null) {
this.mEventList.add(listener);
}
}
public void setSourceInfo(int vasType, String sourceVersion, int sourceChannelId, long hostID, boolean reportHost) {
this.mSourceVersion = sourceVersion;
this.mSourceChannelId = sourceChannelId;
this.mReportHost = reportHost;
this.mVasType = vasType;
this.mHostID = hostID;
}
public void setFromId(int sourceFromId) {
this.mSourceFromId = sourceFromId;
}
public void reportBootStart() {
Log.i(TAG, "reportBootStart");
this.bootTimeStart = System.currentTimeMillis();
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("action", "entershell");
} catch (JSONException e) {
e.printStackTrace();
}
internalReport(jsonObject);
}
public void reportBootComplete(boolean bSuccess, int reason, int res, String descMsg) {
long timeconsume = System.currentTimeMillis() - this.bootTimeStart;
if (this.mReportHost) {
Message msg2 = Message.obtain();
msg2.what = 1;
Bundle bundle = new Bundle();
bundle.putInt("errcode", reason);
bundle.putInt("timeconsume", (int) timeconsume);
msg2.setData(bundle);
this.mHandler.sendMessage(msg2);
}
Log.i(TAG, "reportBootComplete");
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("timeconsume", timeconsume);
jsonObject.put("action", "boot");
if (bSuccess) {
jsonObject.put("int1", 1);
} else {
jsonObject.put("int1", 2);
jsonObject.put("int2", reason);
jsonObject.put("int3", res);
if (descMsg == null) {
descMsg = "";
}
jsonObject.put("str1", descMsg);
}
} catch (JSONException e) {
e.printStackTrace();
}
internalReport(jsonObject);
}
public void reportDownloadStart(int downloadType, int trigger) {
Log.i(TAG, "reportDownloadStart");
this.downloadTimeStart = System.currentTimeMillis();
if (this.mReportHost) {
Message msg2 = Message.obtain();
msg2.what = 2;
Bundle bundle = new Bundle();
bundle.putInt("type", downloadType);
bundle.putInt("trigger", trigger);
msg2.setData(bundle);
this.mHandler.sendMessage(msg2);
}
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("action", "download");
jsonObject.put("int1", 1);
jsonObject.put("int3", trigger);
jsonObject.put("int4", downloadType);
} catch (JSONException e) {
e.printStackTrace();
}
internalReport(jsonObject);
}
public void reportDownloadComplete(int errorCode, int downloadType, int trigger, int httpResponceCode, int hostErrCode, String headInfo, String errMsg, int networkType, int netWorkSubType, String checkUrl) {
Log.i(TAG, "reportDownloadComplete");
long timeconsume = System.currentTimeMillis() - this.downloadTimeStart;
if (this.mReportHost) {
Message msg2 = Message.obtain();
msg2.what = 3;
Bundle bundle = new Bundle();
bundle.putInt("errcode", errorCode);
bundle.putInt("type", downloadType);
bundle.putInt("trigger", trigger);
bundle.putInt("timeconsume", (int) timeconsume);
msg2.setData(bundle);
this.mHandler.sendMessage(msg2);
}
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("action", "download");
jsonObject.put("timeconsume", timeconsume);
jsonObject.put("int1", 2);
jsonObject.put("int2", errorCode);
jsonObject.put("int3", trigger);
jsonObject.put("int4", downloadType);
jsonObject.put("int5", httpResponceCode);
jsonObject.put("str1", headInfo);
jsonObject.put("str2", errMsg);
jsonObject.put("str3", String.valueOf(networkType) + TroopBarUtils.y + String.valueOf(netWorkSubType));
jsonObject.put("str4", String.valueOf(hostErrCode));
jsonObject.put("str5", checkUrl);
} catch (JSONException e) {
e.printStackTrace();
}
internalReport(jsonObject);
}
public void reportUserReload(int status, int networkType, int netWorkSubType) {
Log.i(TAG, "reportUserReload");
if (this.mReportHost) {
}
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("action", "userreload");
jsonObject.put("int1", networkType);
jsonObject.put("int2", netWorkSubType);
jsonObject.put("int3", status);
} catch (JSONException e) {
e.printStackTrace();
}
internalReport(jsonObject);
}
public void reportUserCancelDuringDownload(int status, int errCode, int step, int trigger, int networkType, int netWorkSubType) {
Log.i(TAG, "reportUserCancelDuringDownload");
long timeconsume = System.currentTimeMillis() - this.downloadTimeStart;
if (this.mReportHost) {
Message msg2 = Message.obtain();
msg2.what = 3;
Bundle bundle = new Bundle();
bundle.putInt("status", status);
bundle.putInt("step", step);
bundle.putInt("trigger", trigger);
bundle.putInt("timeconsume", (int) timeconsume);
msg2.setData(bundle);
this.mHandler.sendMessage(msg2);
}
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("action", "usercancel");
jsonObject.put("timeconsume", timeconsume);
jsonObject.put("int1", errCode);
jsonObject.put("int2", step);
jsonObject.put("int3", status);
jsonObject.put("int4", trigger);
if (networkType >= 0) {
jsonObject.put("str1", String.valueOf(networkType));
}
if (netWorkSubType >= 0) {
jsonObject.put("str2", String.valueOf(netWorkSubType));
}
} catch (JSONException e) {
e.printStackTrace();
}
internalReport(jsonObject);
}
public void reportDuplicateEnterDuringDownload() {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("action", "dupplicateenterdownload");
} catch (JSONException e) {
e.printStackTrace();
}
internalReport(jsonObject);
}
public void reportAction(String action, int int1, int int2, String str1, String str2) {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("action", action);
jsonObject.put("int1", int1);
jsonObject.put("int2", int2);
jsonObject.put("str1", str1);
jsonObject.put("str2", str2);
} catch (JSONException e) {
e.printStackTrace();
}
internalReport(jsonObject);
}
public void reportException(String action) {
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("action", action);
} catch (JSONException e) {
e.printStackTrace();
}
internalReport(jsonObject);
}
private void internalReport(JSONObject jsonObject) {
if (jsonObject != null) {
try {
jsonObject.put("platform", 2);
jsonObject.put("channelid", this.mSourceChannelId);
jsonObject.put("shellversion", 2);
jsonObject.put("qiqiversion", this.mSourceVersion);
jsonObject.put("fromid", this.mSourceFromId);
jsonObject.put(Constants.Key.VAS_TYPE, this.mVasType);
jsonObject.put("qquin", this.mHostID);
jsonObject.put("sysversion", Build.VERSION.RELEASE);
jsonObject.put("macversion", Build.MODEL);
} catch (JSONException e) {
e.printStackTrace();
}
doDataReport(jsonObject.toString());
}
}
public boolean doDataReport(final String jsonData) {
if (this.reportThread == null) {
synchronized (this) {
if (this.reportThread == null) {
this.reportThread = new HandlerThread("ODSDK_REPORT");
}
this.reportThread.start();
this.reportThreadHandler = new Handler(this.reportThread.getLooper());
}
}
if (this.reportThreadHandler == null) {
return false;
}
this.reportThreadHandler.post(new Runnable() {
@Override
public void run() {
DataReport.this.postReportData(jsonData);
}
});
return true;
}
public boolean postReportData(String jsonData) {
JSONObject response;
Log.i(TAG, "数据上报开始,上报json为:" + jsonData);
DefaultHttpClient defaultHttpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(REPORT_URL);
List<NameValuePair> pair = new ArrayList<>();
try {
pair.add(new BasicNameValuePair("jsonString", jsonData));
UrlEncodedFormEntity urlEncodedFormEntity = new UrlEncodedFormEntity(pair);
urlEncodedFormEntity.setContentEncoding("UTF-8");
urlEncodedFormEntity.setContentType("application/json");
post.setEntity(urlEncodedFormEntity);
post.setHeader("Content-Type", "application/x-www-form-urlencoded");
try {
HttpResponse res = defaultHttpClient.execute(post);
if (res.getStatusLine().getStatusCode() == 200) {
StringBuilder builder = new StringBuilder();
BufferedReader reader = new BufferedReader(new InputStreamReader(res.getEntity().getContent()));
for (String s = reader.readLine(); s != null; s = reader.readLine()) {
builder.append(s);
}
try {
response = new JSONObject(builder.toString());
} catch (JSONException e) {
e = e;
}
try {
int result = response.getInt("errCode");
if (result == 0) {
ODLog.e(TAG, "数据上报成功,上报json为:" + jsonData);
} else {
ODLog.e(TAG, "数据上报失败,上报json为:" + jsonData + "statusCode = 200result =" + result);
}
} catch (IOException e2) {
e = e2;
ODLog.e(TAG, "数据上报发生IOException e = " + e.toString());
e.printStackTrace();
return false;
} catch (JSONException e3) {
e = e3;
ODLog.i(TAG, "数据上报处理回包,json解析异常");
e.printStackTrace();
return false;
} catch (Exception e4) {
e = e4;
ODLog.e(TAG, "数据上报发生Exception e= " + e.toString());
e.printStackTrace();
return false;
}
} else {
Log.e(TAG, "数据上报失败statusCode = " + res.getStatusLine().getStatusCode());
}
return true;
} catch (IOException e5) {
e = e5;
}
} catch (Exception e6) {
e = e6;
}
}
}