Cancel the call notification as soon as possible

https://github.com/SimpleMobileTools/Simple-Dialer/issues/326
This commit is contained in:
Naveen
2022-10-22 02:26:09 +05:30
parent 764f4a7e66
commit 8699a6d281
2 changed files with 8 additions and 3 deletions

View File

@@ -20,7 +20,7 @@ import com.simplemobiletools.dialer.extensions.powerManager
import com.simplemobiletools.dialer.receivers.CallActionReceiver import com.simplemobiletools.dialer.receivers.CallActionReceiver
class CallNotificationManager(private val context: Context) { 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 ACCEPT_CALL_CODE = 0
private val DECLINE_CALL_CODE = 1 private val DECLINE_CALL_CODE = 1
private val notificationManager = context.notificationManager private val notificationManager = context.notificationManager
@@ -99,9 +99,12 @@ class CallNotificationManager(private val context: Context) {
} }
val notification = builder.build() val notification = builder.build()
// it's rare but possible for the call state to change by now
if (CallManager.getState() == callState) {
notificationManager.notify(CALL_NOTIFICATION_ID, notification) notificationManager.notify(CALL_NOTIFICATION_ID, notification)
} }
} }
}
fun cancelNotification() { fun cancelNotification() {
notificationManager.cancel(CALL_NOTIFICATION_ID) notificationManager.cancel(CALL_NOTIFICATION_ID)

View File

@@ -18,7 +18,9 @@ class CallService : InCallService() {
private val callListener = object : Call.Callback() { private val callListener = object : Call.Callback() {
override fun onStateChanged(call: Call, state: Int) { override fun onStateChanged(call: Call, state: Int) {
super.onStateChanged(call, state) super.onStateChanged(call, state)
if (state != Call.STATE_DISCONNECTED) { if (state == Call.STATE_DISCONNECTED || state == Call.STATE_DISCONNECTING) {
callNotificationManager.cancelNotification()
} else {
callNotificationManager.setupNotification() callNotificationManager.setupNotification()
} }
} }