mirror of
https://github.com/MaintainTeam/Hypatia.git
synced 2025-03-01 05:48:23 +03:00
Start service on app launch too
This commit is contained in:
parent
04b3043f89
commit
ed4d031d1f
4 changed files with 20 additions and 17 deletions
|
@ -6,8 +6,8 @@ android {
|
||||||
applicationId "us.spotco.malwarescanner"
|
applicationId "us.spotco.malwarescanner"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 26
|
targetSdkVersion 26
|
||||||
versionCode 25
|
versionCode 26
|
||||||
versionName "2.1"
|
versionName "2.2"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
debug {
|
debug {
|
||||||
|
|
|
@ -3,7 +3,6 @@ package us.spotco.malwarescanner;
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -15,11 +14,11 @@ public class EventReceiver extends BroadcastReceiver {
|
||||||
@Override
|
@Override
|
||||||
public final void onReceive(Context context, Intent intent) {
|
public final void onReceive(Context context, Intent intent) {
|
||||||
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
|
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
|
||||||
considerStartService(context);
|
Utils.considerStartService(context);
|
||||||
}
|
}
|
||||||
if (intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) {
|
if (intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) {
|
||||||
if (intent.getDataString().contains(context.getPackageName())) {
|
if (intent.getDataString().contains(context.getPackageName())) {
|
||||||
considerStartService(context); //We've been updated, restart service
|
Utils.considerStartService(context); //We've been updated, restart service
|
||||||
} else {
|
} else {
|
||||||
//scanApp(context, intent.getDataString());//An app was updated, scan it
|
//scanApp(context, intent.getDataString());//An app was updated, scan it
|
||||||
}
|
}
|
||||||
|
@ -29,18 +28,6 @@ public class EventReceiver extends BroadcastReceiver {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void considerStartService(Context context) {
|
|
||||||
if (!Utils.isServiceRunning(MalwareScannerService.class, context)) {
|
|
||||||
SharedPreferences prefs = context.getSharedPreferences(BuildConfig.APPLICATION_ID, Context.MODE_PRIVATE);
|
|
||||||
boolean autostart = prefs.getBoolean("autostart", false);
|
|
||||||
|
|
||||||
if (autostart) {
|
|
||||||
Intent realtimeScanner = new Intent(context, MalwareScannerService.class);
|
|
||||||
context.startService(realtimeScanner);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void scanApp(Context context, String appID) {
|
private static void scanApp(Context context, String appID) {
|
||||||
if (Utils.isServiceRunning(MalwareScannerService.class, context)) {
|
if (Utils.isServiceRunning(MalwareScannerService.class, context)) {
|
||||||
THashSet<File> filesToScan = new THashSet<>();
|
THashSet<File> filesToScan = new THashSet<>();
|
||||||
|
|
|
@ -72,6 +72,8 @@ public class MainActivity extends AppCompatActivity {
|
||||||
});
|
});
|
||||||
|
|
||||||
requestPermissions();
|
requestPermissions();
|
||||||
|
|
||||||
|
Utils.considerStartService(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,6 +2,8 @@ package us.spotco.malwarescanner;
|
||||||
|
|
||||||
import android.app.ActivityManager;
|
import android.app.ActivityManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
@ -65,4 +67,16 @@ class Utils {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void considerStartService(Context context) {
|
||||||
|
if (!Utils.isServiceRunning(MalwareScannerService.class, context)) {
|
||||||
|
SharedPreferences prefs = context.getSharedPreferences(BuildConfig.APPLICATION_ID, Context.MODE_PRIVATE);
|
||||||
|
boolean autostart = prefs.getBoolean("autostart", false);
|
||||||
|
|
||||||
|
if (autostart) {
|
||||||
|
Intent realtimeScanner = new Intent(context, MalwareScannerService.class);
|
||||||
|
context.startService(realtimeScanner);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue