Search in sources :

Example 1 with CrashReportFileNameParser

use of org.acra.file.CrashReportFileNameParser in project acra by ACRA.

the class SenderService method onHandleIntent.

@Override
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);
    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);
        // Mark reports as approved
        if (approveReportsFirst) {
            markReportsAsApproved();
        }
        // Get approved reports
        final File[] reports = locator.getApprovedReports();
        final ReportDistributor reportDistributor = new ReportDistributor(this, config, senderInstances);
        // Iterate over approved reports and send via all Senders.
        // Use to rate limit sending
        int reportsSentCount = 0;
        final CrashReportFileNameParser fileNameParser = new CrashReportFileNameParser();
        for (final File report : reports) {
            if (onlySendSilentReports && !fileNameParser.isSilent(report.getName())) {
                continue;
            }
            if (reportsSentCount >= ACRAConstants.MAX_SEND_REPORTS) {
                // send only a few reports to avoid overloading the network
                break;
            }
            reportDistributor.distribute(report);
            reportsSentCount++;
        }
    } catch (Exception e) {
        ACRA.log.e(LOG_TAG, "", e);
    }
    if (ACRA.DEV_LOGGING)
        ACRA.log.d(LOG_TAG, "Finished sending reports from SenderService");
}
Also used : CrashReportFileNameParser(org.acra.file.CrashReportFileNameParser) ACRAConfiguration(org.acra.config.ACRAConfiguration) File(java.io.File)

Aggregations

File (java.io.File)1 ACRAConfiguration (org.acra.config.ACRAConfiguration)1 CrashReportFileNameParser (org.acra.file.CrashReportFileNameParser)1