导航菜单

页面标题

页面副标题

Brevistay v5.8.2 - SimplAirbrakeNotifier.java 源代码

正在查看: Brevistay v5.8.2 应用的 SimplAirbrakeNotifier.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.simpl.android.fingerprint.commons.exception;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.os.AsyncTask;
import android.os.Build;
import android.util.Log;
import android.util.Xml;
import com.google.common.net.HttpHeaders;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.google.firebase.perf.network.FirebasePerfUrlConnection;
import com.trackier.sdk.Constants;
import in.juspay.hyper.constants.LogCategory;
import in.juspay.hypersdk.core.PaymentConstants;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.Thread;
import java.lang.ref.WeakReference;
import java.net.URL;
import java.net.URLConnection;
import java.util.Map;
import java.util.Random;
import javax.net.ssl.HttpsURLConnection;
import org.xmlpull.v1.XmlSerializer;

final class SimplAirbrakeNotifier {
    private static String a = "production";
    private static String b = "unknown";
    private static String c = "unknown";
    private static Map<String, String> d = null;
    private static String e = null;
    private static boolean f = false;
    private static String g = null;
    private static boolean h = false;

    public static class SimplAsyncTask extends AsyncTask<Void, Void, Void> {
        private WeakReference<Context> contextRef;

        public SimplAsyncTask(Context context) {
            this.contextRef = new WeakReference<>(context);
        }

        @Override
        public Void doInBackground(Void... voidArr) {
            try {
                Context context = this.contextRef.get();
                if (context != null) {
                    String unused = SimplAirbrakeNotifier.g = context.getFilesDir().getAbsolutePath() + "/unsent_airbrake_exceptions/";
                    File file = new File(SimplAirbrakeNotifier.g);
                    file.mkdirs();
                    boolean unused2 = SimplAirbrakeNotifier.h = file.exists();
                }
                SimplAirbrakeNotifier.b((String) null, (Map<String, String>) null);
            } catch (Exception unused3) {
            }
            return null;
        }
    }

    static class a implements Thread.UncaughtExceptionHandler {
        private Thread.UncaughtExceptionHandler a;

        a(Thread.UncaughtExceptionHandler uncaughtExceptionHandler) {
            this.a = uncaughtExceptionHandler;
        }

        @Override
        public final void uncaughtException(Thread thread, Throwable th) {
            if (SimplAirbrakeNotifier.b(th)) {
                SimplAirbrakeNotifier.a(th);
            }
            this.a.uncaughtException(thread, th);
        }
    }

    static void a(Context context, String str, String str2) {
        e = str;
        if (context == null) {
            throw new IllegalArgumentException("context cannot be null.");
        }
        a = str2;
        f = true;
        Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
        if (!(defaultUncaughtExceptionHandler instanceof a) && str2.equals(Constants.ENV_PRODUCTION)) {
            Thread.setDefaultUncaughtExceptionHandler(new a(defaultUncaughtExceptionHandler));
        }
        try {
            b = context.getPackageName();
            PackageInfo packageInfo = context.getPackageManager().getPackageInfo(b, 0);
            if (packageInfo.versionName != null) {
                c = packageInfo.versionName;
            }
            new SimplAsyncTask(context).execute(new Void[0]);
        } catch (Exception unused) {
        }
    }

    private static void a(File file) {
        try {
            HttpsURLConnection httpsURLConnection = (HttpsURLConnection) ((URLConnection) FirebasePerfUrlConnection.instrument(new URL("https://airbrakeapp.com/notifier_api/v2/notices").openConnection()));
            try {
                try {
                    httpsURLConnection.setDoOutput(true);
                    httpsURLConnection.setRequestProperty(HttpHeaders.CONTENT_TYPE, "text/xml; charset=utf-8");
                    FileInputStream fileInputStream = new FileInputStream(file);
                    OutputStream outputStream = httpsURLConnection.getOutputStream();
                    byte[] bArr = new byte[4096];
                    while (true) {
                        int read = fileInputStream.read(bArr);
                        if (read < 0) {
                            outputStream.flush();
                            outputStream.close();
                            fileInputStream.close();
                            Log.d("AirbrakeNotifier", "Sent exception file " + file.getName() + " to airbrake. Got response code " + String.valueOf(httpsURLConnection.getResponseCode()));
                            file.delete();
                            return;
                        }
                        outputStream.write(bArr, 0, read);
                    }
                } catch (IOException e2) {
                    Log.v("AirbrakeNotifier", "Exception caught:", e2);
                }
            } finally {
                httpsURLConnection.disconnect();
            }
        } catch (Exception e3) {
            Log.v("AirbrakeNotifier", "Exception caught:", e3);
        }
    }

