diff --git a/changelog.d/4781.bugfix b/changelog.d/4781.bugfix new file mode 100644 index 0000000000..7ac6e62448 --- /dev/null +++ b/changelog.d/4781.bugfix @@ -0,0 +1 @@ +Tentative fix for the speaker being used instead of earpiece for the outgoing call ringtone on lineage os \ No newline at end of file diff --git a/vector/src/main/java/im/vector/app/core/services/CallRingPlayer.kt b/vector/src/main/java/im/vector/app/core/services/CallRingPlayer.kt index 524ff37914..b2d9382aae 100644 --- a/vector/src/main/java/im/vector/app/core/services/CallRingPlayer.kt +++ b/vector/src/main/java/im/vector/app/core/services/CallRingPlayer.kt @@ -28,6 +28,8 @@ import android.os.VibrationEffect import android.os.Vibrator import androidx.core.content.getSystemService import im.vector.app.R +import im.vector.app.features.call.audio.CallAudioManager.Mode +import im.vector.app.features.call.webrtc.WebRtcCallManager import im.vector.app.features.notifications.NotificationUtils import org.matrix.android.sdk.api.extensions.orFalse import timber.log.Timber @@ -94,7 +96,8 @@ class CallRingPlayerIncoming( } class CallRingPlayerOutgoing( - context: Context + context: Context, + private val callManager: WebRtcCallManager ) { private val applicationContext = context.applicationContext @@ -102,7 +105,7 @@ class CallRingPlayerOutgoing( private var player: MediaPlayer? = null fun start() { - applicationContext.getSystemService()?.mode = AudioManager.MODE_IN_COMMUNICATION + callManager.setAudioModeToCallType() player?.release() player = createPlayer() if (player != null) { @@ -120,6 +123,11 @@ class CallRingPlayerOutgoing( } } + private fun WebRtcCallManager.setAudioModeToCallType() { + val callMode = if (currentCall.get()?.mxCall?.isVideoCall.orFalse()) Mode.VIDEO_CALL else Mode.AUDIO_CALL + audioManager.setMode(callMode) + } + fun stop() { player?.release() player = null diff --git a/vector/src/main/java/im/vector/app/core/services/CallService.kt b/vector/src/main/java/im/vector/app/core/services/CallService.kt index ebda43e024..4dd95fd49a 100644 --- a/vector/src/main/java/im/vector/app/core/services/CallService.kt +++ b/vector/src/main/java/im/vector/app/core/services/CallService.kt @@ -84,7 +84,7 @@ class CallService : VectorService() { super.onCreate() notificationManager = NotificationManagerCompat.from(this) callRingPlayerIncoming = CallRingPlayerIncoming(applicationContext, notificationUtils) - callRingPlayerOutgoing = CallRingPlayerOutgoing(applicationContext) + callRingPlayerOutgoing = CallRingPlayerOutgoing(applicationContext, callManager) } override fun onDestroy() {