From 97e5588b54c95adace23057ec2b4335486c8cf36 Mon Sep 17 00:00:00 2001 From: "sergei.bakhtiarov" Date: Tue, 10 Dec 2024 17:09:29 +0100 Subject: [PATCH] feat: add more debug information (WPB-14930) --- .../wire/android/ui/debug/DebugDataOptions.kt | 15 ++++++++++ .../android/ui/debug/DebugDataOptionsState.kt | 5 +++- .../ui/debug/DebugDataOptionsViewModel.kt | 30 +++++++++++++++++++ .../debug/DebugDataOptionsViewModelTest.kt | 30 +++++++++++++++++++ 4 files changed, 79 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/wire/android/ui/debug/DebugDataOptions.kt b/app/src/main/kotlin/com/wire/android/ui/debug/DebugDataOptions.kt index 756669e1442..f120295c591 100644 --- a/app/src/main/kotlin/com/wire/android/ui/debug/DebugDataOptions.kt +++ b/app/src/main/kotlin/com/wire/android/ui/debug/DebugDataOptions.kt @@ -161,6 +161,21 @@ fun DebugDataOptionsContent( ) ) + Column { + SettingsItem( + title = "Federation Enabled", + text = state.isFederationEnabled.toString(), + ) + SettingsItem( + title = "Default Backend Protocol", + text = state.defaultProtocol, + ) + SettingsItem( + title = "Current API Version", + text = state.currentApiVersion.toString(), + ) + } + if (BuildConfig.DEBUG) { GetE2EICertificateSwitch( enrollE2EI = enrollE2EICertificate diff --git a/app/src/main/kotlin/com/wire/android/ui/debug/DebugDataOptionsState.kt b/app/src/main/kotlin/com/wire/android/ui/debug/DebugDataOptionsState.kt index acc93712f82..7a8edf2cd96 100644 --- a/app/src/main/kotlin/com/wire/android/ui/debug/DebugDataOptionsState.kt +++ b/app/src/main/kotlin/com/wire/android/ui/debug/DebugDataOptionsState.kt @@ -29,5 +29,8 @@ data class DebugDataOptionsState( val certificate: String = "null", val showCertificate: Boolean = false, val startGettingE2EICertificate: Boolean = false, - val analyticsTrackingId: String = "null" + val analyticsTrackingId: String = "null", + val isFederationEnabled: Boolean = false, + val currentApiVersion: Int = 0, + val defaultProtocol: String = "null", ) diff --git a/app/src/main/kotlin/com/wire/android/ui/debug/DebugDataOptionsViewModel.kt b/app/src/main/kotlin/com/wire/android/ui/debug/DebugDataOptionsViewModel.kt index b23e0d65238..4b95ae92fc0 100644 --- a/app/src/main/kotlin/com/wire/android/ui/debug/DebugDataOptionsViewModel.kt +++ b/app/src/main/kotlin/com/wire/android/ui/debug/DebugDataOptionsViewModel.kt @@ -34,6 +34,7 @@ import com.wire.android.util.getGitBuildId import com.wire.android.util.ui.UIText import com.wire.kalium.logic.CoreFailure import com.wire.kalium.logic.E2EIFailure +import com.wire.kalium.logic.data.user.SupportedProtocol import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.feature.analytics.GetCurrentAnalyticsTrackingIdentifierUseCase import com.wire.kalium.logic.feature.e2ei.CheckCrlRevocationListUseCase @@ -42,6 +43,8 @@ import com.wire.kalium.logic.feature.keypackage.MLSKeyPackageCountResult import com.wire.kalium.logic.feature.keypackage.MLSKeyPackageCountUseCase import com.wire.kalium.logic.feature.notificationToken.SendFCMTokenError import com.wire.kalium.logic.feature.notificationToken.SendFCMTokenUseCase +import com.wire.kalium.logic.feature.user.GetDefaultProtocolUseCase +import com.wire.kalium.logic.feature.user.SelfServerConfigUseCase import com.wire.kalium.logic.functional.Either import com.wire.kalium.logic.functional.fold import com.wire.kalium.logic.sync.periodic.UpdateApiVersionsScheduler @@ -87,6 +90,8 @@ class DebugDataOptionsViewModelImpl private val getCurrentAnalyticsTrackingIdentifier: GetCurrentAnalyticsTrackingIdentifierUseCase, private val sendFCMToken: SendFCMTokenUseCase, private val dispatcherProvider: DispatcherProvider, + private val selfServerConfigUseCase: SelfServerConfigUseCase, + private val getDefaultProtocolUseCase: GetDefaultProtocolUseCase, ) : ViewModel(), DebugDataOptionsViewModel { var state by mutableStateOf( @@ -102,6 +107,31 @@ class DebugDataOptionsViewModelImpl checkIfCanTriggerManualMigration() setGitHashAndDeviceId() setAnalyticsTrackingId() + setServerConfigData() + setDefaultProtocol() + } + + private fun setDefaultProtocol() { + viewModelScope.launch { + state = state.copy( + defaultProtocol = when (getDefaultProtocolUseCase()) { + SupportedProtocol.PROTEUS -> "Proteus" + SupportedProtocol.MLS -> "MLS" + } + ) + } + } + + private fun setServerConfigData() { + viewModelScope.launch { + val result = selfServerConfigUseCase() + if (result is SelfServerConfigUseCase.Result.Success) { + state = state.copy( + isFederationEnabled = result.serverLinks.metaData.federation, + currentApiVersion = result.serverLinks.metaData.commonApiVersion.version, + ) + } + } } private fun setAnalyticsTrackingId() { diff --git a/app/src/test/kotlin/com/wire/android/ui/settings/debug/DebugDataOptionsViewModelTest.kt b/app/src/test/kotlin/com/wire/android/ui/settings/debug/DebugDataOptionsViewModelTest.kt index f4476ca976c..d1d2fcbb35f 100644 --- a/app/src/test/kotlin/com/wire/android/ui/settings/debug/DebugDataOptionsViewModelTest.kt +++ b/app/src/test/kotlin/com/wire/android/ui/settings/debug/DebugDataOptionsViewModelTest.kt @@ -31,7 +31,10 @@ import com.wire.android.ui.debug.DebugDataOptionsViewModelImpl import com.wire.android.util.getDeviceIdString import com.wire.android.util.getGitBuildId import com.wire.android.util.ui.UIText +import com.wire.kalium.logic.configuration.server.CommonApiVersionType +import com.wire.kalium.logic.configuration.server.ServerConfig import com.wire.kalium.logic.data.conversation.ClientId +import com.wire.kalium.logic.data.user.SupportedProtocol import com.wire.kalium.logic.data.user.UserId import com.wire.kalium.logic.feature.analytics.GetCurrentAnalyticsTrackingIdentifierUseCase import com.wire.kalium.logic.feature.e2ei.CheckCrlRevocationListUseCase @@ -39,6 +42,8 @@ import com.wire.kalium.logic.feature.keypackage.MLSKeyPackageCountResult import com.wire.kalium.logic.feature.keypackage.MLSKeyPackageCountUseCase import com.wire.kalium.logic.feature.notificationToken.SendFCMTokenError import com.wire.kalium.logic.feature.notificationToken.SendFCMTokenUseCase +import com.wire.kalium.logic.feature.user.GetDefaultProtocolUseCase +import com.wire.kalium.logic.feature.user.SelfServerConfigUseCase import com.wire.kalium.logic.functional.Either import com.wire.kalium.logic.sync.periodic.UpdateApiVersionsScheduler import com.wire.kalium.logic.sync.slow.RestartSlowSyncProcessForRecoveryUseCase @@ -46,6 +51,7 @@ import io.mockk.MockKAnnotations import io.mockk.coEvery import io.mockk.every import io.mockk.impl.annotations.MockK +import io.mockk.mockk import io.mockk.mockkStatic import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi @@ -155,6 +161,12 @@ internal class DebugDataOptionsHiltArrangement { @MockK lateinit var getCurrentAnalyticsTrackingIdentifier: GetCurrentAnalyticsTrackingIdentifierUseCase + @MockK + lateinit var selfServerConfigUseCase: SelfServerConfigUseCase + + @MockK + lateinit var getDefaultProtocolUseCase: GetDefaultProtocolUseCase + @MockK lateinit var sendFCMToken: SendFCMTokenUseCase @@ -170,6 +182,8 @@ internal class DebugDataOptionsHiltArrangement { getCurrentAnalyticsTrackingIdentifier = getCurrentAnalyticsTrackingIdentifier, sendFCMToken = sendFCMToken, dispatcherProvider = TestDispatcherProvider(), + selfServerConfigUseCase = selfServerConfigUseCase, + getDefaultProtocolUseCase = getDefaultProtocolUseCase, ) } @@ -196,6 +210,22 @@ internal class DebugDataOptionsHiltArrangement { coEvery { globalDataStore.getUserMigrationStatus(TestUser.SELF_USER_ID.value) } returns flowOf(UserMigrationStatus.NoNeed) + coEvery { + selfServerConfigUseCase() + } returns SelfServerConfigUseCase.Result.Success( + ServerConfig( + id = "id", + links = mockk(), + metaData = ServerConfig.MetaData( + federation = true, + commonApiVersion = CommonApiVersionType.Unknown, + domain = null, + ) + ) + ) + every { + getDefaultProtocolUseCase() + } returns SupportedProtocol.PROTEUS } fun arrange() = this to viewModel