Skip to content

Commit

Permalink
Add audio only CallService to avoid requiring CAMERA permission (#…
Browse files Browse the repository at this point in the history
…1171)

* Add audio only livestream call service.

* Apidump
  • Loading branch information
aleksandar-apostolov authored Sep 5, 2024
1 parent 9b4ffee commit efbe440
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4238,6 +4238,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 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;
public static final fun livestreamGuestCallServiceConfig ()Lio/getstream/video/android/core/notifications/internal/service/CallServiceConfig;
}
Expand Down
5 changes: 5 additions & 0 deletions stream-video-android-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,11 @@
android:foregroundServiceType="camera|microphone"
android:exported="false" />

<service
android:name=".notifications.internal.service.LivestreamAudioCallService"
android:foregroundServiceType="microphone"
android:exported="false" />

<service
android:name=".notifications.internal.service.LivestreamViewerService"
android:foregroundServiceType="mediaPlayback"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ public fun livestreamCallServiceConfig(): CallServiceConfig {
)
}

/**
* Return a default configuration for the call service configuration for livestream which has no camera
*/
public fun livestreamAudioCallServiceConfig(): CallServiceConfig {
return CallServiceConfig(
runCallServiceInForeground = true,
callServicePerType = mapOf(
Pair(ANY_MARKER, CallService::class.java),
Pair("livestream", LivestreamAudioCallService::class.java),
),
)
}

/**
* Return a default configuration for the call service configuration.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ internal open class LivestreamCallService : CallService() {
override val serviceType = ServiceInfo.FOREGROUND_SERVICE_TYPE_CAMERA or ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
}

/**
* Due to the nature of the livestream calls, the service that is used is of different type.
*/
internal open class LivestreamAudioCallService : CallService() {
override val logger: TaggedLogger by taggedLogger("LivestreamHostCallService")
override val serviceType = ServiceInfo.FOREGROUND_SERVICE_TYPE_MICROPHONE
}

/**
* Due to the nature of the livestream calls, the service that is used is of different type.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,24 @@ class CallServiceConfigTest {
assertEquals(LivestreamViewerService::class.java, livestreamServiceClass)
assertEquals(AudioAttributes.USAGE_MEDIA, audioUsage)
}

@Test
fun `livestreamAudioCallServiceConfig should return correct default configuration`() {
// Given
val config = livestreamAudioCallServiceConfig()

// When
val runInForeground = config.runCallServiceInForeground
val servicePerTypeSize = config.callServicePerType.size
val hostServiceClass = config.callServicePerType[ANY_MARKER]
val livestreamServiceClass = config.callServicePerType["livestream"]
val audioUsage = config.audioUsage

// Then
assertEquals(true, runInForeground)
assertEquals(2, servicePerTypeSize)
assertEquals(CallService::class.java, hostServiceClass)
assertEquals(LivestreamAudioCallService::class.java, livestreamServiceClass)
assertEquals(AudioAttributes.USAGE_VOICE_COMMUNICATION, audioUsage)
}
}

0 comments on commit efbe440

Please sign in to comment.