From f34b3774e412eaf9d24598d2310cf68496d6fa5d Mon Sep 17 00:00:00 2001
From: Liviu Timar <65943217+liviu-timar@users.noreply.github.com>
Date: Wed, 9 Oct 2024 16:43:51 +0300
Subject: [PATCH] [PBE-6041] Fix mic muted in background bug (#1200)
* Change CallService type
* Add new AudioCallService and audioCallServiceConfig
* Improve inline docs and comments
* Restore CallService type
* Update KDocs and comments
---
.../api/stream-video-android-core.api | 1 +
.../src/main/AndroidManifest.xml | 31 ++++++++---------
.../video/android/core/StreamVideoBuilder.kt | 1 +
.../internal/service/AudioCallService.kt | 26 ++++++++++++++
.../internal/service/CallServiceConfig.kt | 34 ++++++++++++++++---
5 files changed, 72 insertions(+), 21 deletions(-)
create mode 100644 stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/AudioCallService.kt
diff --git a/stream-video-android-core/api/stream-video-android-core.api b/stream-video-android-core/api/stream-video-android-core.api
index 44e4b6f76d..84ad355e93 100644
--- a/stream-video-android-core/api/stream-video-android-core.api
+++ b/stream-video-android-core/api/stream-video-android-core.api
@@ -4239,6 +4239,7 @@ public final class io/getstream/video/android/core/notifications/internal/servic
}
public final class io/getstream/video/android/core/notifications/internal/service/CallServiceConfigKt {
+ public static final fun audioCallServiceConfig ()Lio/getstream/video/android/core/notifications/internal/service/CallServiceConfig;
public static final fun callServiceConfig ()Lio/getstream/video/android/core/notifications/internal/service/CallServiceConfig;
public static final fun livestreamAudioCallServiceConfig ()Lio/getstream/video/android/core/notifications/internal/service/CallServiceConfig;
public static final fun livestreamCallServiceConfig ()Lio/getstream/video/android/core/notifications/internal/service/CallServiceConfig;
diff --git a/stream-video-android-core/src/main/AndroidManifest.xml b/stream-video-android-core/src/main/AndroidManifest.xml
index 7360e764c4..b8258835b8 100644
--- a/stream-video-android-core/src/main/AndroidManifest.xml
+++ b/stream-video-android-core/src/main/AndroidManifest.xml
@@ -26,37 +26,32 @@
-
-
-
-
-
-
+
+
-
+
-
-
-
+
+
+
+
-
+
-
+
-
+
-
-
-
@@ -112,5 +106,10 @@
android:name=".notifications.internal.service.LivestreamViewerService"
android:foregroundServiceType="mediaPlayback"
android:exported="false" />
+
+
\ No newline at end of file
diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoBuilder.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoBuilder.kt
index 1994a351db..6ee266c5be 100644
--- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoBuilder.kt
+++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/StreamVideoBuilder.kt
@@ -74,6 +74,7 @@ import java.net.ConnectException
* @property ensureSingleInstance Verify that only 1 version of the video client exists. Prevents integration mistakes.
* @property videoDomain URL overwrite to allow for testing against a local instance of video.
* @property runForegroundServiceForCalls If set to true, when there is an active call the SDK will run a foreground service to keep the process alive. (default: true)
+ * @property callServiceConfig Configuration for the call foreground service. See [CallServiceConfig].
* @property localSfuAddress Local SFU address (IP:port) to be used for testing. Leave null if not needed.
* @property sounds Overwrite the default SDK sounds. See [Sounds].
* @property permissionCheck Used to check for system permission based on call capabilities. See [StreamPermissionCheck].
diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/AudioCallService.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/AudioCallService.kt
new file mode 100644
index 0000000000..2234044205
--- /dev/null
+++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/AudioCallService.kt
@@ -0,0 +1,26 @@
+/*
+ * Copyright (c) 2014-2024 Stream.io Inc. All rights reserved.
+ *
+ * Licensed under the Stream License;
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * https://github.com/GetStream/stream-video-android/blob/main/LICENSE
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package io.getstream.video.android.core.notifications.internal.service
+
+import android.content.pm.ServiceInfo
+import io.getstream.log.TaggedLogger
+import io.getstream.log.taggedLogger
+
+internal class AudioCallService : CallService() {
+ override val logger: TaggedLogger by taggedLogger("AudioCallService")
+ override val serviceType = ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
+}
diff --git a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/CallServiceConfig.kt b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/CallServiceConfig.kt
index 0226507d86..5083006d4f 100644
--- a/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/CallServiceConfig.kt
+++ b/stream-video-android-core/src/main/kotlin/io/getstream/video/android/core/notifications/internal/service/CallServiceConfig.kt
@@ -25,9 +25,15 @@ internal const val ANY_MARKER = "ALL_CALL_TYPES"
// API
/**
- * Configuration class for the call service.
+ * Configuration class for the call foreground service.
* @param runCallServiceInForeground If the call service should run in the foreground.
* @param callServicePerType A map of call service per type.
+ *
+ * @see callServiceConfig
+ * @see livestreamCallServiceConfig
+ * @see livestreamAudioCallServiceConfig
+ * @see livestreamGuestCallServiceConfig
+ * @see audioCallServiceConfig
*/
public data class CallServiceConfig(
val runCallServiceInForeground: Boolean = true,
@@ -38,7 +44,8 @@ public data class CallServiceConfig(
)
/**
- * Return a default configuration for the call service configuration.
+ * Returns the default call foreground service configuration.
+ * Uses: `FOREGROUND_SERVICE_TYPE_PHONE_CALL`.
*/
public fun callServiceConfig(): CallServiceConfig {
return CallServiceConfig(
@@ -50,7 +57,8 @@ public fun callServiceConfig(): CallServiceConfig {
}
/**
- * Return a default configuration for the call service configuration.
+ * Returns a foreground service configuration appropriate for livestream hosts.
+ * Uses: `FOREGROUND_SERVICE_TYPE_CAMERA` and `FOREGROUND_SERVICE_TYPE_MICROPHONE`.
*/
public fun livestreamCallServiceConfig(): CallServiceConfig {
return CallServiceConfig(
@@ -63,7 +71,8 @@ public fun livestreamCallServiceConfig(): CallServiceConfig {
}
/**
- * Return a default configuration for the call service configuration for livestream which has no camera
+ * Returns a foreground service configuration appropriate for audio-only livestream hosts.
+ * Uses: `FOREGROUND_SERVICE_TYPE_MICROPHONE`.
*/
public fun livestreamAudioCallServiceConfig(): CallServiceConfig {
return CallServiceConfig(
@@ -76,7 +85,8 @@ public fun livestreamAudioCallServiceConfig(): CallServiceConfig {
}
/**
- * Return a default configuration for the call service configuration.
+ * Returns a foreground service configuration appropriate for livestream viewers.
+ * Uses: `FOREGROUND_SERVICE_TYPE_MEDIA_PLAYBACK`.
*/
public fun livestreamGuestCallServiceConfig(): CallServiceConfig {
return CallServiceConfig(
@@ -89,6 +99,20 @@ public fun livestreamGuestCallServiceConfig(): CallServiceConfig {
)
}
+/**
+ * Returns a foreground service configuration appropriate for audio-only calls.
+ * Uses: `FOREGROUND_SERVICE_TYPE_MICROPHONE`.
+ */
+public fun audioCallServiceConfig(): CallServiceConfig {
+ return CallServiceConfig(
+ runCallServiceInForeground = true,
+ callServicePerType = mapOf(
+ Pair(ANY_MARKER, CallService::class.java),
+ Pair("audio_call", AudioCallService::class.java),
+ ),
+ )
+}
+
// Internal
internal fun resolveServiceClass(callId: StreamCallId, config: CallServiceConfig): Class<*> {
val callType = callId.type