@@ -50,7 +50,7 @@ private val loggerTag = LoggerTag("CallService", LoggerTag.VOIP)
50
50
class CallService : VectorService () {
51
51
52
52
private val connections = mutableMapOf<String , CallConnection >()
53
- private val knownCalls = mutableSetOf< CallInformation >()
53
+ private val knownCalls = mutableMapOf< String , CallInformation >()
54
54
private val connectedCallIds = mutableSetOf<String >()
55
55
56
56
private lateinit var notificationManager: NotificationManagerCompat
@@ -190,28 +190,30 @@ class CallService : VectorService() {
190
190
} else {
191
191
notificationManager.notify(callId.hashCode(), notification)
192
192
}
193
- knownCalls.add( callInformation)
193
+ knownCalls[callId] = callInformation
194
194
}
195
195
196
196
private fun handleCallTerminated (intent : Intent ) {
197
197
val callId = intent.getStringExtra(EXTRA_CALL_ID ) ? : " "
198
198
val endCallReason = intent.getSerializableExtra(EXTRA_END_CALL_REASON ) as EndCallReason
199
199
val rejected = intent.getBooleanExtra(EXTRA_END_CALL_REJECTED , false )
200
200
alertManager.cancelAlert(callId)
201
- val terminatedCall = knownCalls.firstOrNull { it. callId == callId }
201
+ val terminatedCall = knownCalls.remove( callId)
202
202
if (terminatedCall == null ) {
203
- Timber .tag(loggerTag.value).v(" Call terminated for unknown call $callId $ " )
203
+ Timber .tag(loggerTag.value).v(" Call terminated for unknown call $callId " )
204
204
handleUnexpectedState(callId)
205
205
return
206
206
}
207
- knownCalls.remove(terminatedCall)
207
+ val notification = notificationUtils.buildCallEndedNotification(false )
208
+ val notificationId = callId.hashCode()
209
+ startForeground(notificationId, notification)
208
210
if (knownCalls.isEmpty()) {
211
+ Timber .tag(loggerTag.value).v(" No more call, stop the service" )
212
+ stopForeground(true )
209
213
mediaSession?.isActive = false
210
214
myStopSelf()
211
215
}
212
216
val wasConnected = connectedCallIds.remove(callId)
213
- val notification = notificationUtils.buildCallEndedNotification(terminatedCall.isVideoCall)
214
- notificationManager.notify(callId.hashCode(), notification)
215
217
if (! wasConnected && ! terminatedCall.isOutgoing && ! rejected && endCallReason != EndCallReason .ANSWERED_ELSEWHERE ) {
216
218
val missedCallNotification = notificationUtils.buildCallMissedNotification(terminatedCall)
217
219
notificationManager.notify(MISSED_CALL_TAG , terminatedCall.nativeRoomId.hashCode(), missedCallNotification)
@@ -243,7 +245,7 @@ class CallService : VectorService() {
243
245
} else {
244
246
notificationManager.notify(callId.hashCode(), notification)
245
247
}
246
- knownCalls.add( callInformation)
248
+ knownCalls[callId] = callInformation
247
249
}
248
250
249
251
/* *
@@ -267,18 +269,19 @@ class CallService : VectorService() {
267
269
} else {
268
270
notificationManager.notify(callId.hashCode(), notification)
269
271
}
270
- knownCalls.add( callInformation)
272
+ knownCalls[callId] = callInformation
271
273
}
272
274
273
275
private fun handleUnexpectedState (callId : String? ) {
274
276
Timber .tag(loggerTag.value).v(" Fallback to clear everything" )
275
277
callRingPlayerIncoming?.stop()
276
278
callRingPlayerOutgoing?.stop()
279
+ val notification = notificationUtils.buildCallEndedNotification(false )
277
280
if (callId != null ) {
278
- notificationManager.cancel(callId.hashCode())
281
+ startForeground(callId.hashCode(), notification)
282
+ } else {
283
+ startForeground(DEFAULT_NOTIFICATION_ID , notification)
279
284
}
280
- val notification = notificationUtils.buildCallEndedNotification(false )
281
- startForeground(DEFAULT_NOTIFICATION_ID , notification)
282
285
if (knownCalls.isEmpty()) {
283
286
mediaSession?.isActive = false
284
287
myStopSelf()
@@ -371,7 +374,7 @@ class CallService : VectorService() {
371
374
putExtra(EXTRA_END_CALL_REASON , endCallReason)
372
375
putExtra(EXTRA_END_CALL_REJECTED , rejected)
373
376
}
374
- ContextCompat .startForegroundService(context, intent)
377
+ context.startService( intent)
375
378
}
376
379
}
377
380
0 commit comments