Merge pull request #467 from Naveen3Singh/notification_fix

Persistent notification fix
This commit is contained in:
Tibor Kaputa 2022-10-25 10:11:09 +02:00 committed by GitHub
commit 28e2ce0487
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View File

@ -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? {

View File

@ -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)
}
}
}

View File

@ -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()
}
}