X-Git-Url: https://git.ktnx.net/?p=mobile-ledger.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fnet%2Fktnx%2Fmobileledger%2Fui%2Factivity%2FCrashReportingActivity.java;h=183a5e9184d84ad0ec847a507e013d17f75ff791;hp=911d2cec400698795669641e705b187083d80ffa;hb=HEAD;hpb=09e26d2279484b4dfe0de218b05f075362fff4b5 diff --git a/app/src/main/java/net/ktnx/mobileledger/ui/activity/CrashReportingActivity.java b/app/src/main/java/net/ktnx/mobileledger/ui/activity/CrashReportingActivity.java index 911d2cec..a134c892 100644 --- a/app/src/main/java/net/ktnx/mobileledger/ui/activity/CrashReportingActivity.java +++ b/app/src/main/java/net/ktnx/mobileledger/ui/activity/CrashReportingActivity.java @@ -1,44 +1,66 @@ +/* + * Copyright © 2020 Damyan Ivanov. + * This file is part of MoLe. + * MoLe is free software: you can distribute it and/or modify it + * under the term of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your opinion), any later version. + * + * MoLe is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License terms for details. + * + * You should have received a copy of the GNU General Public License + * along with MoLe. If not, see . + */ + package net.ktnx.mobileledger.ui.activity; +import android.content.pm.PackageInfo; +import android.os.Build; import android.os.Bundle; +import android.util.Log; + import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; -import android.util.Log; import net.ktnx.mobileledger.ui.CrashReportDialogFragment; -import net.ktnx.mobileledger.utils.Colors; import java.io.PrintWriter; import java.io.StringWriter; +import static net.ktnx.mobileledger.utils.Logger.debug; + public abstract class CrashReportingActivity extends AppCompatActivity { - protected void setupProfileColors() { - Colors.setupTheme(this); - } - @Override - protected void onStart() { - super.onStart(); - Colors.refreshColors(getTheme()); - } @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); - Colors.setupTheme(this); - - Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { - @Override - public void uncaughtException(Thread t, Throwable e) { - StringWriter sw = new StringWriter(); - PrintWriter pw = new PrintWriter(sw); - e.printStackTrace(pw); - Log.e(null, sw.toString()); + Thread.setDefaultUncaughtExceptionHandler((t, e) -> { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); - CrashReportDialogFragment df = new CrashReportDialogFragment(); - df.setCrashReportText(sw.toString()); - df.show(getSupportFragmentManager(), "crash_report"); + try { + PackageInfo pi = getApplicationContext().getPackageManager() + .getPackageInfo(getPackageName(), 0); + pw.format("MoLe version: %s\n", pi.versionName); } + catch (Exception oh) { + pw.print("Error getting package version:\n"); + oh.printStackTrace(pw); + pw.print("\n"); + } + pw.format("OS version: %s; API level %d\n\n", Build.VERSION.RELEASE, + Build.VERSION.SDK_INT); + e.printStackTrace(pw); + + Log.e(null, sw.toString()); + + CrashReportDialogFragment df = new CrashReportDialogFragment(); + df.setCrashReportText(sw.toString()); + df.show(getSupportFragmentManager(), "crash_report"); }); - Log.d("crash", "Uncaught exception handler set"); + debug("crash", "Uncaught exception handler set"); } }