From b3d8b1527cc545ce81def083b7b113a3cc32ae4d Mon Sep 17 00:00:00 2001 From: valere Date: Wed, 30 Nov 2022 15:14:31 +0100 Subject: [PATCH] cleaning --- matrix-sdk-android/build.gradle | 1 - .../internal/crypto/DefaultCryptoService.kt | 4 +-- .../EnsureOlmSessionsForDevicesAction.kt | 25 ++++++++----------- .../VerificationTransportLayer.kt | 3 +-- .../crypto/store/db/RealmCryptoStore.kt | 4 +-- .../internal/crypto/tasks/SendEventTask.kt | 11 ++++---- .../session/sync/SyncResponseHandler.kt | 5 ++-- .../coroutines/builder/FlowBuilders.kt | 4 ++- .../android/sdk/internal/crypto/OlmMachine.kt | 2 +- .../vector/app/core/pushers/PushersManager.kt | 4 +-- .../self/SelfVerificationController.kt | 1 + .../user/UserVerificationController.kt | 2 +- .../features/navigation/DefaultNavigator.kt | 6 +++-- .../app/features/rageshake/BugReporter.kt | 2 +- .../settings/devices/DevicesViewModel.kt | 6 ++--- ...leNotificationsForCurrentSessionUseCase.kt | 2 +- ...leNotificationsForCurrentSessionUseCase.kt | 2 +- 17 files changed, 40 insertions(+), 44 deletions(-) rename matrix-sdk-android/src/{main => rustCrypto}/java/org/matrix/android/sdk/internal/coroutines/builder/FlowBuilders.kt (91%) diff --git a/matrix-sdk-android/build.gradle b/matrix-sdk-android/build.gradle index a06d6e59ed..92d1c067f3 100644 --- a/matrix-sdk-android/build.gradle +++ b/matrix-sdk-android/build.gradle @@ -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", ] diff --git a/matrix-sdk-android/src/kotlinCrypto/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt b/matrix-sdk-android/src/kotlinCrypto/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt index aa6d54ad3c..cfbfd45ef4 100755 --- a/matrix-sdk-android/src/kotlinCrypto/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt +++ b/matrix-sdk-android/src/kotlinCrypto/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt @@ -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) diff --git a/matrix-sdk-android/src/kotlinCrypto/java/org/matrix/android/sdk/internal/crypto/actions/EnsureOlmSessionsForDevicesAction.kt b/matrix-sdk-android/src/kotlinCrypto/java/org/matrix/android/sdk/internal/crypto/actions/EnsureOlmSessionsForDevicesAction.kt index c0769edfdb..cb89975464 100644 --- a/matrix-sdk-android/src/kotlinCrypto/java/org/matrix/android/sdk/internal/crypto/actions/EnsureOlmSessionsForDevicesAction.kt +++ b/matrix-sdk-android/src/kotlinCrypto/java/org/matrix/android/sdk/internal/crypto/actions/EnsureOlmSessionsForDevicesAction.kt @@ -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() - 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() + 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 diff --git a/matrix-sdk-android/src/kotlinCrypto/java/org/matrix/android/sdk/internal/crypto/verification/VerificationTransportLayer.kt b/matrix-sdk-android/src/kotlinCrypto/java/org/matrix/android/sdk/internal/crypto/verification/VerificationTransportLayer.kt index 465480b445..275ad752b8 100644 --- a/matrix-sdk-android/src/kotlinCrypto/java/org/matrix/android/sdk/internal/crypto/verification/VerificationTransportLayer.kt +++ b/matrix-sdk-android/src/kotlinCrypto/java/org/matrix/android/sdk/internal/crypto/verification/VerificationTransportLayer.kt @@ -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( diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt index 00cfcdaa6f..c0e0a89d64 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/store/db/RealmCryptoStore.kt @@ -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 } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt index 2a950f1f19..51bb322c0f 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/tasks/SendEventTask.kt @@ -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 } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncResponseHandler.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncResponseHandler.kt index b2bdd65896..3e2939a3bb 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncResponseHandler.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/session/sync/SyncResponseHandler.kt @@ -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, diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/coroutines/builder/FlowBuilders.kt b/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/coroutines/builder/FlowBuilders.kt similarity index 91% rename from matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/coroutines/builder/FlowBuilders.kt rename to matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/coroutines/builder/FlowBuilders.kt index 64b513552b..86a6f2f0bb 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/coroutines/builder/FlowBuilders.kt +++ b/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/coroutines/builder/FlowBuilders.kt @@ -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 ProducerScope.safeInvokeOnClose(handler: (cause: Throwable?) -> Unit): CompletableDeferred { val onClose = CompletableDeferred() invokeOnClose { diff --git a/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt b/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt index e28b53245b..74d8724e79 100644 --- a/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt +++ b/matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt @@ -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) { diff --git a/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt b/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt index 6f186262fc..fb78feaef1 100644 --- a/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt +++ b/vector/src/main/java/im/vector/app/core/pushers/PushersManager.kt @@ -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 ) } diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/self/SelfVerificationController.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/self/SelfVerificationController.kt index 67224a65df..24948f9f67 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/self/SelfVerificationController.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/self/SelfVerificationController.kt @@ -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) } diff --git a/vector/src/main/java/im/vector/app/features/crypto/verification/user/UserVerificationController.kt b/vector/src/main/java/im/vector/app/features/crypto/verification/user/UserVerificationController.kt index 39c4b2fd25..e995f33621 100644 --- a/vector/src/main/java/im/vector/app/features/crypto/verification/user/UserVerificationController.kt +++ b/vector/src/main/java/im/vector/app/features/crypto/verification/user/UserVerificationController.kt @@ -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 { diff --git a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt index c9e16bcf16..bfd22f8d82 100644 --- a/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/navigation/DefaultNavigator.kt @@ -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 } diff --git a/vector/src/main/java/im/vector/app/features/rageshake/BugReporter.kt b/vector/src/main/java/im/vector/app/features/rageshake/BugReporter.kt index a9ff47bfb1..df0879da24 100755 --- a/vector/src/main/java/im/vector/app/features/rageshake/BugReporter.kt +++ b/vector/src/main/java/im/vector/app/features/rageshake/BugReporter.kt @@ -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) } diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/DevicesViewModel.kt b/vector/src/main/java/im/vector/app/features/settings/devices/DevicesViewModel.kt index 2255eb9cef..154e92a7d8 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/DevicesViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/DevicesViewModel.kt @@ -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, diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/DisableNotificationsForCurrentSessionUseCase.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/DisableNotificationsForCurrentSessionUseCase.kt index 61c884f0bc..a7ef73d647 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/DisableNotificationsForCurrentSessionUseCase.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/DisableNotificationsForCurrentSessionUseCase.kt @@ -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 { diff --git a/vector/src/main/java/im/vector/app/features/settings/notifications/EnableNotificationsForCurrentSessionUseCase.kt b/vector/src/main/java/im/vector/app/features/settings/notifications/EnableNotificationsForCurrentSessionUseCase.kt index 180627a15f..263b9a4160 100644 --- a/vector/src/main/java/im/vector/app/features/settings/notifications/EnableNotificationsForCurrentSessionUseCase.kt +++ b/vector/src/main/java/im/vector/app/features/settings/notifications/EnableNotificationsForCurrentSessionUseCase.kt @@ -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) } }