Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 1:1 calls can not be established on staging environment (WPB-9359) - approach 2 #3035

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
13 changes: 12 additions & 1 deletion app/src/main/kotlin/com/wire/android/WireApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import android.app.Application
import android.content.ComponentCallbacks2
import android.os.Build
import android.os.StrictMode
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.ProcessLifecycleOwner
import androidx.work.Configuration
import co.touchlab.kermit.platformLogWriter
import com.wire.android.datastore.GlobalDataStore
Expand All @@ -43,8 +47,10 @@ import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import javax.inject.Inject

var isAppInForeground = false

@HiltAndroidApp
class WireApplication : Application(), Configuration.Provider {
class WireApplication : Application(), Configuration.Provider, LifecycleEventObserver {

@Inject
@KaliumCoreLogic
Expand Down Expand Up @@ -79,6 +85,7 @@ class WireApplication : Application(), Configuration.Provider {
super.onCreate()

enableStrictMode()
ProcessLifecycleOwner.get().lifecycle.addObserver(this)

globalAppScope.launch {
initializeApplicationLoggingFrameworks()
Expand All @@ -95,6 +102,10 @@ class WireApplication : Application(), Configuration.Provider {
}
}

override fun onStateChanged(source: LifecycleOwner, event: Lifecycle.Event) {
isAppInForeground = event == Lifecycle.Event.ON_RESUME
}

private fun enableStrictMode() {
if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package com.wire.android.util.lifecycle

import com.wire.android.appLogger
import com.wire.android.di.KaliumCoreLogic
import com.wire.android.isAppInForeground
import com.wire.android.migration.MigrationManager
import com.wire.android.util.CurrentScreenManager
import com.wire.android.util.dispatchers.DispatcherProvider
Expand All @@ -36,8 +37,6 @@ import com.wire.kalium.logic.functional.isLeft
import com.wire.kalium.logic.functional.map
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import javax.inject.Inject
import javax.inject.Singleton
Expand Down Expand Up @@ -68,13 +67,9 @@ class ConnectionPolicyManager @Inject constructor(
*/
fun startObservingAppLifecycle() {
CoroutineScope(dispatcherProvider.default()).launch {
combine(
currentScreenManager.isAppVisibleFlow(),
migrationManager.isMigrationCompletedFlow(),
::Pair
).collect { (isVisible, isMigrationCompleted) ->
migrationManager.isMigrationCompletedFlow().collect {isMigrationCompleted ->
if (isMigrationCompleted) {
setPolicyForSessions(allValidSessions(), isVisible)
setPolicyForSessions(allValidSessions(), isAppInForeground)
}
}
}
Expand Down Expand Up @@ -118,9 +113,7 @@ class ConnectionPolicyManager @Inject constructor(
private suspend fun UserSessionScope.downgradePolicyIfNeeded(
userId: UserId
) {
val isAppVisible = currentScreenManager.isAppVisibleFlow().first()
logger.d("$TAG isAppVisible = $isAppVisible")
if (!isAppVisible) {
if (!isAppInForeground) {
logger.d("$TAG ${userId.toString().obfuscateId()} Downgrading policy as conditions to KEEP_ALIVE are not met")
setConnectionPolicy(ConnectionPolicy.DISCONNECT_AFTER_PENDING_EVENTS)
}
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
Loading