mirror of
https://github.com/MaintainTeam/Hypatia.git
synced 2025-03-01 05:48:23 +03:00
More threading
This commit is contained in:
parent
4b66afbc35
commit
4517a2253f
6 changed files with 23 additions and 11 deletions
|
@ -6,7 +6,7 @@ android {
|
|||
applicationId "us.spotco.malwarescanner"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 26
|
||||
versionCode 24
|
||||
versionCode 25
|
||||
versionName "2.1"
|
||||
}
|
||||
buildTypes {
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
|
||||
<receiver
|
||||
android:name=".EventReceiver"
|
||||
android:label="Theia Persistence"
|
||||
android:label="Theia Event Handler"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
|
@ -44,7 +44,6 @@
|
|||
<intent-filter>
|
||||
<action android:name="android.intent.action.PACKAGE_REPLACED" />
|
||||
<action android:name="android.intent.action.PACKAGE_ADDED" />
|
||||
|
||||
<data android:scheme="package" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
|
|
@ -50,7 +50,7 @@ public class EventReceiver extends BroadcastReceiver {
|
|||
e.printStackTrace();
|
||||
}
|
||||
if (filesToScan.size() > 0) {
|
||||
new MalwareScanner(null, context, false).execute(filesToScan);
|
||||
new MalwareScanner(null, context, false).executeOnExecutor(Utils.getThreadPoolExecutor(), filesToScan);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -178,7 +178,7 @@ public class MainActivity extends AppCompatActivity {
|
|||
if (scanExternal) {
|
||||
filesToScan.addAll(Utils.getFilesRecursive(new File("/storage")));
|
||||
}
|
||||
malwareScanner.execute(filesToScan);
|
||||
malwareScanner.executeOnExecutor(Utils.getThreadPoolExecutor(), filesToScan);
|
||||
}
|
||||
|
||||
private void updateDatabase() {
|
||||
|
|
|
@ -11,7 +11,6 @@ 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;
|
||||
|
@ -30,11 +29,7 @@ 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 = Utils.getThreadPoolExecutor();
|
||||
threadPoolExecutor.execute(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -4,6 +4,8 @@ import android.app.ActivityManager;
|
|||
import android.content.Context;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
import gnu.trove.set.hash.THashSet;
|
||||
|
||||
|
@ -13,6 +15,22 @@ class Utils {
|
|||
public final static int MAX_SCAN_SIZE_REALTIME = MAX_SCAN_SIZE / 2; //40MB
|
||||
|
||||
public static int FILES_SCANNED = 0;
|
||||
private static ThreadPoolExecutor threadPoolExecutor = null;
|
||||
|
||||
public static ThreadPoolExecutor getThreadPoolExecutor() {
|
||||
if (threadPoolExecutor == null) {
|
||||
threadPoolExecutor = (ThreadPoolExecutor) Executors.newScheduledThreadPool(getMaxThreads());
|
||||
}
|
||||
return threadPoolExecutor;
|
||||
}
|
||||
|
||||
public static int getMaxThreads() {
|
||||
int maxTheads = Runtime.getRuntime().availableProcessors();
|
||||
if (maxTheads >= 2) {
|
||||
maxTheads /= 2;
|
||||
}
|
||||
return maxTheads;
|
||||
}
|
||||
|
||||
public static THashSet<File> getFilesRecursive(File root) {
|
||||
THashSet<File> filesAll = new THashSet<>();
|
||||
|
|
Loading…
Add table
Reference in a new issue