Skip to content

Commit

Permalink
#8964 Start the MicrophoneAccessService during onPause if the call ha…
Browse files Browse the repository at this point in the history
…s been answered
  • Loading branch information
christianrowlands committed Jan 20, 2025
1 parent 36a74f4 commit af906ce
Showing 1 changed file with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -246,15 +246,20 @@ class VectorCallActivity :
== PackageManager.PERMISSION_GRANTED) {
// Only start the service if the app is in the foreground
if (isAppInForeground()) {
// Starting in Android 14, you can't create a microphone foreground service while your app is in
// the background. If we call startForegroundService the app will crash.
// https://github.com/element-hq/element-android/issues/8964
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
Timber.tag(loggerTag.value).v("Starting microphone foreground service")
val intent = Intent(this, MicrophoneAccessService::class.java)
ContextCompat.startForegroundService(this, intent)
} else {
Timber.tag(loggerTag.value).v("App is in running Android 14+; cannot start microphone service")
withState(callViewModel) {
// Starting in Android 14, you can't create a microphone foreground service while your app is in
// the background. If we call startForegroundService while the call state is ringing (i.e. the
// user has not interacted with the device at all) the app will crash. Make sure the call has
// already been answered before starting the MicrophoneAccessService
// https://github.com/element-hq/element-android/issues/8964
val callState = it.callState.invoke()
if (callState !is CallState.LocalRinging && callState !is CallState.Ended) {
Timber.tag(loggerTag.value).v("Starting microphone foreground service")
val intent = Intent(this, MicrophoneAccessService::class.java)
ContextCompat.startForegroundService(this, intent)
} else {
Timber.tag(loggerTag.value).v("Call is in ringing or ended state; cannot start microphone service. callState: $callState")
}
}
} else {
Timber.tag(loggerTag.value).v("App is not in foreground; cannot start microphone service")
Expand All @@ -276,6 +281,9 @@ class VectorCallActivity :

override fun onPause() {
super.onPause()

// Start the microphone service to keep access to the microphone when the call is in the background
// https://github.com/element-hq/element-android/issues/8881
startMicrophoneService()
}

Expand Down

0 comments on commit af906ce

Please sign in to comment.