1
0
mirror of https://github.com/vector-im/riotX-android synced 2025-10-06 00:02:48 +02:00

Compare commits

...

3 Commits

Author SHA1 Message Date
Benoit Marty
6bffe65053 Tell the system not to defer this notification
Even if this is not necessary according to https://developer.android.com/guide/components/foreground-services#notification-immediate
2022-12-06 17:38:46 +01:00
Benoit Marty
ea03168769 Add comment. 2022-12-06 17:06:35 +01:00
Benoit Marty
2d4ee44854 Increase log level 2022-12-06 17:06:35 +01:00
2 changed files with 12 additions and 8 deletions

View File

@@ -52,6 +52,8 @@ private val loggerTag = LoggerTag("CallService", LoggerTag.VOIP)
/**
* Foreground service to manage calls.
* To see a notification when Service cannot be started in foreground (from background):
* adb shell device_config put activity_manager default_fgs_starts_restriction_notification_enabled true
*/
@AndroidEntryPoint
class CallAndroidService : VectorAndroidService() {
@@ -99,7 +101,7 @@ class CallAndroidService : VectorAndroidService() {
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Timber.tag(loggerTag.value).v("onStartCommand $intent")
Timber.tag(loggerTag.value).d("onStartCommand $intent")
if (mediaSession == null) {
mediaSession = MediaSessionCompat(applicationContext, CallAndroidService::class.java.name).apply {
setCallback(mediaSessionButtonCallback)
@@ -149,7 +151,7 @@ class CallAndroidService : VectorAndroidService() {
*
*/
private fun displayIncomingCallNotification(intent: Intent) {
Timber.tag(loggerTag.value).v("displayIncomingCallNotification $intent")
Timber.tag(loggerTag.value).d("displayIncomingCallNotification $intent")
val callId = intent.getStringExtra(EXTRA_CALL_ID) ?: ""
val call = callManager.getCallById(callId) ?: return Unit.also {
handleUnexpectedState(callId)
@@ -157,7 +159,7 @@ class CallAndroidService : VectorAndroidService() {
val callInformation = call.toCallInformation()
val isVideoCall = call.mxCall.isVideoCall
val fromBg = intent.getBooleanExtra(EXTRA_IS_IN_BG, false)
Timber.tag(loggerTag.value).v("displayIncomingCallNotification : display the dedicated notification")
Timber.tag(loggerTag.value).d("displayIncomingCallNotification : display the dedicated notification")
val incomingCallAlert = IncomingCallAlert(callId,
shouldBeDisplayedIn = { activity ->
if (activity is VectorCallActivity) {
@@ -196,7 +198,7 @@ class CallAndroidService : VectorAndroidService() {
alertManager.cancelAlert(callId)
val terminatedCall = knownCalls.remove(callId)
if (terminatedCall == null) {
Timber.tag(loggerTag.value).v("Call terminated for unknown call $callId")
Timber.tag(loggerTag.value).d("Call terminated for unknown call $callId")
handleUnexpectedState(callId)
return
}
@@ -204,7 +206,7 @@ class CallAndroidService : VectorAndroidService() {
val notificationId = callId.hashCode()
startForegroundCompat(notificationId, notification)
if (knownCalls.isEmpty()) {
Timber.tag(loggerTag.value).v("No more call, stop the service")
Timber.tag(loggerTag.value).d("No more call, stop the service")
stopForegroundCompat()
mediaSession?.isActive = false
myStopSelf()
@@ -231,7 +233,7 @@ class CallAndroidService : VectorAndroidService() {
handleUnexpectedState(callId)
}
val callInformation = call.toCallInformation()
Timber.tag(loggerTag.value).v("displayOutgoingCallNotification : display the dedicated notification")
Timber.tag(loggerTag.value).d("displayOutgoingCallNotification : display the dedicated notification")
val notification = notificationUtils.buildOutgoingRingingCallNotification(
call = call,
title = callInformation.opponentMatrixItem?.getBestName() ?: callInformation.opponentUserId
@@ -248,7 +250,7 @@ class CallAndroidService : VectorAndroidService() {
* Display a call in progress notification.
*/
private fun displayCallInProgressNotification(intent: Intent) {
Timber.tag(loggerTag.value).v("displayCallInProgressNotification")
Timber.tag(loggerTag.value).d("displayCallInProgressNotification")
val callId = intent.getStringExtra(EXTRA_CALL_ID) ?: ""
connectedCallIds.add(callId)
val call = callManager.getCallById(callId) ?: return Unit.also {
@@ -269,7 +271,7 @@ class CallAndroidService : VectorAndroidService() {
}
private fun handleUnexpectedState(callId: String?) {
Timber.tag(loggerTag.value).v("Fallback to clear everything")
Timber.tag(loggerTag.value).d("Fallback to clear everything")
callRingPlayerIncoming?.stop()
callRingPlayerOutgoing?.stop()
val notification = notificationUtils.buildCallEndedNotification(false)

View File

@@ -358,6 +358,8 @@ class NotificationUtils @Inject constructor(
builder.priority = NotificationCompat.PRIORITY_HIGH
builder.setFullScreenIntent(contentPendingIntent, true)
}
// Tell the system not to defer this notification
builder.foregroundServiceBehavior = NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE
return builder.build()
}