Skip to content

Commit

Permalink
Merge pull request #236 from Infomaniak/capture-exception-in-InAppUpd…
Browse files Browse the repository at this point in the history
…ateManager

Make the onInstallFailure directly send the exception to sentry itself
  • Loading branch information
FabianDevel authored Nov 15, 2024
2 parents 23802ba + f264ddd commit bbf284d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -52,7 +51,6 @@ class UpdateRequiredActivity : AppCompatActivity() {
inAppUpdateManager.init(
mustRequireImmediateUpdate = true,
onInstallFailure = {
Sentry.captureException(it)
showToast(RCore.string.errorUpdateInstall)
goToPlayStore()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,16 @@ 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

/**
* 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,
Expand Down Expand Up @@ -101,7 +110,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)
Expand Down Expand Up @@ -145,7 +157,7 @@ class InAppUpdateManager(
.addOnSuccessListener { onInstallSuccess?.invoke() }
.addOnFailureListener {
viewModel.resetUpdateSettings()
onInstallFailure?.invoke(it)
onInstallFailure?.invoke(AppUpdateException(it.message))
}
}

Expand All @@ -157,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)
}
Expand Down Expand Up @@ -192,4 +207,6 @@ class InAppUpdateManager(
AppUpdateOptions.newBuilder(updateType).build(),
)
}

private class AppUpdateException(override val message: String?) : Exception()
}

0 comments on commit bbf284d

Please sign in to comment.