Removed brief wakelock acquire

This commit is contained in:
Juha Heinanen
2026-04-13 10:40:41 +03:00
parent 97a31b5e31
commit e28379253e
@@ -115,8 +115,6 @@ class BaresipService: Service() {
private var isNotificationInCall = false private var isNotificationInCall = false
private var isServiceClean = false private var isServiceClean = false
private val TAG = "BaresipService"
@SuppressLint("WakelockTimeout") @SuppressLint("WakelockTimeout")
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
@@ -748,7 +746,7 @@ class BaresipService: Service() {
if (uas.value[accountIndex].account.aor == aor) { if (uas.value[accountIndex].account.aor == aor) {
when (ev[0]) { when (ev[0]) {
"registering", "unregistering" -> { "registering", "unregistering" -> {
updatePartialWakeLock(brief = true) updatePartialWakeLock()
ua.updateStatus(circleYellow.getValue(colorblind)) ua.updateStatus(circleYellow.getValue(colorblind))
updateStatusNotification() updateStatusNotification()
if (isMainVisible) if (isMainVisible)
@@ -756,7 +754,7 @@ class BaresipService: Service() {
return return
} }
"registered" -> { "registered" -> {
updatePartialWakeLock(brief = true) updatePartialWakeLock()
ua.updateStatus( ua.updateStatus(
if (Api.account_regint(ua.account.accp) == 0) if (Api.account_regint(ua.account.accp) == 0)
R.drawable.circle_white R.drawable.circle_white
@@ -769,7 +767,7 @@ class BaresipService: Service() {
return return
} }
"registering failed" -> { "registering failed" -> {
updatePartialWakeLock(brief = true) updatePartialWakeLock()
ua.updateStatus(if (Api.account_regint(ua.account.accp) == 0) ua.updateStatus(if (Api.account_regint(ua.account.accp) == 0)
R.drawable.circle_white R.drawable.circle_white
else else
@@ -1642,25 +1640,13 @@ class BaresipService: Service() {
} }
@SuppressLint("WakelockTimeout") @SuppressLint("WakelockTimeout")
private fun updatePartialWakeLock(brief: Boolean = false) { private fun updatePartialWakeLock() {
// Only hold a permanent wake lock during active calls. // Hold the wake lock as long as the service is active to ensure
// For registration standby, rely on the foreground service and kernel socket wakes. // native SIP timers (registration, keep-alives) continue to run.
// Also hold it briefly for registration events or network transitions.
val needsToStayAwake = calls.isNotEmpty()
try { try {
if (needsToStayAwake) { if (!partialWakeLock.isHeld) {
if (!partialWakeLock.isHeld) { Log.d(TAG, "Acquiring Partial Wake Lock")
Log.d(TAG, "Acquiring Partial Wake Lock (Call in progress)") partialWakeLock.acquire()
partialWakeLock.acquire()
}
} else if (brief) {
Log.d(TAG, "Acquiring Brief Partial Wake Lock (2s)")
partialWakeLock.acquire(2000L)
} else {
if (partialWakeLock.isHeld) {
Log.d(TAG, "Releasing Partial Wake Lock (No calls in progress)")
partialWakeLock.release()
}
} }
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG, "Error managing partialWakeLock: ${e.message}") Log.e(TAG, "Error managing partialWakeLock: ${e.message}")
@@ -1963,7 +1949,7 @@ class BaresipService: Service() {
private fun updateNetwork() { private fun updateNetwork() {
if (!isNativeReady) return if (!isNativeReady) return
updatePartialWakeLock(brief = true) updatePartialWakeLock()
updateDnsServers() updateDnsServers()
val addresses = linkAddresses() val addresses = linkAddresses()
@@ -2160,6 +2146,8 @@ class BaresipService: Service() {
@SuppressLint("MutableCollectionMutableState") @SuppressLint("MutableCollectionMutableState")
companion object { companion object {
private const val TAG = "BaresipService"
var instance: BaresipService? = null var instance: BaresipService? = null
var isServiceRunning = false var isServiceRunning = false
var isNativeReady = false var isNativeReady = false