From 23e96122a30289772c55d78d23a7d033d78e268e Mon Sep 17 00:00:00 2001 From: serso Date: Sun, 24 Jan 2016 12:43:19 +0100 Subject: [PATCH] Don't crash if ACRA is disabled --- .../android/calculator/AcraErrorReporter.java | 8 ++++++++ .../calculator/CalculatorApplication.java | 17 +++++++---------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/org/solovyev/android/calculator/AcraErrorReporter.java b/app/src/main/java/org/solovyev/android/calculator/AcraErrorReporter.java index 907b51ba..3242fde8 100644 --- a/app/src/main/java/org/solovyev/android/calculator/AcraErrorReporter.java +++ b/app/src/main/java/org/solovyev/android/calculator/AcraErrorReporter.java @@ -28,13 +28,21 @@ import javax.annotation.Nonnull; public class AcraErrorReporter implements ErrorReporter { + public static final boolean ENABLED = !BuildConfig.DEBUG; + @Override public void onException(@Nonnull Throwable e) { + if (!ENABLED) { + return; + } ACRA.getErrorReporter().reportBuilder().forceSilent().exception(e).send(); } @Override public void onError(@Nonnull String message) { + if (!ENABLED) { + return; + } ACRA.getErrorReporter().reportBuilder().forceSilent().exception(new Throwable(message)).send(); } } diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java index 2f6b5b91..a926e4dc 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorApplication.java @@ -26,10 +26,9 @@ import android.content.SharedPreferences; import android.os.Handler; import android.preference.PreferenceManager; import android.util.Log; - import com.squareup.leakcanary.LeakCanary; import com.squareup.otto.Bus; - +import jscl.MathEngine; import org.acra.ACRA; import org.acra.ACRAConfiguration; import org.acra.sender.HttpSender; @@ -42,17 +41,14 @@ import org.solovyev.android.calculator.plot.AndroidCalculatorPlotter; import org.solovyev.android.calculator.plot.CalculatorPlotterImpl; import org.solovyev.common.msg.MessageType; +import javax.annotation.Nonnull; +import javax.inject.Inject; +import javax.inject.Named; import java.util.ArrayList; import java.util.List; import java.util.Locale; import java.util.concurrent.Executor; -import javax.annotation.Nonnull; -import javax.inject.Inject; -import javax.inject.Named; - -import jscl.MathEngine; - public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener { @Inject @@ -161,14 +157,15 @@ public class CalculatorApplication extends android.app.Application implements Sh private void onPreCreate(@Nonnull SharedPreferences preferences, @Nonnull Languages languages) { // first we need to setup crash handler and memory leak analyzer - if (!BuildConfig.DEBUG) { + if (AcraErrorReporter.ENABLED) { ACRA.init(this, new ACRAConfiguration() .setFormUri("https://serso.cloudant.com/acra-cpp/_design/acra-storage/_update/report") .setReportType(HttpSender.Type.JSON) .setHttpMethod(HttpSender.Method.PUT) .setFormUriBasicAuthLogin("timbeenterumisideffecird") .setFormUriBasicAuthPassword("ECL65PO2TH5quIFNAK4hQ5Ng")); - } else { + } + if (BuildConfig.DEBUG) { LeakCanary.install(this); }