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

#8964 Fix app crash on incoming call when running Android 14+ #8989

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions changelog.d/8964.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix incoming call crash on Android 14+. ([#8964](https://github.com/element-hq/element-android/issues/8964))
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,21 @@ class VectorCallActivity :
== PackageManager.PERMISSION_GRANTED) {
// Only start the service if the app is in the foreground
if (isAppInForeground()) {
Timber.tag(loggerTag.value).v("Starting microphone foreground service")
val intent = Intent(this, MicrophoneAccessService::class.java)
ContextCompat.startForegroundService(this, intent)
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 @@ -269,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
Loading