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.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;
|
||||||
|
@ -46,13 +45,13 @@ public class MalwareScanner extends AsyncTask<Set<File>, Object, String> {
|
||||||
logOutput.append(result + "\n");
|
logOutput.append(result + "\n");
|
||||||
} else if (!userFacingOnly) {
|
} else if (!userFacingOnly) {
|
||||||
NotificationCompat.Builder mBuilder =
|
NotificationCompat.Builder mBuilder =
|
||||||
new NotificationCompat.Builder(context)
|
new NotificationCompat.Builder(context)
|
||||||
.setSmallIcon(R.drawable.ic_notification)
|
.setSmallIcon(R.drawable.ic_notification)
|
||||||
.setContentTitle(context.getText(R.string.lblNotificationRealtimeDetection))
|
.setContentTitle(context.getText(R.string.lblNotificationRealtimeDetection))
|
||||||
.setContentText(result)
|
.setContentText(result)
|
||||||
.setPriority(Notification.PRIORITY_MAX)
|
.setPriority(Notification.PRIORITY_MAX)
|
||||||
.setVisibility(Notification.VISIBILITY_SECRET)
|
.setVisibility(Notification.VISIBILITY_SECRET)
|
||||||
.setDefaults(Notification.DEFAULT_VIBRATE);
|
.setDefaults(Notification.DEFAULT_VIBRATE);
|
||||||
notificationManager.notify(new Random().nextInt(), mBuilder.build());
|
notificationManager.notify(new Random().nextInt(), mBuilder.build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 {
|
||||||
|
@ -29,12 +27,12 @@ public class MalwareScannerService extends Service {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
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 = new ArrayList<>();
|
||||||
malwareMonitors.add(new MalwareMonitor(Environment.getExternalStorageDirectory().toString()));
|
malwareMonitors.add(new MalwareMonitor(Environment.getExternalStorageDirectory().toString()));
|
||||||
malwareMonitors.add(new MalwareMonitor(getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).toString()));
|
malwareMonitors.add(new MalwareMonitor(getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).toString()));
|
||||||
|
|
||||||
for(MalwareMonitor malwareMonitor : malwareMonitors) {
|
for (MalwareMonitor malwareMonitor : malwareMonitors) {
|
||||||
malwareMonitor.startWatching();
|
malwareMonitor.startWatching();
|
||||||
}
|
}
|
||||||
Toast.makeText(this, "Theia: Realtime Scanning Started", Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "Theia: Realtime Scanning Started", Toast.LENGTH_SHORT).show();
|
||||||
|
@ -48,7 +46,7 @@ public class MalwareScannerService extends Service {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
for(MalwareMonitor malwareMonitor : malwareMonitors) {
|
for (MalwareMonitor malwareMonitor : malwareMonitors) {
|
||||||
malwareMonitor.stopWatching();
|
malwareMonitor.stopWatching();
|
||||||
}
|
}
|
||||||
Toast.makeText(this, "Theia: Realtime Scanning Stopped", Toast.LENGTH_SHORT).show();
|
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 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);
|
||||||
rootPath = path;
|
rootPath = path;
|
||||||
if(!rootPath.endsWith("/")) {
|
if (!rootPath.endsWith("/")) {
|
||||||
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(file.exists() && file.length() > 0) {
|
if (!filesScannedRecently.contains(file)) {
|
||||||
Set<File> filesToScan = new HashSet<>();
|
filesScannedRecently.clear();
|
||||||
filesToScan.add(file);
|
if (file.exists() && file.length() > 0) {
|
||||||
new MalwareScanner(null, getApplicationContext(), false).execute(filesToScan);
|
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