package com.xbcx.core; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Build; import android.util.Log; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.serializer.SerializerFeature; import com.health.doctor.prescriptionv2.channel.B; import com.yht.app.BaseApplication; import com.yht.d.b; import com.yht.d.g; import com.yht.util.s; import com.yht.util.w; import java.io.File; import java.io.FileInputStream; import java.io.PrintWriter; import java.io.StringWriter; import java.lang.Thread; import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; public class n implements Thread.UncaughtExceptionHandler { /* renamed from: a reason: collision with root package name */ private static n f15501a = new n(); /* renamed from: b reason: collision with root package name */ private static a f15502b; /* renamed from: c reason: collision with root package name */ private Thread.UncaughtExceptionHandler f15503c; /* renamed from: d reason: collision with root package name */ private Context f15504d; /* renamed from: e reason: collision with root package name */ private Map<String, String> f15505e = new HashMap(); /* access modifiers changed from: private */ public static class a extends g { a(Context context) { super(context); } private void a(Map map) { b("params", JSON.toJSONString(map, SerializerFeature.WriteNullStringAsEmpty, SerializerFeature.WriteNullListAsEmpty)); } public void a(String str, b bVar) { HashMap hashMap = new HashMap(); hashMap.put("crashLog", str); a((Map) hashMap); a("uploadCrashLog", com.health.im.b.u(), bVar); } @Override // com.yht.d.g public String c() { return "http://test2.91taogu.com/api"; } /* access modifiers changed from: protected */ @Override // com.yht.d.g public String d() { return "func"; } } private n() { } public static n a() { return f15501a; } private static String a(File file) { s.a("TEST_NAME", B.i + file.getAbsolutePath()); try { byte[] bArr = new byte[((int) file.length())]; FileInputStream fileInputStream = new FileInputStream(file); fileInputStream.read(bArr); fileInputStream.close(); return new String(bArr, "UTF-8"); } catch (Exception e2) { e2.printStackTrace(); return null; } } private void b(Throwable th) { StringBuffer stringBuffer = new StringBuffer(); for (Map.Entry<String, String> entry : this.f15505e.entrySet()) { stringBuffer.append(entry.getKey() + "=" + entry.getValue() + "\r\n"); } StringWriter stringWriter = new StringWriter(); PrintWriter printWriter = new PrintWriter(stringWriter); do { th.printStackTrace(printWriter); th = th.getCause(); } while (th != null); printWriter.close(); stringBuffer.append(stringWriter.toString().replaceAll("\n", "\r\n")); w.a(stringBuffer.toString(), this.f15504d); } /* access modifiers changed from: private */ public static void b(List<File> list) { File file; if (!list.isEmpty() && (file = list.get(0)) != null) { ArrayList arrayList = new ArrayList(); for (int i = 1; i < list.size(); i++) { arrayList.add(list.get(i)); } if (file.length() >= 10240) { b(arrayList); return; } String a2 = a(file); s.a("TEST_NAME", "C" + a2); if (a2 != null) { f15502b.a(a2, new m(file, arrayList)); } } } private static void c(Context context) { File[] listFiles; File a2 = w.a(context); s.a("TEST_NAME", "A" + a2.getAbsolutePath()); if (a2.exists() && (listFiles = a2.listFiles()) != null) { List asList = Arrays.asList(listFiles); if (!asList.isEmpty()) { b(asList); } } } public void a(Context context) { try { PackageInfo packageInfo = context.getPackageManager().getPackageInfo(context.getPackageName(), 1); if (packageInfo != null) { this.f15505e.put("versionName", packageInfo.versionName == null ? "null" : packageInfo.versionName); this.f15505e.put("versionCode", packageInfo.versionCode + ""); this.f15505e.put("dt_", String.valueOf(new Date().getTime())); this.f15505e.put("ai_", context.getApplicationContext().getPackageName()); } } catch (PackageManager.NameNotFoundException e2) { e2.printStackTrace(); } Field[] declaredFields = Build.class.getDeclaredFields(); for (Field field : declaredFields) { try { field.setAccessible(true); this.f15505e.put(field.getName(), field.get("").toString()); } catch (IllegalAccessException | IllegalArgumentException e3) { e3.printStackTrace(); } } } public boolean a(Throwable th) { if (th == null) { return false; } Log.d("T_CRASH_LOG", "start !"); if (BaseApplication.getInstance().isDebugBuild()) { Log.d("T_CRASH_LOG", "debug mode !"); return false; } Log.d("T_CRASH_LOG", "do !"); a(this.f15504d); b(th); return true; } public void b(Context context) { this.f15504d = context; f15502b = new a(context); this.f15503c = Thread.getDefaultUncaughtExceptionHandler(); Thread.setDefaultUncaughtExceptionHandler(this); c(context); } public void uncaughtException(Thread thread, Throwable th) { Thread.UncaughtExceptionHandler uncaughtExceptionHandler; if (a(th) || (uncaughtExceptionHandler = this.f15503c) == null) { uncaughtExceptionHandler = this.f15503c; } uncaughtExceptionHandler.uncaughtException(thread, th); } }