From 8699a6d2814928d4462261ed5fb956e9fe708081 Mon Sep 17 00:00:00 2001 From: Naveen Date: Sat, 22 Oct 2022 02:26:09 +0530 Subject: [PATCH 1/2] Cancel the call notification as soon as possible https://github.com/SimpleMobileTools/Simple-Dialer/issues/326 --- .../dialer/helpers/CallNotificationManager.kt | 7 +++++-- .../com/simplemobiletools/dialer/services/CallService.kt | 4 +++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/CallNotificationManager.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/CallNotificationManager.kt index 9a5a03ef..468db997 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/CallNotificationManager.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/CallNotificationManager.kt @@ -20,7 +20,7 @@ import com.simplemobiletools.dialer.extensions.powerManager import com.simplemobiletools.dialer.receivers.CallActionReceiver class CallNotificationManager(private val context: Context) { - private val CALL_NOTIFICATION_ID = 1 + private val CALL_NOTIFICATION_ID = 42 private val ACCEPT_CALL_CODE = 0 private val DECLINE_CALL_CODE = 1 private val notificationManager = context.notificationManager @@ -99,7 +99,10 @@ class CallNotificationManager(private val context: Context) { } val notification = builder.build() - notificationManager.notify(CALL_NOTIFICATION_ID, notification) + // it's rare but possible for the call state to change by now + if (CallManager.getState() == callState) { + notificationManager.notify(CALL_NOTIFICATION_ID, notification) + } } } diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/services/CallService.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/services/CallService.kt index ed456b76..7edb7fdf 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/services/CallService.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/services/CallService.kt @@ -18,7 +18,9 @@ class CallService : InCallService() { private val callListener = object : Call.Callback() { override fun onStateChanged(call: Call, state: Int) { super.onStateChanged(call, state) - if (state != Call.STATE_DISCONNECTED) { + if (state == Call.STATE_DISCONNECTED || state == Call.STATE_DISCONNECTING) { + callNotificationManager.cancelNotification() + } else { callNotificationManager.setupNotification() } } From 2c7335b86564651a67aaed1cfee7d428da95d51c Mon Sep 17 00:00:00 2001 From: Naveen Date: Sat, 22 Oct 2022 02:29:22 +0530 Subject: [PATCH 2/2] Remove disconnected calls manually A single disconnected but not removed call can cause false in-call state with in the app causing CallActivity to finish instantly even when there are no real active calls. --- .../kotlin/com/simplemobiletools/dialer/helpers/CallManager.kt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/CallManager.kt b/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/CallManager.kt index f86f09ab..f04fc064 100644 --- a/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/CallManager.kt +++ b/app/src/main/kotlin/com/simplemobiletools/dialer/helpers/CallManager.kt @@ -109,6 +109,9 @@ class CallManager { listener.onStateChanged() } } + + // remove all disconnected calls manually in case they are still here + calls.removeAll { it.getStateCompat() == Call.STATE_DISCONNECTED } } fun getPrimaryCall(): Call? {