Fix backups crash when not signed in to play store.

This commit is contained in:
Alex Hart 2024-12-05 13:23:52 -04:00 committed by Greyson Parrelli
parent 07eb323f8c
commit 5e10ccc969
4 changed files with 34 additions and 18 deletions

View file

@ -465,7 +465,7 @@ public class ApplicationDependencyProvider implements AppDependencies.Provider {
@Override
public @NonNull BillingApi provideBillingApi() {
return BillingFactory.create(GooglePlayBillingDependencies.INSTANCE, RemoteConfig.messageBackups() && !Environment.IS_STAGING);
return BillingFactory.create(GooglePlayBillingDependencies.INSTANCE, RemoteConfig.messageBackups() && Environment.Backups.supportsGooglePlayBilling());
}
@Override

View file

@ -6,10 +6,19 @@ import org.signal.donations.StripeApi
import org.thoughtcrime.securesms.BuildConfig
object Environment {
private const val GOOGLE_PLAY_BILLING_APPLICATION_ID = "org.thoughtcrime.securesms"
const val IS_STAGING: Boolean = BuildConfig.BUILD_ENVIRONMENT_TYPE == "Staging" || BuildConfig.BUILD_ENVIRONMENT_TYPE == "Pnp"
const val IS_NIGHTLY: Boolean = BuildConfig.BUILD_DISTRIBUTION_TYPE == "nightly"
const val IS_WEBSITE: Boolean = BuildConfig.BUILD_DISTRIBUTION_TYPE == "website"
object Backups {
@JvmStatic
fun supportsGooglePlayBilling(): Boolean {
return BuildConfig.APPLICATION_ID == GOOGLE_PLAY_BILLING_APPLICATION_ID
}
}
object Donations {
@JvmStatic
@get:JvmName("getGooglePayConfiguration")

View file

@ -170,6 +170,7 @@ internal class BillingApiImpl(
}
override suspend fun queryProduct(): BillingProduct? {
return withContext(Dispatchers.IO) {
try {
val products = queryProductsInternal()
@ -178,15 +179,16 @@ internal class BillingApiImpl(
if (pricing == null) {
Log.d(TAG, "No pricing available.")
return null
}
return BillingProduct(
null
} else {
BillingProduct(
price = FiatMoney(BigDecimal.valueOf(pricing.priceAmountMicros, 6), Currency.getInstance(pricing.priceCurrencyCode))
)
}
} catch (e: BillingError) {
Log.w(TAG, "Failed to query product. Returning null. Error code: ${e.billingResponseCode}", e)
return null
null
}
}
}
@ -255,9 +257,14 @@ internal class BillingApiImpl(
* to out-of-date Google Play API
*/
override suspend fun isApiAvailable(): Boolean {
return doOnConnectionReady {
return try {
doOnConnectionReady {
billingClient.isFeatureSupported(BillingClient.FeatureType.SUBSCRIPTIONS).responseCode == BillingResponseCode.OK
}
} catch (e: BillingError) {
Log.e(TAG, "Failed to connect to Google Play Billing", e)
false
}
}
private fun Int.toBillingPurchaseState(): BillingPurchaseState {

View file

@ -7,4 +7,4 @@ package org.signal.core.util.billing
class BillingError(
val billingResponseCode: Int
) : Exception()
) : Exception("$billingResponseCode")