Update call foreground service types when disabling/enabling video

This commit is contained in:
Sylvain Berfini 2024-04-16 11:11:09 +02:00
parent 7e0208f8e8
commit 8c7c4bee0d
3 changed files with 20 additions and 5 deletions

View file

@ -174,7 +174,7 @@ dependencies {
// https://github.com/Baseflow/PhotoView/blob/master/LICENSE Apache v2.0
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
implementation platform('com.google.firebase:firebase-bom:32.7.2')
implementation platform('com.google.firebase:firebase-bom:32.8.1')
implementation 'com.google.firebase:firebase-messaging'
implementation 'com.google.firebase:firebase-crashlytics-ndk'

View file

@ -45,6 +45,7 @@
android:localeConfig="@xml/locales_config"
tools:targetApi="34">
<!-- Required for chat message notifications to be displayed in Android auto -->
<meta-data
android:name="com.google.android.gms.car.application"
android:resource="@xml/automotive_app_desc"/>
@ -126,7 +127,7 @@
<service
android:name=".core.CoreForegroundService"
android:exported="false"
android:foregroundServiceType="phoneCall|camera|microphone|dataSync"
android:foregroundServiceType="phoneCall|camera|microphone"
android:stopWithTask="false"
android:label="@string/app_name" />

View file

@ -112,6 +112,7 @@ class NotificationsManager @MainThread constructor(private val context: Context)
state: Call.State?,
message: String
) {
Log.i("$TAG Call state changed: [$state]")
when (state) {
Call.State.IncomingReceived, Call.State.IncomingEarlyMedia -> {
Log.i(
@ -132,6 +133,15 @@ class NotificationsManager @MainThread constructor(private val context: Context)
)
showCallNotification(call, false)
}
Call.State.Updating -> {
val notifiable = getNotifiableForCall(call)
if (notifiable.notificationId == currentForegroundServiceNotificationId) {
Log.i(
"$TAG Update foreground service type in case video was enabled/disabled since last time"
)
startCallForeground(call)
}
}
Call.State.End, Call.State.Error -> {
val remoteSipAddress = call.remoteAddress
if (call.dir == Call.Dir.Incoming && currentlyRingingCallRemoteAddress?.weakEqual(
@ -598,10 +608,14 @@ class NotificationsManager @MainThread constructor(private val context: Context)
) {
mask = mask or Compatibility.FOREGROUND_SERVICE_TYPE_MICROPHONE
Log.i(
"$TAG RECORD_AUDIO permission has been granted, adding FOREGROUND_SERVICE_TYPE_MICROPHONE"
"$TAG RECORD_AUDIO permission has been granted, adding FOREGROUND_SERVICE_TYPE_MICROPHONE to foreground service types mask"
)
}
if (call.currentParams.isVideoEnabled) {
val isSendingVideo = when (call.currentParams.videoDirection) {
MediaDirection.SendRecv, MediaDirection.SendOnly -> true
else -> false
}
if (call.currentParams.isVideoEnabled && isSendingVideo) {
if (ActivityCompat.checkSelfPermission(
context,
Manifest.permission.CAMERA
@ -609,7 +623,7 @@ class NotificationsManager @MainThread constructor(private val context: Context)
) {
mask = mask or Compatibility.FOREGROUND_SERVICE_TYPE_CAMERA
Log.i(
"$TAG CAMERA permission has been granted, adding FOREGROUND_SERVICE_TYPE_CAMERA"
"$TAG CAMERA permission has been granted, adding FOREGROUND_SERVICE_TYPE_CAMERA to foreground service types mask"
)
}
}