mirror of
https://github.com/MaintainTeam/Hypatia.git
synced 2025-03-01 05:48:23 +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.SystemClock;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.io.File;
|
||||
|
@ -46,13 +45,13 @@ public class MalwareScanner extends AsyncTask<Set<File>, Object, String> {
|
|||
logOutput.append(result + "\n");
|
||||
} else if (!userFacingOnly) {
|
||||
NotificationCompat.Builder mBuilder =
|
||||
new NotificationCompat.Builder(context)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setContentTitle(context.getText(R.string.lblNotificationRealtimeDetection))
|
||||
.setContentText(result)
|
||||
.setPriority(Notification.PRIORITY_MAX)
|
||||
.setVisibility(Notification.VISIBILITY_SECRET)
|
||||
.setDefaults(Notification.DEFAULT_VIBRATE);
|
||||
new NotificationCompat.Builder(context)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setContentTitle(context.getText(R.string.lblNotificationRealtimeDetection))
|
||||
.setContentText(result)
|
||||
.setPriority(Notification.PRIORITY_MAX)
|
||||
.setVisibility(Notification.VISIBILITY_SECRET)
|
||||
.setDefaults(Notification.DEFAULT_VIBRATE);
|
||||
notificationManager.notify(new Random().nextInt(), mBuilder.build());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,13 +9,11 @@ import android.os.Environment;
|
|||
import android.os.FileObserver;
|
||||
import android.os.IBinder;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
public class MalwareScannerService extends Service {
|
||||
|
@ -29,12 +27,12 @@ public class MalwareScannerService extends Service {
|
|||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if(true) {//Check if we're enabled
|
||||
if (true) {//Check if we're enabled
|
||||
malwareMonitors = new ArrayList<>();
|
||||
malwareMonitors.add(new MalwareMonitor(Environment.getExternalStorageDirectory().toString()));
|
||||
malwareMonitors.add(new MalwareMonitor(getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).toString()));
|
||||
|
||||
for(MalwareMonitor malwareMonitor : malwareMonitors) {
|
||||
for (MalwareMonitor malwareMonitor : malwareMonitors) {
|
||||
malwareMonitor.startWatching();
|
||||
}
|
||||
Toast.makeText(this, "Theia: Realtime Scanning Started", Toast.LENGTH_SHORT).show();
|
||||
|
@ -48,7 +46,7 @@ public class MalwareScannerService extends Service {
|
|||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
for(MalwareMonitor malwareMonitor : malwareMonitors) {
|
||||
for (MalwareMonitor malwareMonitor : malwareMonitors) {
|
||||
malwareMonitor.stopWatching();
|
||||
}
|
||||
Toast.makeText(this, "Theia: Realtime Scanning Stopped", Toast.LENGTH_SHORT).show();
|
||||
|
@ -71,22 +69,28 @@ public class MalwareScannerService extends Service {
|
|||
private class MalwareMonitor extends FileObserver {
|
||||
|
||||
private String rootPath = null;
|
||||
private Set<File> filesScannedRecently = new HashSet<>();
|
||||
|
||||
public MalwareMonitor(String path) {
|
||||
super(path);
|
||||
rootPath = path;
|
||||
if(!rootPath.endsWith("/")) {
|
||||
if (!rootPath.endsWith("/")) {
|
||||
rootPath += "/";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEvent(int eventID, String path) {
|
||||
if(eventID == FileObserver.CLOSE_WRITE) {
|
||||
if (eventID == FileObserver.CLOSE_WRITE) {
|
||||
File file = new File(rootPath + path);
|
||||
if(file.exists() && file.length() > 0) {
|
||||
Set<File> filesToScan = new HashSet<>();
|
||||
filesToScan.add(file);
|
||||
new MalwareScanner(null, getApplicationContext(), false).execute(filesToScan);
|
||||
if (!filesScannedRecently.contains(file)) {
|
||||
filesScannedRecently.clear();
|
||||
if (file.exists() && file.length() > 0) {
|
||||
Set<File> filesToScan = new HashSet<>();
|
||||
filesToScan.add(file);
|
||||
filesScannedRecently.add(file);
|
||||
new MalwareScanner(null, getApplicationContext(), false).execute(filesToScan);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue