mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-23 18:05:59 +03:00
Merge pull request #284 from vector-im/feature/better_incoming_key_verif_mgmt
Moved incoming key/verif to active session holder
This commit is contained in:
commit
842345df9b
6 changed files with 61 additions and 43 deletions
|
@ -85,6 +85,8 @@ interface CryptoService {
|
|||
|
||||
fun addRoomKeysRequestListener(listener: RoomKeysRequestListener)
|
||||
|
||||
fun removeRoomKeysRequestListener(listener: RoomKeysRequestListener)
|
||||
|
||||
fun getDevicesList(callback: MatrixCallback<DevicesListResponse>)
|
||||
|
||||
fun inboundGroupSessionsCount(onlyBackedUp: Boolean): Int
|
||||
|
|
|
@ -1023,7 +1023,7 @@ internal class CryptoManager @Inject constructor(
|
|||
*
|
||||
* @param listener listener
|
||||
*/
|
||||
fun removeRoomKeysRequestListener(listener: RoomKeysRequestListener) {
|
||||
override fun removeRoomKeysRequestListener(listener: RoomKeysRequestListener) {
|
||||
incomingRoomKeyRequestManager.removeRoomKeysRequestListener(listener)
|
||||
}
|
||||
|
||||
|
|
|
@ -17,24 +17,31 @@
|
|||
package im.vector.riotx.core.di
|
||||
|
||||
import im.vector.matrix.android.api.auth.Authenticator
|
||||
import im.vector.matrix.android.api.auth.data.SessionParams
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import java.lang.IllegalStateException
|
||||
import im.vector.riotx.features.crypto.keysrequest.KeyRequestHandler
|
||||
import im.vector.riotx.features.crypto.verification.IncomingVerificationRequestHandler
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Singleton
|
||||
class ActiveSessionHolder @Inject constructor(private val authenticator: Authenticator) {
|
||||
class ActiveSessionHolder @Inject constructor(private val authenticator: Authenticator,
|
||||
private val keyRequestHandler: KeyRequestHandler,
|
||||
private val incomingVerificationRequestHandler: IncomingVerificationRequestHandler
|
||||
) {
|
||||
|
||||
private var activeSession: AtomicReference<Session?> = AtomicReference()
|
||||
|
||||
fun setActiveSession(session: Session){
|
||||
fun setActiveSession(session: Session) {
|
||||
activeSession.set(session)
|
||||
keyRequestHandler.start(session)
|
||||
incomingVerificationRequestHandler.start(session)
|
||||
}
|
||||
|
||||
fun clearActiveSession(){
|
||||
fun clearActiveSession() {
|
||||
activeSession.set(null)
|
||||
keyRequestHandler.stop()
|
||||
incomingVerificationRequestHandler.stop()
|
||||
}
|
||||
|
||||
fun hasActiveSession(): Boolean {
|
||||
|
@ -46,13 +53,14 @@ class ActiveSessionHolder @Inject constructor(private val authenticator: Authent
|
|||
}
|
||||
|
||||
fun getActiveSession(): Session {
|
||||
return activeSession.get() ?: throw IllegalStateException("You should authenticate before using this")
|
||||
return activeSession.get()
|
||||
?: throw IllegalStateException("You should authenticate before using this")
|
||||
}
|
||||
|
||||
//TODO: Stop sync ?
|
||||
fun switchToSession(sessionParams: SessionParams) {
|
||||
val newActiveSession = authenticator.getSession(sessionParams)
|
||||
activeSession.set(newActiveSession)
|
||||
}
|
||||
// fun switchToSession(sessionParams: SessionParams) {
|
||||
// val newActiveSession = authenticator.getSession(sessionParams)
|
||||
// activeSession.set(newActiveSession)
|
||||
// }
|
||||
|
||||
}
|
|
@ -54,18 +54,27 @@ import kotlin.collections.HashMap
|
|||
*/
|
||||
|
||||
@Singleton
|
||||
class KeyRequestHandler @Inject constructor(val context: Context,
|
||||
val session: Session)
|
||||
class KeyRequestHandler @Inject constructor(val context: Context)
|
||||
: RoomKeysRequestListener,
|
||||
SasVerificationService.SasVerificationListener {
|
||||
SasVerificationService.SasVerificationListener {
|
||||
|
||||
private val alertsToRequests = HashMap<String, ArrayList<IncomingRoomKeyRequest>>()
|
||||
|
||||
init {
|
||||
var session: Session? = null
|
||||
|
||||
|
||||
fun start(session: Session) {
|
||||
this.session = session
|
||||
session.getSasVerificationService().addListener(this)
|
||||
session.addRoomKeysRequestListener(this)
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
session?.getSasVerificationService()?.removeListener(this)
|
||||
session?.removeRoomKeysRequestListener(this)
|
||||
session = null
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle incoming key request.
|
||||
*
|
||||
|
@ -92,7 +101,7 @@ class KeyRequestHandler @Inject constructor(val context: Context,
|
|||
alertsToRequests[mappingKey] = ArrayList<IncomingRoomKeyRequest>().apply { this.add(request) }
|
||||
|
||||
//Add a notification for every incoming request
|
||||
session.downloadKeys(Arrays.asList(userId), false, object : MatrixCallback<MXUsersDevicesMap<MXDeviceInfo>> {
|
||||
session?.downloadKeys(Arrays.asList(userId), false, object : MatrixCallback<MXUsersDevicesMap<MXDeviceInfo>> {
|
||||
override fun onSuccess(data: MXUsersDevicesMap<MXDeviceInfo>) {
|
||||
val deviceInfo = data.getObject(deviceId, userId)
|
||||
|
||||
|
@ -103,12 +112,12 @@ class KeyRequestHandler @Inject constructor(val context: Context,
|
|||
}
|
||||
|
||||
if (deviceInfo.isUnknown) {
|
||||
session.setDeviceVerification(MXDeviceInfo.DEVICE_VERIFICATION_UNVERIFIED, deviceId, userId)
|
||||
session?.setDeviceVerification(MXDeviceInfo.DEVICE_VERIFICATION_UNVERIFIED, deviceId, userId)
|
||||
|
||||
deviceInfo.verified = MXDeviceInfo.DEVICE_VERIFICATION_UNVERIFIED
|
||||
|
||||
//can we get more info on this device?
|
||||
session.getDevicesList(object : MatrixCallback<DevicesListResponse> {
|
||||
session?.getDevicesList(object : MatrixCallback<DevicesListResponse> {
|
||||
override fun onSuccess(data: DevicesListResponse) {
|
||||
data.devices?.find { it.deviceId == deviceId }?.let {
|
||||
postAlert(context, userId, deviceId, true, deviceInfo, it)
|
||||
|
@ -195,8 +204,8 @@ class KeyRequestHandler @Inject constructor(val context: Context,
|
|||
Runnable {
|
||||
alert.weakCurrentActivity?.get()?.let {
|
||||
val intent = SASVerificationActivity.outgoingIntent(it,
|
||||
session.sessionParams.credentials.userId,
|
||||
userId, deviceId)
|
||||
session?.sessionParams?.credentials?.userId ?: "",
|
||||
userId, deviceId)
|
||||
it.startActivity(intent)
|
||||
}
|
||||
},
|
||||
|
@ -247,8 +256,8 @@ class KeyRequestHandler @Inject constructor(val context: Context,
|
|||
val alertMgrUniqueKey = alertManagerId(deviceId!!, userId!!)
|
||||
alertsToRequests[alertMgrUniqueKey]?.removeAll {
|
||||
it.deviceId == request.deviceId
|
||||
&& it.userId == request.userId
|
||||
&& it.requestId == request.requestId
|
||||
&& it.userId == request.userId
|
||||
&& it.requestId == request.requestId
|
||||
}
|
||||
if (alertsToRequests[alertMgrUniqueKey]?.isEmpty() == true) {
|
||||
PopupAlertManager.cancelAlert(alertMgrUniqueKey)
|
||||
|
|
|
@ -16,11 +16,11 @@
|
|||
package im.vector.riotx.features.crypto.verification
|
||||
|
||||
import android.content.Context
|
||||
import im.vector.matrix.android.api.session.Session
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationService
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTransaction
|
||||
import im.vector.matrix.android.api.session.crypto.sas.SasVerificationTxState
|
||||
import im.vector.riotx.R
|
||||
import im.vector.riotx.core.di.ActiveSessionHolder
|
||||
import im.vector.riotx.features.popup.PopupAlertManager
|
||||
import javax.inject.Inject
|
||||
import javax.inject.Singleton
|
||||
|
@ -29,12 +29,18 @@ import javax.inject.Singleton
|
|||
* Listens to the VerificationManager and add a new notification when an incoming request is detected.
|
||||
*/
|
||||
@Singleton
|
||||
class IncomingVerificationRequestHandler @Inject constructor(val context: Context,
|
||||
private val activeSessionHolder: ActiveSessionHolder
|
||||
) : SasVerificationService.SasVerificationListener {
|
||||
class IncomingVerificationRequestHandler @Inject constructor(val context: Context) : SasVerificationService.SasVerificationListener {
|
||||
|
||||
init {
|
||||
activeSessionHolder.getActiveSession().getSasVerificationService().addListener(this)
|
||||
private var session: Session? = null
|
||||
|
||||
fun start(session: Session) {
|
||||
this.session = session
|
||||
session.getSasVerificationService().addListener(this)
|
||||
}
|
||||
|
||||
fun stop() {
|
||||
session?.getSasVerificationService()?.removeListener(this)
|
||||
this.session = null
|
||||
}
|
||||
|
||||
override fun transactionCreated(tx: SasVerificationTransaction) {}
|
||||
|
@ -43,9 +49,8 @@ class IncomingVerificationRequestHandler @Inject constructor(val context: Contex
|
|||
when (tx.state) {
|
||||
SasVerificationTxState.OnStarted -> {
|
||||
//Add a notification for every incoming request
|
||||
val session = activeSessionHolder.getActiveSession()
|
||||
val name = session.getUser(tx.otherUserId)?.displayName
|
||||
?: tx.otherUserId
|
||||
val name = session?.getUser(tx.otherUserId)?.displayName
|
||||
?: tx.otherUserId
|
||||
|
||||
val alert = PopupAlertManager.VectorAlert(
|
||||
"kvr_${tx.transactionId}",
|
||||
|
@ -55,9 +60,9 @@ class IncomingVerificationRequestHandler @Inject constructor(val context: Contex
|
|||
.apply {
|
||||
contentAction = Runnable {
|
||||
val intent = SASVerificationActivity.incomingIntent(context,
|
||||
session.sessionParams.credentials.userId,
|
||||
tx.otherUserId,
|
||||
tx.transactionId)
|
||||
session?.sessionParams?.credentials?.userId ?: "",
|
||||
tx.otherUserId,
|
||||
tx.transactionId)
|
||||
weakCurrentActivity?.get()?.startActivity(intent)
|
||||
}
|
||||
dismissedAction = Runnable {
|
||||
|
@ -73,9 +78,9 @@ class IncomingVerificationRequestHandler @Inject constructor(val context: Contex
|
|||
context.getString(R.string.action_open),
|
||||
Runnable {
|
||||
val intent = SASVerificationActivity.incomingIntent(context,
|
||||
session.sessionParams.credentials.userId,
|
||||
tx.otherUserId,
|
||||
tx.transactionId)
|
||||
session?.sessionParams?.credentials?.userId ?: "",
|
||||
tx.otherUserId,
|
||||
tx.transactionId)
|
||||
weakCurrentActivity?.get()?.startActivity(intent)
|
||||
}
|
||||
)
|
||||
|
|
|
@ -39,8 +39,6 @@ import im.vector.riotx.core.platform.OnBackPressed
|
|||
import im.vector.riotx.core.platform.ToolbarConfigurable
|
||||
import im.vector.riotx.core.platform.VectorBaseActivity
|
||||
import im.vector.riotx.core.pushers.PushersManager
|
||||
import im.vector.riotx.features.crypto.keysrequest.KeyRequestHandler
|
||||
import im.vector.riotx.features.crypto.verification.IncomingVerificationRequestHandler
|
||||
import im.vector.riotx.features.disclaimer.showDisclaimerDialog
|
||||
import im.vector.riotx.features.notifications.NotificationDrawerManager
|
||||
import im.vector.riotx.features.rageshake.VectorUncaughtExceptionHandler
|
||||
|
@ -64,10 +62,6 @@ class HomeActivity : VectorBaseActivity(), ToolbarConfigurable {
|
|||
@Inject lateinit var homeActivityViewModelFactory: HomeActivityViewModel.Factory
|
||||
@Inject lateinit var homeNavigator: HomeNavigator
|
||||
@Inject lateinit var vectorUncaughtExceptionHandler: VectorUncaughtExceptionHandler
|
||||
// TODO Move this elsewhere
|
||||
@Inject lateinit var incomingVerificationRequestHandler: IncomingVerificationRequestHandler
|
||||
// TODO Move this elsewhere
|
||||
@Inject lateinit var keyRequestHandler: KeyRequestHandler
|
||||
@Inject lateinit var pushManager: PushersManager
|
||||
@Inject lateinit var notificationDrawerManager: NotificationDrawerManager
|
||||
|
||||
|
|
Loading…
Reference in a new issue