    static void a(String str) {
        a = str;
    }

    public static void a(Throwable th) {
        a(th, (Map<String, String>) null);
    }

    public static void a(final Throwable th, final Map<String, String> map) {
        if (th == null || !h) {
            return;
        }
        new AsyncTask<Void, Void, Void>() {
            @Override
            protected final Void doInBackground(Void[] voidArr) {
                SimplAirbrakeNotifier.c(th, map);
                SimplAirbrakeNotifier.b(th.getMessage(), (Map<String, String>) map);
                return null;
            }
        }.execute(new Void[0]);
    }

    static void a(Map<String, String> map) {
        d = map;
    }

    public static synchronized void b(String str, Map<String, String> map) {
        synchronized (SimplAirbrakeNotifier.class) {
            try {
                File file = new File(g);
                if (file.exists() && file.isDirectory()) {
                    for (File file2 : file.listFiles()) {
                        if (file2.exists() && file2.isFile()) {
                            a(file2);
                        }
                    }
                }
            } catch (Throwable th) {
                if (map != null) {
                    map.put("message_caused_error", str);
                }
                c(th, map);
            }
        }
    }

    static boolean b(Throwable th) {
        if (th != null) {
            if (th.getMessage() != null && th.getMessage().contains("simpl")) {
                return true;
            }
            for (StackTraceElement stackTraceElement : th.getStackTrace()) {
                if (stackTraceElement != null && stackTraceElement.toString().contains("simpl")) {
                    return true;
                }
            }
        }
        return false;
    }

