Skip to content

Commit d12662f

Browse files
committed
chore: simplify new login selector
1 parent fcb37fb commit d12662f

File tree

7 files changed

+26
-51
lines changed

7 files changed

+26
-51
lines changed

app/src/main/kotlin/com/wire/android/di/AppModule.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import dagger.hilt.InstallIn
4040
import dagger.hilt.android.qualifiers.ApplicationContext
4141
import dagger.hilt.components.SingletonComponent
4242
import linc.com.amplituda.Amplituda
43+
import javax.inject.Named
4344
import javax.inject.Qualifier
4445
import javax.inject.Singleton
4546

@@ -110,4 +111,8 @@ object AppModule {
110111
@Provides
111112
fun provideAudioManager(@ApplicationContext context: Context): AudioManager =
112113
context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
114+
115+
@Provides
116+
@Named("useNewLoginForDefaultBackend")
117+
fun provideUseNewLoginForDefaultBackend(): Boolean = BuildConfig.USE_NEW_LOGIN_FOR_DEFAULT_BACKEND
113118
}

app/src/main/kotlin/com/wire/android/navigation/LoginTypeSelector.kt

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,12 @@ package com.wire.android.navigation
1919

2020
import com.wire.android.config.DefaultServerConfig
2121
import com.wire.android.di.KaliumCoreLogic
22-
import com.wire.android.util.dispatchers.DispatcherProvider
2322
import com.wire.kalium.logic.CoreLogic
2423
import com.wire.kalium.logic.configuration.server.ServerConfig
2524
import com.wire.kalium.logic.feature.auth.LoginContext
26-
import kotlinx.coroutines.CoroutineScope
27-
import kotlinx.coroutines.SupervisorJob
28-
import kotlinx.coroutines.flow.StateFlow
2925
import kotlinx.coroutines.flow.first
30-
import kotlinx.coroutines.flow.stateIn
3126
import javax.inject.Inject
27+
import javax.inject.Named
3228
import javax.inject.Singleton
3329

3430
/**
@@ -37,21 +33,9 @@ import javax.inject.Singleton
3733
*/
3834
@Singleton
3935
class LoginTypeSelector @Inject constructor(
40-
dispatcherProvider: DispatcherProvider,
4136
@KaliumCoreLogic private val coreLogic: CoreLogic,
37+
@Named("useNewLoginForDefaultBackend") private val useNewLoginForDefaultBackend: Boolean,
4238
) {
43-
private val scope = CoroutineScope(SupervisorJob() + dispatcherProvider.default())
44-
45-
// 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
46-
// to be executed every time the app needs to determine if the new login flow can be used.
47-
private lateinit var loginContextForDefaultServerConfigStateFlow: StateFlow<LoginContext>
48-
49-
// it needs to be initialised before navigation is setup
50-
suspend fun init() {
51-
if (!::loginContextForDefaultServerConfigStateFlow.isInitialized) {
52-
loginContextForDefaultServerConfigStateFlow = loginContextFlow(DefaultServerConfig).stateIn(scope)
53-
}
54-
}
5539

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

7155
/**
7256
* Determine if the new login flow can be used for the default [ServerConfig.Links] - [DefaultServerConfig].
7357
*/
74-
fun canUseNewLogin() = loginContextForDefaultServerConfigStateFlow.value == LoginContext.EnterpriseLogin
58+
fun canUseNewLogin() = useNewLoginForDefaultBackend
7559
}

