From c7e849e7417d0b3216f57c995ac27e41f7aa5880 Mon Sep 17 00:00:00 2001 From: Fabian Devel Date: Fri, 15 Nov 2024 11:36:09 +0100 Subject: [PATCH 1/2] feat(InAppUpdateManager): Make the onInstallFailure directly send the exception to sentry itself --- .../lib/stores/updaterequired/UpdateRequiredActivity.kt | 1 - .../lib/stores/updatemanagers/InAppUpdateManager.kt | 6 +++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Stores/src/main/java/com/infomaniak/lib/stores/updaterequired/UpdateRequiredActivity.kt b/Stores/src/main/java/com/infomaniak/lib/stores/updaterequired/UpdateRequiredActivity.kt index 590016dd..504fa3b9 100644 --- a/Stores/src/main/java/com/infomaniak/lib/stores/updaterequired/UpdateRequiredActivity.kt +++ b/Stores/src/main/java/com/infomaniak/lib/stores/updaterequired/UpdateRequiredActivity.kt @@ -52,7 +52,6 @@ class UpdateRequiredActivity : AppCompatActivity() { inAppUpdateManager.init( mustRequireImmediateUpdate = true, onInstallFailure = { - Sentry.captureException(it) showToast(RCore.string.errorUpdateInstall) goToPlayStore() }, 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 59842779..59c4a53d 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 @@ -36,6 +36,7 @@ import com.infomaniak.lib.core.utils.SentryLog import com.infomaniak.lib.stores.BaseInAppUpdateManager import com.infomaniak.lib.stores.StoreUtils import com.infomaniak.lib.stores.StoresSettingsRepository +import io.sentry.Sentry class InAppUpdateManager( private val activity: FragmentActivity, @@ -101,7 +102,10 @@ class InAppUpdateManager( this.updateType = if (mustRequireImmediateUpdate) AppUpdateType.IMMEDIATE else AppUpdateType.FLEXIBLE this.onUserChoice = onUserChoice this.onInstallStart = onInstallStart - this.onInstallFailure = onInstallFailure + this.onInstallFailure = { + Sentry.captureException(it) + onInstallFailure?.invoke(it) + } this.onInstallSuccess = onInstallSuccess super.init(mustRequireImmediateUpdate, onInAppUpdateUiChange, onFDroidResult) From f264dddaaa0461dbd07daa6ac56f948d732b4cf5 Mon Sep 17 00:00:00 2001 From: Fabian Devel Date: Fri, 15 Nov 2024 12:44:35 +0100 Subject: [PATCH 2/2] feat(InAppUpdateManager): Add kdoc for the inAppUpdate manager --- .../updaterequired/UpdateRequiredActivity.kt | 1 - .../stores/updatemanagers/InAppUpdateManager.kt | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Stores/src/main/java/com/infomaniak/lib/stores/updaterequired/UpdateRequiredActivity.kt b/Stores/src/main/java/com/infomaniak/lib/stores/updaterequired/UpdateRequiredActivity.kt index 504fa3b9..7e595d41 100644 --- a/Stores/src/main/java/com/infomaniak/lib/stores/updaterequired/UpdateRequiredActivity.kt +++ b/Stores/src/main/java/com/infomaniak/lib/stores/updaterequired/UpdateRequiredActivity.kt @@ -33,7 +33,6 @@ import com.infomaniak.lib.core.utils.goToPlayStore import com.infomaniak.lib.core.utils.showToast import com.infomaniak.lib.stores.databinding.ActivityUpdateRequiredBinding import com.infomaniak.lib.stores.updatemanagers.InAppUpdateManager -import io.sentry.Sentry import kotlin.system.exitProcess import com.infomaniak.lib.core.R as RCore 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 59c4a53d..45d639da 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 @@ -38,6 +38,14 @@ import com.infomaniak.lib.stores.StoreUtils import com.infomaniak.lib.stores.StoresSettingsRepository import io.sentry.Sentry +/** + * Manager encapsulating all the needed logic for Google Play's in-app update api + * Implements [BaseInAppUpdateManager] to add compatibility with fDroid + * + * @param activity: Activity on which the lifecycleObserver will be bound + * @param appId: Parameter needed for the fDroid manager, won't compile without it + * @param versionCode: Parameter needed for the fDroid manager, won't compile without it + */ class InAppUpdateManager( private val activity: FragmentActivity, appId: String, @@ -149,7 +157,7 @@ class InAppUpdateManager( .addOnSuccessListener { onInstallSuccess?.invoke() } .addOnFailureListener { viewModel.resetUpdateSettings() - onInstallFailure?.invoke(it) + onInstallFailure?.invoke(AppUpdateException(it.message)) } } @@ -161,6 +169,9 @@ class InAppUpdateManager( if (isUpdateStalled || !viewModel.isUpdateBottomSheetShown) startUpdateFlow(appUpdateInfo) } }.addOnFailureListener { + Sentry.captureMessage("Impossible to require update") { scope -> + scope.setTag("reason", it.message.toString()) + } it.printStackTrace() onFailure?.invoke(it) } @@ -196,4 +207,6 @@ class InAppUpdateManager( AppUpdateOptions.newBuilder(updateType).build(), ) } + + private class AppUpdateException(override val message: String?) : Exception() }