From 5a111af2fe50682fc018ac62345a1789f8d36d5c Mon Sep 17 00:00:00 2001 From: Valere Date: Tue, 27 Oct 2020 00:03:49 +0100 Subject: [PATCH] Fix / add close to IncomingRequestManager --- .../sdk/internal/crypto/DefaultCryptoService.kt | 2 +- .../crypto/IncomingGossipingRequestManager.kt | 4 ++++ .../java/im/vector/app/features/MainActivity.kt | 17 ++++++++++------- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt index 0a18aba8ba..f4ec7acd88 100755 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/DefaultCryptoService.kt @@ -386,7 +386,7 @@ internal class DefaultCryptoService @Inject constructor( */ fun close() = runBlocking(coroutineDispatchers.crypto) { cryptoCoroutineScope.coroutineContext.cancelChildren(CancellationException("Closing crypto module")) - + incomingGossipingRequestManager.close() olmDevice.release() cryptoStore.close() } diff --git a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingGossipingRequestManager.kt b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingGossipingRequestManager.kt index 6f135ceb49..ae017b33f5 100644 --- a/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingGossipingRequestManager.kt +++ b/matrix-sdk-android/src/main/java/org/matrix/android/sdk/internal/crypto/IncomingGossipingRequestManager.kt @@ -66,6 +66,10 @@ internal class IncomingGossipingRequestManager @Inject constructor( receivedGossipingRequests.addAll(cryptoStore.getPendingIncomingGossipingRequests()) } + fun close() { + executor.shutdownNow() + } + // Recently verified devices (map of deviceId and timestamp) private val recentlyVerifiedDevices = HashMap() diff --git a/vector/src/main/java/im/vector/app/features/MainActivity.kt b/vector/src/main/java/im/vector/app/features/MainActivity.kt index b5552e4d62..e553b5e0d3 100644 --- a/vector/src/main/java/im/vector/app/features/MainActivity.kt +++ b/vector/src/main/java/im/vector/app/features/MainActivity.kt @@ -21,6 +21,7 @@ import android.content.Intent import android.os.Bundle import android.os.Parcelable import androidx.appcompat.app.AlertDialog +import androidx.lifecycle.Lifecycle import com.bumptech.glide.Glide import im.vector.app.R import im.vector.app.core.di.ActiveSessionHolder @@ -205,13 +206,15 @@ class MainActivity : VectorBaseActivity(), UnlockedActivity { } private fun displayError(failure: Throwable) { - AlertDialog.Builder(this) - .setTitle(R.string.dialog_title_error) - .setMessage(errorFormatter.toHumanReadable(failure)) - .setPositiveButton(R.string.global_retry) { _, _ -> doCleanUp() } - .setNegativeButton(R.string.cancel) { _, _ -> startNextActivityAndFinish() } - .setCancelable(false) - .show() + if (lifecycle.currentState.isAtLeast(Lifecycle.State.RESUMED)) { + AlertDialog.Builder(this) + .setTitle(R.string.dialog_title_error) + .setMessage(errorFormatter.toHumanReadable(failure)) + .setPositiveButton(R.string.global_retry) { _, _ -> doCleanUp() } + .setNegativeButton(R.string.cancel) { _, _ -> startNextActivityAndFinish() } + .setCancelable(false) + .show() + } } private fun startNextActivityAndFinish() {