From 1a36c88f72534e48d3972689a68b67f0fc60f16c Mon Sep 17 00:00:00 2001 From: Stanislav Dmitrenko <7953703+avently@users.noreply.github.com> Date: Wed, 31 Aug 2022 23:50:08 +0300 Subject: [PATCH] android: prevent orientation change in calls (#995) - orientation will be locked in calls to portrait and then returned back - calls ends audio session when they will be ended --- .../chat/simplex/app/views/call/CallView.kt | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/apps/android/app/src/main/java/chat/simplex/app/views/call/CallView.kt b/apps/android/app/src/main/java/chat/simplex/app/views/call/CallView.kt index b6f529600b..2b0f39a346 100644 --- a/apps/android/app/src/main/java/chat/simplex/app/views/call/CallView.kt +++ b/apps/android/app/src/main/java/chat/simplex/app/views/call/CallView.kt @@ -1,7 +1,10 @@ package chat.simplex.app.views.call import android.Manifest +import android.annotation.SuppressLint +import android.app.Activity import android.content.Context +import android.content.pm.ActivityInfo import android.media.AudioManager import android.util.Log import android.view.ViewGroup @@ -41,6 +44,7 @@ import kotlinx.coroutines.launch import kotlinx.serialization.decodeFromString import kotlinx.serialization.encodeToString +@SuppressLint("SourceLockedOrientationActivity") @Composable fun ActiveCallView(chatModel: ChatModel) { BackHandler(onBack = { @@ -122,6 +126,17 @@ fun ActiveCallView(chatModel: ChatModel) { val call = chatModel.activeCall.value if (call != null) ActiveCallOverlay(call, chatModel) } + + val context = LocalContext.current + DisposableEffect(Unit) { + val activity = context as? Activity ?: return@DisposableEffect onDispose {} + // Lock orientation to portrait in order to have good experience with calls + activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + onDispose { + // Unlock orientation + activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED + } + } } @Composable @@ -337,6 +352,8 @@ fun WebRTCView(callCommand: MutableState, onResponse: (WVAPIMessa val wv = webView.value if (wv != null) processCommand(wv, WCallCommand.End) lifecycleOwner.lifecycle.removeObserver(observer) + webView.value?.destroy() + webView.value = null } } LaunchedEffect(callCommand.value, webView.value) {