Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the onInstallFailure directly send the exception to sentry itself #236

Merged
merged 2 commits into from
Nov 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
}
Loading