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");
}
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);
}
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);
}
Aggregations