Merge pull request #467 from vector-im/feature/playstore_crash

Feature/playstore crash
This commit is contained in:
Benoit Marty 2019-08-07 17:10:49 +02:00 committed by GitHub
commit 24f391dac0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 14 deletions

View file

@ -79,8 +79,7 @@ internal class MXOlmDevice @Inject constructor(
// //
// The first level keys are timeline ids. // The first level keys are timeline ids.
// The second level keys are strings of form "<senderKey>|<session_id>|<message_index>" // The second level keys are strings of form "<senderKey>|<session_id>|<message_index>"
// Values are true. private val inboundGroupSessionMessageIndexes: MutableMap<String, MutableSet<String>> = HashMap()
private val inboundGroupSessionMessageIndexes: MutableMap<String, MutableMap<String, Boolean>> = HashMap()
init { init {
// Retrieve the account from the store // Retrieve the account from the store
@ -662,19 +661,17 @@ internal class MXOlmDevice @Inject constructor(
} }
if (null != timeline) { if (null != timeline) {
if (!inboundGroupSessionMessageIndexes.containsKey(timeline)) { val timelineSet = inboundGroupSessionMessageIndexes.getOrPut(timeline) { mutableSetOf() }
inboundGroupSessionMessageIndexes[timeline] = HashMap()
}
val messageIndexKey = senderKey + "|" + sessionId + "|" + decryptResult.mIndex val messageIndexKey = senderKey + "|" + sessionId + "|" + decryptResult.mIndex
if (inboundGroupSessionMessageIndexes[timeline]?.get(messageIndexKey) != null) { if (timelineSet.contains(messageIndexKey)) {
val reason = String.format(MXCryptoError.DUPLICATE_MESSAGE_INDEX_REASON, decryptResult.mIndex) val reason = String.format(MXCryptoError.DUPLICATE_MESSAGE_INDEX_REASON, decryptResult.mIndex)
Timber.e("## decryptGroupMessage() : $reason") Timber.e("## decryptGroupMessage() : $reason")
throw MXCryptoError.Base(MXCryptoError.ErrorType.DUPLICATED_MESSAGE_INDEX, reason) throw MXCryptoError.Base(MXCryptoError.ErrorType.DUPLICATED_MESSAGE_INDEX, reason)
} }
inboundGroupSessionMessageIndexes[timeline]!!.put(messageIndexKey, true) timelineSet.add(messageIndexKey)
} }
store.storeInboundGroupSessions(listOf(session)) store.storeInboundGroupSessions(listOf(session))

View file

@ -35,9 +35,9 @@ fun getFilenameFromUri(context: Context?, uri: Uri): String? {
} }
if (result == null) { if (result == null) {
result = uri.path result = uri.path
val cut = result.lastIndexOf('/') val cut = result?.lastIndexOf('/') ?: -1
if (cut != -1) { if (cut != -1) {
result = result.substring(cut + 1) result = result?.substring(cut + 1)
} }
} }
return result return result

View file

@ -29,7 +29,7 @@ import javax.inject.Inject
class SasVerificationViewModel @Inject constructor() : ViewModel(), class SasVerificationViewModel @Inject constructor() : ViewModel(),
SasVerificationService.SasVerificationListener { SasVerificationService.SasVerificationListener {
companion object { companion object {
@ -40,7 +40,7 @@ class SasVerificationViewModel @Inject constructor() : ViewModel(),
const val NAVIGATE_CANCELLED = "NAVIGATE_CANCELLED" const val NAVIGATE_CANCELLED = "NAVIGATE_CANCELLED"
} }
lateinit var sasVerificationService: SasVerificationService private lateinit var sasVerificationService: SasVerificationService
var otherUserId: String? = null var otherUserId: String? = null
var otherDeviceId: String? = null var otherDeviceId: String? = null
@ -154,8 +154,8 @@ class SasVerificationViewModel @Inject constructor() : ViewModel(),
override fun onCleared() { override fun onCleared() {
super.onCleared() super.onCleared()
sasVerificationService.removeListener(this) if (::sasVerificationService.isInitialized) {
sasVerificationService.removeListener(this)
}
} }
} }