package com.pgyersdk.crash; import android.content.Context; import android.util.Log; import com.pgyersdk.c.a; import com.pgyersdk.utils.d; import com.pgyersdk.utils.f; import com.pgyersdk.utils.j; import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FilenameFilter; import java.io.IOException; import java.io.InputStreamReader; import java.lang.ref.WeakReference; import java.util.HashMap; import java.util.Map; public class PgyCrashManager { /* renamed from: a reason: collision with root package name */ private static String f2725a = null; private static String b = null; private static boolean c = false; private static WeakReference<Context> d; private static int e; /* renamed from: com.pgyersdk.crash.PgyCrashManager$1 reason: invalid class name */ static class AnonymousClass1 extends Thread { /* renamed from: a reason: collision with root package name */ final /* synthetic */ StringBuilder f2726a; public void run() { PgyCrashManager.b((Context) PgyCrashManager.d.get(), this.f2726a.toString()); } } /* renamed from: com.pgyersdk.crash.PgyCrashManager$2 reason: invalid class name */ static class AnonymousClass2 extends Thread { /* renamed from: a reason: collision with root package name */ final /* synthetic */ Context f2727a; final /* synthetic */ b b; public void run() { PgyCrashManager.b(this.f2727a, this.b); boolean unused = PgyCrashManager.c = false; } } /* access modifiers changed from: private */ public static void b(Context context, String str) { try { if (a(str, (Boolean) true)) { f.a("PgyerSDK", "Transmission succeeded"); return; } } catch (Exception unused) { } catch (Throwable th) { f.a("PgyerSDK", "Transmission failed"); throw th; } f.a("PgyerSDK", "Transmission failed"); } /* access modifiers changed from: private */ /* JADX WARNING: Removed duplicated region for block: B:32:0x00ad */ /* JADX WARNING: Removed duplicated region for block: B:35:0x00d6 */ /* JADX WARNING: Removed duplicated region for block: B:43:0x00ee */ /* JADX WARNING: Removed duplicated region for block: B:46:0x0117 */ public static void b(Context context, b bVar) { Boolean bool; Throwable th; Exception e2; String[] b2 = b(); if (b2 != null && b2.length > 0) { f.a("PgyerSDK", "Found " + b2.length + " stacktrace(s)."); Boolean bool2 = false; for (int i = 0; i < b2.length; i++) { try { String d2 = d(context, b2[i]); if (d2.length() > 0) { bool = Boolean.valueOf(a(d2, (Boolean) false)); try { Log.e("tao", bool + " submitStackTraces reportIssue "); bool2 = bool; } catch (Exception e3) { e2 = e3; try { e2.printStackTrace(); if (!bool.booleanValue()) { f.a("PgyerSDK", "Transmission succeeded"); c(context, b2[i]); Log.e("tao", b2.length + " Delete"); if (bVar != null) { bVar.f(); } } else { f.a("PgyerSDK", "Transmission failed, will retry on next register() call"); if (bVar != null) { bVar.g(); } } bool2 = bool; } catch (Throwable th2) { th = th2; if (!bool.booleanValue()) { f.a("PgyerSDK", "Transmission succeeded"); c(context, b2[i]); Log.e("tao", b2.length + " Delete"); if (bVar != null) { bVar.f(); } } else { f.a("PgyerSDK", "Transmission failed, will retry on next register() call"); if (bVar != null) { bVar.g(); } } throw th; } } } if (bool2.booleanValue()) { f.a("PgyerSDK", "Transmission succeeded"); c(context, b2[i]); Log.e("tao", b2.length + " Delete"); if (bVar != null) { bVar.f(); } } else { f.a("PgyerSDK", "Transmission failed, will retry on next register() call"); if (bVar != null) { bVar.g(); } } } catch (Exception e4) { bool = bool2; e2 = e4; e2.printStackTrace(); if (!bool.booleanValue()) { } bool2 = bool; } catch (Throwable th3) { th = th3; bool = bool2; if (!bool.booleanValue()) { } throw th; } } } } private static boolean a(String str, Boolean bool) { try { if (j.a(str)) { return false; } f.a("PgyerSDK", "Transmitting exception data: \n" + str); HashMap hashMap = new HashMap(); hashMap.put("crashLog", str); hashMap.put("isException", bool.booleanValue() ? "2" : "1"); hashMap.put("versionCode", a.b); hashMap.put("version", a.d); hashMap.put("agKey", f2725a); hashMap.put("deviceId", a.i); hashMap.put("deviceName", a.g); hashMap.put("deviceModel", a.f); hashMap.put("osVersion", a.e); hashMap.put("resolution", a.j); hashMap.put("osType", "2"); hashMap.put("jailBroken", a.a() ? "1" : "2"); String[] a2 = com.pgyersdk.d.a.a(); hashMap.put("freeSpace", a2[1] + " / " + a2[0]); if (com.pgyersdk.d.a.c()) { String[] b2 = com.pgyersdk.d.a.b(); hashMap.put("freeSdc", b2[1] + " / " + b2[0]); } String[] b3 = com.pgyersdk.d.a.b(d.get()); String str2 = ""; if (b3.length == 2) { str2 = b3[1] + " / " + b3[0]; } hashMap.put("freeRam", str2); hashMap.put("protrait", d.get().getResources().getConfiguration().orientation + ""); String str3 = ""; Map<String, String> a3 = com.pgyersdk.d.a.a(d.get()); if (a3.containsKey("network_type")) { str3 = a3.get("network_type"); } hashMap.put("network", str3); hashMap.put("sdkVersion", a.k); hashMap.put("_api_key", "305092bc73c180b55c26012a94809131"); int responseCode = new d("https://www.pgyer.com/apiv1/crash/add").a("POST").a(hashMap, d.get(), null, null).a().getResponseCode(); if (responseCode == 202 || responseCode == 200) { return true; } return false; } catch (Exception e2) { e2.printStackTrace(); return false; } } private static void c(Context context, String str) { if (context != null) { context.deleteFile(str); context.deleteFile(str.replace(".stacktrace", ".user")); context.deleteFile(str.replace(".stacktrace", ".contact")); context.deleteFile(str.replace(".stacktrace", ".description")); } } /* JADX WARNING: Code restructure failed: missing block: B:21:0x003b, code lost: if (r0 != null) goto L_0x003d; */ /* JADX WARNING: Code restructure failed: missing block: B:22:0x003d, code lost: r0.close(); */ /* JADX WARNING: Code restructure failed: missing block: B:29:0x0048, code lost: if (r0 != null) goto L_0x003d; */ /* JADX WARNING: Removed duplicated region for block: B:24:0x0043 A[SYNTHETIC, Splitter:B:24:0x0043] */ private static String d(Context context, String str) { Throwable th; IOException e2; BufferedReader bufferedReader = null; if (context == null) { return null; } StringBuilder sb = new StringBuilder(); try { BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(context.openFileInput(str))); while (true) { try { String readLine = bufferedReader2.readLine(); if (readLine != null) { sb.append(readLine); sb.append(System.getProperty("line.separator")); } else { try { break; } catch (IOException unused) { } } } catch (FileNotFoundException unused2) { bufferedReader = bufferedReader2; } catch (IOException e3) { e2 = e3; bufferedReader = bufferedReader2; try { e2.printStackTrace(); } catch (Throwable th2) { th = th2; if (bufferedReader != null) { try { bufferedReader.close(); } catch (IOException unused3) { } } throw th; } } catch (Throwable th3) { th = th3; bufferedReader = bufferedReader2; if (bufferedReader != null) { } throw th; } } bufferedReader2.close(); } catch (FileNotFoundException unused4) { } catch (IOException e4) { e2 = e4; e2.printStackTrace(); } return sb.toString(); } private static String[] b() { if (a.f2723a != null) { f.a("PgyerSDK", "Looking for exceptions in: " + a.f2723a); File file = new File(a.f2723a + "/"); if (file.mkdir() || file.exists()) { return file.list(new FilenameFilter() { /* class com.pgyersdk.crash.PgyCrashManager.AnonymousClass3 */ public boolean accept(File file, String str) { return str.endsWith(".stacktrace"); } }); } return new String[0]; } f.a("PgyerSDK", "Can't search for exception as file path is null."); return null; } }