ReportMigrator(@NonNull Context context) { this.context = context; this.reportLocator = new ReportLocator(context); }
/** * @param approved Whether to delete approved or unapproved reports. * @param nrToKeep Number of latest reports to keep. */ public void deleteReports(boolean approved, int nrToKeep) { final File[] files = approved ? reportLocator.getApprovedReports() : reportLocator.getUnapprovedReports(); Arrays.sort(files, new LastModifiedComparator()); for (int i = 0; i < files.length - nrToKeep; i++) { if (!files[i].delete()) { ACRA.log.w(LOG_TAG, "Could not delete report : " + files[i]); } } } }
/** * @return Approved reports sorted by creation time. */ @NonNull public File[] getApprovedReports() { final File[] reports = getApprovedFolder().listFiles(); if (reports == null) { return new File[0]; } Arrays.sort(reports, new LastModifiedComparator()); return reports; } }
@NonNull private File getReportFileName(@NonNull CrashReportData crashData) { final String timestamp = crashData.getString(USER_CRASH_DATE); final String isSilent = crashData.getString(IS_SILENT); final String fileName = timestamp + (isSilent != null ? ACRAConstants.SILENT_SUFFIX : "") + ACRAConstants.REPORTFILE_EXTENSION; final ReportLocator reportLocator = new ReportLocator(context); return new File(reportLocator.getUnapprovedFolder(), fileName); }
@Override public boolean shouldStartCollecting(@NonNull Context context, @NonNull CoreConfiguration config, @NonNull ReportBuilder reportBuilder) { try { final LimiterConfiguration limiterConfiguration = ConfigUtils.getPluginConfiguration(config, LimiterConfiguration.class); final ReportLocator reportLocator = new ReportLocator(context); if (reportLocator.getApprovedReports().length + reportLocator.getUnapprovedReports().length >= limiterConfiguration.failedReportLimit()) { if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Reached failedReportLimit, not collecting"); return false; } final List<LimiterData.ReportMetadata> reportMetadata = loadLimiterData(context, limiterConfiguration).getReportMetadata(); if (reportMetadata.size() >= limiterConfiguration.overallLimit()) { if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Reached overallLimit, not collecting"); return false; } } catch (IOException e) { ACRA.log.w(LOG_TAG, "Failed to load LimiterData", e); } return true; }
void migrate() { ACRA.log.i(LOG_TAG, "Migrating unsent ACRA reports to new file locations"); final File[] reportFiles = getCrashReportFiles(); for (final File file : reportFiles) { // Move it to unapproved or approved folders. final String fileName = file.getName(); if (fileNameParser.isApproved(fileName)) { if (file.renameTo(new File(reportLocator.getApprovedFolder(), fileName))) { if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Cold not migrate unsent ACRA crash report : " + fileName); } } else { if (file.renameTo(new File(reportLocator.getUnapprovedFolder(), fileName))) { if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Cold not migrate unsent ACRA crash report : " + fileName); } } } ACRA.log.i(LOG_TAG, "Migrated " + reportFiles.length + " unsent reports"); }
final File[] reports = locator.getApprovedReports();
@NonNull public File[] getUnapprovedReports() { final File[] reports = getUnapprovedFolder().listFiles(); if (reports == null) { return new File[0]; } return reports; }
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<>(); reportFiles.addAll(Arrays.asList(locator.getUnapprovedReports())); reportFiles.addAll(Arrays.asList(locator.getApprovedReports())); int converted = 0; for (File report : reportFiles) {
for (File r : reportLocator.getUnapprovedReports()) { reports.add(new Report(r, false)); for (File r : reportLocator.getApprovedReports()) { reports.add(new Report(r, true));
public SendingConductor(@NonNull Context context, @NonNull CoreConfiguration config) { this.context = context; this.config = config; locator = new ReportLocator(context); }
/** * Starts a process to start sending outstanding error reports. * * @param report If not null, this report will be approved before scheduling. * @param onlySendSilentReports If true then only send silent reports. */ public void scheduleReports(@Nullable File report, boolean onlySendSilentReports) { if (report != null) { if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Mark " + report.getName() + " as approved."); final File approvedReport = new File(locator.getApprovedFolder(), report.getName()); if (!report.renameTo(approvedReport)) { ACRA.log.w(LOG_TAG, "Could not rename approved report from " + report + " to " + approvedReport); } } if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Schedule report sending"); senderScheduler.scheduleReportSending(onlySendSilentReports); }
public BulkReportDeleter(@NonNull Context context) { this.reportLocator = new ReportLocator(context); }
public StartupProcessorExecutor(@NonNull final Context context, @NonNull final CoreConfiguration config, @NonNull SchedulerStarter schedulerStarter) { this.context = context; this.config = config; this.reportLocator = new ReportLocator(context); this.schedulerStarter = schedulerStarter; this.fileNameParser = new CrashReportFileNameParser(); }
public SchedulerStarter(@NonNull Context context, @NonNull CoreConfiguration config) { locator = new ReportLocator(context); List<SenderSchedulerFactory> schedulerFactories = config.pluginLoader().loadEnabled(config, SenderSchedulerFactory.class); if (schedulerFactories.isEmpty()) { senderScheduler = new DefaultSenderScheduler(context, config); } else { senderScheduler = schedulerFactories.get(0).create(context, config); if (schedulerFactories.size() > 1) ACRA.log.w(ACRA.LOG_TAG, "More than one SenderScheduler found. Will use only " + senderScheduler.getClass().getSimpleName()); } }