Show the number of scanned files in the foreground notification

This commit is contained in:
Tad 2017-12-26 17:28:44 -05:00
parent 65c3306dc2
commit 147d99480c
4 changed files with 19 additions and 5 deletions

View file

@ -6,7 +6,7 @@ android {
applicationId "us.spotco.malwarescanner"
minSdkVersion 21
targetSdkVersion 26
versionCode 21
versionCode 23
versionName "2.0"
}
buildTypes {

View file

@ -97,6 +97,7 @@ class MalwareScanner extends AsyncTask<Set<File>, Object, String> {
fileHashesSHA1.clear();
fileHashesSHA256.clear();
System.gc();
Utils.FILES_SCANNED += filesToScan[0].size();
Log.d("Thiea", "Scan completed in " + (SystemClock.elapsedRealtime() - scanTime) + " ms!");
publishProgress("Scan completed in " + ((SystemClock.elapsedRealtime() - scanTime) / 1000) + " seconds!\n\n\n\n", true);
} else {

View file

@ -1,7 +1,9 @@
package us.spotco.malwarescanner;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Environment;
import android.os.FileObserver;
@ -15,6 +17,8 @@ import gnu.trove.set.hash.THashSet;
public class MalwareScannerService extends Service {
private THashSet<RecursiveFileObserver> malwareMonitors = new THashSet<>();
private NotificationCompat.Builder foregroundNotification = null;
private NotificationManager notificationManager = null;
@Override
public final IBinder onBind(Intent intent) {
@ -30,6 +34,8 @@ public class MalwareScannerService extends Service {
malwareMonitor.startWatching();
}
//Toast.makeText(this, "Theia: Realtime Scanning Started", Toast.LENGTH_SHORT).show();
notificationManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
setForeground();
return START_STICKY;
}
@ -47,6 +53,7 @@ public class MalwareScannerService extends Service {
filesToScan.add(file);
new MalwareScanner(null, getApplicationContext(), false).execute(filesToScan);
}
updateForegroundNotification();
break;
}
}
@ -64,16 +71,20 @@ public class MalwareScannerService extends Service {
}
private void setForeground() {
Notification notification =
foregroundNotification =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_notification)
.setContentTitle(getText(R.string.lblNotificationRealtimeTitle))
.setContentText(getText(R.string.lblNotificationRealtimeText))
.setPriority(Notification.PRIORITY_MIN)
.setShowWhen(false)
.build();
.setShowWhen(false);
startForeground(-1, notification);
startForeground(-1, foregroundNotification.build());
}
private void updateForegroundNotification() {
foregroundNotification.setSubText(Utils.FILES_SCANNED + " files scanned");
notificationManager.notify(-1, foregroundNotification.build());
}
}

View file

@ -12,6 +12,8 @@ class Utils {
public final static int MAX_SCAN_SIZE = (1000 * 1000) * 80; //80MB
public final static int MAX_SCAN_SIZE_REALTIME = MAX_SCAN_SIZE / 2; //40MB
public static int FILES_SCANNED = 0;
public static THashSet<File> getFilesRecursive(File root) {
THashSet<File> filesAll = new THashSet<>();