mirror of
https://github.com/MaintainTeam/Hypatia.git
synced 2025-03-01 13:58:21 +03:00
Formatting and prevent double scanning
This commit is contained in:
parent
ec0f10221c
commit
c1473846a6
2 changed files with 22 additions and 19 deletions
|
@ -7,7 +7,6 @@ import android.content.Context;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.SystemClock;
|
import android.os.SystemClock;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
|
@ -9,13 +9,11 @@ import android.os.Environment;
|
||||||
import android.os.FileObserver;
|
import android.os.FileObserver;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.support.v4.app.NotificationCompat;
|
import android.support.v4.app.NotificationCompat;
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Random;
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class MalwareScannerService extends Service {
|
public class MalwareScannerService extends Service {
|
||||||
|
@ -71,6 +69,7 @@ public class MalwareScannerService extends Service {
|
||||||
private class MalwareMonitor extends FileObserver {
|
private class MalwareMonitor extends FileObserver {
|
||||||
|
|
||||||
private String rootPath = null;
|
private String rootPath = null;
|
||||||
|
private Set<File> filesScannedRecently = new HashSet<>();
|
||||||
|
|
||||||
public MalwareMonitor(String path) {
|
public MalwareMonitor(String path) {
|
||||||
super(path);
|
super(path);
|
||||||
|
@ -79,17 +78,22 @@ public class MalwareScannerService extends Service {
|
||||||
rootPath += "/";
|
rootPath += "/";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEvent(int eventID, String path) {
|
public void onEvent(int eventID, String path) {
|
||||||
if (eventID == FileObserver.CLOSE_WRITE) {
|
if (eventID == FileObserver.CLOSE_WRITE) {
|
||||||
File file = new File(rootPath + path);
|
File file = new File(rootPath + path);
|
||||||
|
if (!filesScannedRecently.contains(file)) {
|
||||||
|
filesScannedRecently.clear();
|
||||||
if (file.exists() && file.length() > 0) {
|
if (file.exists() && file.length() > 0) {
|
||||||
Set<File> filesToScan = new HashSet<>();
|
Set<File> filesToScan = new HashSet<>();
|
||||||
filesToScan.add(file);
|
filesToScan.add(file);
|
||||||
|
filesScannedRecently.add(file);
|
||||||
new MalwareScanner(null, getApplicationContext(), false).execute(filesToScan);
|
new MalwareScanner(null, getApplicationContext(), false).execute(filesToScan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue