Also keep the same parameter order: (userId, deviceId) to avoid silly errors

This commit is contained in:
Benoit Marty 2020-01-22 17:00:16 +01:00
parent 79df6b8402
commit 81337d1624
7 changed files with 24 additions and 24 deletions

View file

@ -1161,7 +1161,7 @@ class KeysBackupTest : InstrumentedTest {
assertFalse(keysBackup2.isEnabled)
// - Validate the old device from the new one
aliceSession2.setDeviceVerification(DeviceTrustLevel(false, true), oldDeviceId, aliceSession2.myUserId)
aliceSession2.setDeviceVerification(DeviceTrustLevel(false, true), aliceSession2.myUserId, oldDeviceId)
// -> Backup should automatically enable on the new device
val latch4 = CountDownLatch(1)

View file

@ -59,7 +59,7 @@ interface CryptoService {
fun setWarnOnUnknownDevices(warn: Boolean)
fun setDeviceVerification(trustLevel: DeviceTrustLevel, deviceId: String, userId: String)
fun setDeviceVerification(trustLevel: DeviceTrustLevel, userId: String, deviceId: String)
fun getUserDevices(userId: String): MutableList<CryptoDeviceInfo>

View file

@ -428,12 +428,12 @@ internal class DefaultCryptoService @Inject constructor(
/**
* Update the blocked/verified state of the given device.
*
* @param verificationStatus the new verification status
* @param deviceId the unique identifier for the device.
* @param trustLevel the new trust level
* @param userId the owner of the device
* @param deviceId the unique identifier for the device.
*/
override fun setDeviceVerification(trustLevel: DeviceTrustLevel, deviceId: String, userId: String) {
setDeviceVerificationAction.handle(trustLevel, deviceId, userId)
override fun setDeviceVerification(trustLevel: DeviceTrustLevel, userId: String, deviceId: String) {
setDeviceVerificationAction.handle(trustLevel, userId, deviceId)
}
/**

View file

@ -28,7 +28,7 @@ internal class SetDeviceVerificationAction @Inject constructor(
@UserId private val userId: String,
private val keysBackup: KeysBackup) {
fun handle(trustLevel: DeviceTrustLevel, deviceId: String, userId: String) {
fun handle(trustLevel: DeviceTrustLevel, userId: String, deviceId: String) {
val device = cryptoStore.getUserDevice(userId, deviceId)
// Sanity check

View file

@ -204,8 +204,8 @@ internal class DefaultSasVerificationService @Inject constructor(
override fun markedLocallyAsManuallyVerified(userId: String, deviceID: String) {
setDeviceVerificationAction.handle(DeviceTrustLevel(false, true),
deviceID,
userId)
userId,
deviceID)
listeners.forEach {
try {

View file

@ -332,17 +332,17 @@ internal abstract class SASVerificationTransaction(
// TODO what if the otherDevice is not in this list? and should we
verifiedDevices.forEach {
setDeviceVerified(it, otherUserId)
setDeviceVerified(otherUserId, it)
}
transport.done(transactionId)
state = SasVerificationTxState.Verified
}
private fun setDeviceVerified(deviceId: String, userId: String) {
private fun setDeviceVerified(userId: String, deviceId: String) {
// TODO should not override cross sign status
setDeviceVerificationAction.handle(DeviceTrustLevel(false, true),
deviceId,
userId)
userId,
deviceId)
}
override fun cancel() {

View file

@ -89,7 +89,7 @@ class KeyRequestHandler @Inject constructor(private val context: Context)
}
// Do we already have alerts for this user/device
val mappingKey = keyForMap(deviceId, userId)
val mappingKey = keyForMap(userId, deviceId)
if (alertsToRequests.containsKey(mappingKey)) {
// just add the request, there is already an alert for this
alertsToRequests[mappingKey]?.add(request)
@ -110,7 +110,7 @@ class KeyRequestHandler @Inject constructor(private val context: Context)
}
if (deviceInfo.isUnknown) {
session?.setDeviceVerification(DeviceTrustLevel(false, false), deviceId, userId)
session?.setDeviceVerification(DeviceTrustLevel(false, false), userId, deviceId)
deviceInfo.trustLevel = DeviceTrustLevel(false, false)
@ -181,7 +181,7 @@ class KeyRequestHandler @Inject constructor(private val context: Context)
}
val alert = PopupAlertManager.VectorAlert(
alertManagerId(deviceId, userId),
alertManagerId(userId, deviceId),
context.getString(R.string.key_share_request),
dialogText,
R.drawable.key_small
@ -189,7 +189,7 @@ class KeyRequestHandler @Inject constructor(private val context: Context)
alert.colorRes = R.color.key_share_req_accent_color
val mappingKey = keyForMap(deviceId, userId)
val mappingKey = keyForMap(userId, deviceId)
alert.dismissedAction = Runnable {
denyAllRequests(mappingKey)
}
@ -249,7 +249,7 @@ class KeyRequestHandler @Inject constructor(private val context: Context)
return
}
val alertMgrUniqueKey = alertManagerId(deviceId, userId)
val alertMgrUniqueKey = alertManagerId(userId, deviceId)
alertsToRequests[alertMgrUniqueKey]?.removeAll {
it.deviceId == request.deviceId
&& it.userId == request.userId
@ -257,7 +257,7 @@ class KeyRequestHandler @Inject constructor(private val context: Context)
}
if (alertsToRequests[alertMgrUniqueKey]?.isEmpty() == true) {
PopupAlertManager.cancelAlert(alertMgrUniqueKey)
alertsToRequests.remove(keyForMap(deviceId, userId))
alertsToRequests.remove(keyForMap(userId, deviceId))
}
}
@ -275,11 +275,11 @@ class KeyRequestHandler @Inject constructor(private val context: Context)
override fun markedAsManuallyVerified(userId: String, deviceId: String) {
// accept related requests
shareAllSessions(keyForMap(deviceId, userId))
PopupAlertManager.cancelAlert(alertManagerId(deviceId, userId))
shareAllSessions(keyForMap(userId, deviceId))
PopupAlertManager.cancelAlert(alertManagerId(userId, deviceId))
}
private fun keyForMap(deviceId: String, userId: String) = "$deviceId$userId"
private fun keyForMap(userId: String, deviceId: String) = "$deviceId$userId"
private fun alertManagerId(deviceId: String, userId: String) = "ikr_$deviceId$userId"
private fun alertManagerId(userId: String, deviceId: String) = "ikr_$deviceId$userId"
}