Don't crash if ACRA is disabled

This commit is contained in:
serso 2016-01-24 12:43:19 +01:00
parent b5705702eb
commit 23e96122a3
2 changed files with 15 additions and 10 deletions

View File

@ -28,13 +28,21 @@ import javax.annotation.Nonnull;
public class AcraErrorReporter implements ErrorReporter { public class AcraErrorReporter implements ErrorReporter {
public static final boolean ENABLED = !BuildConfig.DEBUG;
@Override @Override
public void onException(@Nonnull Throwable e) { public void onException(@Nonnull Throwable e) {
if (!ENABLED) {
return;
}
ACRA.getErrorReporter().reportBuilder().forceSilent().exception(e).send(); ACRA.getErrorReporter().reportBuilder().forceSilent().exception(e).send();
} }
@Override @Override
public void onError(@Nonnull String message) { public void onError(@Nonnull String message) {
if (!ENABLED) {
return;
}
ACRA.getErrorReporter().reportBuilder().forceSilent().exception(new Throwable(message)).send(); ACRA.getErrorReporter().reportBuilder().forceSilent().exception(new Throwable(message)).send();
} }
} }

View File

@ -26,10 +26,9 @@ import android.content.SharedPreferences;
import android.os.Handler; import android.os.Handler;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.util.Log; import android.util.Log;
import com.squareup.leakcanary.LeakCanary; import com.squareup.leakcanary.LeakCanary;
import com.squareup.otto.Bus; import com.squareup.otto.Bus;
import jscl.MathEngine;
import org.acra.ACRA; import org.acra.ACRA;
import org.acra.ACRAConfiguration; import org.acra.ACRAConfiguration;
import org.acra.sender.HttpSender; 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.android.calculator.plot.CalculatorPlotterImpl;
import org.solovyev.common.msg.MessageType; 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.ArrayList;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.concurrent.Executor; 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 { public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener {
@Inject @Inject
@ -161,14 +157,15 @@ public class CalculatorApplication extends android.app.Application implements Sh
private void onPreCreate(@Nonnull SharedPreferences preferences, @Nonnull Languages languages) { private void onPreCreate(@Nonnull SharedPreferences preferences, @Nonnull Languages languages) {
// first we need to setup crash handler and memory leak analyzer // first we need to setup crash handler and memory leak analyzer
if (!BuildConfig.DEBUG) { if (AcraErrorReporter.ENABLED) {
ACRA.init(this, new ACRAConfiguration() ACRA.init(this, new ACRAConfiguration()
.setFormUri("https://serso.cloudant.com/acra-cpp/_design/acra-storage/_update/report") .setFormUri("https://serso.cloudant.com/acra-cpp/_design/acra-storage/_update/report")
.setReportType(HttpSender.Type.JSON) .setReportType(HttpSender.Type.JSON)
.setHttpMethod(HttpSender.Method.PUT) .setHttpMethod(HttpSender.Method.PUT)
.setFormUriBasicAuthLogin("timbeenterumisideffecird") .setFormUriBasicAuthLogin("timbeenterumisideffecird")
.setFormUriBasicAuthPassword("ECL65PO2TH5quIFNAK4hQ5Ng")); .setFormUriBasicAuthPassword("ECL65PO2TH5quIFNAK4hQ5Ng"));
} else { }
if (BuildConfig.DEBUG) {
LeakCanary.install(this); LeakCanary.install(this);
} }