From 36a74f4912f0461920220fd2cdd5781eacf0398f Mon Sep 17 00:00:00 2001 From: Christian Rowlands Date: Mon, 13 Jan 2025 11:58:10 -0500 Subject: [PATCH] #8964 Fix app crash on incoming call when running Android 14+ --- changelog.d/8964.bugfix | 1 + .../vector/app/features/call/VectorCallActivity.kt | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 changelog.d/8964.bugfix diff --git a/changelog.d/8964.bugfix b/changelog.d/8964.bugfix new file mode 100644 index 00000000000..2b9144a8f5d --- /dev/null +++ b/changelog.d/8964.bugfix @@ -0,0 +1 @@ +Fix incoming call crash on Android 14+. ([#8964](https://github.com/element-hq/element-android/issues/8964)) diff --git a/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt b/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt index dcbb5e5d942..99fdfb2a489 100644 --- a/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt +++ b/vector/src/main/java/im/vector/app/features/call/VectorCallActivity.kt @@ -246,9 +246,16 @@ 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) + // 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") + } } else { Timber.tag(loggerTag.value).v("App is not in foreground; cannot start microphone service") }