Skip to content

Commit

Permalink
fix: 1:1 calls can not be established on staging environment (WPB-935…
Browse files Browse the repository at this point in the history
…9) - approach 3 (#3037)

Co-authored-by: Oussama Hassine <[email protected]>
  • Loading branch information
2 people authored and github-actions[bot] committed May 27, 2024
1 parent c4d8002 commit 5d92eb5
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 33 deletions.
1 change: 1 addition & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
10 changes: 10 additions & 0 deletions app/src/main/kotlin/com/wire/android/WireApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -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")
Expand Down
1 change: 0 additions & 1 deletion app/src/main/kotlin/com/wire/android/ui/WireActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ class WireActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
splashScreen.setKeepOnScreenCondition { shouldKeepSplashOpen }

lifecycle.addObserver(currentScreenManager)
WindowCompat.setDecorFitsSystemWindows(window, false)

lifecycleScope.launch(Dispatchers.Default) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ class CurrentScreenManager @Inject constructor(
*/
fun isAppVisibleFlow(): StateFlow<Boolean> = isApplicationVisibleFlow

override fun onResume(owner: LifecycleOwner) {
super.onResume(owner)
appLogger.i("${TAG}: onResume called")
}

override fun onStart(owner: LifecycleOwner) {
super.onStart(owner)
appLogger.i("${TAG}: onStart called")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -58,7 +55,6 @@ class OngoingCallViewModelTest {
fun givenAnOngoingCall_WhenTurningOnCamera_ThenSetVideoSendStateToStarted() = runTest {
val (arrangement, ongoingCallViewModel) = Arrangement()
.withCall(provideCall())
.withCurrentScreen(CurrentScreen.SomeOther)
.withShouldShowDoubleTapToastReturning(false)
.withSetVideoSendState()
.arrange()
Expand All @@ -72,7 +68,6 @@ class OngoingCallViewModelTest {
fun givenAnOngoingCall_WhenTurningOffCamera_ThenSetVideoSendStateToStopped() = runTest {
val (arrangement, ongoingCallViewModel) = Arrangement()
.withCall(provideCall())
.withCurrentScreen(CurrentScreen.SomeOther)
.withShouldShowDoubleTapToastReturning(false)
.withSetVideoSendState()
.arrange()
Expand All @@ -92,7 +87,6 @@ class OngoingCallViewModelTest {

val (arrangement, ongoingCallViewModel) = Arrangement()
.withCall(provideCall())
.withCurrentScreen(CurrentScreen.SomeOther)
.withShouldShowDoubleTapToastReturning(false)
.withSetVideoSendState()
.withRequestVideoStreams(conversationId, expectedClients)
Expand All @@ -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)
Expand All @@ -134,7 +127,6 @@ class OngoingCallViewModelTest {
runTest {
val (arrangement, ongoingCallViewModel) = Arrangement()
.withCall(provideCall())
.withCurrentScreen(CurrentScreen.SomeOther)
.withShouldShowDoubleTapToastReturning(false)
.withSetVideoSendState()
.arrange()
Expand All @@ -151,7 +143,6 @@ class OngoingCallViewModelTest {
runTest {
val (arrangement, ongoingCallViewModel) = Arrangement()
.withCall(provideCall())
.withCurrentScreen(CurrentScreen.SomeOther)
.withShouldShowDoubleTapToastReturning(false)
.withSetVideoSendState()
.arrange()
Expand All @@ -168,7 +159,6 @@ class OngoingCallViewModelTest {
runTest {
val (arrangement, ongoingCallViewModel) = Arrangement()
.withCall(provideCall().copy(isCameraOn = true))
.withCurrentScreen(CurrentScreen.SomeOther)
.withShouldShowDoubleTapToastReturning(false)
.withSetVideoSendState()
.arrange()
Expand All @@ -188,9 +178,6 @@ class OngoingCallViewModelTest {
@MockK
lateinit var requestVideoStreams: RequestVideoStreamsUseCase

@MockK
private lateinit var currentScreenManager: CurrentScreenManager

@MockK
lateinit var setVideoSendState: SetVideoSendStateUseCase

Expand All @@ -202,7 +189,6 @@ class OngoingCallViewModelTest {
conversationId = conversationId,
establishedCalls = establishedCall,
requestVideoStreams = requestVideoStreams,
currentScreenManager = currentScreenManager,
currentUserId = currentUserId,
setVideoSendState = setVideoSendState,
globalDataStore = globalDataStore,
Expand All @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down

0 comments on commit 5d92eb5

Please sign in to comment.