/** * Checks if an array of reports files names contains only silent or approved reports. * * @param reportFileNames Array of report locations to check. * @return True if there are only silent or approved reports. False if there is at least one * non-approved report. */ private boolean containsOnlySilentOrApprovedReports(String[] reportFileNames) { for (String reportFileName : reportFileNames) { if (!fileNameParser.isApproved(reportFileName)) { return false; } } return true; }
/** * Retrieve the most recently created "non silent" report from an array of report file names. A * non silent is any report which has not been created with {@link * #handleSilentException(Throwable)}. * * @param filesList An array of report file names. * @return The most recently created "non silent" report file name. */ private String getLatestNonSilentReport(String[] filesList) { if (filesList != null && filesList.length > 0) { for (int i = filesList.length - 1; i >= 0; i--) { if (!fileNameParser.isSilent(filesList[i])) { return filesList[i]; } } // We should never have this result, but this should be secure... return filesList[filesList.length - 1]; } else { return null; } }
/** * Delete pending reports. * * @param deleteApprovedReports Set to true to delete approved and silent reports. * @param deleteNonApprovedReports Set to true to delete non approved/silent reports. * @param nbOfLatestToKeep Number of pending reports to retain. */ private void deletePendingReports( boolean deleteApprovedReports, boolean deleteNonApprovedReports, int nbOfLatestToKeep) { // TODO Check logic and instances where nbOfLatestToKeep = X, because // that might stop us from deleting any reports. final CrashReportFinder reportFinder = new CrashReportFinder(mContext); final String[] filesList = reportFinder.getCrashReportFiles(); Arrays.sort(filesList); for (int iFile = 0; iFile < filesList.length - nbOfLatestToKeep; iFile++) { final String fileName = filesList[iFile]; final boolean isReportApproved = fileNameParser.isApproved(fileName); if ((isReportApproved && deleteApprovedReports) || (!isReportApproved && deleteNonApprovedReports)) { final File fileToDelete = new File(mContext.getFilesDir(), fileName); ACRA.log.d(ACRA.LOG_TAG, "Deleting file " + fileName); if (!fileToDelete.delete()) { Log.e(ACRA.LOG_TAG, "Could not delete report : " + fileToDelete); } } } }