diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index a583e6d5..256ffced 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -1552,16 +1552,20 @@ class BaresipService: Service() { val isAnyUaActive = uasStatus.value.values.any { it != R.drawable.circle_white } val isAnyCallActive = calls.isNotEmpty() val needsToStayAwake = isAnyUaActive || isAnyCallActive - if (needsToStayAwake) { - if (!partialWakeLock.isHeld) { - Log.d(TAG, "Acquiring Partial Wake Lock") - partialWakeLock.acquire() - } - } else { - if (partialWakeLock.isHeld) { - Log.d(TAG, "Releasing Partial Wake Lock") - partialWakeLock.release() + try { + if (needsToStayAwake) { + if (!partialWakeLock.isHeld) { + Log.d(TAG, "Acquiring Partial Wake Lock (UA Active or Call in progress)") + partialWakeLock.acquire() + } + } else { + if (partialWakeLock.isHeld) { + Log.d(TAG, "Releasing Partial Wake Lock (All UAs idle and no calls)") + partialWakeLock.release() + } } + } catch (e: Exception) { + Log.e(TAG, "Error managing partialWakeLock: ${e.message}") } }