From ae255644ffbc59212c6620e9912c4c7758ca7747 Mon Sep 17 00:00:00 2001 From: Fabian Devel Date: Tue, 19 Nov 2024 13:46:27 +0100 Subject: [PATCH] fix: Catch crash when resultLauncher is not unregistered we don't know why --- .../updatemanagers/InAppUpdateManager.kt | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/Stores/src/standard/java/com/infomaniak/lib/stores/updatemanagers/InAppUpdateManager.kt b/Stores/src/standard/java/com/infomaniak/lib/stores/updatemanagers/InAppUpdateManager.kt index 45d639da..206ef11d 100644 --- a/Stores/src/standard/java/com/infomaniak/lib/stores/updatemanagers/InAppUpdateManager.kt +++ b/Stores/src/standard/java/com/infomaniak/lib/stores/updatemanagers/InAppUpdateManager.kt @@ -37,6 +37,7 @@ import com.infomaniak.lib.stores.BaseInAppUpdateManager import com.infomaniak.lib.stores.StoreUtils import com.infomaniak.lib.stores.StoresSettingsRepository import io.sentry.Sentry +import io.sentry.SentryLevel /** * Manager encapsulating all the needed logic for Google Play's in-app update api @@ -199,13 +200,24 @@ class InAppUpdateManager( } private fun startUpdateFlow(appUpdateInfo: AppUpdateInfo) = with(appUpdateManager) { - registerListener(installStateUpdatedListener) - viewModel.isUpdateBottomSheetShown = true - startUpdateFlowForResult( - appUpdateInfo, - inAppUpdateResultLauncher, - AppUpdateOptions.newBuilder(updateType).build(), - ) + runCatching { + registerListener(installStateUpdatedListener) + viewModel.isUpdateBottomSheetShown = true + startUpdateFlowForResult( + appUpdateInfo, + inAppUpdateResultLauncher, + AppUpdateOptions.newBuilder(updateType).build(), + ) + }.onFailure { exception -> + exception.printStackTrace() + exception.message?.let { + Sentry.captureMessage(it, SentryLevel.WARNING) { scope -> + scope.setExtra("contract", inAppUpdateResultLauncher.contract.toString()) + scope.setTag("updateType", updateType.toString()) + scope.setTag("onInstallFailure is null", (onInstallFailure == null).toString()) + } + } + } } private class AppUpdateException(override val message: String?) : Exception()