Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/src/main/kotlin/com/wire/android/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import linc.com.amplituda.Amplituda
import javax.inject.Named
import javax.inject.Qualifier
import javax.inject.Singleton

Expand Down Expand Up @@ -110,4 +111,8 @@ object AppModule {
@Provides
fun provideAudioManager(@ApplicationContext context: Context): AudioManager =
context.getSystemService(Context.AUDIO_SERVICE) as AudioManager

@Provides
@Named("useNewLoginForDefaultBackend")
fun provideUseNewLoginForDefaultBackend(): Boolean = BuildConfig.USE_NEW_LOGIN_FOR_DEFAULT_BACKEND
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ package com.wire.android.navigation

import com.wire.android.config.DefaultServerConfig
import com.wire.android.di.KaliumCoreLogic
import com.wire.android.util.dispatchers.DispatcherProvider
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.configuration.server.ServerConfig
import com.wire.kalium.logic.feature.auth.LoginContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.stateIn
import javax.inject.Inject
import javax.inject.Named
import javax.inject.Singleton

/**
Expand All @@ -37,21 +33,9 @@ import javax.inject.Singleton
*/
@Singleton
class LoginTypeSelector @Inject constructor(
dispatcherProvider: DispatcherProvider,
@KaliumCoreLogic private val coreLogic: CoreLogic,
@Named("useNewLoginForDefaultBackend") private val useNewLoginForDefaultBackend: Boolean,
) {
private val scope = CoroutineScope(SupervisorJob() + dispatcherProvider.default())

// StateFlow of the login context for the default server config, so that the value is kept ready to use and the use case doesn't need
// to be executed every time the app needs to determine if the new login flow can be used.
private lateinit var loginContextForDefaultServerConfigStateFlow: StateFlow<LoginContext>

// it needs to be initialised before navigation is setup
suspend fun init() {
if (!::loginContextForDefaultServerConfigStateFlow.isInitialized) {
loginContextForDefaultServerConfigStateFlow = loginContextFlow(DefaultServerConfig).stateIn(scope)
}
}

/**
* Observe the [LoginContext] for the given [ServerConfig.Links].
Expand All @@ -65,11 +49,11 @@ class LoginTypeSelector @Inject constructor(
// if the server links are provided, get the login context for the given server links and check if it's enterprise login
serverLinks != null -> loginContextFlow(serverLinks).first() == LoginContext.EnterpriseLogin
// otherwise, use the function for the default server config links to determine if the new login flow can be used
else -> loginContextForDefaultServerConfigStateFlow.value == LoginContext.EnterpriseLogin
else -> canUseNewLogin()
}

/**
* Determine if the new login flow can be used for the default [ServerConfig.Links] - [DefaultServerConfig].
*/
fun canUseNewLogin() = loginContextForDefaultServerConfigStateFlow.value == LoginContext.EnterpriseLogin
fun canUseNewLogin() = useNewLoginForDefaultBackend
}
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 @@ -185,7 +185,6 @@ class WireActivity : AppCompatActivity() {
legalHoldRequestedViewModel.observeLegalHoldRequest()

appLogger.i("$TAG init login type selector")
loginTypeSelector.init()

appLogger.i("$TAG start destination")
val startDestination = when (viewModel.initialAppState()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package com.wire.android.navigation

import com.wire.android.config.DefaultServerConfig
import com.wire.android.config.TestDispatcherProvider
import com.wire.android.util.newServerConfig
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.configuration.server.ServerConfig
Expand All @@ -34,75 +33,60 @@ import org.amshove.kluent.internal.assertEquals
import org.junit.jupiter.api.Test

class LoginTypeSelectorTest {
private val dispatcherProvider = TestDispatcherProvider()

@Test
fun `given default config with enterprise context, then can use new login`() =
runTest(dispatcherProvider.main()) {
runTest {
val (_, loginTypeSelector) = Arrangement()
.withContextFlowForConfig(DefaultServerConfig, flowOf(LoginContext.EnterpriseLogin))
.arrange()
.arrange(true)
val result = loginTypeSelector.canUseNewLogin()
assertEquals(true, result)
}

@Test
fun `given custom config with enterprise context, then can use new login`() =
runTest(dispatcherProvider.main()) {
runTest {
val config = newServerConfig(1)
val (_, loginTypeSelector) = Arrangement()
.withContextFlowForConfig(DefaultServerConfig, flowOf(LoginContext.FallbackLogin))
.withContextFlowForConfig(config.links, flowOf(LoginContext.EnterpriseLogin))
.arrange()
.arrange(true)
val result = loginTypeSelector.canUseNewLogin(config.links)
assertEquals(true, result)
}

@Test
fun `given default config with fallback context, then cannot use new login`() =
runTest(dispatcherProvider.main()) {
runTest {
val (_, loginTypeSelector) = Arrangement()
.withContextFlowForConfig(DefaultServerConfig, flowOf(LoginContext.FallbackLogin))
.arrange()
.arrange(false)
val result = loginTypeSelector.canUseNewLogin()
assertEquals(false, result)
}

@Test
fun `given custom config with fallback context, then cannot use new login`() =
runTest(dispatcherProvider.main()) {
runTest {
val config = newServerConfig(1)
val (_, loginTypeSelector) = Arrangement()
.withContextFlowForConfig(DefaultServerConfig, flowOf(LoginContext.EnterpriseLogin))
.withContextFlowForConfig(config.links, flowOf(LoginContext.FallbackLogin))
.arrange()
.arrange(true)
val result = loginTypeSelector.canUseNewLogin(config.links)
assertEquals(false, result)
}

@Test
fun `given default config with fallback context, when context changes to enterprise, then can use new login after it changes`() =
runTest(dispatcherProvider.main()) {
val contextFlow = MutableStateFlow<LoginContext>(LoginContext.FallbackLogin)
val (_, loginTypeSelector) = Arrangement()
.withContextFlowForConfig(DefaultServerConfig, contextFlow)
.arrange()
val resultBeforeChange = loginTypeSelector.canUseNewLogin()
assertEquals(false, resultBeforeChange)
contextFlow.value = LoginContext.EnterpriseLogin
val resultAfterChange = loginTypeSelector.canUseNewLogin()
assertEquals(true, resultAfterChange)
}

@Test
fun `given custom config with fallback context, when context changes to enterprise, then can use new login after it changes`() =
runTest(dispatcherProvider.main()) {
runTest {
val config = newServerConfig(1)
val contextFlow = MutableStateFlow<LoginContext>(LoginContext.FallbackLogin)
val (_, loginTypeSelector) = Arrangement()
.withContextFlowForConfig(DefaultServerConfig, flowOf(LoginContext.FallbackLogin))
.withContextFlowForConfig(config.links, contextFlow)
.arrange()
.arrange(true)
val resultBeforeChange = loginTypeSelector.canUseNewLogin(config.links)
assertEquals(false, resultBeforeChange)
contextFlow.value = LoginContext.EnterpriseLogin
Expand All @@ -118,7 +102,7 @@ class LoginTypeSelectorTest {
MockKAnnotations.init(this, relaxUnitFun = true)
}

suspend fun arrange() = this to LoginTypeSelector(dispatcherProvider, coreLogic).also { it.init() }
fun arrange(useNewLoginForDefaultBackend: Boolean) = this to LoginTypeSelector(coreLogic, useNewLoginForDefaultBackend)

fun withContextFlowForConfig(config: ServerConfig.Links, contextFlow: Flow<LoginContext>) = apply {
coEvery { coreLogic.getGlobalScope().observeLoginContext(config) } returns contextFlow
Expand Down
2 changes: 2 additions & 0 deletions buildSrc/src/main/kotlin/customization/FeatureConfigs.kt
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ enum class FeatureConfigs(val value: String, val configType: ConfigType) {
PAGINATED_CONVERSATION_LIST_ENABLED("paginated_conversation_list_enabled", ConfigType.BOOLEAN),

PUBLIC_CHANNELS_ENABLED("public_channels_enabled", ConfigType.BOOLEAN),

USE_NEW_LOGIN_FOR_DEFAULT_BACKEND("use_new_login_for_default_backend", ConfigType.BOOLEAN),
/**
* Anonymous Analytics
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ class AnonymousAnalyticsRecorderImpl(
Countly.sharedInstance()?.init(countlyConfig)

val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0)
val globalSegmentations = mapOf<String, Any>(
val globalSegmentations = mapOf<String, String>(
APP_NAME to AnalyticsEventConstants.APP_NAME_ANDROID,
APP_VERSION to packageInfo.versionName
APP_VERSION to packageInfo.versionName.orEmpty()
)
Countly.sharedInstance()?.views()?.setGlobalViewSegmentation(globalSegmentations)
isConfigured = true
Expand Down
3 changes: 2 additions & 1 deletion default.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,5 +134,6 @@
"picture_in_picture_enabled": false,
"paginated_conversation_list_enabled": false,
"should_display_release_notes": true,
"public_channels_enabled": false
"public_channels_enabled": false,
"use_new_login_for_default_backend": true
}
Loading