app/src/main/kotlin/com/wire/android/ui/WireActivity.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ class WireActivity : AppCompatActivity() {
185185
legalHoldRequestedViewModel.observeLegalHoldRequest()
186186

187187
appLogger.i("$TAG init login type selector")
188-
loginTypeSelector.init()
189188

190189
appLogger.i("$TAG start destination")
191190
val startDestination = when (viewModel.initialAppState()) {

app/src/test/kotlin/com/wire/android/navigation/LoginTypeSelectorTest.kt

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
package com.wire.android.navigation
1919

2020
import com.wire.android.config.DefaultServerConfig
21-
import com.wire.android.config.TestDispatcherProvider
2221
import com.wire.android.util.newServerConfig
2322
import com.wire.kalium.logic.CoreLogic
2423
import com.wire.kalium.logic.configuration.server.ServerConfig
@@ -34,75 +33,60 @@ import org.amshove.kluent.internal.assertEquals
3433
import org.junit.jupiter.api.Test
3534

3635
class LoginTypeSelectorTest {
37-
private val dispatcherProvider = TestDispatcherProvider()
3836

3937
@Test
4038
fun `given default config with enterprise context, then can use new login`() =
41-
runTest(dispatcherProvider.main()) {
39+
runTest {
4240
val (_, loginTypeSelector) = Arrangement()
4341
.withContextFlowForConfig(DefaultServerConfig, flowOf(LoginContext.EnterpriseLogin))
44-
.arrange()
42+
.arrange(true)
4543
val result = loginTypeSelector.canUseNewLogin()
4644
assertEquals(true, result)
4745
}
4846

4947
@Test
5048
fun `given custom config with enterprise context, then can use new login`() =
51-
runTest(dispatcherProvider.main()) {
49+
runTest {
5250
val config = newServerConfig(1)
5351
val (_, loginTypeSelector) = Arrangement()
5452
.withContextFlowForConfig(DefaultServerConfig, flowOf(LoginContext.FallbackLogin))
5553
.withContextFlowForConfig(config.links, flowOf(LoginContext.EnterpriseLogin))
56-
.arrange()
54+
.arrange(true)
5755
val result = loginTypeSelector.canUseNewLogin(config.links)
5856
assertEquals(true, result)
5957
}
6058

6159
@Test
6260
fun `given default config with fallback context, then cannot use new login`() =
63-
runTest(dispatcherProvider.main()) {
61+
runTest {
6462
val (_, loginTypeSelector) = Arrangement()
6563
.withContextFlowForConfig(DefaultServerConfig, flowOf(LoginContext.FallbackLogin))
66-
.arrange()
64+
.arrange(false)
6765
val result = loginTypeSelector.canUseNewLogin()
6866
assertEquals(false, result)
6967
}
7068

7169
@Test
7270
fun `given custom config with fallback context, then cannot use new login`() =
73-
runTest(dispatcherProvider.main()) {
71+
runTest {
7472
val config = newServerConfig(1)
7573
val (_, loginTypeSelector) = Arrangement()
7674
.withContextFlowForConfig(DefaultServerConfig, flowOf(LoginContext.EnterpriseLogin))
7775
.withContextFlowForConfig(config.links, flowOf(LoginContext.FallbackLogin))
78-
.arrange()
76+
.arrange(true)
7977
val result = loginTypeSelector.canUseNewLogin(config.links)
8078
assertEquals(false, result)
8179
}
8280

83-
@Test
84-
fun `given default config with fallback context, when context changes to enterprise, then can use new login after it changes`() =
85-
runTest(dispatcherProvider.main()) {
86-
val contextFlow = MutableStateFlow<LoginContext>(LoginContext.FallbackLogin)
87-
val (_, loginTypeSelector) = Arrangement()
88-
.withContextFlowForConfig(DefaultServerConfig, contextFlow)
89-
.arrange()
90-
val resultBeforeChange = loginTypeSelector.canUseNewLogin()
91-
assertEquals(false, resultBeforeChange)
92-
contextFlow.value = LoginContext.EnterpriseLogin
93-
val resultAfterChange = loginTypeSelector.canUseNewLogin()
94-
assertEquals(true, resultAfterChange)
95-
}
96-
9781
@Test
9882
fun `given custom config with fallback context, when context changes to enterprise, then can use new login after it changes`() =
99-
runTest(dispatcherProvider.main()) {
83+
runTest {
10084
val config = newServerConfig(1)
10185
val contextFlow = MutableStateFlow<LoginContext>(LoginContext.FallbackLogin)
10286
val (_, loginTypeSelector) = Arrangement()
10387
.withContextFlowForConfig(DefaultServerConfig, flowOf(LoginContext.FallbackLogin))
10488
.withContextFlowForConfig(config.links, contextFlow)
105-
.arrange()
89+
.arrange(true)
10690
val resultBeforeChange = loginTypeSelector.canUseNewLogin(config.links)
10791
assertEquals(false, resultBeforeChange)
10892
contextFlow.value = LoginContext.EnterpriseLogin
@@ -118,7 +102,7 @@ class LoginTypeSelectorTest {
118102
MockKAnnotations.init(this, relaxUnitFun = true)
119103
}
120104

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

123107
fun withContextFlowForConfig(config: ServerConfig.Links, contextFlow: Flow<LoginContext>) = apply {
124108
coEvery { coreLogic.getGlobalScope().observeLoginContext(config) } returns contextFlow

buildSrc/src/main/kotlin/customization/FeatureConfigs.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ enum class FeatureConfigs(val value: String, val configType: ConfigType) {
107107
PAGINATED_CONVERSATION_LIST_ENABLED("paginated_conversation_list_enabled", ConfigType.BOOLEAN),
108108

109109
PUBLIC_CHANNELS_ENABLED("public_channels_enabled", ConfigType.BOOLEAN),
110+
111+
USE_NEW_LOGIN_FOR_DEFAULT_BACKEND("use_new_login_for_default_backend", ConfigType.BOOLEAN),
110112
/**
111113
* Anonymous Analytics
112114
*/

core/analytics-enabled/src/main/kotlin/com/wire/android/feature/analytics/AnonymousAnalyticsRecorderImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ class AnonymousAnalyticsRecorderImpl(
6363
Countly.sharedInstance()?.init(countlyConfig)
6464

6565
val packageInfo = context.packageManager.getPackageInfo(context.packageName, 0)
66-
val globalSegmentations = mapOf<String, Any>(
66+
val globalSegmentations = mapOf<String, String>(
6767
APP_NAME to AnalyticsEventConstants.APP_NAME_ANDROID,
68-
APP_VERSION to packageInfo.versionName
68+
APP_VERSION to packageInfo.versionName.orEmpty()
6969
)
7070
Countly.sharedInstance()?.views()?.setGlobalViewSegmentation(globalSegmentations)
7171
isConfigured = true

default.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,5 +134,6 @@
134134
"picture_in_picture_enabled": false,
135135
"paginated_conversation_list_enabled": false,
136136
"should_display_release_notes": true,
137-
"public_channels_enabled": false
137+
"public_channels_enabled": false,
138+
"use_new_login_for_default_backend": true
138139
}

0 commit comments

Comments
 (0)