package com.ironsource;

import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkCapabilities;
import android.text.TextUtils;
import android.util.Log;
import com.facebook.react.views.textinput.ReactEditTextInputConnectionWrapper;
import com.ironsource.environment.ContextProvider;
import com.ironsource.mediationsdk.logger.IronLog;
import com.ironsource.y8;
import java.lang.Thread;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.json.JSONObject;
/* loaded from: classes4.dex */
public class l9 {
    private static final String k = "1.0.6";
    public static String l = "";

    /* renamed from: a  reason: collision with root package name */
    private final oe f2542a;
    private String b;
    private String c;
    private String d;
    private String e;
    private ContextProvider f;
    public Thread.UncaughtExceptionHandler g;
    public String h;
    private String i;
    private boolean j;

    /* loaded from: classes4.dex */
    class a implements com.ironsource.b {
        a() {
        }

        @Override // com.ironsource.b
        public void a() {
            Map<Thread, StackTraceElement[]> allStackTraces = Thread.getAllStackTraces();
            StringBuilder sb = new StringBuilder(128);
            for (Thread thread : allStackTraces.keySet()) {
                StackTraceElement[] stackTrace = thread.getStackTrace();
                if (stackTrace != null && stackTrace.length > 0) {
                    sb.append("*** Thread Name ").append(thread.getName()).append(" Thread ID ").append(thread.getId()).append(" (").append(thread.getState().toString()).append(") ***\n");
                    for (StackTraceElement stackTraceElement : stackTrace) {
                        sb.append(stackTraceElement.toString()).append(" ").append(thread.getState().toString()).append(ReactEditTextInputConnectionWrapper.NEWLINE_RAW_VALUE);
                    }
                }
            }
            l9.l = sb.toString();
        }

        @Override // com.ironsource.b
        public void b() {
        }
    }

    /* loaded from: classes4.dex */
    class b implements Runnable {

        /* renamed from: a  reason: collision with root package name */
        final /* synthetic */ Context f2544a;
        final /* synthetic */ String b;

        b(Context context, String str) {
            this.f2544a = context;
            this.b = str;
        }

