Set up ACRA with email crash alerts for foss build

This commit is contained in:
Sylvia van Os
2024-10-10 17:41:46 +02:00
parent a6bf282db5
commit dc9f4fafde
5 changed files with 56 additions and 1 deletions

View File

@@ -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());
}

View File

@@ -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) {