use of org.acra.file.CrashReportPersister in project acra by ACRA.
the class BaseCrashReportDialog method sendCrash.
/**
* Send crash report given user's comment and email address. If none should be empty strings
*
* @param comment Comment (may be null) provided by the user.
* @param userEmail Email address (may be null) provided by the client.
*/
protected final void sendCrash(@Nullable String comment, @Nullable String userEmail) {
final CrashReportPersister persister = new CrashReportPersister();
try {
if (ACRA.DEV_LOGGING)
ACRA.log.d(LOG_TAG, "Add user comment to " + reportFile);
final CrashReportData crashData = persister.load(reportFile);
crashData.putString(USER_COMMENT, comment == null ? "" : comment);
crashData.putString(USER_EMAIL, userEmail == null ? "" : userEmail);
persister.store(crashData, reportFile);
} catch (IOException e) {
ACRA.log.w(LOG_TAG, "User comment not added: ", e);
} catch (JSONException e) {
ACRA.log.w(LOG_TAG, "User comment not added: ", e);
}
// Start the report sending task
final SenderServiceStarter starter = new SenderServiceStarter(getApplicationContext(), config);
starter.startService(false, true);
// Optional Toast to thank the user
final int toastId = config.resDialogOkToast();
if (toastId != 0) {
ToastSender.sendToast(getApplicationContext(), toastId, Toast.LENGTH_LONG);
}
}
use of org.acra.file.CrashReportPersister 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.CrashReportPersister in project acra by ACRA.
the class ReportExecutor method saveCrashReportFile.
/**
* When a report can't be sent, it is saved here in a file in the root of
* the application private directory.
*
* @param file
* In a few rare cases, we write the report again with additional
* data (user comment for example). In such cases, you can
* provide the already existing file name here to overwrite the
* report file. If null, a new file report will be generated
* @param crashData
* Can be used to save an alternative (or previously generated)
* report data. Used to store again a report with the addition of
* user comment. If null, the default current crash data are
* used.
*/
private void saveCrashReportFile(@NonNull File file, @NonNull CrashReportData crashData) {
try {
if (ACRA.DEV_LOGGING)
ACRA.log.d(LOG_TAG, "Writing crash report file " + file);
final CrashReportPersister persister = new CrashReportPersister();
persister.store(crashData, file);
} catch (Exception e) {
ACRA.log.e(LOG_TAG, "An error occurred while writing the report file...", e);
}
}
use of org.acra.file.CrashReportPersister in project acra by ACRA.
the class ReportDistributor method distribute.
/**
* Send report via all senders.
*
* @param reportFile Report to send.
*/
public void distribute(@NonNull File reportFile) {
ACRA.log.i(LOG_TAG, "Sending report " + reportFile);
try {
final CrashReportPersister persister = new CrashReportPersister();
final CrashReportData previousCrashReport = persister.load(reportFile);
sendCrashReport(previousCrashReport);
IOUtils.deleteReport(reportFile);
} catch (RuntimeException e) {
ACRA.log.e(LOG_TAG, "Failed to send crash reports for " + reportFile, e);
IOUtils.deleteReport(reportFile);
} catch (IOException e) {
ACRA.log.e(LOG_TAG, "Failed to load crash report for " + reportFile, e);
IOUtils.deleteReport(reportFile);
} catch (JSONException e) {
ACRA.log.e(LOG_TAG, "Failed to load crash report for " + reportFile, e);
IOUtils.deleteReport(reportFile);
} catch (ReportSenderException e) {
ACRA.log.e(LOG_TAG, "Failed to send crash report for " + reportFile, e);
// An issue occurred while sending this report but we can still try to
// send other reports. Report sending is limited by ACRAConstants.MAX_SEND_REPORTS
// so there's not much to fear about overloading a failing server.
}
}
Aggregations