        @Override // java.lang.Runnable
        public void run() {
            try {
                String p = l9.this.f2542a.p(this.f2544a);
                if (!TextUtils.isEmpty(p)) {
                    l9.this.c = p;
                }
                String a2 = l9.this.f2542a.a(this.f2544a);
                if (!TextUtils.isEmpty(a2)) {
                    l9.this.e = a2;
                }
                SharedPreferences.Editor edit = this.f2544a.getSharedPreferences("CRep", 0).edit();
                edit.putString("String1", l9.this.c);
                edit.putString("sId", this.b);
                edit.apply();
            } catch (Exception e) {
                IronLog.INTERNAL.error(e.toString());
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes4.dex */
    public class c extends m9 {
        c(JSONObject jSONObject) {
            super(jSONObject);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes4.dex */
    public static class d {

        /* renamed from: a  reason: collision with root package name */
        static volatile l9 f2545a = new l9(null);

        private d() {
        }
    }

    private l9() {
        this.j = false;
        this.f2542a = jl.P().f();
        this.f = ContextProvider.getInstance();
        Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
        this.g = defaultUncaughtExceptionHandler;
        this.i = " ";
        this.h = "https://o-crash.mediation.unity3d.com/reporter";
        Thread.setDefaultUncaughtExceptionHandler(new j9(defaultUncaughtExceptionHandler));
    }

    /* synthetic */ l9(a aVar) {
        this();
    }

    private String a(Context context) {
        ConnectivityManager connectivityManager;
        if (context == null || (connectivityManager = (ConnectivityManager) context.getSystemService("connectivity")) == null) {
            return "none";
        }
        try {
            NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(connectivityManager.getActiveNetwork());
            return networkCapabilities == null ? "none" : networkCapabilities.hasTransport(1) ? u8.b : networkCapabilities.hasTransport(0) ? u8.g : "none";
        } catch (Exception e) {
            IronLog.INTERNAL.error(e.toString());
            return "none";
        }
    }

    private void a(Context context, HashSet<String> hashSet) {
        String a2 = a(a());
        if (a2.equals("none")) {
            return;
        }
        SharedPreferences sharedPreferences = context.getSharedPreferences("CRep", 0);
        String string = sharedPreferences.getString("String1", this.c);
        String string2 = sharedPreferences.getString("sId", this.d);
        List<ac> b2 = v9.b();
        IronLog.INTERNAL.verbose("reportList size " + b2.size());
        for (ac acVar : b2) {
            JSONObject jSONObject = new JSONObject();
            String b3 = acVar.b();
            String e = acVar.e();
            String d2 = acVar.d();
            String packageName = context.getPackageName();
            JSONObject jSONObject2 = new JSONObject();
            try {
                jSONObject2.put("crashDate", b3);
                jSONObject2.put("stacktraceCrash", e);
                jSONObject2.put("crashType", d2);
                jSONObject2.put("CrashReporterVersion", k);
                jSONObject2.put(y8.i.q, "8.5.0");
                jSONObject2.put(y8.i.x, this.f2542a.b(context));
                jSONObject2.put("appVersion", z3.b(context, packageName));
                jSONObject2.put(y8.i.n, this.f2542a.o());
                jSONObject2.put("network", a2);
                jSONObject2.put(y8.i.p, this.f2542a.k());
                jSONObject2.put(y8.i.l, this.f2542a.e());
                jSONObject2.put("deviceOS", this.f2542a.l());
                jSONObject2.put("advertisingId", string);
                jSONObject2.put(y8.i.k, this.f2542a.g());
                jSONObject2.put("systemProperties", System.getProperties());
                jSONObject2.put("bundleId", packageName);
                jSONObject2.put("sId", string2);
                if (!TextUtils.isEmpty(this.e)) {
                    jSONObject2.put(y8.i.M, Boolean.parseBoolean(this.e));
                }
                if (hashSet == null || hashSet.isEmpty()) {
                    jSONObject = jSONObject2;
                } else {
                    Iterator<String> it = hashSet.iterator();
                    while (it.hasNext()) {
                        String next = it.next();
                        try {
                            if (jSONObject2.has(next)) {
                                jSONObject.put(next, jSONObject2.opt(next));
                            }
                        } catch (Exception e2) {
                            IronLog.INTERNAL.error(e2.toString());
                        }
                    }
                }
            } catch (Exception unused) {
            }
            if (jSONObject.length() == 0) {
                Log.d("ISCrashReport", " Is Empty");
            } else {
                new Thread(new c(jSONObject)).start();
            }
        }
        v9.a();
    }

    static List<ac> c() {
        return null;
    }

    public static l9 d() {
        return d.f2545a;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public Context a() {
        return this.f.getApplicationContext();
    }

    public void a(Throwable th) {
        IronLog.INTERNAL.verbose("isInitialized=" + this.j);
        if (!this.j || th == null) {
            return;
        }
        new ac(new k9(th).b(), "" + System.currentTimeMillis(), "Caught_IS_Crash").a();
    }

    public void a(HashSet<String> hashSet, String str, String str2, boolean z, String str3, int i, boolean z2) {
        Context applicationContext = this.f.getApplicationContext();
        if (applicationContext != null) {
            Log.d("automation_log", "init ISCrashReporter");
            if (!TextUtils.isEmpty(str2)) {
                this.i = str2;
            }
            if (!TextUtils.isEmpty(str)) {
                this.h = str;
            }
            this.d = str3;
            if (z) {
                new com.ironsource.a(i).a(z2).b(true).a(new a()).start();
            }
            a(applicationContext, hashSet);
            new Thread(new b(applicationContext, str3)).start();
        }
        this.j = true;
        IronLog.INTERNAL.verbose("initialized");
    }

    public String b() {
        return k;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public String e() {
        return this.i;
    }
}
