From b98994f2f1d3e842f3746380a3bf10e508c192af Mon Sep 17 00:00:00 2001 From: darken Date: Mon, 30 Jun 2025 12:42:27 +0200 Subject: [PATCH] Revert "Fix IRK-only mode to prevent heuristic fallback + auto battery optimization" This reverts commit ca5041b27d8504c248f7161001e9ae714f141115. --- .../darken/capod/monitor/core/PodMonitor.kt | 25 ++++++------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/app-common/src/main/java/eu/darken/capod/monitor/core/PodMonitor.kt b/app-common/src/main/java/eu/darken/capod/monitor/core/PodMonitor.kt index 09daa257..f197988d 100644 --- a/app-common/src/main/java/eu/darken/capod/monitor/core/PodMonitor.kt +++ b/app-common/src/main/java/eu/darken/capod/monitor/core/PodMonitor.kt @@ -52,7 +52,6 @@ class PodMonitor @Inject constructor( private val deviceCache = mutableMapOf() private val cacheLock = Mutex() - private var lastIrkMatchedDevice: PodDevice? = null // Stores the last IRK-matched device val devices: Flow> = combine( permissionTool.missingPermissions, @@ -108,11 +107,15 @@ class PodMonitor @Inject constructor( generalSettings.isOffloadedBatchingDisabled.flow, generalSettings.isOffloadedFilteringDisabled.flow, generalSettings.useIndirectScanResultCallback.flow, - ) { scannermode, showUnfiltered, isOffloadedBatchingDisabled, isOffloadedFilteringDisabled, useIndirectScanResultCallback -> - // If IRK match exists, force LOW_POWER scan mode for battery saving - val effectiveScannerMode = if (lastIrkMatchedDevice != null) ScannerMode.LOW_POWER else scannermode + ) { + scannermode, + showUnfiltered, + isOffloadedBatchingDisabled, + isOffloadedFilteringDisabled, + useIndirectScanResultCallback, + -> ScannerOptions( - scannerMode = effectiveScannerMode, + scannerMode = scannermode, showUnfiltered = showUnfiltered, offloadedFilteringDisabled = isOffloadedFilteringDisabled, offloadedBatchingDisabled = isOffloadedBatchingDisabled, @@ -195,24 +198,12 @@ class PodMonitor @Inject constructor( } private fun determineMainDevice(pods: List): PodDevice? { - // Prioritize IRK match val irkHit = pods.filterIsInstance().firstOrNull { it.flags.isIRKMatch } if (irkHit != null) { log(TAG) { "Main device determined via IRK: $irkHit" } - lastIrkMatchedDevice = irkHit // Update state when IRK match occurs return irkHit } - // If IRK/ENC keys are configured, prevent heuristic fallback and keep last IRK-matched device - val identityKey = generalSettings.mainDeviceIdentityKey.value - val encryptionKey = generalSettings.mainDeviceEncryptionKey.value - val hasValidIrkKeys = (identityKey != null) || (encryptionKey != null) - if (hasValidIrkKeys) { - log(TAG) { "IRK/ENC keys are configured but no IRK match found, maintaining last known IRK-matched device state." } - return lastIrkMatchedDevice - } - - // Original heuristic logic (only if keys are not set) val mainDeviceModel = generalSettings.mainDeviceModel.value val presorted = sortPodsToInterest(pods).sortedByDescending { it.model == mainDeviceModel && it.model != PodDevice.Model.UNKNOWN