From 5d8f2847b754584ae8953b7774720fc92a28ad3d Mon Sep 17 00:00:00 2001 From: darken Date: Tue, 24 Sep 2024 14:49:14 +0200 Subject: [PATCH] Analyzer: Improve scan and deletion performance --- .../eu/darken/sdmse/analyzer/core/Analyzer.kt | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/darken/sdmse/analyzer/core/Analyzer.kt b/app/src/main/java/eu/darken/sdmse/analyzer/core/Analyzer.kt index 459da4f0e..8e08186f5 100644 --- a/app/src/main/java/eu/darken/sdmse/analyzer/core/Analyzer.kt +++ b/app/src/main/java/eu/darken/sdmse/analyzer/core/Analyzer.kt @@ -38,6 +38,7 @@ import eu.darken.sdmse.common.progress.updateProgressPrimary import eu.darken.sdmse.common.progress.updateProgressSecondary import eu.darken.sdmse.common.progress.withProgress import eu.darken.sdmse.common.sharedresource.SharedResource +import eu.darken.sdmse.common.sharedresource.keepResourceHoldersAlive import eu.darken.sdmse.common.storage.StorageId import eu.darken.sdmse.main.core.SDMTool import eu.darken.sdmse.setup.IncompleteSetupException @@ -66,6 +67,7 @@ class Analyzer @Inject constructor( override val type: SDMTool.Type = SDMTool.Type.ANALYZER + private val usedResources = setOf(gatewaySwitch) override val sharedResource = SharedResource.createKeepAlive(TAG, appScope) private val progressPub = MutableStateFlow(null) @@ -114,14 +116,15 @@ class Analyzer @Inject constructor( log(TAG) { "submit($task) starting..." } updateProgress { Progress.Data() } try { - val result = when (task) { - is DeviceStorageScanTask -> scanStorageDevices(task) - is StorageScanTask -> scanStorageContents(task) - is ContentDeleteTask -> deleteContent(task) - is AppDeepScanTask -> deepScanApp(task) - else -> throw UnsupportedOperationException("Unsupported task: $task") + val result = keepResourceHoldersAlive(usedResources) { + when (task) { + is DeviceStorageScanTask -> scanStorageDevices(task) + is StorageScanTask -> scanStorageContents(task) + is ContentDeleteTask -> deleteContent(task) + is AppDeepScanTask -> deepScanApp(task) + else -> throw UnsupportedOperationException("Unsupported task: $task") + } } - log(TAG, INFO) { "submit($task) finished: $result" } result } finally {