Add backup upgrade availability checks.

This commit is contained in:
Alex Hart
2025-11-04 13:27:47 -04:00
committed by Michelle Tang
parent fa334b3752
commit 4cce6d3c86
6 changed files with 65 additions and 7 deletions

View File

@@ -0,0 +1,36 @@
/*
* Copyright 2025 Signal Messenger, LLC
* SPDX-License-Identifier: AGPL-3.0-only
*/
package org.thoughtcrime.securesms.backup.v2.ui.subscription
import android.content.Context
import com.google.android.gms.common.GoogleApiAvailability
import org.thoughtcrime.securesms.dependencies.AppDependencies
/**
* Delegate object for checking whether backup upgrade prompts should be shown to the user.
*/
object BackupUpgradeAvailabilityChecker {
/**
* Best effort check for upgrade access. We check availability and show proper dialogs in the checkout
* flow, so this is fine as "best effort"
*/
suspend fun isUpgradeAvailable(
context: Context
): Boolean {
val googlePlayServicesCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context)
val googlePlayServicesAvailability = GooglePlayServicesAvailability.fromCode(googlePlayServicesCode)
return when (googlePlayServicesAvailability) {
GooglePlayServicesAvailability.UNKNOWN, GooglePlayServicesAvailability.SERVICE_MISSING, GooglePlayServicesAvailability.SERVICE_DISABLED, GooglePlayServicesAvailability.SERVICE_INVALID -> false
GooglePlayServicesAvailability.SERVICE_VERSION_UPDATE_REQUIRED, GooglePlayServicesAvailability.SERVICE_UPDATING -> true
GooglePlayServicesAvailability.SUCCESS -> {
val billingResponseCode = AppDependencies.billingApi.getApiAvailability()
billingResponseCode.isSuccess
}
}
}
}