Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ import eu.darken.sdmse.common.permissions.Permission
import eu.darken.sdmse.common.pkgs.features.Installed
import eu.darken.sdmse.common.storage.StorageId
import eu.darken.sdmse.common.storage.StorageStatsManager2
import kotlinx.coroutines.TimeoutCancellationException
import kotlinx.coroutines.withTimeout
import java.util.Locale
import javax.inject.Inject
import kotlin.math.ln
import kotlin.math.pow
import kotlin.time.Duration.Companion.seconds

class StorageEntryFinder @Inject constructor(
@ApplicationContext private val context: Context,
Expand Down Expand Up @@ -78,19 +81,33 @@ class StorageEntryFinder @Inject constructor(
return null
}

val start = System.currentTimeMillis()

val stats1: StorageStats = try {
// OS uses queryStatsForPkg and NOT queryStatsForAppUid
// https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppStorageSize.kt;l=51
statsManager.queryStatsForPkg(storageId, pkg)
// Query on larger apps, e.g. Amazon Prime Video exceeds 15 seconds on a samsung/gts9wifieea/gts9wifi:15/AP3A.240905.015.A2/X710XXS5CYG1:user/release-keys
// Default step time out is 30 seconds, so after failing the query we can continue still and try something else
withTimeout(20.seconds) {
// OS uses queryStatsForPkg and NOT queryStatsForAppUid
// https://cs.android.com/android/platform/superproject/main/+/main:frameworks/base/packages/SettingsLib/SpaPrivileged/src/com/android/settingslib/spaprivileged/template/app/AppStorageSize.kt;l=51
statsManager.queryStatsForPkg(storageId, pkg)
}
} catch (e: SecurityException) {
log(TAG, WARN) { "Don't have permission to query app size for ${pkg.id}: $e" }
return null
} catch (e: TimeoutCancellationException) {
log(TAG, WARN) { "queryStatsForPkg timed outwhen querying app size for ${pkg.id}: $e" }
return null
} catch (e: Exception) {
log(TAG, ERROR) { "Unexpected error when querying app size for ${pkg.id}: ${e.asLog()}" }
return null
}

return stats1.appBytes + stats1.dataBytes
val combined = stats1.appBytes + stats1.dataBytes

val stop = System.currentTimeMillis() - start
log(TAG, VERBOSE) { "queryStatsForPkg($storageId,$pkg) after ${stop}ms: $combined" }

return combined
}

internal fun generateTargetTexts(targetSize: Long): Set<String> {
Expand Down Expand Up @@ -164,8 +181,7 @@ class StorageEntryFinder @Inject constructor(
val matches = host.waitForWindowRoot().crawl()
.map { it.node }
.mapNotNull { node ->
val priority = storageFilter(node)
if (priority == null) return@mapNotNull null
val priority = storageFilter(node) ?: return@mapNotNull null
log(TAG, VERBOSE) { "Priority $priority: $node" }
node to priority
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ open class OneUILabels @Inject constructor(
}

companion object {
private val TAG: String = logTag("AppCleaner", "Automation", "Samsung", "Labels")
private val TAG: String = logTag("AppCleaner", "Automation", "OneUI", "Labels")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class OneUILabels14Plus @Inject constructor(
.toSet()

companion object {
private val TAG: String = logTag("AppCleaner", "Automation", "Samsung", "Labels", "14Plus")
private val TAG: String = logTag("AppCleaner", "Automation", "OneUI", "Labels", "14Plus")
val SETTINGS_PKG = "com.android.settings".toPkgId()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class OneUILabels29Plus @Inject constructor(
.toSet()

companion object {
private val TAG: String = logTag("AppCleaner", "Automation", "Samsung", "Labels", "29Plus")
private val TAG: String = logTag("AppCleaner", "Automation", "OneUI", "Labels", "29Plus")
val SETTINGS_PKG = "com.android.settings".toPkgId()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class OneUISpecs @Inject constructor(
companion object {
val SETTINGS_PKG = "com.android.settings".toPkgId()

private val TAG: String = logTag("AppCleaner", "Automation", "Samsung", "Specs")
private val TAG: String = logTag("AppCleaner", "Automation", "OneUI", "Specs")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ open class OneUILabels @Inject constructor() : AppControlLabelSource {
): Set<String> = acsContext.getStrings(AOSPLabels.SETTINGS_PKG, setOf("cancel", "dlg_cancel"))

companion object {
val TAG: String = logTag("AppControl", "Automation", "Samsung", "Labels")
val TAG: String = logTag("AppControl", "Automation", "OneUI", "Labels")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class OneUISpecs @Inject constructor(
companion object {
val SETTINGS_PKG = "com.android.settings".toPkgId()

val TAG: String = logTag("AppControl", "Automation", "Samsung", "Specs")
val TAG: String = logTag("AppControl", "Automation", "OneUI", "Specs")
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package eu.darken.sdmse.automation.core.common.stepper
import eu.darken.sdmse.automation.core.common.ACSNodeInfo
import eu.darken.sdmse.common.ca.CaDrawable
import eu.darken.sdmse.common.ca.CaString
import kotlin.time.Duration
import kotlin.time.Duration.Companion.seconds

data class AutomationStep(
val source: String,
Expand All @@ -13,7 +15,7 @@ data class AutomationStep(
val windowCheck: (suspend StepContext.() -> ACSNodeInfo)? = null,
val nodeRecovery: (suspend StepContext.(ACSNodeInfo) -> Boolean)? = null,
val nodeAction: (suspend StepContext.() -> Boolean)? = null,
val timeout: Long = 15 * 1000,
val timeout: Duration = 30.seconds, // StorageEntryFinder timeouts at 15s
) {
override fun toString(): String = "Step(source=$source, description=$descriptionInternal)"
}