diff --git a/app/src/main/java/com/etesync/syncadapter/AcraConfiguration.java b/app/src/main/java/com/etesync/syncadapter/AcraConfiguration.java new file mode 100644 index 00000000..030811a6 --- /dev/null +++ b/app/src/main/java/com/etesync/syncadapter/AcraConfiguration.java @@ -0,0 +1,46 @@ +package com.etesync.syncadapter; + +import android.app.Application; +import android.content.Context; +import android.content.pm.PackageManager; +import android.widget.Toast; + +import org.acra.annotation.AcraCore; +import org.acra.config.CoreConfigurationBuilder; +import org.acra.config.MailSenderConfigurationBuilder; +import org.acra.config.ToastConfigurationBuilder; +import org.acra.data.StringFormat; + +public class AcraConfiguration { + private static Boolean shouldReportAsFile(Context context) { + Boolean shouldReport = false; + + try { + context.getPackageManager().getPackageInfo("ch.protonmail.android", 0); + } catch (PackageManager.NameNotFoundException e) { + shouldReport = true; + } + + System.out.println("ACRA with attached files: " + shouldReport.toString()); + return shouldReport; + } + + public static CoreConfigurationBuilder getConfig(Context context) { + CoreConfigurationBuilder builder = new CoreConfigurationBuilder(context) + .setBuildConfigClass(BuildConfig.class) + .setLogcatArguments("-t", "500", "-v", "time") + .setReportFormat(StringFormat.JSON); + builder.getPluginConfigurationBuilder(MailSenderConfigurationBuilder.class) + .setMailTo("reports@etesync.com") + .setResSubject(R.string.crash_email_subject) + .setReportFileName("ACRA-report.stacktrace.json") + .setReportAsFile(shouldReportAsFile(context)) + .setEnabled(true); + builder.getPluginConfigurationBuilder(ToastConfigurationBuilder.class) + .setResText(R.string.crash_message) + .setLength(Toast.LENGTH_SHORT) + .setEnabled(true); + + return builder; + } +} diff --git a/app/src/main/java/com/etesync/syncadapter/App.kt b/app/src/main/java/com/etesync/syncadapter/App.kt index 2054bdba..72cdd05d 100644 --- a/app/src/main/java/com/etesync/syncadapter/App.kt +++ b/app/src/main/java/com/etesync/syncadapter/App.kt @@ -18,6 +18,7 @@ import android.content.ContentValues import android.content.Context import android.content.Intent import android.content.SharedPreferences +import android.content.pm.PackageManager import android.database.Cursor import android.database.DatabaseUtils import android.database.sqlite.SQLiteDatabase @@ -76,10 +77,9 @@ import io.requery.meta.EntityModel import io.requery.sql.Configuration import io.requery.sql.EntityDataStore import okhttp3.internal.tls.OkHostnameVerifier +import org.acra.config.CoreConfigurationBuilder + -@AcraCore(buildConfigClass = BuildConfig::class, logcatArguments = arrayOf("-t", "500", "-v", "time")) -@AcraMailSender(mailTo = "reports@etesync.com", resSubject = R.string.crash_email_subject, reportAsFile = false, reportFileName = "ACRA-report.stacktrace.json") -@AcraToast(resText = R.string.crash_message, length = Toast.LENGTH_LONG) class App : Application() { var certManager: CustomCertManager? = null @@ -123,7 +123,7 @@ class App : Application() { if (!BuildConfig.DEBUG) { // The following line triggers the initialization of ACRA - ACRA.init(this) + ACRA.init(this, AcraConfiguration.getConfig(this)) val pm = base.packageManager var installedFrom = pm.getInstallerPackageName(BuildConfig.APPLICATION_ID) ACRA.getErrorReporter().putCustomData("installedFrom", installedFrom);