diff --git a/src/main/java/org/acra/config/ConfigurationBuilder.java b/src/main/java/org/acra/config/ConfigurationBuilder.java index bd0f1ba6cb..85f1145d86 100644 --- a/src/main/java/org/acra/config/ConfigurationBuilder.java +++ b/src/main/java/org/acra/config/ConfigurationBuilder.java @@ -223,6 +223,10 @@ public ACRAConfiguration build() throws ACRAConfigurationException { break; } + if(reportSenderFactoryClasses().length == 0){ + throw new ACRAConfigurationException("Report sender factories: using no report senders will make ACRA useless. Configure at least one ReportSenderFactory."); + } + return new ACRAConfiguration(this); } diff --git a/src/main/java/org/acra/sender/SenderService.java b/src/main/java/org/acra/sender/SenderService.java index 82424dd4dc..1090ac6dc5 100644 --- a/src/main/java/org/acra/sender/SenderService.java +++ b/src/main/java/org/acra/sender/SenderService.java @@ -3,6 +3,7 @@ import android.app.IntentService; import android.content.Intent; import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import org.acra.ACRA; import org.acra.ACRAConstants; @@ -12,6 +13,7 @@ import java.io.File; import java.util.ArrayList; +import java.util.Collection; import java.util.List; import static org.acra.ACRA.LOG_TAG; @@ -20,26 +22,29 @@ public class SenderService extends IntentService { public static final String EXTRA_ONLY_SEND_SILENT_REPORTS = "onlySendSilentReports"; public static final String EXTRA_APPROVE_REPORTS_FIRST = "approveReportsFirst"; - public static final String EXTRA_REPORT_SENDER_FACTORIES = "reportSenderFactories"; public static final String EXTRA_ACRA_CONFIG = "acraConfig"; private final ReportLocator locator = new ReportLocator(this); public SenderService() { super("ACRA SenderService"); + setIntentRedelivery(true); } @Override - protected void onHandleIntent(@NonNull final Intent intent) { + protected void onHandleIntent(@Nullable final Intent intent) { + if (intent == null || !intent.hasExtra(EXTRA_ACRA_CONFIG)) { + if(ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "SenderService was started but no valid intent was delivered, will now quit"); + return; + } final boolean onlySendSilentReports = intent.getBooleanExtra(EXTRA_ONLY_SEND_SILENT_REPORTS, false); final boolean approveReportsFirst = intent.getBooleanExtra(EXTRA_APPROVE_REPORTS_FIRST, false); - //noinspection unchecked - final List> senderFactoryClasses = (List>) intent.getSerializableExtra(EXTRA_REPORT_SENDER_FACTORIES); - final ACRAConfiguration config = (ACRAConfiguration) intent.getSerializableExtra(EXTRA_ACRA_CONFIG); + final Collection> senderFactoryClasses = config.reportSenderFactoryClasses(); + if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "About to start sending reports from SenderService"); try { final List senderInstances = getSenderInstances(config, senderFactoryClasses); @@ -77,7 +82,7 @@ protected void onHandleIntent(@NonNull final Intent intent) { } @NonNull - private List getSenderInstances(@NonNull ACRAConfiguration config, @NonNull List> factoryClasses) { + private List getSenderInstances(@NonNull ACRAConfiguration config, @NonNull Collection> factoryClasses) { final List reportSenders = new ArrayList(); for (final Class factoryClass : factoryClasses) { try { diff --git a/src/main/java/org/acra/sender/SenderServiceStarter.java b/src/main/java/org/acra/sender/SenderServiceStarter.java index 71ee6dd2f0..4475e24738 100644 --- a/src/main/java/org/acra/sender/SenderServiceStarter.java +++ b/src/main/java/org/acra/sender/SenderServiceStarter.java @@ -7,8 +7,6 @@ import org.acra.ACRA; import org.acra.config.ACRAConfiguration; -import java.util.ArrayList; - import static org.acra.ACRA.LOG_TAG; /** @@ -35,9 +33,6 @@ public void startService(boolean onlySendSilentReports, boolean approveReportsFi final Intent intent = new Intent(context, SenderService.class); intent.putExtra(SenderService.EXTRA_ONLY_SEND_SILENT_REPORTS, onlySendSilentReports); intent.putExtra(SenderService.EXTRA_APPROVE_REPORTS_FIRST, approveReportsFirst); - - intent.putExtra(SenderService.EXTRA_REPORT_SENDER_FACTORIES, new ArrayList>(config.reportSenderFactoryClasses())); - intent.putExtra(SenderService.EXTRA_ACRA_CONFIG, config); context.startService(intent); }