crypto: Get rid of the DeviceKeysManager

This commit is contained in:
Damir Jelić 2021-04-08 15:55:10 +02:00
parent 08d0787cc9
commit edfd1b2fe0
2 changed files with 22 additions and 7 deletions

View file

@ -122,8 +122,6 @@ internal class DefaultCryptoService @Inject constructor(
private val cryptoStore: IMXCryptoStore, private val cryptoStore: IMXCryptoStore,
// Set of parameters used to configure/customize the end-to-end crypto. // Set of parameters used to configure/customize the end-to-end crypto.
private val mxCryptoConfig: MXCryptoConfig, private val mxCryptoConfig: MXCryptoConfig,
// Device list manager
private val deviceListManager: DeviceListManager,
// The key backup service. // The key backup service.
private val keysBackupService: DefaultKeysBackupService, private val keysBackupService: DefaultKeysBackupService,
// The verification service. // The verification service.
@ -915,7 +913,13 @@ internal class DefaultCryptoService @Inject constructor(
override fun downloadKeys(userIds: List<String>, forceDownload: Boolean, callback: MatrixCallback<MXUsersDevicesMap<CryptoDeviceInfo>>) { override fun downloadKeys(userIds: List<String>, forceDownload: Boolean, callback: MatrixCallback<MXUsersDevicesMap<CryptoDeviceInfo>>) {
cryptoCoroutineScope.launch(coroutineDispatchers.crypto) { cryptoCoroutineScope.launch(coroutineDispatchers.crypto) {
runCatching { 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) }.foldToCallback(callback)
} }
} }

View file

@ -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.crosssigning.DeviceTrustLevel
import org.matrix.android.sdk.internal.crypto.model.CryptoDeviceInfo 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.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.crypto.model.rest.UnsignedDeviceInfo
import org.matrix.android.sdk.internal.di.MoshiProvider import org.matrix.android.sdk.internal.di.MoshiProvider
import org.matrix.android.sdk.internal.session.sync.model.DeviceListResponse 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 * Let the state machine know about E2EE related sync changes that we
* received from the server. * received from the server.
@ -261,7 +261,6 @@ internal class OlmMachine(user_id: String, device_id: String, path: File) {
inner.updateTrackedUsers(users) inner.updateTrackedUsers(users)
} }
/** /**
* Generate one-time key claiming requests for all the users we are missing * Generate one-time key claiming requests for all the users we are missing
* sessions for. * sessions for.
@ -394,7 +393,6 @@ internal class OlmMachine(user_id: String, device_id: String, path: File) {
inner.exportKeys(passphrase, rounds).toByteArray() inner.exportKeys(passphrase, rounds).toByteArray()
} }
/** /**
* Import room keys from the given serialized key export. * 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) ImportRoomKeysResult(result.total, result.imported)
} }
/** /**
* Get a `Device` from the store. * 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() } return inner.getUserDevices(userId).map { Device(it, inner).toCryptoDeviceInfo() }
} }
suspend fun getUserDevicesMap(userIds: List<String>): MXUsersDevicesMap<CryptoDeviceInfo> {
val userMap = MXUsersDevicesMap<CryptoDeviceInfo>()
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. * Get all the devices of multiple users.
* *