Search in sources :

Example 1 with ReportLocator

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

the class ReportConverter method convert.

void convert() {
    ACRA.log.i(LOG_TAG, "Converting unsent ACRA reports to json");
    final ReportLocator locator = new ReportLocator(context);
    final CrashReportPersister persister = new CrashReportPersister();
    final List<File> reportFiles = new ArrayList<File>();
    reportFiles.addAll(Arrays.asList(locator.getUnapprovedReports()));
    reportFiles.addAll(Arrays.asList(locator.getApprovedReports()));
    int converted = 0;
    for (File report : reportFiles) {
        InputStream in = null;
        try {
            in = new BufferedInputStream(new FileInputStream(report), ACRAConstants.DEFAULT_BUFFER_SIZE_IN_BYTES);
            //$NON-NLS-1$
            CrashReportData data = legacyLoad(new InputStreamReader(in, "ISO8859-1"));
            if (data.containsKey(ReportField.REPORT_ID) && data.containsKey(ReportField.USER_CRASH_DATE)) {
                persister.store(data, report);
                converted++;
            } else {
                //reports without these keys are probably invalid
                IOUtils.deleteReport(report);
            }
        } catch (Throwable e) {
            try {
                //If this succeeds the report has already been converted, happens e.g. on preference clear.
                persister.load(report);
                if (ACRA.DEV_LOGGING)
                    ACRA.log.d(LOG_TAG, "Tried to convert already converted report file " + report.getPath() + ". Ignoring");
            } catch (Throwable t) {
                //File matches neither of the known formats, remove it.
                ACRA.log.w(LOG_TAG, "Unable to read report file " + report.getPath() + ". Deleting", e);
                IOUtils.deleteReport(report);
            }
        } finally {
            IOUtils.safeClose(in);
        }
    }
    ACRA.log.i(LOG_TAG, "Converted " + converted + " unsent reports");
}
Also used : CrashReportData(org.acra.collector.CrashReportData) InputStreamReader(java.io.InputStreamReader) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ReportLocator(org.acra.file.ReportLocator) ArrayList(java.util.ArrayList) CrashReportPersister(org.acra.file.CrashReportPersister) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with ReportLocator

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

the class ApplicationStartupProcessor method sendApprovedReports.

/**
     * If ReportingInteractionMode == Toast and at least one non silent report then show a Toast.
     * All approved reports will be sent.
     */
public void sendApprovedReports() {
    final ReportLocator reportLocator = new ReportLocator(context);
    final File[] reportFiles = reportLocator.getApprovedReports();
    if (reportFiles.length == 0) {
        // There are no approved reports, so bail now.
        return;
    }
    if (config.mode() == ReportingInteractionMode.TOAST && hasNonSilentApprovedReports(reportFiles)) {
        ToastSender.sendToast(context, config.resToastText(), Toast.LENGTH_LONG);
    }
    // Send the approved reports.
    final SenderServiceStarter starter = new SenderServiceStarter(context, config);
    starter.startService(false, false);
}
Also used : SenderServiceStarter(org.acra.sender.SenderServiceStarter) ReportLocator(org.acra.file.ReportLocator) File(java.io.File)

Example 3 with ReportLocator

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

the class ReportExecutor method getReportFileName.

@NonNull
private File getReportFileName(@NonNull CrashReportData crashData) {
    final String timestamp = crashData.getProperty(USER_CRASH_DATE);
    final String isSilent = crashData.getProperty(IS_SILENT);
    final String fileName = // Need to check for null because old version of ACRA did not always capture USER_CRASH_DATE
    (timestamp != null ? timestamp : new Date().getTime()) + (isSilent != null ? ACRAConstants.SILENT_SUFFIX : "") + ACRAConstants.REPORTFILE_EXTENSION;
    final ReportLocator reportLocator = new ReportLocator(context);
    return new File(reportLocator.getUnapprovedFolder(), fileName);
}
Also used : ReportLocator(org.acra.file.ReportLocator) File(java.io.File) Date(java.util.Date) NonNull(android.support.annotation.NonNull)

Aggregations

File (java.io.File)3 ReportLocator (org.acra.file.ReportLocator)3 NonNull (android.support.annotation.NonNull)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 CrashReportData (org.acra.collector.CrashReportData)1 CrashReportPersister (org.acra.file.CrashReportPersister)1 SenderServiceStarter (org.acra.sender.SenderServiceStarter)1