Skip to content

Commit

Permalink
feat: database logger [WPB-14608] (#3798)
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadJaara authored Jan 15, 2025
1 parent 8d45505 commit b0aa25c
Show file tree
Hide file tree
Showing 11 changed files with 160 additions and 275 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ class DebugScreenComposeTest {
onManualMigrationPressed = {},
state = UserDebugState(logPath = "logPath"),
onLoggingEnabledChange = {},
onDeleteLogs = {}
onDeleteLogs = {},
onDatabaseLoggerEnabledChanged = {},
)
}
}
Expand Down
8 changes: 0 additions & 8 deletions app/src/main/kotlin/com/wire/android/WireApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import co.touchlab.kermit.platformLogWriter
import com.wire.android.analytics.ObserveCurrentSessionAnalyticsUseCase
import com.wire.android.datastore.GlobalDataStore
import com.wire.android.datastore.UserDataStoreProvider
import com.wire.android.debug.DatabaseProfilingManager
import com.wire.android.di.ApplicationScope
import com.wire.android.di.KaliumCoreLogic
import com.wire.android.feature.analytics.AnonymousAnalyticsManager
Expand Down Expand Up @@ -94,9 +93,6 @@ class WireApplication : BaseApp() {
@Inject
lateinit var currentScreenManager: CurrentScreenManager

@Inject
lateinit var databaseProfilingManager: DatabaseProfilingManager

@Inject
lateinit var analyticsManager: Lazy<AnonymousAnalyticsManager>

Expand Down Expand Up @@ -207,10 +203,6 @@ class WireApplication : BaseApp() {
logDeviceInformation()
// 5. Verify if we can initialize Anonymous Analytics
initializeAnonymousAnalytics()
// 6. Observe and update profiling when needed
globalAppScope.launch {
databaseProfilingManager.observeAndUpdateProfiling()
}
}

private fun initializeAnonymousAnalytics() {
Expand Down

This file was deleted.

16 changes: 0 additions & 16 deletions app/src/main/kotlin/com/wire/android/di/CoreLogicModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import com.wire.kalium.logic.feature.connection.BlockUserUseCase
import com.wire.kalium.logic.feature.connection.UnblockUserUseCase
import com.wire.kalium.logic.feature.conversation.ObserveOtherUserSecurityClassificationLabelUseCase
import com.wire.kalium.logic.feature.conversation.ObserveSecurityClassificationLabelUseCase
import com.wire.kalium.logic.feature.debug.BreakSessionUseCase
import com.wire.kalium.logic.feature.e2ei.usecase.FetchConversationMLSVerificationStatusUseCase
import com.wire.kalium.logic.feature.featureConfig.ObserveIsAppLockEditableUseCase
import com.wire.kalium.logic.feature.selfDeletingMessages.ObserveSelfDeletionTimerSettingsForConversationUseCase
Expand Down Expand Up @@ -214,11 +213,6 @@ class UseCaseModule {
fun provideUpdateApiVersionsUseCase(@KaliumCoreLogic coreLogic: CoreLogic) =
coreLogic.getGlobalScope().updateApiVersions

@ViewModelScoped
@Provides
fun provideDisableEventProcessing(@KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId) =
coreLogic.getSessionScope(currentAccount).debug.disableEventProcessing

@ViewModelScoped
@Provides
fun provideCurrentSessionFlowUseCase(@KaliumCoreLogic coreLogic: CoreLogic) =
Expand Down Expand Up @@ -483,16 +477,6 @@ class UseCaseModule {
@CurrentAccount currentAccount: UserId
): GetCurrentAnalyticsTrackingIdentifierUseCase = coreLogic.getSessionScope(currentAccount).getCurrentAnalyticsTrackingIdentifier

@ViewModelScoped
@Provides
fun provideBreakSessionUseCase(@KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId): BreakSessionUseCase =
coreLogic.getSessionScope(currentAccount).debug.breakSession

@ViewModelScoped
@Provides
fun provideSendFCMTokenToAPIUseCase(@KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId) =
coreLogic.getSessionScope(currentAccount).debug.sendFCMTokenToServer

@ViewModelScoped
@Provides
fun provideMigrateFromPersonalToTeamUseCase(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Wire
* Copyright (C) 2025 Wire Swiss GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package com.wire.android.di.accountScoped

import com.wire.android.di.CurrentAccount
import com.wire.android.di.KaliumCoreLogic
import com.wire.kalium.logic.CoreLogic
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.debug.BreakSessionUseCase
import com.wire.kalium.logic.feature.debug.DebugScope
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.components.ViewModelComponent
import dagger.hilt.android.scopes.ViewModelScoped

@Module
@InstallIn(ViewModelComponent::class)
class DebugModule {

@ViewModelScoped
@Provides
fun providesDebugScope(
@KaliumCoreLogic coreLogic: CoreLogic,
@CurrentAccount currentAccount: UserId
): DebugScope = coreLogic.getSessionScope(currentAccount).debug

@ViewModelScoped
@Provides
fun provideDisableEventProcessing(debugScope: DebugScope) =
debugScope.disableEventProcessing

@ViewModelScoped
@Provides
fun provideBreakSessionUseCase(debugScope: DebugScope): BreakSessionUseCase =
debugScope.breakSession

@ViewModelScoped
@Provides
fun provideSendFCMTokenToAPIUseCase(debugScope: DebugScope) =
debugScope.sendFCMTokenToServer

@ViewModelScoped
@Provides
fun provideChangeProfilingUseCase(debugScope: DebugScope) =
debugScope.changeProfiling

@ViewModelScoped
@Provides
fun provideObserveDatabaseLoggerState(debugScope: DebugScope) =
debugScope.observeDatabaseLoggerState
}
10 changes: 8 additions & 2 deletions app/src/main/kotlin/com/wire/android/ui/debug/DebugScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ fun DebugScreen(navigator: Navigator, userDebugViewModel: UserDebugViewModel = h
},
state = userDebugViewModel.state,
onLoggingEnabledChange = userDebugViewModel::setLoggingEnabledState,
onDeleteLogs = userDebugViewModel::deleteLogs
onDeleteLogs = userDebugViewModel::deleteLogs,
onDatabaseLoggerEnabledChanged = userDebugViewModel::setDatabaseLoggerEnabledState
)
}

Expand All @@ -83,6 +84,7 @@ internal fun UserDebugContent(
onNavigationPressed: () -> Unit,
onManualMigrationPressed: (currentAccount: UserId) -> Unit,
onLoggingEnabledChange: (Boolean) -> Unit,
onDatabaseLoggerEnabledChanged: (Boolean) -> Unit,
onDeleteLogs: () -> Unit,
) {
val debugContentState: DebugContentState = rememberDebugContentState(state.logPath)
Expand All @@ -109,6 +111,9 @@ internal fun UserDebugContent(
onLoggingEnabledChange = onLoggingEnabledChange,
onDeleteLogs = onDeleteLogs,
onShareLogs = debugContentState::shareLogs,
isDBLoggerEnabled = state.isDBLoggingEnabled,
onDBLoggerEnabledChange = onDatabaseLoggerEnabledChanged,
isPrivateBuild = BuildConfig.PRIVATE_BUILD,
)
DebugDataOptions(
appVersion = AppNameUtil.createAppName(),
Expand Down Expand Up @@ -178,6 +183,7 @@ internal fun PreviewUserDebugContent() = WireTheme {
onNavigationPressed = {},
onManualMigrationPressed = {},
onLoggingEnabledChange = {},
onDeleteLogs = {}
onDeleteLogs = {},
onDatabaseLoggerEnabledChanged = {}
)
}
63 changes: 60 additions & 3 deletions app/src/main/kotlin/com/wire/android/ui/debug/LogOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.wire.android.R
import com.wire.android.model.Clickable
import com.wire.android.ui.common.RowItemTemplate
import com.wire.android.ui.common.SurfaceBackgroundWrapper
import com.wire.android.ui.common.WireSwitch
import com.wire.android.ui.common.colorsScheme
Expand All @@ -49,16 +50,26 @@ import com.wire.android.util.ui.PreviewMultipleThemes
fun LogOptions(
isLoggingEnabled: Boolean,
onLoggingEnabledChange: (Boolean) -> Unit,
isDBLoggerEnabled: Boolean,
onDBLoggerEnabledChange: (Boolean) -> Unit,
onDeleteLogs: () -> Unit,
onShareLogs: () -> Unit,
modifier: Modifier = Modifier,
isPrivateBuild: Boolean,
modifier: Modifier = Modifier
) {
Column(modifier = modifier) {
FolderHeader(stringResource(R.string.label_logs_option_title))
EnableLoggingSwitch(
isEnabled = isLoggingEnabled,
onCheckedChange = onLoggingEnabledChange
)

if (isPrivateBuild) {
UserDataBaseProfileSwitch(
isEnabled = isDBLoggerEnabled,
onCheckedChange = onDBLoggerEnabledChange
)
}
if (isLoggingEnabled) {
SettingsItem(
text = stringResource(R.string.label_share_logs),
Expand Down Expand Up @@ -123,13 +134,59 @@ private fun EnableLoggingSwitch(
}
}

@Composable
private fun UserDataBaseProfileSwitch(
isEnabled: Boolean,
onCheckedChange: ((Boolean) -> Unit),
) {
RowItemTemplate(
title = {
Text(
style = MaterialTheme.wireTypography.body01,
color = MaterialTheme.wireColorScheme.onBackground,
text = stringResource(R.string.label_user_database_profile),
modifier = Modifier.padding(start = dimensions().spacing8x)
)
},
actions = {
WireSwitch(
checked = isEnabled,
onCheckedChange = onCheckedChange,
modifier = Modifier
.padding(end = dimensions().spacing8x)
.size(
width = dimensions().buttonSmallMinSize.width,
height = dimensions().buttonSmallMinSize.height
)
)
}
)
}

@PreviewMultipleThemes
@Composable
fun PreviewLoggingOptionsPublicBuild() {
LogOptions(
isLoggingEnabled = true,
onLoggingEnabledChange = {},
isDBLoggerEnabled = true,
onDBLoggerEnabledChange = {},
onDeleteLogs = {},
onShareLogs = {},
isPrivateBuild = false,
)
}

@PreviewMultipleThemes
@Composable
fun PreviewLoggingOptions() {
fun PreviewLoggingOptionsPrivateBuild() {
LogOptions(
isLoggingEnabled = true,
onLoggingEnabledChange = {},
isDBLoggerEnabled = true,
onDBLoggerEnabledChange = {},
onDeleteLogs = {},
onShareLogs = {}
onShareLogs = {},
isPrivateBuild = true,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,15 @@ import com.wire.kalium.logger.KaliumLogLevel
import com.wire.kalium.logic.CoreLogger
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.client.ObserveCurrentClientIdUseCase
import com.wire.kalium.logic.feature.debug.ChangeProfilingUseCase
import com.wire.kalium.logic.feature.debug.ObserveDatabaseLoggerStateUseCase
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

data class UserDebugState(
val isLoggingEnabled: Boolean = false,
val isDBLoggingEnabled: Boolean = false,
val clientId: String = String.EMPTY,
val commitish: String = String.EMPTY,
val debugId: String = String.EMPTY,
Expand All @@ -50,7 +53,9 @@ class UserDebugViewModel
@CurrentAccount val currentAccount: UserId,
private val logFileWriter: LogFileWriter,
private val currentClientIdUseCase: ObserveCurrentClientIdUseCase,
private val globalDataStore: GlobalDataStore
private val globalDataStore: GlobalDataStore,
private val changeProfilingUseCase: ChangeProfilingUseCase,
private val observeDatabaseLoggerState: ObserveDatabaseLoggerStateUseCase
) : ViewModel() {

var state by mutableStateOf(
Expand All @@ -60,6 +65,21 @@ class UserDebugViewModel
init {
observeLoggingState()
observeCurrentClientId()
observeDBLoggingState()
}

fun setDatabaseLoggerEnabledState(isEnabled: Boolean) {
viewModelScope.launch {
changeProfilingUseCase(isEnabled)
}
}

fun observeDBLoggingState() {
viewModelScope.launch {
observeDatabaseLoggerState().collect {
state = state.copy(isDBLoggingEnabled = it)
}
}
}

fun deleteLogs() {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,7 @@ In group conversations, the group admin can overwrite this setting.</string>
<string name="personal_to_team_migration_error_message_unknown_error">Wire could not complete your team creation due to an unknown error.</string>
<string name="reaction_sender_self">You</string>
<string name="emoji_picker_select_reaction">Select Reaction</string>
<string name="label_user_database_profile">Database Logger</string>

<!-- Move to Folder -->
<string name="move_to_folder_success">“%1$s” was moved to “%2$s”</string>
Expand Down
Loading

0 comments on commit b0aa25c

Please sign in to comment.