use of org.acra.ReportingInteractionMode in project acra by ACRA.
the class ReportExecutor method execute.
/**
* Try to send a report, if an error occurs stores a report file for a later attempt.
*
* @param reportBuilder The report builder used to assemble the report
*/
public void execute(@NonNull final ReportBuilder reportBuilder) {
if (!enabled) {
ACRA.log.v(LOG_TAG, "ACRA is disabled. Report not sent.");
return;
}
// Prime this crash report with any extra data.
reportPrimer.primeReport(context, reportBuilder);
boolean sendOnlySilentReports = false;
final ReportingInteractionMode reportingInteractionMode;
if (!reportBuilder.isSendSilently()) {
// No interaction mode defined in the ReportBuilder, we assume it has been set during ACRA.initACRA()
reportingInteractionMode = config.mode();
} else {
reportingInteractionMode = ReportingInteractionMode.SILENT;
// explicitly declared as silent via handleSilentException().
if (config.mode() != ReportingInteractionMode.SILENT) {
sendOnlySilentReports = true;
}
}
final boolean shouldDisplayToast = reportingInteractionMode == ReportingInteractionMode.TOAST || (config.resToastText() != 0 && (reportingInteractionMode == ReportingInteractionMode.NOTIFICATION || reportingInteractionMode == ReportingInteractionMode.DIALOG));
final TimeHelper sentToastTimeMillis = new TimeHelper();
if (shouldDisplayToast) {
new Thread() {
/*
* (non-Javadoc)
*
* @see java.lang.Thread#run()
*/
@Override
public void run() {
Looper.prepare();
ToastSender.sendToast(context, config.resToastText(), Toast.LENGTH_LONG);
sentToastTimeMillis.setInitialTimeMillis(System.currentTimeMillis());
Looper.loop();
}
}.start();
// We will wait a few seconds at the end of the method to be sure
// that the Toast can be read by the user.
}
final CrashReportData crashReportData = crashReportDataFactory.createCrashData(reportBuilder);
// Always write the report file
final File reportFile = getReportFileName(crashReportData);
saveCrashReportFile(reportFile, crashReportData);
final SharedPreferences prefs = new SharedPreferencesFactory(context, config).create();
if (reportingInteractionMode == ReportingInteractionMode.SILENT || reportingInteractionMode == ReportingInteractionMode.TOAST || prefs.getBoolean(ACRA.PREF_ALWAYS_ACCEPT, false)) {
// Approve and then send reports now
startSendingReports(sendOnlySilentReports);
if ((reportingInteractionMode == ReportingInteractionMode.SILENT) && !reportBuilder.isEndApplication()) {
// So no need to wait around for the sender to complete.
return;
}
} else if (reportingInteractionMode == ReportingInteractionMode.NOTIFICATION) {
if (ACRA.DEV_LOGGING)
ACRA.log.d(LOG_TAG, "Creating Notification.");
createNotification(reportFile, reportBuilder);
}
final boolean showDirectDialog = (reportingInteractionMode == ReportingInteractionMode.DIALOG) && !prefs.getBoolean(ACRA.PREF_ALWAYS_ACCEPT, false);
if (shouldDisplayToast) {
// A toast is being displayed, we have to wait for its end before doing anything else.
new Thread() {
@Override
public void run() {
if (ACRA.DEV_LOGGING)
ACRA.log.d(LOG_TAG, "Waiting for " + ACRAConstants.TOAST_WAIT_DURATION + " millis from " + sentToastTimeMillis.initialTimeMillis + " currentMillis=" + System.currentTimeMillis());
final long sleep = ACRAConstants.TOAST_WAIT_DURATION - sentToastTimeMillis.getElapsedTime();
try {
// Wait a bit to let the user read the toast
if (sleep > 0L)
Thread.sleep(sleep);
} catch (InterruptedException e1) {
if (ACRA.DEV_LOGGING)
ACRA.log.d(LOG_TAG, "Interrupted while waiting for Toast to end.", e1);
}
if (ACRA.DEV_LOGGING)
ACRA.log.d(LOG_TAG, "Finished waiting for Toast");
dialogAndEnd(reportBuilder, reportFile, showDirectDialog);
}
}.start();
} else {
dialogAndEnd(reportBuilder, reportFile, showDirectDialog);
}
}
Aggregations