Skip to content

Commit

Permalink
feat(debug): add debug option for disabling event processing (#2277)
Browse files Browse the repository at this point in the history
  • Loading branch information
typfel committed Oct 6, 2023
1 parent bd6094b commit 842b54b
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 62 deletions.
5 changes: 5 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 @@ -219,6 +219,11 @@ 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
167 changes: 106 additions & 61 deletions app/src/main/kotlin/com/wire/android/ui/debug/DebugDataOptions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ import com.wire.android.ui.common.button.WirePrimaryButton
import com.wire.android.ui.common.dimensions
import com.wire.android.ui.home.conversationslist.common.FolderHeader
import com.wire.android.ui.home.settings.SettingsItem
import com.wire.android.ui.theme.WireTheme
import com.wire.android.ui.theme.wireColorScheme
import com.wire.android.ui.theme.wireDimensions
import com.wire.android.ui.theme.wireTypography
import com.wire.android.util.getDeviceIdString
import com.wire.android.util.getGitBuildId
import com.wire.android.util.ui.PreviewMultipleThemes
import com.wire.kalium.logic.data.user.UserId
import com.wire.kalium.logic.feature.debug.DisableEventProcessingUseCase
import com.wire.kalium.logic.feature.keypackage.MLSKeyPackageCountResult
import com.wire.kalium.logic.feature.keypackage.MLSKeyPackageCountUseCase
import com.wire.kalium.logic.sync.periodic.UpdateApiVersionsScheduler
Expand All @@ -66,6 +66,7 @@ import javax.inject.Inject
//region DebugDataOptionsViewModel
data class DebugDataOptionsState(
val isEncryptedProteusStorageEnabled: Boolean = false,
val isEventProcessingDisabled: Boolean = false,
val keyPackagesCount: Int = 0,
val mslClientId: String = "null",
val mlsErrorMessage: String = "null",
Expand All @@ -83,7 +84,8 @@ class DebugDataOptionsViewModel
private val globalDataStore: GlobalDataStore,
private val updateApiVersions: UpdateApiVersionsScheduler,
private val mlsKeyPackageCountUseCase: MLSKeyPackageCountUseCase,
private val restartSlowSyncProcessForRecovery: RestartSlowSyncProcessForRecoveryUseCase
private val restartSlowSyncProcessForRecovery: RestartSlowSyncProcessForRecoveryUseCase,
private val disableEventProcessingUseCase: DisableEventProcessingUseCase
) : ViewModel() {

var state by mutableStateOf(
Expand Down Expand Up @@ -118,6 +120,13 @@ class DebugDataOptionsViewModel
updateApiVersions.scheduleImmediateApiVersionUpdate()
}

fun disableEventProcessing(disabled: Boolean) {
viewModelScope.launch {
disableEventProcessingUseCase(disabled)
state = state.copy(isEventProcessingDisabled = disabled)
}
}

//region Private
private fun observeEncryptedProteusStorageState() {
viewModelScope.launch {
Expand Down Expand Up @@ -189,7 +198,8 @@ fun DebugDataOptions(
onEnableEncryptedProteusStorageChange = viewModel::enableEncryptedProteusStorage,
onRestartSlowSyncForRecovery = viewModel::restartSlowSyncForRecovery,
onForceUpdateApiVersions = viewModel::forceUpdateApiVersions,
onManualMigrationPressed = { onManualMigrationPressed(viewModel.currentAccount) }
onManualMigrationPressed = { onManualMigrationPressed(viewModel.currentAccount) },
onDisableEventProcessingChange = viewModel::disableEventProcessing
)
}

Expand All @@ -201,6 +211,7 @@ fun DebugDataOptionsContent(
buildVariant: String,
onCopyText: (String) -> Unit,
onEnableEncryptedProteusStorageChange: (Boolean) -> Unit,
onDisableEventProcessingChange: (Boolean) -> Unit,
onRestartSlowSyncForRecovery: () -> Unit,
onForceUpdateApiVersions: () -> Unit,
onManualMigrationPressed: () -> Unit
Expand Down Expand Up @@ -264,7 +275,12 @@ fun DebugDataOptionsContent(
onCopyText = onCopyText
)

DevelopmentApiVersioningOptions(onForceLatestDevelopmentApiChange = onForceUpdateApiVersions)
DebugToolsOptions(
isEventProcessingEnabled = state.isEventProcessingDisabled,
onDisableEventProcessingChange = onDisableEventProcessingChange,
onRestartSlowSyncForRecovery = onRestartSlowSyncForRecovery,
onForceUpdateApiVersions = onForceUpdateApiVersions
)
}

if (state.isManualMigrationAllowed) {
Expand Down Expand Up @@ -304,35 +320,6 @@ private fun ManualMigrationOptions(
}
//endregion

//region Development API Options
@Composable
private fun DevelopmentApiVersioningOptions(
onForceLatestDevelopmentApiChange: () -> Unit
) {
FolderHeader(stringResource(R.string.debug_settings_api_versioning_title))
RowItemTemplate(
modifier = Modifier.wrapContentWidth(),
title = {
Text(
style = MaterialTheme.wireTypography.body01,
color = MaterialTheme.wireColorScheme.onBackground,
text = stringResource(R.string.debug_settings_force_api_versioning_update),
modifier = Modifier.padding(start = dimensions().spacing8x)
)
},
actions = {
WirePrimaryButton(
minSize = MaterialTheme.wireDimensions.buttonMediumMinSize,
minClickableSize = MaterialTheme.wireDimensions.buttonMinClickableSize,
onClick = onForceLatestDevelopmentApiChange,
text = stringResource(R.string.debug_settings_force_api_versioning_update_button_text),
fillMaxWidth = false
)
}
)
}
//endregion

//region MLS Options
@Composable
private fun MLSOptions(
Expand Down Expand Up @@ -371,6 +358,68 @@ private fun MLSOptions(
onClick = { onCopyText(mlsClientId) }
)
)
}
}
//endregion

//region Proteus Options
@Composable
private fun ProteusOptions(
isEncryptedStorageEnabled: Boolean,
onEncryptedStorageEnabledChange: (Boolean) -> Unit,
) {
FolderHeader(stringResource(R.string.label_proteus_option_title))
EnableEncryptedProteusStorageSwitch(
isEnabled = isEncryptedStorageEnabled,
onCheckedChange = onEncryptedStorageEnabledChange
)
}

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

//region Debug Tools
@Composable
private fun DebugToolsOptions(
isEventProcessingEnabled: Boolean,
onDisableEventProcessingChange: (Boolean) -> Unit,
onRestartSlowSyncForRecovery: () -> Unit,
onForceUpdateApiVersions: () -> Unit
) {
FolderHeader(stringResource(R.string.label_debug_tools_title))
Column {
DisableEventProcessingSwitch(
isEnabled = isEventProcessingEnabled,
onCheckedChange = onDisableEventProcessingChange
)
RowItemTemplate(
modifier = Modifier.wrapContentWidth(),
title = {
Expand All @@ -385,31 +434,37 @@ private fun MLSOptions(
WirePrimaryButton(
minSize = MaterialTheme.wireDimensions.buttonMediumMinSize,
minClickableSize = MaterialTheme.wireDimensions.buttonMinClickableSize,
onClick = restartSlowSyncForRecovery,
onClick = onRestartSlowSyncForRecovery,
text = stringResource(R.string.restart_slowsync_for_recovery_button),
fillMaxWidth = false
)
}
)
RowItemTemplate(
modifier = Modifier.wrapContentWidth(),
title = {
Text(
style = MaterialTheme.wireTypography.body01,
color = MaterialTheme.wireColorScheme.onBackground,
text = stringResource(R.string.debug_settings_force_api_versioning_update),
modifier = Modifier.padding(start = dimensions().spacing8x)
)
},
actions = {
WirePrimaryButton(
minSize = MaterialTheme.wireDimensions.buttonMediumMinSize,
minClickableSize = MaterialTheme.wireDimensions.buttonMinClickableSize,
onClick = onForceUpdateApiVersions,
text = stringResource(R.string.debug_settings_force_api_versioning_update_button_text),
fillMaxWidth = false
)
}
)
}
}
//endregion

//region Proteus Options
@Composable
private fun ProteusOptions(
isEncryptedStorageEnabled: Boolean,
onEncryptedStorageEnabledChange: (Boolean) -> Unit,
) {
FolderHeader(stringResource(R.string.label_proteus_option_title))
EnableEncryptedProteusStorageSwitch(
isEnabled = isEncryptedStorageEnabled,
onCheckedChange = onEncryptedStorageEnabledChange
)
}

@Composable
private fun EnableEncryptedProteusStorageSwitch(
private fun DisableEventProcessingSwitch(
isEnabled: Boolean = false,
onCheckedChange: ((Boolean) -> Unit)?,
) {
Expand All @@ -418,15 +473,14 @@ private fun EnableEncryptedProteusStorageSwitch(
Text(
style = MaterialTheme.wireTypography.body01,
color = MaterialTheme.wireColorScheme.onBackground,
text = stringResource(R.string.label_enable_encrypted_proteus_storage),
text = stringResource(R.string.label_disable_event_processing),
modifier = Modifier.padding(start = dimensions().spacing8x)
)
},
actions = {
WireSwitch(
checked = isEnabled,
onCheckedChange = onCheckedChange,
enabled = !isEnabled,
modifier = Modifier
.padding(end = dimensions().spacing8x)
.size(
Expand Down Expand Up @@ -457,17 +511,8 @@ fun PreviewOtherDebugOptions() {
),
onEnableEncryptedProteusStorageChange = {},
onForceUpdateApiVersions = {},
onDisableEventProcessingChange = {},
onRestartSlowSyncForRecovery = {},
onManualMigrationPressed = {}
)
}

@PreviewMultipleThemes
@Composable
fun PreviewDevelopmentApiVersioningOptions() {
WireTheme {
DevelopmentApiVersioningOptions(
onForceLatestDevelopmentApiChange = {}
)
}
}
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@
<string name="give_feedback_screen_title">Give Feedback</string>
<string name="report_bug_screen_title">Report Bug</string>
<string name="debug_settings_screen_title">Debug Settings</string>
<string name="debug_settings_api_versioning_title" translatable="false">API VERSIONING</string>
<string name="debug_settings_force_api_versioning_update" translatable="false">Force API versioning update</string>
<string name="debug_settings_force_api_versioning_update_button_text" translatable="false">Update</string>
<string name="support_screen_title">Support</string>
Expand Down Expand Up @@ -942,6 +941,8 @@
<string name="label_enable_logging">Enable Logging</string>
<string name="label_proteus_option_title">Proteus Options</string>
<string name="label_enable_encrypted_proteus_storage">Enable encrypted proteus storage</string>
<string name="label_debug_tools_title" translatable="false">Debug Tools</string>
<string name="label_disable_event_processing" translatable="false">Disable event processing</string>
<string name="label_debug_title">Debug Settings</string>
<string name="label_client_option_title">Client ID</string>
<string name="label_device_id">Device ID: %1$s</string>
Expand Down

0 comments on commit 842b54b

Please sign in to comment.