From d57758432ea6da1699dc585151972f775eb98e25 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 22 Nov 2024 10:36:35 +0100 Subject: [PATCH 1/3] Fix crash when resuming the call from the notification. Fixes #3905 --- .../android/features/call/impl/ui/ElementCallActivity.kt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt index 0495f8ec7d..8b6d1e45bd 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt @@ -200,12 +200,14 @@ class ElementCallActivity : Timber.tag(loggerTag.value).d("Set the call type and create the presenter") webViewTarget.value = callType presenter = presenterFactory.create(callType!!, this) + } else if (callType == null) { + Timber.tag(loggerTag.value).d("Coming back from notification, do nothing") } else if (callType != currentCallType) { Timber.tag(loggerTag.value).d("User starts another call, restart the Activity") setIntent(intent) recreate() } else { - Timber.tag(loggerTag.value).d("Coming back from notification, do nothing") + Timber.tag(loggerTag.value).d("Other case, do nothing") } } From 75202f1b8f98084bc878f9f6019ce57883daf380 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 22 Nov 2024 10:38:04 +0100 Subject: [PATCH 2/3] Protect from Presenter not being initialized by setCallType. --- .../android/features/call/impl/ui/ElementCallActivity.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt index 8b6d1e45bd..08ad912b54 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt @@ -44,6 +44,7 @@ import io.element.android.features.call.impl.pip.PictureInPictureState import io.element.android.features.call.impl.pip.PipView import io.element.android.features.call.impl.services.CallForegroundService import io.element.android.features.call.impl.utils.CallIntentDataParser +import io.element.android.libraries.architecture.Presenter import io.element.android.libraries.architecture.bindings import io.element.android.libraries.core.log.logger.LoggerTag import io.element.android.libraries.designsystem.theme.ElementThemeApp @@ -62,7 +63,7 @@ class ElementCallActivity : @Inject lateinit var appPreferencesStore: AppPreferencesStore @Inject lateinit var pictureInPicturePresenter: PictureInPicturePresenter - private lateinit var presenter: CallScreenPresenter + private lateinit var presenter: Presenter private lateinit var audioManager: AudioManager @@ -92,6 +93,10 @@ class ElementCallActivity : ) setCallType(intent) + // If presenter is not created at this point, it means we have no call to display, the Activity is finishing, so return early + if (!::presenter.isInitialized) { + return + } if (savedInstanceState == null) { updateUiMode(resources.configuration) From 0a1c441a79b54c61b9571593bc5a9d6bbe2aec35 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 22 Nov 2024 11:13:13 +0100 Subject: [PATCH 3/3] Update the code to improve readability --- .../call/impl/ui/ElementCallActivity.kt | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt index 08ad912b54..2622c48529 100644 --- a/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt +++ b/features/call/impl/src/main/kotlin/io/element/android/features/call/impl/ui/ElementCallActivity.kt @@ -198,21 +198,26 @@ class ElementCallActivity : ?: intent.dataString?.let(::parseUrl)?.let(::ExternalUrl) } val currentCallType = webViewTarget.value - if (currentCallType == null && callType == null) { - Timber.tag(loggerTag.value).d("Re-opened the activity but we have no url to load or a cached one, finish the activity") - finish() - } else if (currentCallType == null) { - Timber.tag(loggerTag.value).d("Set the call type and create the presenter") - webViewTarget.value = callType - presenter = presenterFactory.create(callType!!, this) - } else if (callType == null) { - Timber.tag(loggerTag.value).d("Coming back from notification, do nothing") - } else if (callType != currentCallType) { - Timber.tag(loggerTag.value).d("User starts another call, restart the Activity") - setIntent(intent) - recreate() + if (currentCallType == null) { + if (callType == null) { + Timber.tag(loggerTag.value).d("Re-opened the activity but we have no url to load or a cached one, finish the activity") + finish() + } else { + Timber.tag(loggerTag.value).d("Set the call type and create the presenter") + webViewTarget.value = callType + presenter = presenterFactory.create(callType, this) + } } else { - Timber.tag(loggerTag.value).d("Other case, do nothing") + if (callType == null) { + Timber.tag(loggerTag.value).d("Coming back from notification, do nothing") + } else if (callType != currentCallType) { + Timber.tag(loggerTag.value).d("User starts another call, restart the Activity") + setIntent(intent) + recreate() + } else { + // Starting the same call again, should not happen, the UI is preventing this. But maybe when using external links. + Timber.tag(loggerTag.value).d("Starting the same call again, do nothing") + } } }