Skip to content

Commit

Permalink
AppCleaner: Make text matching during accessibility based deletion mo…
Browse files Browse the repository at this point in the history
…re resilient

Check for NBSP when generating dynamic labels.
  • Loading branch information
d4rken committed Nov 12, 2024
1 parent 4af2600 commit c882af4
Showing 1 changed file with 39 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>()

// 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 {
Expand Down

0 comments on commit c882af4

Please sign in to comment.