mirror of
https://github.com/MaintainTeam/Hypatia.git
synced 2025-03-01 05:48:23 +03:00
Many changes
- Add back EventReceiver - Add back missing database bits - Request permissions - More Settings work - Tor handling - Service handling - Reformat code - Misc tweaks
This commit is contained in:
parent
fa649dc25f
commit
68f5fee17c
11 changed files with 156 additions and 11 deletions
2
.idea/misc.xml
generated
2
.idea/misc.xml
generated
|
@ -24,7 +24,7 @@
|
|||
</value>
|
||||
</option>
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="JDK" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||
</component>
|
||||
<component name="ProjectType">
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="us.spotco.malwarescanner">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
@ -13,7 +14,9 @@
|
|||
android:largeHeap="true"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
android:theme="@style/AppTheme"
|
||||
tools:ignore="GoogleAppIndexingWarning">
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/title_activity_main"
|
||||
|
@ -24,6 +27,23 @@
|
|||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<receiver
|
||||
android:name=".EventReceiver"
|
||||
android:label="Event Handler"
|
||||
android:enabled="true"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED" />
|
||||
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
|
||||
</intent-filter>
|
||||
<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>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -85,6 +85,7 @@ public class DatabaseManager {
|
|||
new DownloaderTask().execute(db.getUrl(), databasePath + "/" + db.getName());
|
||||
}
|
||||
}
|
||||
loadAllAvailableDatabases(true);
|
||||
}
|
||||
|
||||
public void loadAllAvailableDatabases(boolean forceReload) {
|
||||
|
@ -96,6 +97,8 @@ public class DatabaseManager {
|
|||
loadDatabase(dbLocation);
|
||||
}
|
||||
}
|
||||
Signatures.MD5.put("44d88612fea8a8f36de82e1278abb02f".substring(0, Utils.prefs.getInt("database_hash_length", 12)), "Eicar-Test-Signature");
|
||||
System.gc();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,4 +66,9 @@ public class DownloaderTask extends AsyncTask<Object, String, String> {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected final void onProgressUpdate(String... progress) {
|
||||
|
||||
}
|
||||
}
|
|
@ -17,5 +17,45 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
*/
|
||||
package us.spotco.malwarescanner;
|
||||
|
||||
public class EventReceiver {
|
||||
}
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
|
||||
public class EventReceiver extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public final void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) {
|
||||
Utils.considerStartService(context);
|
||||
}
|
||||
if (intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED)) {
|
||||
if (intent.getDataString().contains(context.getPackageName())) {
|
||||
Utils.considerStartService(context); //We've been updated, restart service
|
||||
} else {
|
||||
//scanApp(context, intent.getDataString());//An app was updated, scan it //TODO FIX ME
|
||||
}
|
||||
}
|
||||
if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) {
|
||||
//scanApp(context, intent.getDataString());//An app was installed, scan it //TODO FIX ME
|
||||
}
|
||||
}
|
||||
|
||||
private static void scanApp(Context context, String appID) {
|
||||
if (Utils.isServiceRunning(MalwareScannerService.class, context)) {
|
||||
HashSet<File> filesToScan = new HashSet<>();
|
||||
try {
|
||||
filesToScan.add(new File(context.getPackageManager().getApplicationInfo(appID, PackageManager.GET_META_DATA).sourceDir));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (filesToScan.size() > 0) {
|
||||
//new MalwareScanner(null, context, false).executeOnExecutor(Utils.getThreadPoolExecutor(), filesToScan); //TODO UPDATE ME
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -17,12 +17,16 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
*/
|
||||
package us.spotco.malwarescanner;
|
||||
|
||||
import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.BottomNavigationView;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.view.MenuItem;
|
||||
|
||||
public class MainActivity extends FragmentActivity {
|
||||
|
@ -50,8 +54,20 @@ public class MainActivity extends FragmentActivity {
|
|||
fragmentManager.beginTransaction().add(R.id.main_fragment, scannerFragment, "MalwareScanner").commit();
|
||||
activeFragment = scannerFragment;
|
||||
|
||||
requestPermissions();
|
||||
|
||||
new Utils(this);
|
||||
new DatabaseManager(this);
|
||||
if(Utils.useTor()) {
|
||||
Utils.requestStartOrbot(this);
|
||||
}
|
||||
Utils.considerStartService(this);
|
||||
}
|
||||
|
||||
private void requestPermissions() {
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.READ_EXTERNAL_STORAGE}, 0);
|
||||
}
|
||||
}
|
||||
|
||||
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
|
||||
|
|
|
@ -18,18 +18,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
package us.spotco.malwarescanner;
|
||||
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v7.preference.PreferenceFragmentCompat;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
*/
|
||||
public class SettingsFragment extends PreferenceFragmentCompat {
|
||||
|
||||
public SettingsFragment() {
|
||||
}
|
||||
|
||||
public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -41,4 +40,37 @@ public class SettingsFragment extends PreferenceFragmentCompat {
|
|||
setPreferencesFromResource(R.xml.fragment_settings, rootKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Utils.prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
Utils.prefs.unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences prefs, String key) {
|
||||
if(key.equals("network_use_tor")) {
|
||||
if(prefs.getBoolean("network_use_tor", false)) {
|
||||
if (!Utils.isOrbotInstalled(getContext())) {
|
||||
prefs.edit().putBoolean("ONION_ROUTING", false).apply();
|
||||
Toast.makeText(getContext(), R.string.toast_orbot_unavailable, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(key.equals("scanner_realtime_enabled")) {
|
||||
if(prefs.getBoolean("scanner_realtime_enabled", false)) {
|
||||
Utils.considerStartService(getContext());
|
||||
} else {
|
||||
Intent realtimeScanner = new Intent(getContext(), MalwareScannerService.class);
|
||||
getContext().stopService(realtimeScanner);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ import java.util.HashMap;
|
|||
|
||||
public class Signatures {
|
||||
|
||||
|
||||
public final static HashMap<String, String> MD5 = new HashMap<>();
|
||||
public final static HashMap<String, String> SHA1 = new HashMap<>();
|
||||
public final static HashMap<String, String> SHA256 = new HashMap<>();
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.HttpURLConnection;
|
||||
|
@ -91,6 +92,20 @@ public class Utils {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static void considerStartService(Context context) {
|
||||
if (!isServiceRunning(MalwareScannerService.class, context)) {
|
||||
boolean autostart = prefs.getBoolean("scanner_realtime_enabled", false);
|
||||
if (autostart) {
|
||||
Intent realtimeScanner = new Intent(context, MalwareScannerService.class);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
context.startForegroundService(realtimeScanner);
|
||||
} else {
|
||||
context.startService(realtimeScanner);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Credit: https://stackoverflow.com/a/6758962
|
||||
public static boolean isPackageInstalled(Context context, String packageID) {
|
||||
PackageManager pm = context.getPackageManager();
|
||||
|
@ -146,10 +161,14 @@ public class Utils {
|
|||
return listening;
|
||||
}
|
||||
|
||||
public static boolean useTor() {
|
||||
return prefs.getBoolean("network_use_tor", false);
|
||||
}
|
||||
|
||||
public static HttpURLConnection getConnection(String url) {
|
||||
try {
|
||||
HttpURLConnection connection;
|
||||
if (prefs.getBoolean("network_use_tor", false)) {
|
||||
if (useTor()) {
|
||||
waitUntilOrbotIsAvailable();
|
||||
Proxy orbot = new Proxy(Proxy.Type.SOCKS, new InetSocketAddress("127.0.0.1", 9050));
|
||||
connection = (HttpURLConnection) new URL(url).openConnection(orbot);
|
||||
|
|
|
@ -9,8 +9,14 @@
|
|||
<string name="title_settings">Settings</string>
|
||||
<!-- END MainActivity -->
|
||||
|
||||
<!-- START TOASTS -->
|
||||
<string name="toast_orbot_unavailable">Orbot is required for this feature</string>
|
||||
<!-- END TOASTS -->
|
||||
|
||||
<!-- START SettingsFragment -->
|
||||
<string name="settings_category_scanner_realtime">Realtime Scanner</string>
|
||||
<string name="settings_pref_scanner_realtime_enabled">Realtime Scanning</string>
|
||||
<string name="settings_pref_scanner_realtime_enabled_summary">Monitor for threats in realtime using settings below</string>
|
||||
<string name="settings_pref_scanner_realtime_path_apps">Scan apps</string>
|
||||
<string name="settings_pref_scanner_realtime_path_apps_summary">Check apps on install</string>
|
||||
<string name="settings_pref_scanner_realtime_path_internal">Watch Internal storage</string>
|
||||
|
|
|
@ -3,6 +3,11 @@
|
|||
tools:context="us.spotco.malwarescanner.SettingsFragment">
|
||||
|
||||
<PreferenceCategory android:title="@string/settings_category_scanner_realtime">
|
||||
<CheckBoxPreference
|
||||
android:key="scanner_realtime_enabled"
|
||||
android:title="@string/settings_pref_scanner_realtime_enabled"
|
||||
android:summary="@string/settings_pref_scanner_realtime_enabled_summary"
|
||||
android:defaultValue="false" />
|
||||
<CheckBoxPreference
|
||||
android:key="scanner_realtime_path_apps"
|
||||
android:title="@string/settings_pref_scanner_realtime_path_apps"
|
||||
|
|
Loading…
Add table
Reference in a new issue