    public static void c(Throwable th, Map<String, String> map) {
        Throwable th2;
        int i;
        StringBuilder sb;
        try {
            BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(g + c + "-" + String.valueOf(new Random().nextInt(99999)) + ".xml"));
            XmlSerializer newSerializer = Xml.newSerializer();
            newSerializer.setOutput(bufferedWriter);
            newSerializer.startDocument("UTF-8", Boolean.TRUE);
            newSerializer.startTag("", "notice");
            newSerializer.attribute("", "version", "2.0");
            newSerializer.startTag("", "api-key");
            newSerializer.text(e);
            newSerializer.endTag("", "api-key");
            newSerializer.startTag("", "notifier");
            newSerializer.startTag("", "name");
            newSerializer.text("Android Airbrake Notifier");
            newSerializer.endTag("", "name");
            newSerializer.startTag("", "version");
            newSerializer.text("1.3.0");
            newSerializer.endTag("", "version");
            newSerializer.startTag("", PaymentConstants.URL);
            newSerializer.text("http://loopj.com");
            newSerializer.endTag("", PaymentConstants.URL);
            newSerializer.endTag("", "notifier");
            newSerializer.startTag("", "error");
            newSerializer.startTag("", "class");
            newSerializer.text(th.getClass().getName());
            newSerializer.endTag("", "class");
            newSerializer.startTag("", "message");
            newSerializer.text("[" + c + "] " + th.toString());
            newSerializer.endTag("", "message");
            newSerializer.startTag("", "backtrace");
            Throwable th3 = th;
            while (th3 != null) {
                try {
                    StackTraceElement[] stackTrace = th3.getStackTrace();
                    int length = stackTrace.length;
                    int i2 = 0;
                    while (i2 < length) {
                        StackTraceElement stackTraceElement = stackTrace[i2];
                        newSerializer.startTag("", "line");
                        Throwable th4 = th3;
                        StackTraceElement[] stackTraceElementArr = stackTrace;
                        try {
                            sb = new StringBuilder();
                            i = length;
                        } catch (Throwable th5) {
                            th = th5;
                            i = length;
                        }
                        try {
                            sb.append(stackTraceElement.getClassName());
                            sb.append(".");
                            sb.append(stackTraceElement.getMethodName());
                            newSerializer.attribute("", FirebaseAnalytics.Param.METHOD, sb.toString());
                            newSerializer.attribute("", "file", stackTraceElement.getFileName() == null ? "Unknown" : stackTraceElement.getFileName());
                            newSerializer.attribute("", "number", String.valueOf(stackTraceElement.getLineNumber()));
                        } catch (Throwable th6) {
                            th = th6;
                            Log.v("AirbrakeNotifier", "Exception caught:", th);
                            newSerializer.endTag("", "line");
                            i2++;
                            th3 = th4;
                            stackTrace = stackTraceElementArr;
                            length = i;
                        }
                        newSerializer.endTag("", "line");
                        i2++;
                        th3 = th4;
                        stackTrace = stackTraceElementArr;
                        length = i;
                    }
                    th3 = th3.getCause();
                    if (th3 != null) {
                        newSerializer.startTag("", "line");
                        try {
                            newSerializer.attribute("", "file", "### CAUSED BY ###: " + th3.toString());
                            newSerializer.attribute("", "number", "");
                        } catch (Throwable th7) {
                            Log.v("AirbrakeNotifier", "Exception caught:", th7);
                        }
                        newSerializer.endTag("", "line");
                    }
                } catch (Throwable unused) {
                    th2 = th;
                    Log.v("AirbrakeNotifier", "Exception caught:", th2);
                }
            }
            th2 = th;
            newSerializer.endTag("", "backtrace");
            newSerializer.endTag("", "error");
            newSerializer.startTag("", "request");
            newSerializer.startTag("", PaymentConstants.URL);
            newSerializer.endTag("", PaymentConstants.URL);
            newSerializer.startTag("", "component");
            newSerializer.endTag("", "component");
            newSerializer.startTag("", LogCategory.ACTION);
            newSerializer.endTag("", LogCategory.ACTION);
            newSerializer.startTag("", "cgi-data");
            newSerializer.startTag("", "var");
            newSerializer.attribute("", "key", "Device");
            newSerializer.text(Build.MODEL);
            newSerializer.endTag("", "var");
            newSerializer.startTag("", "var");
            newSerializer.attribute("", "key", "Android Version");
            newSerializer.text(Build.VERSION.RELEASE);
            newSerializer.endTag("", "var");
            newSerializer.startTag("", "var");
            newSerializer.attribute("", "key", "App Version");
            newSerializer.text(c);
            newSerializer.endTag("", "var");
            newSerializer.startTag("", "var");
            newSerializer.attribute("", "key", "Parent App");
            newSerializer.text(b);
            newSerializer.endTag("", "var");
            Map<String, String> map2 = d;
            if (map2 != null && !map2.isEmpty()) {
                for (Map.Entry<String, String> entry : d.entrySet()) {
                    newSerializer.startTag("", "var");
                    newSerializer.attribute("", "key", entry.getKey());
                    newSerializer.text(entry.getValue());
                    newSerializer.endTag("", "var");
                }
            }
            if (map != null && !map.isEmpty()) {
                for (Map.Entry<String, String> entry2 : map.entrySet()) {
                    newSerializer.startTag("", "var");
                    newSerializer.attribute("", "key", entry2.getKey());
                    newSerializer.text(entry2.getValue());
                    newSerializer.endTag("", "var");
                }
            }
            newSerializer.endTag("", "cgi-data");
            newSerializer.endTag("", "request");
            newSerializer.startTag("", "server-environment");
            newSerializer.startTag("", "environment-name");
            newSerializer.text(a);
            newSerializer.endTag("", "environment-name");
            newSerializer.startTag("", "app-version");
            newSerializer.text(c);
            newSerializer.endTag("", "app-version");
            newSerializer.endTag("", "server-environment");
            newSerializer.endTag("", "notice");
            newSerializer.endDocument();
            bufferedWriter.flush();
            bufferedWriter.close();
            Log.d("AirbrakeNotifier", "Writing new " + th2.getClass().getName() + " exception to disk.");
        } catch (Exception e2) {
            Log.v("AirbrakeNotifier", "Exception caught:", e2);
        }
    }
}