From 820e62da150863fcf7a4de93e29145963ed51bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Saleniuk?= Date: Fri, 24 May 2024 14:28:47 +0200 Subject: [PATCH 1/4] fix: one on one call could not be established on staging env using beta build --- app/build.gradle.kts | 1 + .../main/kotlin/com/wire/android/WireApplication.kt | 10 ++++++++++ .../main/kotlin/com/wire/android/ui/WireActivity.kt | 1 - .../com/wire/android/util/CurrentScreenManager.kt | 5 +++++ gradle/libs.versions.toml | 1 + 5 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/build.gradle.kts b/app/build.gradle.kts index 0514dcb80a2..bae74e567ec 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -130,6 +130,7 @@ dependencies { implementation(libs.androidx.lifecycle.viewModel) implementation(libs.androidx.lifecycle.viewModelCompose) implementation(libs.androidx.lifecycle.liveData) + implementation(libs.androidx.lifecycle.process) implementation(libs.androidx.lifecycle.runtime) implementation(libs.androidx.lifecycle.viewModelSavedState) diff --git a/app/src/main/kotlin/com/wire/android/WireApplication.kt b/app/src/main/kotlin/com/wire/android/WireApplication.kt index 432b8d95170..1e4e54b44d4 100644 --- a/app/src/main/kotlin/com/wire/android/WireApplication.kt +++ b/app/src/main/kotlin/com/wire/android/WireApplication.kt @@ -22,11 +22,13 @@ import android.app.Application import android.content.ComponentCallbacks2 import android.os.Build import android.os.StrictMode +import androidx.lifecycle.ProcessLifecycleOwner import androidx.work.Configuration import co.touchlab.kermit.platformLogWriter import com.wire.android.datastore.GlobalDataStore import com.wire.android.di.ApplicationScope import com.wire.android.di.KaliumCoreLogic +import com.wire.android.util.CurrentScreenManager import com.wire.android.util.DataDogLogger import com.wire.android.util.LogFileWriter import com.wire.android.util.getGitBuildId @@ -39,8 +41,10 @@ import com.wire.kalium.logic.CoreLogic import dagger.Lazy import dagger.hilt.android.HiltAndroidApp import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.first import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import javax.inject.Inject @HiltAndroidApp @@ -69,6 +73,9 @@ class WireApplication : Application(), Configuration.Provider { @ApplicationScope lateinit var globalAppScope: CoroutineScope + @Inject + lateinit var currentScreenManager: CurrentScreenManager + override val workManagerConfiguration: Configuration get() = Configuration.Builder() .setWorkerFactory(wireWorkerFactory.get()) @@ -84,6 +91,9 @@ class WireApplication : Application(), Configuration.Provider { initializeApplicationLoggingFrameworks() appLogger.i("$TAG app lifecycle") + withContext(Dispatchers.Main) { + ProcessLifecycleOwner.get().lifecycle.addObserver(currentScreenManager) + } connectionPolicyManager.get().startObservingAppLifecycle() appLogger.i("$TAG api version update") diff --git a/app/src/main/kotlin/com/wire/android/ui/WireActivity.kt b/app/src/main/kotlin/com/wire/android/ui/WireActivity.kt index 9878749fc2e..4025bb05ebb 100644 --- a/app/src/main/kotlin/com/wire/android/ui/WireActivity.kt +++ b/app/src/main/kotlin/com/wire/android/ui/WireActivity.kt @@ -149,7 +149,6 @@ class WireActivity : AppCompatActivity() { super.onCreate(savedInstanceState) splashScreen.setKeepOnScreenCondition { shouldKeepSplashOpen } - lifecycle.addObserver(currentScreenManager) WindowCompat.setDecorFitsSystemWindows(window, false) lifecycleScope.launch(Dispatchers.Default) { diff --git a/app/src/main/kotlin/com/wire/android/util/CurrentScreenManager.kt b/app/src/main/kotlin/com/wire/android/util/CurrentScreenManager.kt index a2d69dc3e99..8e39bcc6719 100644 --- a/app/src/main/kotlin/com/wire/android/util/CurrentScreenManager.kt +++ b/app/src/main/kotlin/com/wire/android/util/CurrentScreenManager.kt @@ -104,6 +104,11 @@ class CurrentScreenManager @Inject constructor( appLogger.i("${TAG}: onResume called") } + override fun onPause(owner: LifecycleOwner) { + super.onPause(owner) + appLogger.i("${TAG}: onPause called") + } + override fun onStart(owner: LifecycleOwner) { super.onStart(owner) appLogger.i("${TAG}: onStart called") diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 32ae97c1b02..fe23043e22d 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -156,6 +156,7 @@ firebase-fcm = { module = "com.google.firebase:firebase-messaging-ktx" } ## AndroidX - Lifecycle androidx-lifecycle-liveData = { module = "androidx.lifecycle:lifecycle-livedata-ktx", version.ref = "androidx-lifecycle" } +androidx-lifecycle-process = { module = "androidx.lifecycle:lifecycle-process", version.ref = "androidx-lifecycle" } androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "androidx-lifecycle" } androidx-lifecycle-viewModel = { module = "androidx.lifecycle:lifecycle-viewmodel-ktx", version.ref = "androidx-lifecycle" } androidx-lifecycle-viewModelCompose = { module = "androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidx-lifecycle" } From ff90a0ea8d0d6fc535f0a8f3168868869f365d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Saleniuk?= Date: Fri, 24 May 2024 14:34:55 +0200 Subject: [PATCH 2/4] remove onResume and onPause - they are not used --- .../com/wire/android/util/CurrentScreenManager.kt | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/util/CurrentScreenManager.kt b/app/src/main/kotlin/com/wire/android/util/CurrentScreenManager.kt index 8e39bcc6719..31a8ce88979 100644 --- a/app/src/main/kotlin/com/wire/android/util/CurrentScreenManager.kt +++ b/app/src/main/kotlin/com/wire/android/util/CurrentScreenManager.kt @@ -99,16 +99,6 @@ class CurrentScreenManager @Inject constructor( */ fun isAppVisibleFlow(): StateFlow = isApplicationVisibleFlow - override fun onResume(owner: LifecycleOwner) { - super.onResume(owner) - appLogger.i("${TAG}: onResume called") - } - - override fun onPause(owner: LifecycleOwner) { - super.onPause(owner) - appLogger.i("${TAG}: onPause called") - } - override fun onStart(owner: LifecycleOwner) { super.onStart(owner) appLogger.i("${TAG}: onStart called") From 7d1de23f312d7063f7b4dc1210f6521fd4771941 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Saleniuk?= Date: Fri, 24 May 2024 15:27:47 +0200 Subject: [PATCH 3/4] remove CurrentScreenManager from OngoingCallViewModel --- .../android/ui/calling/ongoing/OngoingCallViewModel.kt | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/app/src/main/kotlin/com/wire/android/ui/calling/ongoing/OngoingCallViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/calling/ongoing/OngoingCallViewModel.kt index 8792a0d8356..6b6551de0ad 100644 --- a/app/src/main/kotlin/com/wire/android/ui/calling/ongoing/OngoingCallViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/calling/ongoing/OngoingCallViewModel.kt @@ -28,8 +28,6 @@ import com.wire.android.appLogger import com.wire.android.datastore.GlobalDataStore import com.wire.android.di.CurrentAccount import com.wire.android.ui.calling.model.UICallParticipant -import com.wire.android.util.CurrentScreen -import com.wire.android.util.CurrentScreenManager import com.wire.kalium.logic.data.call.Call import com.wire.kalium.logic.data.call.CallClient import com.wire.kalium.logic.data.call.VideoState @@ -58,7 +56,6 @@ class OngoingCallViewModel @AssistedInject constructor( private val establishedCalls: ObserveEstablishedCallsUseCase, private val requestVideoStreams: RequestVideoStreamsUseCase, private val setVideoSendState: SetVideoSendStateUseCase, - private val currentScreenManager: CurrentScreenManager ) : ViewModel() { var shouldShowDoubleTapToast: Boolean by mutableStateOf(false) private set @@ -112,10 +109,7 @@ class OngoingCallViewModel @AssistedInject constructor( .distinctUntilChanged() .collect { calls -> val currentCall = calls.find { call -> call.conversationId == conversationId } - val currentScreen = - currentScreenManager.observeCurrentScreen(viewModelScope).first() - val isOnBackground = currentScreen is CurrentScreen.InBackground - if (currentCall == null && isOnBackground) { + if (currentCall == null) { state = state.copy(flowState = OngoingCallState.FlowState.CallClosed) } } From 2fdafbec3e3d33c2814ae1b40a9e33aaeb6ddd94 Mon Sep 17 00:00:00 2001 From: Oussama Hassine Date: Mon, 27 May 2024 09:58:59 +0200 Subject: [PATCH 4/4] chore: unit test --- .../ui/calling/OngoingCallViewModelTest.kt | 20 ------------------- 1 file changed, 20 deletions(-) diff --git a/app/src/test/kotlin/com/wire/android/ui/calling/OngoingCallViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/calling/OngoingCallViewModelTest.kt index a8189b39edc..7e3d84b66c8 100644 --- a/app/src/test/kotlin/com/wire/android/ui/calling/OngoingCallViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/calling/OngoingCallViewModelTest.kt @@ -24,8 +24,6 @@ import com.wire.android.datastore.GlobalDataStore import com.wire.android.ui.calling.model.UICallParticipant import com.wire.android.ui.calling.ongoing.OngoingCallViewModel import com.wire.android.ui.home.conversationslist.model.Membership -import com.wire.android.util.CurrentScreen -import com.wire.android.util.CurrentScreenManager import com.wire.kalium.logic.data.call.Call import com.wire.kalium.logic.data.call.CallClient import com.wire.kalium.logic.data.call.CallStatus @@ -42,7 +40,6 @@ import io.mockk.coEvery import io.mockk.coVerify import io.mockk.impl.annotations.MockK import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.runTest import org.amshove.kluent.internal.assertEquals @@ -58,7 +55,6 @@ class OngoingCallViewModelTest { fun givenAnOngoingCall_WhenTurningOnCamera_ThenSetVideoSendStateToStarted() = runTest { val (arrangement, ongoingCallViewModel) = Arrangement() .withCall(provideCall()) - .withCurrentScreen(CurrentScreen.SomeOther) .withShouldShowDoubleTapToastReturning(false) .withSetVideoSendState() .arrange() @@ -72,7 +68,6 @@ class OngoingCallViewModelTest { fun givenAnOngoingCall_WhenTurningOffCamera_ThenSetVideoSendStateToStopped() = runTest { val (arrangement, ongoingCallViewModel) = Arrangement() .withCall(provideCall()) - .withCurrentScreen(CurrentScreen.SomeOther) .withShouldShowDoubleTapToastReturning(false) .withSetVideoSendState() .arrange() @@ -92,7 +87,6 @@ class OngoingCallViewModelTest { val (arrangement, ongoingCallViewModel) = Arrangement() .withCall(provideCall()) - .withCurrentScreen(CurrentScreen.SomeOther) .withShouldShowDoubleTapToastReturning(false) .withSetVideoSendState() .withRequestVideoStreams(conversationId, expectedClients) @@ -112,7 +106,6 @@ class OngoingCallViewModelTest { fun givenDoubleTabIndicatorIsDisplayed_whenUserTapsOnIt_thenHideIt() = runTest { val (arrangement, ongoingCallViewModel) = Arrangement() .withCall(provideCall()) - .withCurrentScreen(CurrentScreen.SomeOther) .withShouldShowDoubleTapToastReturning(false) .withSetVideoSendState() .withSetShouldShowDoubleTapToastStatus(currentUserId.toString(), false) @@ -134,7 +127,6 @@ class OngoingCallViewModelTest { runTest { val (arrangement, ongoingCallViewModel) = Arrangement() .withCall(provideCall()) - .withCurrentScreen(CurrentScreen.SomeOther) .withShouldShowDoubleTapToastReturning(false) .withSetVideoSendState() .arrange() @@ -151,7 +143,6 @@ class OngoingCallViewModelTest { runTest { val (arrangement, ongoingCallViewModel) = Arrangement() .withCall(provideCall()) - .withCurrentScreen(CurrentScreen.SomeOther) .withShouldShowDoubleTapToastReturning(false) .withSetVideoSendState() .arrange() @@ -168,7 +159,6 @@ class OngoingCallViewModelTest { runTest { val (arrangement, ongoingCallViewModel) = Arrangement() .withCall(provideCall().copy(isCameraOn = true)) - .withCurrentScreen(CurrentScreen.SomeOther) .withShouldShowDoubleTapToastReturning(false) .withSetVideoSendState() .arrange() @@ -188,9 +178,6 @@ class OngoingCallViewModelTest { @MockK lateinit var requestVideoStreams: RequestVideoStreamsUseCase - @MockK - private lateinit var currentScreenManager: CurrentScreenManager - @MockK lateinit var setVideoSendState: SetVideoSendStateUseCase @@ -202,7 +189,6 @@ class OngoingCallViewModelTest { conversationId = conversationId, establishedCalls = establishedCall, requestVideoStreams = requestVideoStreams, - currentScreenManager = currentScreenManager, currentUserId = currentUserId, setVideoSendState = setVideoSendState, globalDataStore = globalDataStore, @@ -219,12 +205,6 @@ class OngoingCallViewModelTest { coEvery { establishedCall() } returns flowOf(listOf(call)) } - fun withCurrentScreen(screen: CurrentScreen) = apply { - coEvery { currentScreenManager.observeCurrentScreen(any()) } returns MutableStateFlow( - screen - ) - } - fun withShouldShowDoubleTapToastReturning(shouldShow: Boolean) = apply { coEvery { globalDataStore.getShouldShowDoubleTapToast(any()) } returns shouldShow }