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
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package com.wire.android
import android.content.Context
import androidx.work.WorkManager
import com.wire.android.di.CoreLogicModule
import com.wire.android.di.DefaultWebSocketEnabledByDefault
import com.wire.android.di.KaliumCoreLogic
import com.wire.android.di.NoSession
import com.wire.android.util.UserAgentProvider
Expand Down Expand Up @@ -119,4 +120,8 @@ class TestCoreLogicModule {
@Provides
fun provideAudioNormalizedLoudnessBuilder(@KaliumCoreLogic coreLogic: CoreLogic): AudioNormalizedLoudnessBuilder =
coreLogic.audioNormalizedLoudnessBuilder

@DefaultWebSocketEnabledByDefault
@Provides
fun provideDefaultWebSocketEnabledByDefault(): Boolean = true
}
10 changes: 10 additions & 0 deletions app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.work.WorkManager
import com.wire.android.datastore.UserDataStoreProvider
import com.wire.android.util.ImageUtil
import com.wire.android.util.UserAgentProvider
import com.wire.android.util.isWebsocketEnabledByDefault
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.data.asset.KaliumFileSystem
import com.wire.kalium.logic.data.id.FederatedIdMapper
Expand Down Expand Up @@ -81,6 +82,10 @@ annotation class CurrentAccount
@Retention(AnnotationRetention.BINARY)
annotation class NoSession

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class DefaultWebSocketEnabledByDefault

