From c882af4b90aeb7eed6e9e188968acea07aad8e74 Mon Sep 17 00:00:00 2001 From: darken Date: Tue, 12 Nov 2024 19:03:16 +0100 Subject: [PATCH] AppCleaner: Make text matching during accessibility based deletion more resilient Check for NBSP when generating dynamic labels. --- .../core/automation/specs/OnTheFlyLabler.kt | 61 ++++++++++++------- 1 file changed, 39 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/darken/sdmse/appcleaner/core/automation/specs/OnTheFlyLabler.kt b/app/src/main/java/eu/darken/sdmse/appcleaner/core/automation/specs/OnTheFlyLabler.kt index a7174fb2d..1519f63a2 100644 --- a/app/src/main/java/eu/darken/sdmse/appcleaner/core/automation/specs/OnTheFlyLabler.kt +++ b/app/src/main/java/eu/darken/sdmse/appcleaner/core/automation/specs/OnTheFlyLabler.kt @@ -59,31 +59,48 @@ class OnTheFlyLabler @Inject constructor( val targetSize = stats1.appBytes + stats1.dataBytes - val baseTexts = setOfNotNull( - // https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppStorageSize.kt - Formatter.formatFileSize(context, targetSize).also { - log(TAG, VERBOSE) { "formatFileSize=$it" } - }, - Formatter.formatShortFileSize(context, targetSize).also { - log(TAG, VERBOSE) { "formatShortFileSize=$it" } - }, - try { - formatExtraFileSize(targetSize).also { log(TAG, VERBOSE) { "formatExtraFileSize=$it" } } - } catch (e: Exception) { - log(TAG, ERROR) { "formatExtraFileSize($targetSize) failed: ${e.asLog()}" } - null - }, - ) - - val targetTexts = baseTexts.flatMap { - when { - it.contains(".") -> setOf(it, it.replace(".", ",")) - it.contains(",") -> setOf(it, it.replace(",", ".")) - else -> setOf(it) + val targetTexts = mutableSetOf() + + // https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppStorageSize.kt + Formatter.formatFileSize(context, targetSize).run { + log(TAG, VERBOSE) { "formatFileSize=$this" } + targetTexts.add(this) + } + + Formatter.formatShortFileSize(context, targetSize).run { + log(TAG, VERBOSE) { "formatShortFileSize=$this" } + targetTexts.add(this) + } + + try { + formatExtraFileSize(targetSize).run { + log(TAG, VERBOSE) { "formatExtraFileSize=$this" } + targetTexts.add(this) } + } catch (e: Exception) { + log(TAG, ERROR) { "formatExtraFileSize($targetSize) failed: ${e.asLog()}" } } - log(TAG) { "Loaded ${targetTexts.size} targets from $targetSize for ${pkg.installId}: $targetTexts" } + targetTexts.mapNotNull { + when { + it.contains(".") -> setOf(it.replace(".", ",")) + it.contains(",") -> setOf(it.replace(",", ".")) + else -> null + } + }.forEach { targetTexts.addAll(it) } + + targetTexts.mapNotNull { + when { + it.contains(" ") -> setOf(it.replace(" ", " ")) + it.contains(" ") -> setOf(it.replace(" ", " ")) + else -> null + } + }.forEach { targetTexts.addAll(it) } + + log(TAG) { + val distinguisable = targetTexts.map { it.replace("\u00A0", "\\u00A0") } + "Loaded ${targetTexts.size} targets from $targetSize for ${pkg.installId}: $distinguisable" + } return { node -> node.textContainsAny(targetTexts).also {