diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml index b268ef3..fc8303f 100644 --- a/.idea/deploymentTargetSelector.xml +++ b/.idea/deploymentTargetSelector.xml @@ -5,6 +5,9 @@ + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 8374ab4..7a3132d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -6,8 +6,8 @@ android { applicationId "us.spotco.malwarescanner" minSdkVersion 16 targetSdkVersion 32 - versionCode 311 - versionName "3.11" + versionCode 312 + versionName "3.12" resConfigs 'en', 'af', 'cs', 'de', 'el', 'es', 'fi', 'fr', 'gl', 'it', 'pl', 'pt', 'pt-rBR', 'ru', 'tr', 'zh-rCN' } buildTypes { diff --git a/app/src/main/java/us/spotco/malwarescanner/LinkScannerService.java b/app/src/main/java/us/spotco/malwarescanner/LinkScannerService.java index e24c053..a00f1ed 100644 --- a/app/src/main/java/us/spotco/malwarescanner/LinkScannerService.java +++ b/app/src/main/java/us/spotco/malwarescanner/LinkScannerService.java @@ -10,6 +10,7 @@ import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityNodeInfo; import java.util.Random; +import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.ConcurrentSkipListSet; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -18,6 +19,9 @@ public class LinkScannerService extends AccessibilityService { private static final String hostnameRegex = "^((?!-)[A-Za-z0-9-]{1,63}(? scannedPackages = new ConcurrentSkipListMap<>(); + private static final ConcurrentSkipListMap scannerThreads = new ConcurrentSkipListMap<>(); + private static final ConcurrentSkipListSet scannedText = new ConcurrentSkipListSet<>(); private static final ConcurrentSkipListSet scannedDomains = new ConcurrentSkipListSet<>(); private NotificationManager notificationManager = null; @@ -35,7 +39,34 @@ public class LinkScannerService extends AccessibilityService { @Override public void onAccessibilityEvent(AccessibilityEvent event) { if (Database.isDomainDatabaseLoaded()) { - scanViews(event.getSource()); + boolean shouldScanView = true; + String packageName = (String) event.getPackageName(); + if (event.getSource() != null) { + packageName += event.getSource().getClassName(); + } + if (scannedPackages.containsKey(packageName)) { + if ((System.currentTimeMillis() - scannedPackages.get(packageName)) < 1000) { + shouldScanView = false; + } + } + if (shouldScanView) { + if (scannerThreads.containsKey(packageName)) { + Thread oldThread = scannerThreads.get(packageName); + if (oldThread != null) { + if (oldThread.isAlive()) { + shouldScanView = false; + } else { + scannerThreads.remove(packageName); + } + } + } + } + if (shouldScanView) { + scannedPackages.put(packageName, System.currentTimeMillis()); + Thread thread = new Thread(() -> scanViews(event.getSource())); + scannerThreads.put(packageName, thread); + thread.start(); + } } } diff --git a/app/src/main/res/xml/accessibility_service_config.xml b/app/src/main/res/xml/accessibility_service_config.xml index 0e65fb3..496a184 100644 --- a/app/src/main/res/xml/accessibility_service_config.xml +++ b/app/src/main/res/xml/accessibility_service_config.xml @@ -4,5 +4,5 @@ android:accessibilityEventTypes="typeWindowContentChanged|typeViewTextChanged" android:accessibilityFlags="flagDefault" android:accessibilityFeedbackType="feedbackGeneric" - android:notificationTimeout="1" + android:notificationTimeout="100" android:canRetrieveWindowContent="true" /> \ No newline at end of file diff --git a/fastlane/metadata/android/en-US/changelogs/312.txt b/fastlane/metadata/android/en-US/changelogs/312.txt new file mode 100644 index 0000000..e005308 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/312.txt @@ -0,0 +1 @@ +* Many optimizations to the link scanner feature