mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2025-02-20 14:00:03 +03:00
Fix crash when starting app with no available network.
This commit is contained in:
parent
3727b653ba
commit
613dc3d7fa
6 changed files with 19 additions and 14 deletions
matrix-sdk-android/src/rustCrypto/java/org/matrix/android/sdk/internal/crypto
vector/src/main/java/im/vector/app/features
|
@ -196,9 +196,7 @@ internal class RustCryptoService @Inject constructor(
|
||||||
override suspend fun fetchDevicesList(): List<DeviceInfo> {
|
override suspend fun fetchDevicesList(): List<DeviceInfo> {
|
||||||
val devicesList: List<DeviceInfo>
|
val devicesList: List<DeviceInfo>
|
||||||
withContext(coroutineDispatchers.io) {
|
withContext(coroutineDispatchers.io) {
|
||||||
devicesList = tryOrNull {
|
devicesList = getDevicesTask.execute(Unit).devices.orEmpty()
|
||||||
getDevicesTask.execute(Unit).devices
|
|
||||||
}.orEmpty()
|
|
||||||
cryptoStore.saveMyDevicesInfo(devicesList)
|
cryptoStore.saveMyDevicesInfo(devicesList)
|
||||||
}
|
}
|
||||||
return devicesList
|
return devicesList
|
||||||
|
@ -247,7 +245,7 @@ internal class RustCryptoService @Inject constructor(
|
||||||
cryptoCoroutineScope.launch(coroutineDispatchers.io) {
|
cryptoCoroutineScope.launch(coroutineDispatchers.io) {
|
||||||
cryptoStore.open()
|
cryptoStore.open()
|
||||||
// Just update
|
// Just update
|
||||||
fetchDevicesList()
|
tryOrNull { fetchDevicesList() }
|
||||||
cryptoStore.tidyUpDataBase()
|
cryptoStore.tidyUpDataBase()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,7 @@ import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.flow.sample
|
import kotlinx.coroutines.flow.sample
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.extensions.orFalse
|
import org.matrix.android.sdk.api.extensions.orFalse
|
||||||
|
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
|
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
|
||||||
import org.matrix.android.sdk.api.session.getUserOrDefault
|
import org.matrix.android.sdk.api.session.getUserOrDefault
|
||||||
|
@ -101,7 +102,7 @@ class UnknownDeviceDetectorSharedViewModel @AssistedInject constructor(
|
||||||
session.flow().liveUserCryptoDevices(session.myUserId),
|
session.flow().liveUserCryptoDevices(session.myUserId),
|
||||||
session.flow().liveMyDevicesInfo(),
|
session.flow().liveMyDevicesInfo(),
|
||||||
session.flow().liveCrossSigningPrivateKeys(),
|
session.flow().liveCrossSigningPrivateKeys(),
|
||||||
) { cryptoList, infoList, pInfo ->
|
) { cryptoList, infoList, pInfo ->
|
||||||
Timber.v("## Detector trigger ${cryptoList.map { "${it.deviceId} ${it.trustLevel}" }}")
|
Timber.v("## Detector trigger ${cryptoList.map { "${it.deviceId} ${it.trustLevel}" }}")
|
||||||
Timber.v("## Detector trigger canCrossSign ${pInfo.get().selfSigned != null}")
|
Timber.v("## Detector trigger canCrossSign ${pInfo.get().selfSigned != null}")
|
||||||
|
|
||||||
|
@ -146,13 +147,13 @@ class UnknownDeviceDetectorSharedViewModel @AssistedInject constructor(
|
||||||
.sample(5_000)
|
.sample(5_000)
|
||||||
.onEach {
|
.onEach {
|
||||||
// If we have a new crypto device change, we might want to trigger refresh of device info
|
// If we have a new crypto device change, we might want to trigger refresh of device info
|
||||||
session.cryptoService().fetchDevicesList()
|
tryOrNull { session.cryptoService().fetchDevicesList() }
|
||||||
}
|
}
|
||||||
.launchIn(viewModelScope)
|
.launchIn(viewModelScope)
|
||||||
|
|
||||||
// trigger a refresh of lastSeen / last Ip
|
// trigger a refresh of lastSeen / last Ip
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
session.cryptoService().fetchDevicesList()
|
tryOrNull { session.cryptoService().fetchDevicesList() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,6 +76,7 @@ import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import me.gujun.android.span.span
|
import me.gujun.android.span.span
|
||||||
import org.matrix.android.sdk.api.extensions.getFingerprintHumanReadable
|
import org.matrix.android.sdk.api.extensions.getFingerprintHumanReadable
|
||||||
|
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||||
import org.matrix.android.sdk.api.raw.RawService
|
import org.matrix.android.sdk.api.raw.RawService
|
||||||
import org.matrix.android.sdk.api.session.crypto.crosssigning.isVerified
|
import org.matrix.android.sdk.api.session.crypto.crosssigning.isVerified
|
||||||
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
|
import org.matrix.android.sdk.api.session.crypto.model.DeviceInfo
|
||||||
|
@ -646,9 +647,11 @@ class VectorSettingsSecurityPrivacyFragment :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO Move to a ViewModel...
|
// TODO Move to a ViewModel...
|
||||||
val devicesList = session.cryptoService().fetchDevicesList()
|
val devicesList = tryOrNull { session.cryptoService().fetchDevicesList() }
|
||||||
withContext(Dispatchers.Main) {
|
devicesList?.let {
|
||||||
refreshCryptographyPreference(devicesList)
|
withContext(Dispatchers.Main) {
|
||||||
|
refreshCryptographyPreference(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ import org.matrix.android.sdk.api.auth.data.LoginFlowTypes
|
||||||
import org.matrix.android.sdk.api.auth.registration.RegistrationFlowResponse
|
import org.matrix.android.sdk.api.auth.registration.RegistrationFlowResponse
|
||||||
import org.matrix.android.sdk.api.auth.registration.nextUncompletedStage
|
import org.matrix.android.sdk.api.auth.registration.nextUncompletedStage
|
||||||
import org.matrix.android.sdk.api.extensions.orFalse
|
import org.matrix.android.sdk.api.extensions.orFalse
|
||||||
|
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||||
import org.matrix.android.sdk.api.failure.Failure
|
import org.matrix.android.sdk.api.failure.Failure
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
|
import org.matrix.android.sdk.api.session.crypto.model.CryptoDeviceInfo
|
||||||
|
@ -190,7 +191,7 @@ class DevicesViewModel @AssistedInject constructor(
|
||||||
.sample(5_000)
|
.sample(5_000)
|
||||||
.onEach {
|
.onEach {
|
||||||
// If we have a new crypto device change, we might want to trigger refresh of device info
|
// If we have a new crypto device change, we might want to trigger refresh of device info
|
||||||
session.cryptoService().fetchDevicesList()
|
tryOrNull { session.cryptoService().fetchDevicesList() }
|
||||||
}
|
}
|
||||||
.launchIn(viewModelScope)
|
.launchIn(viewModelScope)
|
||||||
|
|
||||||
|
@ -203,7 +204,7 @@ class DevicesViewModel @AssistedInject constructor(
|
||||||
|
|
||||||
refreshSource.stream().throttleFirst(4_000)
|
refreshSource.stream().throttleFirst(4_000)
|
||||||
.onEach {
|
.onEach {
|
||||||
session.cryptoService().fetchDevicesList()
|
tryOrNull { session.cryptoService().fetchDevicesList() }
|
||||||
session.cryptoService().downloadKeysIfNeeded(listOf(session.myUserId), true)
|
session.cryptoService().downloadKeysIfNeeded(listOf(session.myUserId), true)
|
||||||
}
|
}
|
||||||
.launchIn(viewModelScope)
|
.launchIn(viewModelScope)
|
||||||
|
|
|
@ -22,6 +22,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
import kotlinx.coroutines.flow.map
|
import kotlinx.coroutines.flow.map
|
||||||
import kotlinx.coroutines.flow.onEach
|
import kotlinx.coroutines.flow.onEach
|
||||||
import kotlinx.coroutines.flow.sample
|
import kotlinx.coroutines.flow.sample
|
||||||
|
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||||
import org.matrix.android.sdk.flow.flow
|
import org.matrix.android.sdk.flow.flow
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
@ -40,7 +41,7 @@ class RefreshDevicesOnCryptoDevicesChangeUseCase @Inject constructor(
|
||||||
.sample(samplingPeriodMs)
|
.sample(samplingPeriodMs)
|
||||||
.onEach {
|
.onEach {
|
||||||
// If we have a new crypto device change, we might want to trigger refresh of device info
|
// If we have a new crypto device change, we might want to trigger refresh of device info
|
||||||
session.cryptoService().fetchDevicesList()
|
tryOrNull { session.cryptoService().fetchDevicesList() }
|
||||||
}
|
}
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package im.vector.app.features.settings.devices.v2
|
package im.vector.app.features.settings.devices.v2
|
||||||
|
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
import im.vector.app.core.di.ActiveSessionHolder
|
||||||
|
import org.matrix.android.sdk.api.extensions.tryOrNull
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class RefreshDevicesUseCase @Inject constructor(
|
class RefreshDevicesUseCase @Inject constructor(
|
||||||
|
@ -24,7 +25,7 @@ class RefreshDevicesUseCase @Inject constructor(
|
||||||
) {
|
) {
|
||||||
suspend fun execute() {
|
suspend fun execute() {
|
||||||
activeSessionHolder.getSafeActiveSession()?.let { session ->
|
activeSessionHolder.getSafeActiveSession()?.let { session ->
|
||||||
session.cryptoService().fetchDevicesList()
|
tryOrNull { session.cryptoService().fetchDevicesList() }
|
||||||
session.cryptoService().downloadKeysIfNeeded(listOf(session.myUserId), true)
|
session.cryptoService().downloadKeysIfNeeded(listOf(session.myUserId), true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue