Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle null Intent on SenderService restart #501

Merged
merged 3 commits into from
Sep 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/main/java/org/acra/config/ConfigurationBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
17 changes: 11 additions & 6 deletions src/main/java/org/acra/sender/SenderService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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<Class<? extends ReportSenderFactory>> senderFactoryClasses = (List<Class<? extends ReportSenderFactory>>) intent.getSerializableExtra(EXTRA_REPORT_SENDER_FACTORIES);

final ACRAConfiguration config = (ACRAConfiguration) intent.getSerializableExtra(EXTRA_ACRA_CONFIG);

final Collection<Class<? extends ReportSenderFactory>> senderFactoryClasses = config.reportSenderFactoryClasses();

if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "About to start sending reports from SenderService");
try {
final List<ReportSender> senderInstances = getSenderInstances(config, senderFactoryClasses);
Expand Down Expand Up @@ -77,7 +82,7 @@ protected void onHandleIntent(@NonNull final Intent intent) {
}

@NonNull
private List<ReportSender> getSenderInstances(@NonNull ACRAConfiguration config, @NonNull List<Class<? extends ReportSenderFactory>> factoryClasses) {
private List<ReportSender> getSenderInstances(@NonNull ACRAConfiguration config, @NonNull Collection<Class<? extends ReportSenderFactory>> factoryClasses) {
final List<ReportSender> reportSenders = new ArrayList<ReportSender>();
for (final Class<? extends ReportSenderFactory> factoryClass : factoryClasses) {
try {
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/org/acra/sender/SenderServiceStarter.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.acra.ACRA;
import org.acra.config.ACRAConfiguration;

import java.util.ArrayList;

import static org.acra.ACRA.LOG_TAG;

/**
Expand All @@ -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<Class<? extends ReportSenderFactory>>(config.reportSenderFactoryClasses()));

intent.putExtra(SenderService.EXTRA_ACRA_CONFIG, config);
context.startService(intent);
}
Expand Down