This commit is contained in:
valere 2022-11-30 15:14:31 +01:00
parent dd991e759e
commit b3d8b1527c
17 changed files with 40 additions and 44 deletions

View File

@ -112,7 +112,6 @@ android {
// Disabled for now, there are too many errors. Could be handled in another dedicated PR
// '-Xexplicit-api=strict', // or warning
"-opt-in=kotlin.RequiresOptIn",
"-opt-in=kotlin.OptIn",
// Opt in for kotlinx.coroutines.FlowPreview
"-opt-in=kotlinx.coroutines.FlowPreview",
]

View File

@ -201,7 +201,7 @@ internal class DefaultCryptoService @Inject constructor(
}
}
override fun onLiveEvent(roomId: String, event: Event, isInitialSync: Boolean) {
override fun onLiveEvent(roomId: String, event: Event, initialSync: Boolean) {
// handle state events
if (event.isStateEvent()) {
when (event.type) {
@ -212,7 +212,7 @@ internal class DefaultCryptoService @Inject constructor(
}
// handle verification
if (!isInitialSync) {
if (!initialSync) {
if (event.type != null && verificationMessageProcessor.shouldProcess(event.type)) {
cryptoCoroutineScope.launch(coroutineDispatchers.dmVerif) {
verificationMessageProcessor.process(roomId, event)

View File

@ -92,24 +92,19 @@ internal class EnsureOlmSessionsForDevicesAction @Inject constructor(
// Let's now claim one time keys
val claimParams = ClaimOneTimeKeysForUsersDeviceTask.Params(usersDevicesToClaim.map)
val oneTimeKeys = withContext(coroutineDispatchers.io) {
val oneTimeKeysForUsers = withContext(coroutineDispatchers.io) {
oneTimeKeysForUsersDeviceTask.executeRetry(claimParams, ONE_TIME_KEYS_RETRY_COUNT)
}.oneTimeKeys.let { oneTimeKeys ->
val map = MXUsersDevicesMap<MXKey>()
oneTimeKeys?.let { oneTimeKeys ->
for ((userId, mapByUserId) in oneTimeKeys) {
for ((deviceId, deviceKey) in mapByUserId) {
val mxKey = MXKey.from(deviceKey)
if (mxKey != null) {
map.setObject(userId, deviceId, mxKey)
} else {
Timber.e("## claimOneTimeKeysForUsersDevices : fail to create a MXKey")
}
}
}
val oneTimeKeys = MXUsersDevicesMap<MXKey>()
for ((userId, mapByUserId) in oneTimeKeysForUsers.oneTimeKeys.orEmpty()) {
for ((deviceId, deviceKey) in mapByUserId) {
val mxKey = MXKey.from(deviceKey)
if (mxKey != null) {
oneTimeKeys.setObject(userId, deviceId, mxKey)
} else {
Timber.e("## claimOneTimeKeysForUsersDevices : fail to create a MXKey")
}
}
map
}
// let now start olm session using the new otks

View File

@ -77,8 +77,7 @@ internal class VerificationTransportLayer @Inject constructor(
}
}
suspend fun sendInRoom(localId: String = LocalEcho.createLocalEchoId(),
type: String,
suspend fun sendInRoom(type: String,
roomId: String,
content: Content): String {
val event = createEventAndLocalEcho(

View File

@ -522,9 +522,7 @@ internal class RealmCryptoStore @Inject constructor(
val key = it.keyBackupRecoveryKey
val version = it.keyBackupRecoveryKeyVersion
if (!key.isNullOrBlank() && !version.isNullOrBlank()) {
BackupUtils.recoveryKeyFromBase58(key)?.let { key ->
SavedKeyBackupKeyInfo(recoveryKey = key, version = version)
}
SavedKeyBackupKeyInfo(recoveryKey = BackupUtils.recoveryKeyFromBase58(key), version = version)
} else {
null
}

View File

@ -95,12 +95,13 @@ internal class DefaultSendEventTask @Inject constructor(
@Throws
private suspend fun handleEncryption(params: SendEventTask.Params): Event {
if (params.encrypt && !params.event.isEncrypted()) {
val params = EncryptEventTask.Params(
params.event.roomId ?: "",
params.event,
listOf("m.relates_to")
return encryptEventTask.execute(
EncryptEventTask.Params(
params.event.roomId ?: "",
params.event,
listOf("m.relates_to")
)
)
return encryptEventTask.execute(params)
}
return params.event
}

View File

@ -74,7 +74,7 @@ internal class SyncResponseHandler @Inject constructor(
// Handle the to device events before the room ones
// to ensure to decrypt them properly
handleToDevice(syncResponse, reporter)
handleToDevice(syncResponse)
val aggregator = SyncResponsePostTreatmentAggregator()
@ -112,11 +112,10 @@ internal class SyncResponseHandler @Inject constructor(
}
}
private suspend fun handleToDevice(syncResponse: SyncResponse, reporter: ProgressReporter?) {
private suspend fun handleToDevice(syncResponse: SyncResponse) {
relevantPlugins.measureSpan("task", "handle_to_device") {
measureTimeMillis {
Timber.v("Handle toDevice")
cryptoService.receiveSyncChanges(
syncResponse.toDevice,
syncResponse.deviceLists,

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 The Matrix.org Foundation C.I.C.
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,6 +17,7 @@
package org.matrix.android.sdk.internal.coroutines.builder
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.channels.ProducerScope
/**
@ -34,6 +35,7 @@ import kotlinx.coroutines.channels.ProducerScope
* }
*
*/
@OptIn(ExperimentalCoroutinesApi::class)
internal fun <T> ProducerScope<T>.safeInvokeOnClose(handler: (cause: Throwable?) -> Unit): CompletableDeferred<Unit> {
val onClose = CompletableDeferred<Unit>()
invokeOnClose {

View File

@ -772,7 +772,7 @@ internal class OlmMachine @Inject constructor(
UserTrustResult.Success
} catch (failure: Exception) {
// KeyImportError?
UserTrustResult.Failure(failure.localizedMessage)
UserTrustResult.Failure(failure.localizedMessage ?: "Unknown Error")
}
}
withContext(coroutineDispatchers.main) {

View File

@ -74,7 +74,7 @@ class PushersManager @Inject constructor(
deviceDisplayName = getDeviceInfoUseCase.execute().displayName().orEmpty(),
url = gateway,
enabled = true,
deviceId = activeSessionHolder.getActiveSession().sessionParams.deviceId ?: "MOBILE",
deviceId = activeSessionHolder.getActiveSession().sessionParams.deviceId,
append = false,
withEventIdOnly = true,
)
@ -87,7 +87,7 @@ class PushersManager @Inject constructor(
lang = localeProvider.current().language,
emailBranding = appName,
appDisplayName = appName,
deviceDisplayName = currentSession.sessionParams.deviceId ?: "MOBILE"
deviceDisplayName = currentSession.sessionParams.deviceId
)
}

View File

@ -302,6 +302,7 @@ class SelfVerificationController @Inject constructor(
private fun renderTransaction(state: SelfVerificationViewState, transaction: VerificationTransactionData) {
when (transaction) {
is VerificationTransactionData.QrTransactionData -> {
TODO("Render QR transaction $state")
// TODO
// renderQrTransaction(transaction, state.otherUserMxItem)
}

View File

@ -257,7 +257,7 @@ class UserVerificationController @Inject constructor(
private fun renderQrTransaction(transaction: VerificationTransactionData.QrTransactionData, otherUserItem: MatrixItem) {
val host = this
when (val txState = transaction.state) {
when (transaction.state) {
QRCodeVerificationState.Reciprocated -> {
// we are waiting for confirmation from the other side
bottomSheetVerificationNoticeItem {

View File

@ -254,7 +254,8 @@ class DefaultNavigator @Inject constructor(
override fun requestSessionVerification(context: Context, otherSessionId: String) {
coroutineScope.launch {
val session = sessionHolder.getSafeActiveSession() ?: return@launch
val pr = session.cryptoService().verificationService().requestSelfKeyVerification(
// val pr =
session.cryptoService().verificationService().requestSelfKeyVerification(
supportedVerificationMethodsProvider.provide()
)
if (context is AppCompatActivity) {
@ -269,7 +270,8 @@ class DefaultNavigator @Inject constructor(
override fun requestSelfSessionVerification(context: Context) {
coroutineScope.launch {
val session = sessionHolder.getSafeActiveSession() ?: return@launch
// TODO
// val session = sessionHolder.getSafeActiveSession() ?: return@launch
// val otherSessions = session.cryptoService()
// .getCryptoDeviceInfoList(session.myUserId)
// .filter { it.deviceId != session.sessionParams.deviceId }

View File

@ -261,7 +261,7 @@ class BugReporter @Inject constructor(
activeSessionHolder.getSafeActiveSession()?.let { session ->
userId = session.myUserId
deviceId = session.sessionParams.deviceId ?: "undefined"
deviceId = session.sessionParams.deviceId
olmVersion = session.cryptoService().getCryptoVersion(context, true)
}

View File

@ -223,7 +223,7 @@ class DevicesViewModel @AssistedInject constructor(
viewModelScope.launch {
val hasAccountCrossSigning = session.cryptoService().crossSigningService().isCrossSigningInitialized()
val accountCrossSigningIsTrusted = session.cryptoService().crossSigningService().isCrossSigningVerified()
val myDeviceId = session.sessionParams.deviceId ?: ""
val myDeviceId = session.sessionParams.deviceId
setState {
copy(
hasAccountCrossSigning = hasAccountCrossSigning,
@ -279,8 +279,8 @@ class DevicesViewModel @AssistedInject constructor(
supportedVerificationMethodsProvider.provide(),
session.myUserId,
action.deviceId
)?.transactionId
?.let {
).transactionId
.let {
_viewEvents.post(
DevicesViewEvents.ShowVerifyDevice(
session.myUserId,

View File

@ -33,7 +33,7 @@ class DisableNotificationsForCurrentSessionUseCase @Inject constructor(
suspend fun execute() {
val session = activeSessionHolder.getSafeActiveSession() ?: return
val deviceId = session.sessionParams.deviceId ?: return
val deviceId = session.sessionParams.deviceId
if (checkIfCanTogglePushNotificationsViaPusherUseCase.execute(session)) {
togglePushNotificationUseCase.execute(deviceId, enabled = false)
} else {

View File

@ -45,7 +45,7 @@ class EnableNotificationsForCurrentSessionUseCase @Inject constructor(
val session = activeSessionHolder.getSafeActiveSession() ?: return
if (checkIfCanTogglePushNotificationsViaPusherUseCase.execute(session)) {
val deviceId = session.sessionParams.deviceId ?: return
val deviceId = session.sessionParams.deviceId
togglePushNotificationUseCase.execute(deviceId, enabled = true)
}
}