From 9fc00fe6ff5245cbd967ab6a5b33b6c66ea114b0 Mon Sep 17 00:00:00 2001 From: Benoit Marty Date: Fri, 16 Apr 2021 14:32:38 +0200 Subject: [PATCH] App crashes on "troubleshoot notifications" button (#3187) --- CHANGES.md | 1 + .../troubleshoot/TestPushFromPushGateway.kt | 36 +++++++++++-------- .../troubleshoot/TestAccountSettings.kt | 9 +++-- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index bb7668accf..a6221116b7 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,7 @@ Changes in Element 1.1.6 (2021-04-16) Bugfix 🐛: - Fix crash on the timeline + - App crashes on "troubleshoot notifications" button (#3187) Changes in Element 1.1.5 (2021-04-15) =================================================== diff --git a/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestPushFromPushGateway.kt b/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestPushFromPushGateway.kt index 015754145f..ad4b9ecb01 100644 --- a/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestPushFromPushGateway.kt +++ b/vector/src/gplay/java/im/vector/app/gplay/features/settings/troubleshoot/TestPushFromPushGateway.kt @@ -24,9 +24,11 @@ import im.vector.app.core.pushers.PushersManager import im.vector.app.core.resources.StringProvider import im.vector.app.features.settings.troubleshoot.TroubleshootTest import im.vector.app.push.fcm.FcmHelper +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.Job import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext import org.matrix.android.sdk.api.session.pushers.PushGatewayFailure import javax.inject.Inject @@ -47,22 +49,26 @@ class TestPushFromPushGateway @Inject constructor(private val context: AppCompat return } action = GlobalScope.launch { - status = runCatching { pushersManager.testPush(fcmToken) } - .fold( - { - // Wait for the push to be received - description = stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_waiting_for_push) - TestStatus.RUNNING - }, - { - description = if (it is PushGatewayFailure.PusherRejected) { - stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_failed) - } else { - errorFormatter.toHumanReadable(it) + val result = runCatching { pushersManager.testPush(fcmToken) } + + withContext(Dispatchers.Main) { + status = result + .fold( + { + // Wait for the push to be received + description = stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_waiting_for_push) + TestStatus.RUNNING + }, + { + description = if (it is PushGatewayFailure.PusherRejected) { + stringProvider.getString(R.string.settings_troubleshoot_test_push_loop_failed) + } else { + errorFormatter.toHumanReadable(it) + } + TestStatus.FAILED } - TestStatus.FAILED - } - ) + ) + } } } diff --git a/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestAccountSettings.kt b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestAccountSettings.kt index b78dba07f5..1f9b59af54 100644 --- a/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestAccountSettings.kt +++ b/vector/src/main/java/im/vector/app/features/settings/troubleshoot/TestAccountSettings.kt @@ -20,8 +20,11 @@ import androidx.activity.result.ActivityResultLauncher import im.vector.app.R import im.vector.app.core.di.ActiveSessionHolder import im.vector.app.core.resources.StringProvider +import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext +import org.matrix.android.sdk.api.extensions.tryOrNull import org.matrix.android.sdk.api.pushrules.RuleIds import org.matrix.android.sdk.api.pushrules.RuleKind import javax.inject.Inject @@ -50,10 +53,12 @@ class TestAccountSettings @Inject constructor(private val stringProvider: String if (manager?.diagStatus == TestStatus.RUNNING) return // wait before all is finished GlobalScope.launch { - runCatching { + tryOrNull { session.updatePushRuleEnableStatus(RuleKind.OVERRIDE, defaultRule, !defaultRule.enabled) } - manager?.retry(activityResultLauncher) + withContext(Dispatchers.Main) { + manager?.retry(activityResultLauncher) + } } } }