Fix backups crash when not signed in to play store.
This commit is contained in:
parent
07eb323f8c
commit
5e10ccc969
4 changed files with 34 additions and 18 deletions
|
@ -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
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -170,23 +170,25 @@ internal class BillingApiImpl(
|
|||
}
|
||||
|
||||
override suspend fun queryProduct(): BillingProduct? {
|
||||
try {
|
||||
val products = queryProductsInternal()
|
||||
return withContext(Dispatchers.IO) {
|
||||
try {
|
||||
val products = queryProductsInternal()
|
||||
|
||||
val details: ProductDetails? = products.productDetailsList?.firstOrNull { it.productId == billingDependencies.getProductId() }
|
||||
val pricing: ProductDetails.PricingPhase? = details?.subscriptionOfferDetails?.firstOrNull()?.pricingPhases?.pricingPhaseList?.firstOrNull()
|
||||
val details: ProductDetails? = products.productDetailsList?.firstOrNull { it.productId == billingDependencies.getProductId() }
|
||||
val pricing: ProductDetails.PricingPhase? = details?.subscriptionOfferDetails?.firstOrNull()?.pricingPhases?.pricingPhaseList?.firstOrNull()
|
||||
|
||||
if (pricing == null) {
|
||||
Log.d(TAG, "No pricing available.")
|
||||
return null
|
||||
if (pricing == null) {
|
||||
Log.d(TAG, "No pricing available.")
|
||||
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)
|
||||
null
|
||||
}
|
||||
|
||||
return 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
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,8 +257,13 @@ internal class BillingApiImpl(
|
|||
* to out-of-date Google Play API
|
||||
*/
|
||||
override suspend fun isApiAvailable(): Boolean {
|
||||
return doOnConnectionReady {
|
||||
billingClient.isFeatureSupported(BillingClient.FeatureType.SUBSCRIPTIONS).responseCode == BillingResponseCode.OK
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,4 +7,4 @@ package org.signal.core.util.billing
|
|||
|
||||
class BillingError(
|
||||
val billingResponseCode: Int
|
||||
) : Exception()
|
||||
) : Exception("$billingResponseCode")
|
||||
|
|
Loading…
Add table
Reference in a new issue