Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Display ErrorCode for DecryptionError [WPB-1795] #3414

Merged
merged 7 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 6 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 @@ -36,6 +36,7 @@ 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 @@ -481,4 +482,9 @@ class UseCaseModule {
@KaliumCoreLogic coreLogic: CoreLogic,
@CurrentAccount currentAccount: UserId
): GetCurrentAnalyticsTrackingIdentifierUseCase = coreLogic.getSessionScope(currentAccount).getCurrentAnalyticsTrackingIdentifier

@ViewModelScoped
@Provides
fun provideBreakSessionUseCase(@KaliumCoreLogic coreLogic: CoreLogic, @CurrentAccount currentAccount: UserId): BreakSessionUseCase =
coreLogic.getSessionScope(currentAccount).debug.breakSession
}
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class MessageMapper @Inject constructor(

val content = message.content
val flowStatus = if (content is MessageContent.FailedDecryption) {
MessageFlowStatus.Failure.Decryption(content.isDecryptionResolved)
MessageFlowStatus.Failure.Decryption(content.isDecryptionResolved, content.errorCode)
} else {
when (val status = message.status) {
Message.Status.Pending -> MessageFlowStatus.Sending
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,12 @@ class RegularMessageMapper @Inject constructor(
)
} ?: UIText.StringResource(R.string.sent_a_message_with_unknown_content)

is MessageContent.FailedDecryption -> UIText.StringResource(R.string.label_message_decryption_failure_message)
is MessageContent.FailedDecryption -> {
content.errorCode?.let {
UIText.StringResource(R.string.label_message_decryption_failure_message_with_error_code, it)
} ?: UIText.StringResource(R.string.label_message_decryption_failure_message)
}

else -> UIText.StringResource(R.string.sent_a_message_with_unknown_content)
},
quotedMessage = quotedMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ fun PreviewMessageDecryptionFailure() {
WireTheme {
MessageDecryptionFailure(
mockHeader,
MessageFlowStatus.Failure.Decryption(false),
MessageFlowStatus.Failure.Decryption(false, 0),
{ _, _ -> },
Conversation.ProtocolInfo.Proteus
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ fun PreviewFailedDecryptionMessage() {
it.copy(
header = it.header.copy(
messageStatus = MessageStatus(
flowStatus = MessageFlowStatus.Failure.Decryption(false),
flowStatus = MessageFlowStatus.Failure.Decryption(false, 222),
expirationStatus = ExpirationStatus.NotExpirable
)
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,10 @@ sealed class MessageFlowStatus {
)
}

data class Decryption(val isDecryptionResolved: Boolean) : Failure(
UIText.StringResource(R.string.label_message_decryption_failure_message)
data class Decryption(val isDecryptionResolved: Boolean, private val errorCode: Int?) : Failure(
errorCode?.let {
UIText.StringResource(R.string.label_message_decryption_failure_message_with_error_code, it)
} ?: UIText.StringResource(R.string.label_message_decryption_failure_message)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ fun DeviceDetailsScreen(
)
},
onEnrollE2EIErrorDismiss = viewModel::hideEnrollE2EICertificateError,
onEnrollE2EISuccessDismiss = viewModel::hideEnrollE2EICertificateSuccess
onEnrollE2EISuccessDismiss = viewModel::hideEnrollE2EICertificateSuccess,
onBreakSession = viewModel::breakSession
)
}
}
Expand All @@ -155,7 +156,8 @@ fun DeviceDetailsContent(
enrollE2eiCertificate: () -> Unit = {},
onUpdateClientVerification: (Boolean) -> Unit = {},
onEnrollE2EIErrorDismiss: () -> Unit = {},
onEnrollE2EISuccessDismiss: () -> Unit = {}
onEnrollE2EISuccessDismiss: () -> Unit = {},
onBreakSession: () -> Unit = {}
) {
val screenState = rememberConversationScreenState()
WireScaffold(
Expand Down Expand Up @@ -268,6 +270,10 @@ fun DeviceDetailsContent(
HorizontalDivider(color = MaterialTheme.wireColorScheme.background)
}
}

if (BuildConfig.DEBUG && !state.isCurrentDevice) {
item { BreakSessionButton(onBreakSession) }
}
}
if (state.removeDeviceDialogState is RemoveDeviceDialogState.Visible) {
RemoveDeviceDialog(
Expand Down Expand Up @@ -317,6 +323,21 @@ fun DeviceDetailsContent(
}
}

@Composable
private fun BreakSessionButton(onBreakSession: () -> Unit) {
WirePrimaryButton(
text = stringResource(R.string.debug_settings_break_session),
onClick = onBreakSession,
colors = wirePrimaryButtonColors(),
modifier = Modifier.padding(
start = dimensions().spacing16x,
top = dimensions().spacing16x,
end = dimensions().spacing16x,
bottom = dimensions().spacing16x
)
)
}

@Composable
private fun DeviceDetailsTopBar(
onNavigateBack: () -> Unit,
Expand Down Expand Up @@ -391,17 +412,17 @@ fun DeviceMLSSignatureItem(
) {
Column(modifier = modifier) {

DeviceDetailSectionContent(
stringResource(id = R.string.label_mls_thumbprint),
sectionText = mlsThumbprint.formatAsFingerPrint(),
titleTrailingItem = {
CopyButton(
onCopyClicked = { onCopy(mlsThumbprint) },
state = WireButtonState.Default
)
}
)
}
DeviceDetailSectionContent(
stringResource(id = R.string.label_mls_thumbprint),
sectionText = mlsThumbprint.formatAsFingerPrint(),
titleTrailingItem = {
CopyButton(
onCopyClicked = { onCopy(mlsThumbprint) },
state = WireButtonState.Default
)
}
)
}
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import com.wire.kalium.logic.feature.client.GetClientDetailsResult
import com.wire.kalium.logic.feature.client.ObserveClientDetailsUseCase
import com.wire.kalium.logic.feature.client.Result
import com.wire.kalium.logic.feature.client.UpdateClientVerificationStatusUseCase
import com.wire.kalium.logic.feature.debug.BreakSessionUseCase
import com.wire.kalium.logic.feature.e2ei.usecase.E2EIEnrollmentResult
import com.wire.kalium.logic.feature.e2ei.usecase.GetMLSClientIdentityUseCase
import com.wire.kalium.logic.feature.user.GetUserInfoResult
Expand Down Expand Up @@ -72,6 +73,7 @@ class DeviceDetailsViewModel @Inject constructor(
private val updateClientVerificationStatus: UpdateClientVerificationStatusUseCase,
private val observeUserInfo: ObserveUserInfoUseCase,
private val e2eiCertificate: GetMLSClientIdentityUseCase,
private val breakSession: BreakSessionUseCase,
isE2EIEnabledUseCase: IsE2EIEnabledUseCase
) : SavedStateViewModel(savedStateHandle) {

Expand Down Expand Up @@ -287,4 +289,8 @@ class DeviceDetailsViewModel @Inject constructor(
fun hideEnrollE2EICertificateSuccess() {
state = state.copy(isE2EICertificateEnrollSuccess = false)
}

fun breakSession() {
viewModelScope.launch { breakSession(userId, deviceId) }
}
}
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<string name="label_message_edit_sent_remotely_failure">The edited message could not be sent, as the backend of %s could not be reached.</string>
<string name="label_message_receive_failure">Download Error</string>
<string name="label_message_decryption_failure_message">Message could not be decrypted.</string>
<string name="label_message_decryption_failure_message_with_error_code">Message could not be decrypted (Error %s).</string>
<string name="label_message_decryption_failure_informative_message">Try resetting the session to generate new encryption keys.</string>
<string name="label_system_message_self_user_knock">%s pinged</string>
<string name="label_system_message_other_user_knock">%s pinged</string>
Expand Down Expand Up @@ -222,6 +223,7 @@
<string name="debug_settings_api_versioning_title" translatable="false">API VERSIONING</string>
<string name="debug_settings_e2ei_enrollment_title" translatable="false">E2EI Manual Enrollment</string>
<string name="debug_settings_force_api_versioning_update" translatable="false">Force API versioning update</string>
<string name="debug_settings_break_session" translatable="false">⚠️ Break Session</string>
<string name="item_dependencies_title">Dependencies:</string>
<string name="debug_settings_force_api_versioning_update_button_text" translatable="false">Update</string>
<string name="support_screen_title">Support</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ object TestMessage {
content = MessageContent.FailedDecryption(
null,
senderUserId = UserId("user-id", "domain"),
isDecryptionResolved = false
isDecryptionResolved = false,
errorCode = null
),
conversationId = ConversationId("convo-id", "convo.domain"),
date = Instant.parse("2022-03-30T15:36:00.000Z"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ private fun Message.Regular.failureToDecrypt(isDecryptionResolved: Boolean) =
.copy(
content = MessageContent.FailedDecryption(
encodedData = null,
errorCode = null,
senderUserId = this.senderUserId,
isDecryptionResolved = isDecryptionResolved
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ private val LightWireColorScheme = WireColorScheme(
disabledCheckedColor = WireColorPalette.Gray80,
disabledIndeterminateColor = WireColorPalette.Gray80,
disabledUncheckedColor = WireColorPalette.Gray80,
messageErrorBackgroundColor = WireColorPalette.DarkRed50,
messageErrorBackgroundColor = WireColorPalette.LightRed50,
groupAvatarColors = listOf(
// Red
WireColorPalette.LightRed300,
Expand Down
2 changes: 1 addition & 1 deletion kalium
Submodule kalium updated 16 files
+14 −2 cryptography/src/commonJvmAndroid/kotlin/com.wire.kalium.cryptography/ProteusClientCoreCryptoImpl.kt
+32 −2 cryptography/src/commonMain/kotlin/com/wire/kalium/cryptography/exceptions/ProteusException.kt
+1 −0 data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/Message.kt
+1 −0 data/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageContent.kt
+2 −0 logic/src/commonMain/kotlin/com/wire/kalium/logic/data/message/MessageMapper.kt
+3 −0 logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/NewMessageEventHandler.kt
+2 −1 logic/src/commonMain/kotlin/com/wire/kalium/logic/sync/receiver/conversation/message/ProteusMessageUnpacker.kt
+2 −1 persistence/src/commonMain/db_user/com/wire/kalium/persistence/DumpContent.sq
+1 −0 persistence/src/commonMain/db_user/com/wire/kalium/persistence/MessageDetailsView.sq
+3 −2 persistence/src/commonMain/db_user/com/wire/kalium/persistence/Messages.sq
+166 −0 persistence/src/commonMain/db_user/migrations/86.sqm
+1 −0 persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageEntity.kt
+1 −0 persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageInsertExtension.kt
+2 −0 persistence/src/commonMain/kotlin/com/wire/kalium/persistence/dao/message/MessageMapper.kt
+3 −2 persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/message/MessageDAOTest.kt
+2 −0 persistence/src/commonTest/kotlin/com/wire/kalium/persistence/dao/message/MessageMapperTest.kt
Loading