思特奇智慧酒店云平台 v0.0.5版本的 MD5 值为:dedb172bb322639d79d7e0e26262fb5c
以下内容为反编译后的 CrashReporterHandler.java 源代码,内容仅作参考
package com.baidu.ocr.sdk.utils;
import android.content.Context;
import com.baidu.location.BDLocation;
import com.baidu.ocr.sdk.OCR;
import com.baidu.ocr.sdk.utils.HttpsClient;
import com.taobao.weex.el.parse.Operators;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.lang.Thread;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import org.json.JSONException;
import org.json.JSONObject;
public class CrashReporterHandler implements Thread.UncaughtExceptionHandler {
public static final String EMPTY_STR = "";
public static final String HTTP_HEADER_CONTENTTYPE = "application/x-www-form-urlencoded;charset=utf-8";
public static final String HTTP_URL = "https://verify.baidubce.com/verify/1.0/sdk/report";
public static final String REPORT_FILENAME = "bd_aip_crashreport_file";
public static final String REPORT_TIME_FORMATTER = "yyyy-MM-dd HH:mm:ss";
public static Thread.UncaughtExceptionHandler defaultHandler;
public static CrashReporterHandler instance;
public Context ctx;
public Set<Class> sourceClassSet = new HashSet();
public CrashReporterHandler(Context context) {
this.ctx = context;
}
private String createReport(String str) {
JSONObject jSONObject = new JSONObject();
try {
jSONObject.put("id", DeviceUtil.getDeviceId(this.ctx));
jSONObject.put("time", getCurrentTime());
jSONObject.put(BDLocation.BDLOCATION_GNSS_PROVIDER_FROM_SYSTEM, DeviceUtil.getDeviceInfo(this.ctx));
jSONObject.put("sdkver", OCR.OCR_SDK_VERSION);
jSONObject.put("appnm", getPackageName());
jSONObject.put("detail", str);
return jSONObject.toString();
} catch (JSONException e) {
return e.toString();
}
}
private String exDetailContent(Throwable th) {
if (th.getCause() != null) {
return genContent(th) + exDetailContent(th.getCause());
}
return genContent(th);
}
private String genContent(Throwable th) {
StackTraceElement[] stackTrace;
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(Operators.AND_NOT + th.getMessage());
stringBuffer.append("|");
for (StackTraceElement stackTraceElement : th.getStackTrace()) {
stringBuffer.append(stackTraceElement.getClassName() + LogUtil.TAG_LEFT_BRICK + stackTraceElement.getMethodName() + ": " + stackTraceElement.getLineNumber() + "] ");
stringBuffer.append("|");
}
return stringBuffer.toString();
}
private String getCurrentTime() {
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
}
private String getPackageName() {
return this.ctx.getPackageName();
}
public static CrashReporterHandler init(Context context) {
if (instance == null) {
instance = new CrashReporterHandler(context);
}
if (defaultHandler == null) {
defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
}
Thread.setDefaultUncaughtExceptionHandler(instance);
instance.sendPreviousReport();
return instance;
}
private boolean isCauseBySource(Throwable th) {
if (isStackCauseBySource(th.getStackTrace())) {
return true;
}
if (th.getCause() == null) {
return false;
}
return isCauseBySource(th.getCause());
}
private boolean isStackCauseBySource(StackTraceElement[] stackTraceElementArr) {
for (StackTraceElement stackTraceElement : stackTraceElementArr) {
try {
} catch (ClassNotFoundException unused) {
}
if (this.sourceClassSet.contains(Class.forName(stackTraceElement.getClassName()))) {
return true;
}
}
return false;
}
private String readFile() {
StringBuffer stringBuffer = new StringBuffer();
try {
FileInputStream openFileInput = this.ctx.openFileInput(REPORT_FILENAME);
while (true) {
int read = openFileInput.read();
if (read != -1) {
stringBuffer.append((char) read);
} else {
openFileInput.close();
return stringBuffer.toString();
}
}
} catch (Exception unused) {
return null;
}
}
public boolean writeFile(String str) {
try {
FileOutputStream openFileOutput = this.ctx.openFileOutput(REPORT_FILENAME, 0);
openFileOutput.write(str.getBytes("utf8"));
openFileOutput.close();
return true;
} catch (Exception unused) {
return false;
}
}
public CrashReporterHandler addSourceClass(Class cls) {
this.sourceClassSet.add(cls);
return instance;
}
public void postBody(String str) {
HttpsClient httpsClient = new HttpsClient();
HttpsClient.RequestBody requestBody = new HttpsClient.RequestBody();
requestBody.setBody(str);
HttpsClient.RequestInfo requestInfo = new HttpsClient.RequestInfo(HTTP_URL, requestBody);
requestInfo.setHeader("Content-Type", HTTP_HEADER_CONTENTTYPE);
requestInfo.build();
httpsClient.newCall(requestInfo).enqueue(new HttpsClient.Callback() {
@Override
public void onFailure(Throwable th) {
}
@Override
public void onResponse(String str2) {
CrashReporterHandler.this.writeFile("");
}
});
}
public void release() {
this.ctx = null;
}
public void resolveException(Throwable th) {
try {
if (isCauseBySource(th)) {
String createReport = createReport(exDetailContent(th));
if (writeFile(createReport)) {
return;
}
postBody(createReport);
}
} catch (Throwable th2) {
String createReport2 = createReport(exDetailContent(th2));
if (writeFile(createReport2)) {
return;
}
postBody(createReport2);
}
}
public void sendPreviousReport() {
String readFile = readFile();
if (readFile == null || readFile == "") {
return;
}
postBody(readFile);
}
@Override
public void uncaughtException(Thread thread, Throwable th) {
try {
resolveException(th);
} catch (Throwable unused) {
}
defaultHandler.uncaughtException(thread, th);
}
}