From edfd1b2fe06f6b183bc91d96366101b6926d9469 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Thu, 8 Apr 2021 15:55:10 +0200 Subject: [PATCH] crypto: Get rid of the DeviceKeysManager --- .../internal/crypto/DefaultCryptoService.kt | 10 +++++++--- .../android/sdk/internal/crypto/OlmMachine.kt | 19 +++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt index d9d6344de8..d6a47dee0a 100755 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt @@ -122,8 +122,6 @@ internal class DefaultCryptoService @Inject constructor( private val cryptoStore: IMXCryptoStore, // Set of parameters used to configure/customize the end-to-end crypto. private val mxCryptoConfig: MXCryptoConfig, - // Device list manager - private val deviceListManager: DeviceListManager, // The key backup service. private val keysBackupService: DefaultKeysBackupService, // The verification service. @@ -915,7 +913,13 @@ internal class DefaultCryptoService @Inject constructor( override fun downloadKeys(userIds: List, forceDownload: Boolean, callback: MatrixCallback>) { cryptoCoroutineScope.launch(coroutineDispatchers.crypto) { runCatching { - deviceListManager.downloadKeys(userIds, forceDownload) + if (forceDownload) { + // TODO replicate the logic from the device list manager + // where we would download the fresh info from the server. + olmMachine?.getUserDevicesMap(userIds) ?: MXUsersDevicesMap() + } else { + olmMachine?.getUserDevicesMap(userIds) ?: MXUsersDevicesMap() + } }.foldToCallback(callback) } } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt index bc7835db11..646ce03046 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/OlmMachine.kt @@ -29,6 +29,7 @@ import org.matrix.android.sdk.api.util.JsonDict import org.matrix.android.sdk.internal.crypto.crosssigning.DeviceTrustLevel import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo import org.matrix.android.sdk.internal.crypto.model.ImportRoomKeysResult +import org.matrix.android.sdk.internal.crypto.model.MXUsersDevicesMap import org.matrix.android.sdk.internal.crypto.model.rest.UnsignedDeviceInfo import org.matrix.android.sdk.internal.di.MoshiProvider import org.matrix.android.sdk.internal.session.sync.model.DeviceListResponse @@ -213,7 +214,6 @@ internal class OlmMachine(user_id: String, device_id: String, path: File) { } } - /** * Let the state machine know about E2EE related sync changes that we * received from the server. @@ -261,7 +261,6 @@ internal class OlmMachine(user_id: String, device_id: String, path: File) { inner.updateTrackedUsers(users) } - /** * Generate one-time key claiming requests for all the users we are missing * sessions for. @@ -394,7 +393,6 @@ internal class OlmMachine(user_id: String, device_id: String, path: File) { inner.exportKeys(passphrase, rounds).toByteArray() } - /** * Import room keys from the given serialized key export. * @@ -416,7 +414,6 @@ internal class OlmMachine(user_id: String, device_id: String, path: File) { ImportRoomKeysResult(result.total, result.imported) } - /** * Get a `Device` from the store. * @@ -444,6 +441,20 @@ internal class OlmMachine(user_id: String, device_id: String, path: File) { return inner.getUserDevices(userId).map { Device(it, inner).toCryptoDeviceInfo() } } + suspend fun getUserDevicesMap(userIds: List): MXUsersDevicesMap { + val userMap = MXUsersDevicesMap() + + for (user in userIds) { + val devices = getUserDevices(user) + + for (device in devices) { + userMap.setObject(user, device.deviceId, device) + } + } + + return userMap + } + /** * Get all the devices of multiple users. *