Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AND-357] Avoid enabling mic when capabilities don't allow it #1311

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -367,11 +367,17 @@ class MicrophoneManager(
// API
/** Enable the audio, the rtc engine will automatically inform the SFU */
internal fun enable(fromUser: Boolean = true) {
enforceSetup {
if (fromUser) {
_status.value = DeviceStatus.Enabled
val canUserSendAudio = with(mediaManager.call.state) {
ownCapabilities.value.contains(OwnCapability.SendAudio)
}

if (canUserSendAudio) {
enforceSetup {
if (fromUser) {
_status.value = DeviceStatus.Enabled
}
mediaManager.audioTrack.trySetEnabled(true)
}
mediaManager.audioTrack.trySetEnabled(true)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package io.getstream.video.android.core
import android.content.Context
import android.media.AudioAttributes
import android.media.AudioManager
import io.getstream.android.video.generated.models.OwnCapability
import io.getstream.video.android.core.audio.AudioSwitchHandler
import io.mockk.every
import io.mockk.mockk
Expand Down Expand Up @@ -47,14 +48,14 @@ class MicrophoneManagerTest {
every { microphoneManager.setup(capture(slot)) } answers { slot.captured.invoke() }
every {
microphoneManager["ifAudioHandlerInitialized"](
any<
(
AudioSwitchHandler,
) -> Unit,
>(),
any<(AudioSwitchHandler) -> Unit>(),
)
} answers { true }

val mockCallState = mockk<CallState>(relaxed = true)
every { mediaManager.call.state } returns mockCallState
every { mockCallState.ownCapabilities.value } returns listOf(OwnCapability.SendAudio)

// When
microphoneManager.enable() // 1
microphoneManager.select(null) // 2
Expand Down Expand Up @@ -135,8 +136,12 @@ class MicrophoneManagerTest {
val microphoneManager = MicrophoneManager(mediaManager, audioUsage)
val spyMicrophoneManager = spyk(microphoneManager)
val mockContext = mockk<Context>(relaxed = true)
val mockCallState = mockk<CallState>(relaxed = true)

every { mediaManager.context } returns mockContext
every { mockContext.getSystemService(any()) } returns mockk<AudioManager>(relaxed = true)
every { mediaManager.call.state } returns mockCallState
every { mockCallState.ownCapabilities.value } returns listOf(OwnCapability.SendAudio)

val slot = slot<() -> Unit>()
every { spyMicrophoneManager.setup(capture(slot)) } answers { slot.captured.invoke() }
Expand Down
Loading