mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-17 10:17:41 +00:00
Modified Case class to be TSK error observer
This commit is contained in:
parent
793d3d49b2
commit
a197acb18b
@ -86,12 +86,12 @@ import org.sleuthkit.datamodel.TskException;
|
||||
* open at a time. Use getCurrentCase() to retrieve the object for the current
|
||||
* case.
|
||||
*/
|
||||
public class Case {
|
||||
public class Case implements SleuthkitCase.ErrorObserver {
|
||||
|
||||
private static final String autopsyVer = Version.getVersion(); // current version of autopsy. Change it when the version is changed
|
||||
private static final String EVENT_CHANNEL_NAME = "%s-Case-Events";
|
||||
private static String appName = null;
|
||||
private IntervalErrorReportData tskErrorReporter = null;
|
||||
volatile private IntervalErrorReportData tskErrorReporter = null;
|
||||
private static final int MIN_SECONDS_BETWEEN_ERROR_REPORTS = 60; // No less than 60 seconds between warnings for errors
|
||||
private static final int MAX_SANITIZED_NAME_LENGTH = 47;
|
||||
|
||||
@ -371,6 +371,17 @@ public class Case {
|
||||
Logger.setLogDirectory(PlatformUtil.getLogDirectory());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveError(String context, String errorMessage) {
|
||||
/* NOTE: We are accessing currentCase.tskErrorReporter from two different threads.
|
||||
* This is ok as long as we only read the value of currentCase.tskErrorReporter
|
||||
* because currentCase.tskErrorReporter is declared as volatile.
|
||||
*/
|
||||
if (null != currentCase.tskErrorReporter) {
|
||||
currentCase.tskErrorReporter.addProblems(context, errorMessage);
|
||||
}
|
||||
}
|
||||
|
||||
AddImageProcess makeAddImageProcess(String timezone, boolean processUnallocSpace, boolean noFatOrphans) {
|
||||
return this.db.makeAddImageProcess(timezone, processUnallocSpace, noFatOrphans);
|
||||
|
@ -20,16 +20,15 @@ package org.sleuthkit.autopsy.casemodule;
|
||||
|
||||
import org.openide.util.NbBundle;
|
||||
import org.sleuthkit.autopsy.coreutils.MessageNotifyUtil;
|
||||
import org.sleuthkit.datamodel.SleuthkitCase;
|
||||
|
||||
/**
|
||||
* This class enables capturing errors and batching them for reporting on a
|
||||
* no-more-than-x number of seconds basis. When created, you specify what type
|
||||
* of error it will be batching, and the minimum time between user
|
||||
* notifications. When the time between notifications has expired, the next
|
||||
* error encountered will cause a report to be shown to the user.
|
||||
* no-more-than-x number of seconds basis. When created, you specify the minimum
|
||||
* time between user notifications. When the time between notifications has
|
||||
* expired, the next error encountered will cause a report to be shown to the
|
||||
* user.
|
||||
*/
|
||||
class IntervalErrorReportData implements SleuthkitCase.ErrorObserver {
|
||||
class IntervalErrorReportData {
|
||||
|
||||
private final Case currentCase;
|
||||
private long newProblems;
|
||||
@ -39,7 +38,8 @@ class IntervalErrorReportData implements SleuthkitCase.ErrorObserver {
|
||||
private final String message;
|
||||
|
||||
/**
|
||||
* Create a new IntervalErrorReprotData instance.
|
||||
* Create a new IntervalErrorReprotData instance and subscribe for TSK error
|
||||
* notifications for the current case.
|
||||
*
|
||||
* @param currentCase Case for which TSK errors should be tracked
|
||||
* and displayed.
|
||||
@ -48,21 +48,21 @@ class IntervalErrorReportData implements SleuthkitCase.ErrorObserver {
|
||||
* @param message The message that will be shown when warning
|
||||
* the user
|
||||
*/
|
||||
public IntervalErrorReportData(Case currentCase, int secondsBetweenReports, String message) {
|
||||
IntervalErrorReportData(Case currentCase, int secondsBetweenReports, String message) {
|
||||
this.newProblems = 0;
|
||||
this.totalProblems = 0;
|
||||
this.lastReportedDate = 0; // arm the first warning by choosing zero
|
||||
this.milliSecondsBetweenReports = secondsBetweenReports * 1000; // convert to milliseconds
|
||||
this.message = message;
|
||||
this.currentCase = currentCase;
|
||||
this.currentCase.getSleuthkitCase().addErrorObserver(this); // it's ok to use "this" at the end of the constructor
|
||||
this.currentCase.getSleuthkitCase().addErrorObserver(this.currentCase);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuts down this IntervalErrorReprotData instance.
|
||||
* Un-subscribe from TSK error notifications for current case.
|
||||
*/
|
||||
public void shutdown() {
|
||||
this.currentCase.getSleuthkitCase().removeErrorObserver(this);
|
||||
void shutdown() {
|
||||
this.currentCase.getSleuthkitCase().removeErrorObserver(this.currentCase);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,12 +70,11 @@ class IntervalErrorReportData implements SleuthkitCase.ErrorObserver {
|
||||
* (or if this is the first problem encountered), a warning will be shown to
|
||||
* the user.
|
||||
*
|
||||
* @param newProblems the newProblems to set
|
||||
* @param context The context in which the error occurred.
|
||||
* @param errorMessage A description of the error that occurred.
|
||||
*/
|
||||
private void addProblems(long newProblems, String context, String errorMessage) {
|
||||
this.newProblems += newProblems;
|
||||
void addProblems(String context, String errorMessage) {
|
||||
this.newProblems += 1;
|
||||
this.totalProblems += newProblems;
|
||||
|
||||
long currentTimeStamp = System.currentTimeMillis();
|
||||
@ -90,9 +89,4 @@ class IntervalErrorReportData implements SleuthkitCase.ErrorObserver {
|
||||
this.newProblems = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveError(String context, String errorMessage) {
|
||||
addProblems(1, context, errorMessage);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user