Files
rr3-apk/decompiled-community/sources/com/ea/nimble/mtx/googleplay/billing/BillingHelper.java
Daniel Elliott c080f0d97f Add Discord community version (64-bit only)
- Added realracing3-community.apk (71.57 MB)
- Removed 32-bit support (armeabi-v7a)
- Only includes arm64-v8a libraries
- Decompiled source code included
- Added README-community.md with analysis
2026-02-18 15:48:36 -08:00

178 lines
8.8 KiB
Java

package com.ea.nimble.mtx.googleplay.billing;
import android.app.Activity;
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.android.billingclient.api.AcknowledgePurchaseParams;
import com.android.billingclient.api.AcknowledgePurchaseResponseListener;
import com.android.billingclient.api.BillingClient;
import com.android.billingclient.api.BillingClientStateListener;
import com.android.billingclient.api.BillingFlowParams;
import com.android.billingclient.api.BillingResult;
import com.android.billingclient.api.ConsumeParams;
import com.android.billingclient.api.ConsumeResponseListener;
import com.android.billingclient.api.ProductDetails;
import com.android.billingclient.api.ProductDetailsResponseListener;
import com.android.billingclient.api.Purchase;
import com.android.billingclient.api.PurchasesResponseListener;
import com.android.billingclient.api.PurchasesUpdatedListener;
import com.android.billingclient.api.QueryProductDetailsParams;
import com.android.billingclient.api.QueryPurchasesParams;
import com.ea.nimble.Log;
import com.ea.nimble.LogSource;
import com.firemonkeys.cloudcellapi.Consts;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
/* loaded from: classes2.dex */
public class BillingHelper implements LogSource, PurchasesUpdatedListener, ProductDetailsResponseListener, PurchasesResponseListener {
private String m_base64PublicKey;
private BillingClient m_billingClient;
ProductDetailsResponseListener m_productDetailsClientListener;
PurchasesResponseListener m_purchaseResponseListener;
PurchasesUpdatedListener m_purchasesUpdatedListener;
private int m_catalogQueryRequests = 0;
private int m_purchaseHistoryRequests = 0;
List<ProductDetails> m_CatalogItemsList = new LinkedList();
List<Purchase> m_PurchasesList = new LinkedList();
@Override // com.ea.nimble.LogSource
public String getLogSourceTitle() {
return "MTX Google BillingHelper";
}
public BillingHelper(Context context, String str) {
this.m_billingClient = BillingClient.newBuilder(context).enablePendingPurchases().setListener(this).build();
this.m_base64PublicKey = str;
}
public boolean isBillingAvailable() {
return this.m_billingClient.isReady();
}
public void startSetup(@NonNull BillingClientStateListener billingClientStateListener, @NonNull PurchasesUpdatedListener purchasesUpdatedListener) {
this.m_purchasesUpdatedListener = purchasesUpdatedListener;
Log.Helper.LOGFUNC(this);
if (this.m_billingClient.isReady()) {
throw new IllegalStateException("Billing Client is already setup");
}
Log.Helper.LOGV(this, "Starting Billing Setup", new Object[0]);
this.m_billingClient.startConnection(billingClientStateListener);
}
public void dispose() {
Log.Helper.LOGFUNC(this);
Log.Helper.LOGV(this, "Disposing Billing Client Service", new Object[0]);
BillingClient billingClient = this.m_billingClient;
if (billingClient != null) {
billingClient.endConnection();
this.m_billingClient = null;
}
}
public void queryProductDetailsAsync(@NonNull List<QueryProductDetailsParams.Product> list, @NonNull List<QueryProductDetailsParams.Product> list2, @NonNull ProductDetailsResponseListener productDetailsResponseListener) {
Log.Helper.LOGFUNC(this);
this.m_CatalogItemsList.clear();
if (list.size() == 0 && list2.size() == 0) {
Log.Helper.LOGW(this, "Empty Product List passed to queryProductDetails", new Object[0]);
return;
}
this.m_productDetailsClientListener = productDetailsResponseListener;
this.m_billingClient.queryProductDetailsAsync(QueryProductDetailsParams.newBuilder().setProductList(list).build(), this);
this.m_catalogQueryRequests++;
this.m_billingClient.queryProductDetailsAsync(QueryProductDetailsParams.newBuilder().setProductList(list2).build(), this);
this.m_catalogQueryRequests++;
}
public void queryPurchasesAsync(@NonNull PurchasesResponseListener purchasesResponseListener) {
Log.Helper.LOGFUNC(this);
this.m_PurchasesList.clear();
this.m_purchaseResponseListener = purchasesResponseListener;
if (isBillingAvailable()) {
this.m_billingClient.queryPurchasesAsync(QueryPurchasesParams.newBuilder().setProductType(Consts.ITEM_TYPE_SUBSCRIPTION).build(), this);
this.m_purchaseHistoryRequests++;
this.m_billingClient.queryPurchasesAsync(QueryPurchasesParams.newBuilder().setProductType("inapp").build(), this);
this.m_purchaseHistoryRequests++;
return;
}
Log.Helper.LOGE(this, "Billing not available", new Object[0]);
}
@Override // com.android.billingclient.api.PurchasesResponseListener
public void onQueryPurchasesResponse(@NonNull BillingResult billingResult, @NonNull List<Purchase> list) {
Log.Helper.LOGFUNC(this);
this.m_purchaseHistoryRequests--;
if (billingResult.getResponseCode() == 0) {
for (Purchase purchase : list) {
if (isSignatureValid(purchase)) {
this.m_PurchasesList.add(purchase);
} else {
Log.Helper.LOGW(this, "Purchase signature verification **FAILED**. Not adding item.", new Object[0]);
Log.Helper.LOGD(this, " Purchase data: " + purchase.getOriginalJson(), new Object[0]);
Log.Helper.LOGD(this, " Signature: " + purchase.getSignature(), new Object[0]);
}
}
}
if (billingResult.getResponseCode() != 0 || this.m_purchaseHistoryRequests == 0) {
this.m_purchaseHistoryRequests = 0;
PurchasesResponseListener purchasesResponseListener = this.m_purchaseResponseListener;
if (purchasesResponseListener != null) {
purchasesResponseListener.onQueryPurchasesResponse(billingResult, this.m_PurchasesList);
this.m_purchaseResponseListener = null;
}
}
}
@Override // com.android.billingclient.api.ProductDetailsResponseListener
public void onProductDetailsResponse(@NonNull BillingResult billingResult, @Nullable List<ProductDetails> list) {
Log.Helper.LOGFUNC(this);
this.m_catalogQueryRequests--;
if (billingResult.getResponseCode() == 0) {
for (ProductDetails productDetails : list) {
Log.Helper.LOGV(this, "onProductDetailsResponse: " + productDetails, new Object[0]);
this.m_CatalogItemsList.add(productDetails);
}
}
if (this.m_catalogQueryRequests == 0) {
this.m_productDetailsClientListener.onProductDetailsResponse(billingResult, this.m_CatalogItemsList);
}
}
public void launchPurchaseFlow(@NonNull Activity activity, @NonNull ProductDetails productDetails) {
Log.Helper.LOGFUNC(this);
ArrayList arrayList = new ArrayList();
if (Consts.ITEM_TYPE_SUBSCRIPTION.equals(productDetails.getProductType())) {
arrayList.add(BillingFlowParams.ProductDetailsParams.newBuilder().setProductDetails(productDetails).setOfferToken(((ProductDetails.SubscriptionOfferDetails) productDetails.getSubscriptionOfferDetails().get(0)).getOfferToken()).build());
} else {
arrayList.add(BillingFlowParams.ProductDetailsParams.newBuilder().setProductDetails(productDetails).build());
}
this.m_billingClient.launchBillingFlow(activity, BillingFlowParams.newBuilder().setProductDetailsParamsList(arrayList).build());
}
@Override // com.android.billingclient.api.PurchasesUpdatedListener
public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List<Purchase> list) {
Log.Helper.LOGFUNC(this);
this.m_purchasesUpdatedListener.onPurchasesUpdated(billingResult, list);
}
public void consumeAsync(@NonNull String str, @NonNull ConsumeResponseListener consumeResponseListener) {
Log.Helper.LOGFUNC(this);
this.m_billingClient.consumeAsync(ConsumeParams.newBuilder().setPurchaseToken(str).build(), consumeResponseListener);
}
public void acknowledgeAsync(@NonNull String str, @NonNull AcknowledgePurchaseResponseListener acknowledgePurchaseResponseListener) {
Log.Helper.LOGFUNC(this);
this.m_billingClient.acknowledgePurchase(AcknowledgePurchaseParams.newBuilder().setPurchaseToken(str).build(), acknowledgePurchaseResponseListener);
}
private boolean isSignatureValid(@NonNull Purchase purchase) {
String str = this.m_base64PublicKey;
if (str != null) {
return Security.verifyPurchase(str, purchase.getOriginalJson(), purchase.getSignature());
}
return true;
}
}