diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 6ea3be655..07a3147c4 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -29,6 +29,7 @@ android { buildConfigField("boolean", "showDonate", "true") buildConfigField("boolean", "showRateOnGooglePlay", "false") + buildConfigField("boolean", "useAcraCrashReporter", "true") } buildTypes { @@ -61,6 +62,9 @@ android { // Google doesn't allow donation links buildConfigField("boolean", "showDonate", "false") buildConfigField("boolean", "showRateOnGooglePlay", "true") + + // Google Play already sends crashes to the Google Play Console + buildConfigField("boolean", "useAcraCrashReporter", "false") } } @@ -128,6 +132,11 @@ dependencies { implementation("com.jaredrummler:colorpicker:1.1.0") implementation("net.lingala.zip4j:zip4j:2.11.5") + // Crash reporting + val acraVersion = "5.12.0" + implementation("ch.acra:acra-mail:$acraVersion") + implementation("ch.acra:acra-dialog:$acraVersion") + // Testing val androidXTestVersion = "1.7.0" val junitVersion = "4.13.2" diff --git a/app/src/main/java/protect/card_locker/LoyaltyCardLockerApplication.java b/app/src/main/java/protect/card_locker/LoyaltyCardLockerApplication.java index c031f7904..8865ae2a1 100644 --- a/app/src/main/java/protect/card_locker/LoyaltyCardLockerApplication.java +++ b/app/src/main/java/protect/card_locker/LoyaltyCardLockerApplication.java @@ -4,6 +4,12 @@ import android.app.Application; import androidx.appcompat.app.AppCompatDelegate; +import org.acra.ACRA; +import org.acra.config.CoreConfigurationBuilder; +import org.acra.config.DialogConfigurationBuilder; +import org.acra.config.MailSenderConfigurationBuilder; +import org.acra.data.StringFormat; + import protect.card_locker.preferences.Settings; public class LoyaltyCardLockerApplication extends Application { @@ -12,6 +18,27 @@ public class LoyaltyCardLockerApplication extends Application { public void onCreate() { super.onCreate(); + // Initialize crash reporter (if enabled) + if (BuildConfig.useAcraCrashReporter) { + ACRA.init(this, new CoreConfigurationBuilder() + //core configuration: + .withBuildConfigClass(BuildConfig.class) + .withReportFormat(StringFormat.KEY_VALUE_LIST) + .withPluginConfigurations( + new DialogConfigurationBuilder() + .withText(String.format(getString(R.string.acra_catima_has_crashed), getString(R.string.app_name))) + .withCommentPrompt(getString(R.string.acra_explain_crash)) + .withResTheme(R.style.AppTheme) + .build(), + new MailSenderConfigurationBuilder() + .withMailTo("acra-crash@catima.app") + .withSubject(String.format(getString(R.string.acra_crash_email_subject), getString(R.string.app_name))) + .build() + ) + ); + } + + // Set theme Settings settings = new Settings(this); AppCompatDelegate.setDefaultNightMode(settings.getTheme()); } diff --git a/app/src/main/java/protect/card_locker/preferences/SettingsActivity.java b/app/src/main/java/protect/card_locker/preferences/SettingsActivity.java index 5ff0a1021..2ae6cdc0d 100644 --- a/app/src/main/java/protect/card_locker/preferences/SettingsActivity.java +++ b/app/src/main/java/protect/card_locker/preferences/SettingsActivity.java @@ -24,6 +24,7 @@ import java.util.Locale; import java.util.Objects; import java.util.stream.Collectors; +import protect.card_locker.BuildConfig; import protect.card_locker.CatimaAppCompatActivity; import protect.card_locker.MainActivity; import protect.card_locker.R; @@ -193,6 +194,11 @@ public class SettingsActivity extends CatimaAppCompatActivity { Preference contentProviderReadPreference = findPreference(getResources().getString(R.string.settings_key_allow_content_provider_read)); assert contentProviderReadPreference != null; contentProviderReadPreference.setVisible(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M); + + // Hide crash reporter settings on builds it's not enabled on + Preference crashReporterPreference = findPreference("acra.enable"); + assert crashReporterPreference != null; + crashReporterPreference.setVisible(BuildConfig.useAcraCrashReporter); } private void refreshActivity(boolean reloadMain) { diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b3da549f3..4b97f546a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -353,4 +353,9 @@ Card %d Card %d (%s) Please do not rotate the device, as this will cancel the action + We\'re sorry, but %s has crashed. Please help us fix this issue by sending us an error report. + If possible, please add more details on what you were doing here: + %s crash report + Ask to send crash reports + When enabled, you will be asked to report a crash when it happens. Crash reports are never sent automatically. diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 6d21522f2..552f517f0 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -44,6 +44,15 @@ app:iconSpaceReserved="false" app:singleLineTitle="false" app:useSimpleSummaryProvider="true" /> + + -