i自然 v1.5.2版本的 MD5 值为:4186de3133535afd3ad8a76e7e4d0eff
以下内容为反编译后的 CrashExceptionHandler.java 源代码,内容仅作参考
package com.serenegiant.utils;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.preference.PreferenceManager;
import com.taobao.accs.common.Constants;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.lang.Thread;
import java.lang.ref.WeakReference;
import java.util.Map;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public final class CrashExceptionHandler implements Thread.UncaughtExceptionHandler {
static final String LOG_NAME = "crashrepo.txt";
static final String MAIL_TO = "t_saki@serenegiant.com";
private final Thread.UncaughtExceptionHandler mHandler;
private final WeakReference<Context> mWeakContext;
private final WeakReference<PackageInfo> mWeakPackageInfo;
public static void registerCrashHandler(Context context) {
Thread.setDefaultUncaughtExceptionHandler(new CrashExceptionHandler(context));
}
private CrashExceptionHandler(Context context) {
this.mWeakContext = new WeakReference<>(context);
try {
this.mWeakPackageInfo = new WeakReference<>(context.getPackageManager().getPackageInfo(context.getPackageName(), 0));
this.mHandler = Thread.getDefaultUncaughtExceptionHandler();
} catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException(e);
}
}
@Override
public void uncaughtException(Thread thread, Throwable th) {
Thread.UncaughtExceptionHandler uncaughtExceptionHandler;
PrintWriter printWriter;
PrintWriter printWriter2;
Context context = this.mWeakContext.get();
if (context != null) {
PrintWriter printWriter3 = null;
PrintWriter printWriter4 = null;
PrintWriter printWriter5 = null;
try {
try {
printWriter2 = new PrintWriter(context.openFileOutput(LOG_NAME, 0));
} catch (Throwable th2) {
th = th2;
}
} catch (FileNotFoundException e) {
e = e;
} catch (JSONException e2) {
e = e2;
}
try {
JSONObject jSONObject = new JSONObject();
jSONObject.put("Build", getBuildInfo());
jSONObject.put("PackageInfo", getPackageInfo());
jSONObject.put("Exception", getExceptionInfo(th));
?? r1 = "SharedPreferences";
jSONObject.put("SharedPreferences", getPreferencesInfo());
printWriter2.print(jSONObject.toString());
printWriter2.flush();
printWriter2.close();
printWriter3 = r1;
} catch (FileNotFoundException e3) {
e = e3;
printWriter4 = printWriter2;
e.printStackTrace();
printWriter3 = printWriter4;
printWriter = printWriter4;
} catch (JSONException e4) {
e = e4;
printWriter5 = printWriter2;
e.printStackTrace();
printWriter3 = printWriter5;
if (printWriter5 != null) {
printWriter = printWriter5;
printWriter.close();
printWriter3 = printWriter;
}
uncaughtExceptionHandler = this.mHandler;
if (uncaughtExceptionHandler == null) {
}
} catch (Throwable th3) {
th = th3;
printWriter3 = printWriter2;
if (printWriter3 != null) {
printWriter3.close();
}
throw th;
}
}
try {
uncaughtExceptionHandler = this.mHandler;
if (uncaughtExceptionHandler == null) {
uncaughtExceptionHandler.uncaughtException(thread, th);
}
} catch (Exception unused) {
}
}
private JSONObject getBuildInfo() throws JSONException {
JSONObject jSONObject = new JSONObject();
jSONObject.put("BRAND", Build.BRAND);
jSONObject.put("MODEL", Build.MODEL);
jSONObject.put("DEVICE", Build.DEVICE);
jSONObject.put("MANUFACTURER", Build.MANUFACTURER);
jSONObject.put("VERSION.SDK_INT", Build.VERSION.SDK_INT);
jSONObject.put("VERSION.RELEASE", Build.VERSION.RELEASE);
return jSONObject;
}
private JSONObject getPackageInfo() throws JSONException {
PackageInfo packageInfo = this.mWeakPackageInfo.get();
JSONObject jSONObject = new JSONObject();
if (packageInfo != null) {
jSONObject.put(Constants.KEY_PACKAGE_NAME, packageInfo.packageName);
jSONObject.put("versionCode", packageInfo.versionCode);
jSONObject.put("versionName", packageInfo.versionName);
}
return jSONObject;
}
private JSONObject getExceptionInfo(Throwable th) throws JSONException {
JSONObject jSONObject = new JSONObject();
jSONObject.put("name", th.getClass().getName());
jSONObject.put("cause", th.getCause());
jSONObject.put("message", th.getMessage());
JSONArray jSONArray = new JSONArray();
for (StackTraceElement stackTraceElement : th.getStackTrace()) {
jSONArray.put("at " + LogUtils.getMetaInfo(stackTraceElement));
}
jSONObject.put("stacktrace", jSONArray);
return jSONObject;
}
private JSONObject getPreferencesInfo() throws JSONException {
SharedPreferences defaultSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this.mWeakContext.get());
JSONObject jSONObject = new JSONObject();
for (Map.Entry<String, ?> entry : defaultSharedPreferences.getAll().entrySet()) {
jSONObject.put(entry.getKey(), entry.getValue());
}
return jSONObject;
}
}