@Module
@InstallIn(SingletonComponent::class)
class CoreLogicModule {
Expand Down Expand Up @@ -144,6 +149,11 @@ class CoreLogicModule {
@Provides
fun provideAudioNormalizedLoudnessBuilder(@KaliumCoreLogic coreLogic: CoreLogic): AudioNormalizedLoudnessBuilder =
coreLogic.audioNormalizedLoudnessBuilder

@DefaultWebSocketEnabledByDefault
@Provides
fun provideDefaultWebSocketEnabledByDefault(@ApplicationContext context: Context): Boolean =
isWebsocketEnabledByDefault(context)
}

@Module
Expand Down
25 changes: 11 additions & 14 deletions app/src/main/kotlin/com/wire/android/di/KaliumConfigsModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@

package com.wire.android.di

import android.content.Context
import android.os.Build
import com.wire.android.BuildConfig
import com.wire.android.util.isWebsocketEnabledByDefault
import com.wire.kalium.logic.featureFlags.BuildFileRestrictionState
import com.wire.kalium.logic.featureFlags.KaliumConfigs
import dagger.Module
Expand All @@ -34,20 +32,20 @@ import dagger.hilt.components.SingletonComponent
class KaliumConfigsModule {

@Provides
fun provideKaliumConfigs(context: Context): KaliumConfigs {
val fileRestriction: BuildFileRestrictionState = if (BuildConfig.FILE_RESTRICTION_ENABLED) {
BuildConfig.FILE_RESTRICTION_LIST.split(",").map { it.trim() }.let {
BuildFileRestrictionState.AllowSome(it)
}
} else {
BuildFileRestrictionState.NoRestriction
}

fun provideKaliumConfigs(): KaliumConfigs {
return KaliumConfigs(
fileRestrictionState = fileRestriction,
fileRestrictionState = lazy {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure there is any performance gain here. Does the whole refactoring of KaliumConfigs worth it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my goal is to lazy evaluate anything that can should be calculated, this settings have some string manipulation, and yes it is not that much but still not needed on app startup

if (BuildConfig.FILE_RESTRICTION_ENABLED) {
BuildConfig.FILE_RESTRICTION_LIST.split(",").map { it.trim() }.let {
BuildFileRestrictionState.AllowSome(it)
}
} else {
BuildFileRestrictionState.NoRestriction
}
},
forceConstantBitrateCalls = BuildConfig.FORCE_CONSTANT_BITRATE_CALLS,
// we use upsert, available from SQL3.24, which is supported from Android API30, so for older APIs we have to use SQLCipher
shouldEncryptData = !BuildConfig.DEBUG || Build.VERSION.SDK_INT < Build.VERSION_CODES.R,
shouldEncryptData = { !BuildConfig.DEBUG || Build.VERSION.SDK_INT < Build.VERSION_CODES.R },
lowerKeyPackageLimits = BuildConfig.LOWER_KEYPACKAGE_LIMIT,
developmentApiEnabled = BuildConfig.DEVELOPMENT_API_ENABLED,
ignoreSSLCertificatesForUnboundCalls = BuildConfig.IGNORE_SSL_CERTIFICATES,
Expand All @@ -57,7 +55,6 @@ class KaliumConfigsModule {
wipeOnCookieInvalid = BuildConfig.WIPE_ON_COOKIE_INVALID,
wipeOnDeviceRemoval = BuildConfig.WIPE_ON_DEVICE_REMOVAL,
wipeOnRootedDevice = BuildConfig.WIPE_ON_ROOTED_DEVICE,
isWebSocketEnabledByDefault = isWebsocketEnabledByDefault(context),
certPinningConfig = BuildConfig.CERTIFICATE_PINNING_CONFIG,
maxRemoteSearchResultCount = BuildConfig.MAX_REMOTE_SEARCH_RESULT_COUNT,
limitTeamMembersFetchDuringSlowSync = BuildConfig.LIMIT_TEAM_MEMBERS_FETCH_DURING_SLOW_SYNC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import androidx.lifecycle.viewModelScope
import com.wire.android.BuildConfig
import com.wire.android.di.ClientScopeProvider
import com.wire.android.di.DefaultWebSocketEnabledByDefault
import com.wire.android.di.KaliumCoreLogic
import com.wire.android.ui.authentication.create.common.CreateAccountFlowType
import com.wire.android.ui.authentication.create.common.CreateAccountNavArgs
Expand Down Expand Up @@ -58,7 +59,8 @@
@KaliumCoreLogic private val coreLogic: CoreLogic,
private val addAuthenticatedUser: AddAuthenticatedUserUseCase,
private val clientScopeProviderFactory: ClientScopeProvider.Factory,
defaultServerConfig: ServerConfig.Links
defaultServerConfig: ServerConfig.Links,
@DefaultWebSocketEnabledByDefault private val defaultWebSocketEnabledByDefault: Boolean

Check warning on line 63 in app/src/main/kotlin/com/wire/android/ui/authentication/create/code/CreateAccountCodeViewModel.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/authentication/create/code/CreateAccountCodeViewModel.kt#L63

Added line #L63 was not covered by tests
) : ViewModel() {

val createAccountNavArgs: CreateAccountNavArgs = savedStateHandle.navArgs()
Expand Down Expand Up @@ -184,6 +186,7 @@
ssoId = registerResult.ssoID,
serverConfigId = registerResult.serverConfigId,
proxyCredentials = registerResult.proxyCredentials,
isPersistentWebSocketEnabled = defaultWebSocketEnabledByDefault,

Check warning on line 189 in app/src/main/kotlin/com/wire/android/ui/authentication/create/code/CreateAccountCodeViewModel.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/authentication/create/code/CreateAccountCodeViewModel.kt#L189

Added line #L189 was not covered by tests
replace = false
).let {
when (it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.viewModelScope
import com.wire.android.datastore.UserDataStoreProvider
import com.wire.android.di.ClientScopeProvider
import com.wire.android.di.DefaultWebSocketEnabledByDefault
import com.wire.android.di.KaliumCoreLogic
import com.wire.android.ui.authentication.login.LoginNavArgs
import com.wire.android.ui.authentication.login.LoginState
Expand Down Expand Up @@ -79,6 +80,7 @@ class LoginEmailViewModel @Inject constructor(
private val resendCodeTimer: CountdownTimer,
private val dispatchers: DispatcherProvider,
defaultServerConfig: ServerConfig.Links,
@DefaultWebSocketEnabledByDefault private val defaultWebSocketEnabledByDefault: Boolean,
) : LoginViewModel(
savedStateHandle,
clientScopeProviderFactory,
Expand Down Expand Up @@ -206,6 +208,7 @@ class LoginEmailViewModel @Inject constructor(
managedBy = loginResult.managedBy,
serverConfigId = loginResult.serverConfigId,
proxyCredentials = loginResult.proxyCredentials,
isPersistentWebSocketEnabled = defaultWebSocketEnabledByDefault,
replace = false
)
}.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.wire.android.config.DefaultServerConfig
import com.wire.android.datastore.UserDataStoreProvider
import com.wire.android.di.ClientScopeProvider
import com.wire.android.di.DefaultWebSocketEnabledByDefault
import com.wire.android.di.KaliumCoreLogic
import com.wire.android.ui.authentication.login.LoginState
import com.wire.android.ui.authentication.login.LoginViewModel
Expand Down Expand Up @@ -82,15 +83,16 @@
@KaliumCoreLogic coreLogic: CoreLogic,
clientScopeProviderFactory: ClientScopeProvider.Factory,
userDataStoreProvider: UserDataStoreProvider,
serverConfig: ServerConfig.Links
serverConfig: ServerConfig.Links,
@DefaultWebSocketEnabledByDefault defaultWebSocketEnabledByDefault: Boolean,
) : this(
savedStateHandle,
addAuthenticatedUser,
validateEmailUseCase,
coreLogic,
clientScopeProviderFactory,
userDataStoreProvider,
LoginSSOViewModelExtension(addAuthenticatedUser, coreLogic),
LoginSSOViewModelExtension(addAuthenticatedUser, coreLogic, defaultWebSocketEnabledByDefault),

Check warning on line 95 in app/src/main/kotlin/com/wire/android/ui/authentication/login/sso/LoginSSOViewModel.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/authentication/login/sso/LoginSSOViewModel.kt#L95

Added line #L95 was not covered by tests
serverConfig
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
class LoginSSOViewModelExtension(
private val addAuthenticatedUser: AddAuthenticatedUserUseCase,
private val coreLogic: CoreLogic,
private val defaultWebSocketEnabledByDefault: Boolean,

Check warning on line 35 in app/src/main/kotlin/com/wire/android/ui/authentication/login/sso/LoginSSOViewModelExtension.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/authentication/login/sso/LoginSSOViewModelExtension.kt#L35

Added line #L35 was not covered by tests
) {
suspend fun withAuthenticationScope(
serverConfig: ServerConfig.Links,
Expand Down Expand Up @@ -100,6 +101,7 @@
serverConfigId = serverConfigId,
proxyCredentials = ssoLoginResult.proxyCredentials,
managedBy = ssoLoginResult.managedBy,
isPersistentWebSocketEnabled = defaultWebSocketEnabledByDefault,

Check warning on line 104 in app/src/main/kotlin/com/wire/android/ui/authentication/login/sso/LoginSSOViewModelExtension.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/authentication/login/sso/LoginSSOViewModelExtension.kt#L104

Added line #L104 was not covered by tests
replace = false
).let { authenticatedUserResult ->
when (authenticatedUserResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.wire.android.appLogger
import com.wire.android.datastore.UserDataStoreProvider
import com.wire.android.di.ClientScopeProvider
import com.wire.android.di.DefaultWebSocketEnabledByDefault
import com.wire.android.di.KaliumCoreLogic
import com.wire.android.ui.authentication.login.DomainClaimedByOrg
import com.wire.android.ui.authentication.login.LoginNavArgs
Expand Down Expand Up @@ -91,14 +92,15 @@
dispatchers: DispatcherProvider,
defaultServerConfig: ServerConfig.Links,
@Named("ssoCodeConfig") defaultSSOCodeConfig: String,
@DefaultWebSocketEnabledByDefault defaultWebSocketEnabledByDefault: Boolean,
) : this(
validateEmailOrSSOCode,
coreLogic,
savedStateHandle,
clientScopeProviderFactory,
userDataStoreProvider,
LoginViewModelExtension(clientScopeProviderFactory, userDataStoreProvider),
LoginSSOViewModelExtension(addAuthenticatedUser, coreLogic),
LoginSSOViewModelExtension(addAuthenticatedUser, coreLogic, defaultWebSocketEnabledByDefault),

Check warning on line 103 in app/src/main/kotlin/com/wire/android/ui/newauthentication/login/NewLoginViewModel.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/newauthentication/login/NewLoginViewModel.kt#L103

Added line #L103 was not covered by tests
dispatchers,
defaultServerConfig,
defaultSSOCodeConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.wire.android.BuildConfig
import com.wire.android.analytics.RegistrationAnalyticsManagerUseCase
import com.wire.android.di.ClientScopeProvider
import com.wire.android.di.DefaultWebSocketEnabledByDefault
import com.wire.android.di.KaliumCoreLogic
import com.wire.android.feature.analytics.model.AnalyticsEvent
import com.wire.android.ui.authentication.create.common.CreateAccountDataNavArgs
Expand Down Expand Up @@ -56,7 +57,8 @@
private val addAuthenticatedUser: AddAuthenticatedUserUseCase,
private val registrationAnalyticsManager: RegistrationAnalyticsManagerUseCase,
private val clientScopeProviderFactory: ClientScopeProvider.Factory,
defaultServerConfig: ServerConfig.Links
defaultServerConfig: ServerConfig.Links,
@DefaultWebSocketEnabledByDefault private val defaultWebSocketEnabledByDefault: Boolean,

Check warning on line 61 in app/src/main/kotlin/com/wire/android/ui/registration/code/CreateAccountVerificationCodeViewModel.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/registration/code/CreateAccountVerificationCodeViewModel.kt#L61

Added line #L61 was not covered by tests
) : ViewModel() {

val createAccountNavArgs: CreateAccountDataNavArgs = savedStateHandle.navArgs()
Expand Down Expand Up @@ -164,6 +166,7 @@
ssoId = registerResult.ssoID,
serverConfigId = registerResult.serverConfigId,
proxyCredentials = registerResult.proxyCredentials,
isPersistentWebSocketEnabled = defaultWebSocketEnabledByDefault,

Check warning on line 169 in app/src/main/kotlin/com/wire/android/ui/registration/code/CreateAccountVerificationCodeViewModel.kt

View check run for this annotation

Codecov / codecov/patch

app/src/main/kotlin/com/wire/android/ui/registration/code/CreateAccountVerificationCodeViewModel.kt#L169

Added line #L169 was not covered by tests
replace = false
).let {
when (it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ class LoginEmailViewModelTest {
loginViewModel.userIdentifierTextState.setTextAndPlaceCursorAtEnd(email)
loginViewModel.secondFactorVerificationCodeTextState.setTextAndPlaceCursorAtEnd(code)
advanceUntilIdle()
coVerify(exactly = 0) { arrangement.addAuthenticatedUserUseCase(any(), any(), any(), any()) }
coVerify(exactly = 0) { arrangement.addAuthenticatedUserUseCase(any(), any(), any(), any(), any()) }
coVerify(exactly = 0) { arrangement.getOrRegisterClientUseCase(any()) }
assertEquals(LoginState.Error.DialogError.Request2FAWithHandle, loginViewModel.loginState.flowState)
}
Expand Down Expand Up @@ -689,7 +689,7 @@ class LoginEmailViewModelTest {
}
coVerify(exactly = 1) { // verify that the second login job has been started
arrangement.loginUseCase(any(), any(), any(), any(), any())
arrangement.addAuthenticatedUserUseCase(any(), any(), eq(authToken2), any(), any())
arrangement.addAuthenticatedUserUseCase(any(), any(), eq(authToken2), any(), any(), any(), any())
}
}

Expand Down Expand Up @@ -880,7 +880,8 @@ class LoginEmailViewModelTest {
coreLogic,
countdownTimer,
dispatcherProvider,
ServerConfig.STAGING
ServerConfig.STAGING,
false,
).also { it.autoLoginWhenFullCodeEntered = true }

fun withLoginReturning(result: AuthenticationResult) = apply {
Expand All @@ -891,7 +892,7 @@ class LoginEmailViewModelTest {

fun withAddAuthenticatedUserReturning(result: AddAuthenticatedUserUseCase.Result) = apply {
coEvery {
addAuthenticatedUserUseCase(any(), any(), any(), any(), any())
addAuthenticatedUserUseCase(any(), any(), any(), any(), any(), any(), any())
} returns result
}

Expand Down