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: App lock does not show up after fresh install (WPB-5609) #2499

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import com.wire.android.datastore.GlobalDataStore
import com.wire.android.di.KaliumCoreLogic
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.feature.session.CurrentSessionResult
import com.wire.kalium.logic.feature.session.CurrentSessionUseCase
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.collectLatest
Expand All @@ -34,39 +33,39 @@ import kotlin.time.Duration.Companion.seconds
@Singleton
class ObserveAppLockConfigUseCase @Inject constructor(
private val globalDataStore: GlobalDataStore,
@KaliumCoreLogic private val coreLogic: CoreLogic,
private val currentSession: CurrentSessionUseCase
@KaliumCoreLogic private val coreLogic: CoreLogic
) {

operator fun invoke(): Flow<AppLockConfig> = channelFlow {
when (val currentSession = currentSession()) {
is CurrentSessionResult.Failure -> {
send(AppLockConfig.Disabled(DEFAULT_APP_LOCK_TIMEOUT))
}
coreLogic.getGlobalScope().session.currentSessionFlow().collectLatest { sessionResult ->
when (sessionResult) {
is CurrentSessionResult.Failure -> {
send(AppLockConfig.Disabled(DEFAULT_APP_LOCK_TIMEOUT))
}

is CurrentSessionResult.Success -> {
val userId = currentSession.accountInfo.userId
val appLockTeamFeatureConfigFlow =
coreLogic.getSessionScope(userId).appLockTeamFeatureConfigObserver
is CurrentSessionResult.Success -> {
val userId = sessionResult.accountInfo.userId
val appLockTeamFeatureConfigFlow =
coreLogic.getSessionScope(userId).appLockTeamFeatureConfigObserver

appLockTeamFeatureConfigFlow().combineTransform(
globalDataStore.isAppLockPasscodeSetFlow()
) { teamAppLockConfig, isAppLockConfigured ->
when {
isAppLockConfigured -> {
emit(AppLockConfig.Enabled(teamAppLockConfig?.timeout ?: DEFAULT_APP_LOCK_TIMEOUT))
}
appLockTeamFeatureConfigFlow().combineTransform(
globalDataStore.isAppLockPasscodeSetFlow()
) { teamAppLockConfig, isAppLockConfigured ->
when {
isAppLockConfigured -> {
emit(AppLockConfig.Enabled(teamAppLockConfig?.timeout ?: DEFAULT_APP_LOCK_TIMEOUT))
}

teamAppLockConfig != null && teamAppLockConfig.isEnforced -> {
emit(AppLockConfig.EnforcedByTeam(teamAppLockConfig.timeout))
}
teamAppLockConfig != null && teamAppLockConfig.isEnforced -> {
emit(AppLockConfig.EnforcedByTeam(teamAppLockConfig.timeout))
}

else -> {
emit(AppLockConfig.Disabled(teamAppLockConfig?.timeout ?: DEFAULT_APP_LOCK_TIMEOUT))
else -> {
emit(AppLockConfig.Disabled(teamAppLockConfig?.timeout ?: DEFAULT_APP_LOCK_TIMEOUT))
}
}
}.collectLatest {
send(it)
}
}.collectLatest {
send(it)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@ package com.wire.android.feature
import app.cash.turbine.test
import com.wire.android.datastore.GlobalDataStore
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.configuration.AppLockTeamConfig
import com.wire.kalium.logic.data.auth.AccountInfo
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.UserSessionScope
import com.wire.kalium.logic.configuration.AppLockTeamConfig
import com.wire.kalium.logic.feature.applock.AppLockTeamFeatureConfigObserver
import com.wire.kalium.logic.feature.session.CurrentSessionResult
import com.wire.kalium.logic.feature.session.CurrentSessionUseCase
import io.mockk.MockKAnnotations
import io.mockk.coEvery
import io.mockk.every
Expand Down Expand Up @@ -116,9 +115,6 @@ class ObserveAppLockConfigUseCaseTest {
@MockK
lateinit var globalDataStore: GlobalDataStore

@MockK
lateinit var currentSession: CurrentSessionUseCase

@MockK
lateinit var coreLogic: CoreLogic

Expand All @@ -131,8 +127,7 @@ class ObserveAppLockConfigUseCaseTest {
val useCase by lazy {
ObserveAppLockConfigUseCase(
globalDataStore = globalDataStore,
coreLogic = coreLogic,
currentSession = currentSession
coreLogic = coreLogic
)
}

Expand All @@ -143,11 +138,13 @@ class ObserveAppLockConfigUseCaseTest {
fun arrange() = this to useCase

fun withNonValidSession() = apply {
coEvery { currentSession() } returns CurrentSessionResult.Failure.SessionNotFound
coEvery { coreLogic.getGlobalScope().session.currentSessionFlow() } returns
flowOf(CurrentSessionResult.Failure.SessionNotFound)
}

fun withValidSession() = apply {
coEvery { currentSession() } returns CurrentSessionResult.Success(accountInfo)
coEvery { coreLogic.getGlobalScope().session.currentSessionFlow() } returns
flowOf(CurrentSessionResult.Success(accountInfo))
}

fun withTeamAppLockEnabled() = apply {
Expand Down