mirror of
https://github.com/MaintainTeam/Hypatia.git
synced 2025-02-28 21:38:21 +03:00
Use multiple threads for the realtime scanner
This commit is contained in:
parent
147d99480c
commit
2f07219c02
1 changed files with 16 additions and 3 deletions
|
@ -11,12 +11,15 @@ import android.os.IBinder;
|
|||
import android.support.v4.app.NotificationCompat;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
import gnu.trove.set.hash.THashSet;
|
||||
|
||||
public class MalwareScannerService extends Service {
|
||||
|
||||
private THashSet<RecursiveFileObserver> malwareMonitors = new THashSet<>();
|
||||
private ThreadPoolExecutor threadPoolExecutor = null;
|
||||
private NotificationCompat.Builder foregroundNotification = null;
|
||||
private NotificationManager notificationManager = null;
|
||||
|
||||
|
@ -27,13 +30,23 @@ public class MalwareScannerService extends Service {
|
|||
|
||||
@Override
|
||||
public final int onStartCommand(Intent intent, int flags, int startId) {
|
||||
int maxTheads = Runtime.getRuntime().availableProcessors();
|
||||
if (maxTheads >= 2) {
|
||||
maxTheads /= 2;
|
||||
}
|
||||
threadPoolExecutor = (ThreadPoolExecutor) Executors.newScheduledThreadPool(maxTheads);
|
||||
threadPoolExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Database.loadDatabase(getApplicationContext(), true, Database.signatureDatabases);
|
||||
}
|
||||
});
|
||||
|
||||
malwareMonitors.clear();
|
||||
addMalwareMonitor(Environment.getExternalStorageDirectory().toString());
|
||||
|
||||
for (RecursiveFileObserver malwareMonitor : malwareMonitors) {
|
||||
malwareMonitor.startWatching();
|
||||
}
|
||||
//Toast.makeText(this, "Theia: Realtime Scanning Started", Toast.LENGTH_SHORT).show();
|
||||
|
||||
notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
setForeground();
|
||||
|
@ -51,7 +64,7 @@ public class MalwareScannerService extends Service {
|
|||
if (file.exists() && /*file.length() > 0 &&*/ file.length() <= Utils.MAX_SCAN_SIZE_REALTIME) {
|
||||
THashSet<File> filesToScan = new THashSet<>();
|
||||
filesToScan.add(file);
|
||||
new MalwareScanner(null, getApplicationContext(), false).execute(filesToScan);
|
||||
new MalwareScanner(null, getApplicationContext(), false).executeOnExecutor(threadPoolExecutor, filesToScan);
|
||||
}
|
||||
updateForegroundNotification();
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue