Skip to content

Commit

Permalink
feat: database logger
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamadJaara committed Jan 13, 2025
1 parent f21c93e commit 0f20ef0
Show file tree
Hide file tree
Showing 11 changed files with 166 additions and 88 deletions.
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
Expand Up @@ -50,7 +50,7 @@ class KaliumConfigsModule {
fileRestrictionState = fileRestriction,
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 = true,
lowerKeyPackageLimits = BuildConfig.LOWER_KEYPACKAGE_LIMIT,
lowerKeyingMaterialsUpdateThreshold = BuildConfig.PRIVATE_BUILD,
developmentApiEnabled = BuildConfig.DEVELOPMENT_API_ENABLED,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import com.wire.kalium.logic.configuration.server.CommonApiVersionType
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.debug.ChangeProfilingUseCase
import com.wire.kalium.logic.feature.e2ei.CheckCrlRevocationListUseCase
import com.wire.kalium.logic.feature.e2ei.usecase.E2EIEnrollmentResult
import com.wire.kalium.logic.feature.keypackage.MLSKeyPackageCountResult
Expand Down Expand Up @@ -93,6 +94,7 @@ class DebugDataOptionsViewModelImpl
private val dispatcherProvider: DispatcherProvider,
private val selfServerConfigUseCase: SelfServerConfigUseCase,
private val getDefaultProtocolUseCase: GetDefaultProtocolUseCase,
private val changeProfiling: ChangeProfilingUseCase,
) : ViewModel(), DebugDataOptionsViewModel {

var state by mutableStateOf(
Expand Down
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 = {}
)
}
66 changes: 63 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 @@ -31,8 +31,10 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.stringResource
import com.wire.android.BuildConfig
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 +51,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 +135,61 @@ 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,
)
}


Loading

0 comments on commit 0f20ef0

Please sign in to comment.