Files
rr3-apk/decompiled/sources/com/ea/nimble/mtx/googleplay/GooglePlay.java
Daniel Elliott f9d20bb3fc Add decompiled APK source code (JADX)
- 28,932 files
- Full Java source code
- Smali files
- Resources

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-02-18 14:52:23 -08:00

2141 lines
126 KiB
Java

package com.ea.nimble.mtx.googleplay;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import com.android.billingclient.api.AcknowledgePurchaseResponseListener;
import com.android.billingclient.api.BillingClientStateListener;
import com.android.billingclient.api.BillingResult;
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.ea.nimble.ApplicationEnvironment;
import com.ea.nimble.ApplicationLifecycle;
import com.ea.nimble.Base;
import com.ea.nimble.Component;
import com.ea.nimble.Error;
import com.ea.nimble.Global;
import com.ea.nimble.IApplicationEnvironment;
import com.ea.nimble.IApplicationLifecycle;
import com.ea.nimble.IHttpRequest;
import com.ea.nimble.ISynergyEnvironment;
import com.ea.nimble.ISynergyIdManager;
import com.ea.nimble.ISynergyRequest;
import com.ea.nimble.Log;
import com.ea.nimble.LogSource;
import com.ea.nimble.Network;
import com.ea.nimble.NimbleApplicationConfiguration;
import com.ea.nimble.NimbleConfiguration;
import com.ea.nimble.Persistence;
import com.ea.nimble.PersistenceService;
import com.ea.nimble.SynergyEnvironment;
import com.ea.nimble.SynergyIdManager;
import com.ea.nimble.SynergyNetwork;
import com.ea.nimble.SynergyNetworkConnectionCallback;
import com.ea.nimble.SynergyNetworkConnectionHandle;
import com.ea.nimble.SynergyRequest;
import com.ea.nimble.SynergyServerError;
import com.ea.nimble.Timer;
import com.ea.nimble.Utility;
import com.ea.nimble.mtx.INimbleMTX;
import com.ea.nimble.mtx.NimbleCatalogItem;
import com.ea.nimble.mtx.NimbleMTXError;
import com.ea.nimble.mtx.NimbleMTXTransaction;
import com.ea.nimble.mtx.catalog.synergy.SynergyCatalog;
import com.ea.nimble.mtx.catalog.synergy.SynergyCatalogItem;
import com.ea.nimble.mtx.googleplay.GooglePlayError;
import com.ea.nimble.mtx.googleplay.GooglePlayTransaction;
import com.ea.nimble.mtx.googleplay.billing.BillingHelper;
import com.ea.nimble.tracking.ITracking;
import com.ea.nimble.tracking.Tracking;
import com.facebook.FacebookSdk;
import com.firemonkeys.cloudcellapi.Consts;
import com.ironsource.v8;
import com.unity3d.ads.metadata.InAppPurchaseMetaData;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
/* loaded from: classes2.dex */
public class GooglePlay extends Component implements INimbleMTX, IApplicationLifecycle.ActivityEventCallbacks, LogSource, PurchasesUpdatedListener {
private static final double CACHE_EXPIRE_TIME = 3600.0d;
private static final String CACHE_TIMESTAMP_KEY = "cacheTimestamp";
public static final String COMPONENT_ID = "com.ea.nimble.mtx.googleplay";
public static int GOOGLEPLAY_ACTIVITY_RESULT_REQUEST_CODE = 987654;
public static String GOOGLEPLAY_ADDITIONALINFO_KEY_ACKNOWLEDGED = "acknowledged";
public static String GOOGLEPLAY_ADDITIONALINFO_KEY_ORDERID = "orderId";
public static String GOOGLEPLAY_ADDITIONALINFO_KEY_PURCHASEDATA = "purchaseData";
public static String GOOGLEPLAY_ADDITIONALINFO_KEY_PURCHASESTATE = "purchaseState";
public static String GOOGLEPLAY_ADDITIONALINFO_KEY_PURCHASETIME = "purchaseTime";
public static String GOOGLEPLAY_ADDITIONALINFO_KEY_RECEIPT = "receipt";
public static String GOOGLEPLAY_ADDITIONALINFO_KEY_TOKEN = "token";
public static String GOOGLEPLAY_PLATFORM_PARAMETER_APPLICATION_PUBLIC_KEY = "GOOGLEPLAY_APPLICATION_PUBLIC_KEY";
private static final double MAX_REQUEST_RETRY_DELAY = 300.0d;
private static final String NOTIFICATION_TRACKING2_LOG_EVENT = "nimble.notification.tracking2.logEvent";
private static final String PERSISTENCE_CATALOG_ITEMS = "catalogItems";
private static final String PERSISTENCE_PENDING_TRANSACTIONS = "pendingTransactions";
private static final String PERSISTENCE_PURCHASED_TRANSACTIONS = "purchasedTransactions";
private static final String PERSISTENCE_RECOVERED_TRANSACTIONS = "recoveredTransactions";
private static final String PERSISTENCE_UNRECORDED_TRANSACTIONS = "unrecordedTransactions";
private static final String SYNERGY_API_VERIFY_AND_RECORD_GOOGLEPLAY_PURCHASE = "/drm/api/android/verifyAndRecordPurchase";
public static final String TAG = "MTX Google";
String m_appPublicKey;
private BillingHelper m_billingHelper;
private Long m_cacheTimestamp;
private final ItemRestorer m_itemRestorer;
private boolean m_reportingEnabled;
private boolean m_restoreInProgress;
SynergyCatalog m_synergyCatalog;
private final TransactionRecorder m_transactionRecorder;
private boolean m_verificationEnabled;
private boolean m_billingConnectionInProgress = false;
HashMap<String, GooglePlayTransaction> mPendingTransactions = new HashMap<>();
HashMap<String, GooglePlayTransaction> mPurchasedTransactions = new HashMap<>();
HashMap<String, GooglePlayTransaction> mRecoveredTransactions = new HashMap<>();
HashMap<String, GooglePlayCatalogItem> mCatalogItems = new HashMap<>();
ArrayList<GooglePlayTransaction> mUnrecordedTransactions = new ArrayList<>();
public interface CatalogItemCallback {
void onCatalogItemsRetrieved(List<GooglePlayCatalogItem> list, Exception exc);
}
public interface GetNonceCallback {
void onGetNonceComplete(GooglePlayTransaction googlePlayTransaction, String str, Error error);
}
public interface VerifyCallback {
void onVerificationComplete(Exception exc);
}
private String getAppPublicKey() {
return this.m_appPublicKey;
}
@Override // com.ea.nimble.Component
public String getComponentId() {
return COMPONENT_ID;
}
@Override // com.ea.nimble.LogSource
public String getLogSourceTitle() {
return TAG;
}
@Override // com.ea.nimble.IApplicationLifecycle.ActivityEventCallbacks
public boolean onBackPressed() {
return true;
}
@Override // com.ea.nimble.IApplicationLifecycle.ActivityEventCallbacks
public void onNewIntent(Activity activity, Intent intent) {
}
@Override // com.ea.nimble.IApplicationLifecycle.ActivityEventCallbacks
public void onWindowFocusChanged(boolean z) {
}
public class JsonData implements ISynergyRequest.IJsonData {
private final HashMap<String, Object> data;
@Override // com.ea.nimble.ISynergyRequest.IJsonData
public Object getData() {
return this.data;
}
public JsonData(HashMap<String, Object> hashMap) {
this.data = hashMap;
}
@Override // com.ea.nimble.ISynergyRequest.IJsonData
public int size() {
return this.data.size();
}
}
public class ItemRestorer extends BroadcastReceiver implements Runnable {
private double m_requestRetryDelay;
private int m_retryCount;
private final Timer m_timer;
private ItemRestorer() {
this.m_timer = new Timer(this);
this.m_requestRetryDelay = 1.0d;
this.m_retryCount = 0;
}
public void restoreItems() {
if (GooglePlay.this.m_restoreInProgress) {
return;
}
synchronized (GooglePlay.this) {
try {
HashMap<String, GooglePlayCatalogItem> hashMap = GooglePlay.this.mCatalogItems;
if (hashMap != null && !hashMap.isEmpty()) {
GooglePlay.this.restorePurchasedTransactionsImpl(false);
}
GooglePlay.this.m_restoreInProgress = true;
Log.Helper.LOGD(GooglePlay.this, "Restore pending but catalog is unavailable. Initiating refresh now.", new Object[0]);
Utility.registerReceiver(INimbleMTX.NIMBLE_NOTIFICATION_MTX_REFRESH_CATALOG_FINISHED, this);
this.m_retryCount = 0;
GooglePlay.this.refreshAvailableCatalogItems();
} catch (Throwable th) {
throw th;
}
}
}
@Override // android.content.BroadcastReceiver
public void onReceive(Context context, Intent intent) {
Error error;
Object parcelable;
Bundle extras = intent.getExtras();
if (extras != null && extras.getString("result").equals("0")) {
if (Build.VERSION.SDK_INT >= 33) {
parcelable = extras.getParcelable("error", Error.class);
error = (Error) parcelable;
} else {
error = (Error) extras.getParcelable("error");
}
this.m_retryCount++;
if (error.getDomain().equals(SynergyServerError.ERROR_DOMAIN) && this.m_retryCount < 5) {
Log.Helper.LOGD(GooglePlay.this, "Catalog refresh failed with restore pending. Retrying in " + this.m_requestRetryDelay + " seconds.", new Object[0]);
if (this.m_timer.isRunning()) {
return;
}
this.m_timer.schedule(this.m_requestRetryDelay, false);
return;
}
Log.Helper.LOGD(GooglePlay.this, "Catalog refresh failed with restore pending. Skip.", new Object[0]);
}
this.m_retryCount = 0;
this.m_timer.cancel();
Utility.unregisterReceiver(this);
GooglePlay.this.m_restoreInProgress = false;
GooglePlay.this.restorePurchasedTransactionsImpl(false);
}
@Override // java.lang.Runnable
public void run() {
this.m_requestRetryDelay = Math.min(this.m_requestRetryDelay * 2.0d, 300.0d);
GooglePlay.this.refreshAvailableCatalogItems();
}
public void cancel() {
GooglePlay.this.m_restoreInProgress = false;
this.m_timer.cancel();
this.m_requestRetryDelay = 1.0d;
Utility.unregisterReceiver(this);
}
}
private GooglePlay() {
this.m_itemRestorer = new ItemRestorer();
this.m_transactionRecorder = new TransactionRecorder();
}
private void createBillingHelper() {
this.m_billingConnectionInProgress = true;
BillingHelper billingHelper = new BillingHelper(ApplicationEnvironment.getComponent().getApplicationContext(), getAppPublicKey());
this.m_billingHelper = billingHelper;
billingHelper.startSetup(new BillingClientStateListener() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.1
@Override // com.android.billingclient.api.BillingClientStateListener
public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
GooglePlay.this.m_billingConnectionInProgress = false;
if (billingResult.getResponseCode() == 0) {
GooglePlay.this.m_itemRestorer.restoreItems();
return;
}
Log.Helper.LOGD(this, "Error setting up the billing helper: " + billingResult.getResponseCode() + " " + billingResult.getDebugMessage(), new Object[0]);
}
@Override // com.android.billingclient.api.BillingClientStateListener
public void onBillingServiceDisconnected() {
GooglePlay.this.m_billingHelper.dispose();
GooglePlay.this.m_billingHelper = null;
Log.Helper.LOGD(this, "Billing Service Disconnected", new Object[0]);
}
}, this);
}
private void refreshBillingClient() {
if (!this.m_billingConnectionInProgress) {
Log.Helper.LOGD(this, "Refreshing Billing Service Connection", new Object[0]);
BillingHelper billingHelper = this.m_billingHelper;
if (billingHelper != null) {
billingHelper.dispose();
this.m_billingHelper = null;
}
createBillingHelper();
return;
}
Log.Helper.LOGD(this, "Billing Service Connection refresh already in progress", new Object[0]);
}
public static GooglePlay getComponent() {
return (GooglePlay) Base.getComponent(COMPONENT_ID);
}
private static void initialize() {
Base.registerComponent(new GooglePlay(), COMPONENT_ID);
}
@Override // com.ea.nimble.Component
public void setup() {
Log.Helper.LOGD(this, "Component setup", new Object[0]);
if (this.m_billingHelper == null) {
createBillingHelper();
}
this.m_verificationEnabled = true;
this.m_reportingEnabled = true;
String configValueAsString = NimbleApplicationConfiguration.getConfigValueAsString("com.ea.nimble.mtx.enableVerification");
if ("false".equalsIgnoreCase(configValueAsString)) {
Log.Helper.LOGD(this, "Receipt verification has been disabled.", new Object[0]);
this.m_verificationEnabled = false;
String configValueAsString2 = NimbleApplicationConfiguration.getConfigValueAsString("com.ea.nimble.mtx.reportingEnabled");
if ("false".equalsIgnoreCase(configValueAsString2)) {
Log.Helper.LOGD(this, "Transaction reporting has been disabled.", new Object[0]);
this.m_reportingEnabled = false;
return;
} else {
if ("true".equalsIgnoreCase(configValueAsString2)) {
return;
}
Log.Helper.LOGD(this, "Value com.ea.nimble.mtx.reportingEnabled corrupted or non existed in manifest file.", new Object[0]);
return;
}
}
if ("true".equalsIgnoreCase(configValueAsString)) {
return;
}
Log.Helper.LOGD(this, "Value com.ea.nimble.mtx.enableVerification corrupted or non existed in manifest file.", new Object[0]);
}
@Override // com.ea.nimble.Component
public void restore() {
Log.Helper.LOGD(this, "Component restore", new Object[0]);
this.m_synergyCatalog = new SynergyCatalog(SynergyCatalog.StoreType.GOOGLE);
loadFromPersistence();
Utility.registerReceiver(Global.NOTIFICATION_LANGUAGE_CHANGE, new BroadcastReceiver() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.2
@Override // android.content.BroadcastReceiver
public void onReceive(Context context, Intent intent) {
Log.Helper.LOGD(this, "refreshing catalog items after language change", new Object[0]);
GooglePlay.this.refreshAvailableCatalogItems();
}
});
ApplicationLifecycle.getComponent().registerActivityEventCallbacks(this);
}
@Override // com.ea.nimble.Component
public void teardown() {
Log.Helper.LOGD(this, "Component teardown", new Object[0]);
this.m_transactionRecorder.cancel();
this.m_itemRestorer.cancel();
}
@Override // com.ea.nimble.Component
public void suspend() {
Log.Helper.LOGD(this, "Component suspend", new Object[0]);
this.m_transactionRecorder.cancel();
this.m_itemRestorer.cancel();
}
@Override // com.ea.nimble.Component
public void resume() {
Log.Helper.LOGD(this, "Component resume", new Object[0]);
BillingHelper billingHelper = this.m_billingHelper;
if (billingHelper == null || !billingHelper.isBillingAvailable()) {
Log.Helper.LOGD(this, "Billing service is not available, start refreshing connection", new Object[0]);
refreshBillingClient();
}
synchronized (this) {
try {
for (GooglePlayTransaction googlePlayTransaction : this.mPendingTransactions.values()) {
GooglePlayTransaction.GooglePlayTransactionState googlePlayTransactionState = googlePlayTransaction.mGooglePlayTransactionState;
if (googlePlayTransactionState != GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_SYNERGY_VERIFICATION && googlePlayTransactionState != GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_NONCE) {
}
new PurchaseTransactionVerifier().verifyTransaction(googlePlayTransaction);
}
} catch (Throwable th) {
throw th;
}
}
this.m_transactionRecorder.recordTransactions();
this.m_itemRestorer.restoreItems();
}
@Override // com.ea.nimble.Component
public void cleanup() {
Log.Helper.LOGD(this, "Component cleanup", new Object[0]);
BillingHelper billingHelper = this.m_billingHelper;
if (billingHelper != null) {
billingHelper.dispose();
this.m_billingHelper = null;
}
ApplicationLifecycle.getComponent().unregisterActivityEventCallbacks(this);
}
@Override // com.ea.nimble.IApplicationLifecycle.ActivityEventCallbacks
public void onActivityResult(Activity activity, int i, int i2, Intent intent) {
Log.Helper.LOGD(this, "onActivityResult", new Object[0]);
}
@Override // com.ea.nimble.mtx.INimbleMTX
public Error purchaseItem(final String str, INimbleMTX.PurchaseTransactionCallback purchaseTransactionCallback, String str2) {
GooglePlayCatalogItem googlePlayCatalogItem;
float f;
Object obj;
String currencyCode;
Log.Helper.LOGV(this, "purchaseItem() call with sku(%s)", str);
BillingHelper billingHelper = this.m_billingHelper;
if (billingHelper == null || !billingHelper.isBillingAvailable()) {
refreshBillingClient();
Log.Helper.LOGE(this, "billingClient is not set up. Either the GooglePlay app is not present, or the billing server was not bound", new Object[0]);
return new NimbleMTXError(NimbleMTXError.Code.BILLING_NOT_AVAILABLE, "billingClient is not set up. Either the GooglePlay app is not present, or the billing server was not bound");
}
if (purchaseTransactionCallback == null) {
Log.Helper.LOGE(this, "Missing purchase callback", new Object[0]);
return new Error(Error.Code.MISSING_CALLBACK, "Missing purchase callback");
}
if (isTransactionPending()) {
Log.Helper.LOGD(this, "purchaseItem called while transactions still pending.", new Object[0]);
synchronized (this) {
Log.Helper.LOGD(this, "pendingTransactions: " + this.mPendingTransactions, new Object[0]);
Log.Helper.LOGD(this, "recoveredTransactions: " + this.mRecoveredTransactions, new Object[0]);
}
return new NimbleMTXError(NimbleMTXError.Code.TRANSACTION_PENDING, "Another transaction is still outstanding.");
}
if (this.m_restoreInProgress) {
Log.Helper.LOGD(this, "purchaseItem called while restore is in progress.", new Object[0]);
return new NimbleMTXError(NimbleMTXError.Code.TRANSACTION_PENDING, "Can't purchase item while restore is in progress.");
}
if (this.mRecoveredTransactions.size() != 0) {
Log.Helper.LOGE(this, "mRecoveredTransactions.size() != 0. Resuming transaction.", new Object[0]);
for (Map.Entry<String, GooglePlayTransaction> entry : this.mRecoveredTransactions.entrySet()) {
String key = entry.getKey();
Log.Helper.LOGE(this, "transactionId: %s", key);
GooglePlayTransaction value = entry.getValue();
resumeTransaction(key, purchaseTransactionCallback, value.mItemGrantedCallback, value.mFinalizeCallback);
}
}
String generateTransactionId = generateTransactionId();
final GooglePlayTransaction googlePlayTransaction = new GooglePlayTransaction();
googlePlayTransaction.mItemSku = str;
googlePlayTransaction.mTransactionId = generateTransactionId;
googlePlayTransaction.mTransactionType = NimbleMTXTransaction.TransactionType.PURCHASE;
googlePlayTransaction.mPurchaseCallback = purchaseTransactionCallback;
Object[] objArr = new Object[2];
objArr[0] = Utility.validString(str2) ? str2 : "not set; metadata is null";
objArr[1] = str;
Log.Helper.LOGV(this, "Setting metadata... %s for sku %s", objArr);
if (Utility.validString(str2)) {
googlePlayTransaction.mAdditionalInfo.put("metadata", str2);
}
String sellIdFromSku = this.m_synergyCatalog.getSellIdFromSku(str);
synchronized (this) {
try {
googlePlayCatalogItem = this.mCatalogItems.get(str);
if (googlePlayCatalogItem != null) {
googlePlayTransaction.mCatalogItem = new GooglePlayCatalogItem(googlePlayCatalogItem);
sellIdFromSku = googlePlayCatalogItem.getSellId();
}
} catch (Throwable th) {
throw th;
}
}
synchronized (this) {
this.mPendingTransactions.put(generateTransactionId, googlePlayTransaction);
}
updateGooglePlayTransactionRecordState(googlePlayTransaction, GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_PREPURCHASE_INFO);
Object component = Base.getComponent(Tracking.COMPONENT_ID);
if (component != null && sellIdFromSku != null) {
HashMap hashMap = new HashMap();
hashMap.put(Tracking.KEY_MTX_SELLID, sellIdFromSku);
((ITracking) component).logEvent(Tracking.EVENT_MTX_ITEM_BEGIN_PURCHASE, hashMap);
}
HashMap hashMap2 = new HashMap();
hashMap2.put("en", "mtx");
Bundle bundle = new Bundle();
bundle.putSerializable("core", hashMap2);
bundle.putString("action", "begin");
if (sellIdFromSku != null) {
bundle.putString("itemSellId", sellIdFromSku);
} else {
bundle.putString("skuAlias", str);
}
if (googlePlayCatalogItem != null) {
f = googlePlayCatalogItem.getPriceDecimal();
obj = googlePlayCatalogItem.getAdditionalInfo().get(SynergyCatalog.MTX_INFO_KEY_CURRENCY);
} else {
f = 0.0f;
obj = null;
}
if (obj != null) {
currencyCode = obj.toString();
} else {
currencyCode = ApplicationEnvironment.getComponent().getCurrencyCode();
}
bundle.putString("currency", currencyCode);
bundle.putString("price", String.format(Locale.US, "%.2f", Float.valueOf(f)));
bundle.putString("eatid", generateTransactionId);
Intent intent = new Intent();
intent.setAction(NOTIFICATION_TRACKING2_LOG_EVENT);
intent.putExtras(bundle);
LocalBroadcastManager.getInstance(ApplicationEnvironment.getComponent().getApplicationContext()).sendBroadcast(intent);
ArrayList arrayList = new ArrayList();
ArrayList arrayList2 = new ArrayList();
arrayList.add(QueryProductDetailsParams.Product.newBuilder().setProductId(str).setProductType(Consts.ITEM_TYPE_SUBSCRIPTION).build());
arrayList2.add(QueryProductDetailsParams.Product.newBuilder().setProductId(str).setProductType("inapp").build());
this.m_billingHelper.queryProductDetailsAsync(arrayList, arrayList2, new ProductDetailsResponseListener() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.3
@Override // com.android.billingclient.api.ProductDetailsResponseListener
public void onProductDetailsResponse(@NonNull BillingResult billingResult, @Nullable List<ProductDetails> list) {
String priceCurrencyCode;
if (billingResult.getResponseCode() != 0 || list.isEmpty()) {
Log.Helper.LOGD(this, "Query inventory error: " + billingResult.getDebugMessage(), new Object[0]);
GooglePlay.this.createGooglePlayErrorFromBillingResult(billingResult);
NimbleMTXError nimbleMTXError = new NimbleMTXError(NimbleMTXError.Code.ERROR_GETTING_PREPURCHASE_INFO, "Failed to get prepurchase info for item " + str);
GooglePlayTransaction googlePlayTransaction2 = googlePlayTransaction;
googlePlayTransaction2.mError = nimbleMTXError;
googlePlayTransaction2.mFailedState = googlePlayTransaction2.mGooglePlayTransactionState;
GooglePlay.this.updateGooglePlayTransactionRecordState(googlePlayTransaction2, GooglePlayTransaction.GooglePlayTransactionState.COMPLETE);
GooglePlayTransaction googlePlayTransaction3 = googlePlayTransaction;
INimbleMTX.PurchaseTransactionCallback purchaseTransactionCallback2 = googlePlayTransaction3.mPurchaseCallback;
if (purchaseTransactionCallback2 != null) {
try {
purchaseTransactionCallback2.purchaseComplete(googlePlayTransaction3);
return;
} catch (Exception e) {
Log.Helper.LOGE(this, "MTX_GOOGLE: Unhandled exception in mPurchaseCallback: " + e, new Object[0]);
e.printStackTrace();
return;
}
}
return;
}
ProductDetails productDetails = list.get(0);
if (Consts.ITEM_TYPE_SUBSCRIPTION.equals(productDetails.getProductType())) {
ProductDetails.PricingPhase pricingPhase = (ProductDetails.PricingPhase) ((ProductDetails.SubscriptionOfferDetails) productDetails.getSubscriptionOfferDetails().get(0)).getPricingPhases().getPricingPhaseList().get(0);
googlePlayTransaction.mPriceDecimal = pricingPhase.getPriceAmountMicros() / 1000000.0f;
priceCurrencyCode = pricingPhase.getPriceCurrencyCode();
} else {
googlePlayTransaction.mPriceDecimal = productDetails.getOneTimePurchaseOfferDetails().getPriceAmountMicros() / 1000000.0f;
priceCurrencyCode = productDetails.getOneTimePurchaseOfferDetails().getPriceCurrencyCode();
}
if (priceCurrencyCode != null) {
googlePlayTransaction.mAdditionalInfo.put(SynergyCatalog.MTX_INFO_KEY_CURRENCY, priceCurrencyCode.toString());
} else {
Log.Helper.LOGD(this, "Currency information not currently available; using local currency instead.", new Object[0]);
googlePlayTransaction.mAdditionalInfo.put(SynergyCatalog.MTX_INFO_KEY_CURRENCY, ApplicationEnvironment.getComponent().getCurrencyCode());
}
GooglePlayTransaction googlePlayTransaction4 = googlePlayTransaction;
googlePlayTransaction4.mDeveloperPayload = GooglePlay.this.generateDeveloperPayloadForTransaction(googlePlayTransaction4);
GooglePlay.this.updateGooglePlayTransactionRecordState(googlePlayTransaction, GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_GOOGLEPLAY_ACTIVITY_RESPONSE);
GooglePlay.this.m_billingHelper.launchPurchaseFlow(ApplicationEnvironment.getCurrentActivity(), productDetails);
}
});
return null;
}
@Override // com.android.billingclient.api.PurchasesUpdatedListener
public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List<Purchase> list) {
GooglePlayTransaction googlePlayTransaction;
Purchase purchase;
Log.Helper.LOGD(this, "Purchase finished: " + billingResult.getResponseCode() + " " + billingResult.getDebugMessage(), new Object[0]);
if (list != null && !list.isEmpty()) {
purchase = list.get(0);
synchronized (this) {
try {
googlePlayTransaction = null;
for (GooglePlayTransaction googlePlayTransaction2 : this.mPendingTransactions.values()) {
if (Utility.validString(googlePlayTransaction2.mItemSku) && purchase.getProducts().contains(googlePlayTransaction2.mItemSku)) {
if (googlePlayTransaction == null) {
googlePlayTransaction = googlePlayTransaction2;
} else {
Log.Helper.LOGE(this, "Multiple transactions with the same sku found! Using the first one. TransactionA: " + googlePlayTransaction + " TransactionB: " + googlePlayTransaction2, new Object[0]);
}
}
}
} finally {
}
}
} else {
synchronized (this) {
try {
googlePlayTransaction = null;
for (GooglePlayTransaction googlePlayTransaction3 : this.mPendingTransactions.values()) {
if (googlePlayTransaction3.mGooglePlayTransactionState == GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_GOOGLEPLAY_ACTIVITY_RESPONSE) {
if (googlePlayTransaction == null) {
googlePlayTransaction = googlePlayTransaction3;
} else {
Log.Helper.LOGE(this, "More than one transaction record in WAITING_FOR_GOOGLE_PLAY_RESPONSE state found! Using: " + googlePlayTransaction.getItemSku() + ". Additional transaction for: " + googlePlayTransaction3.getItemSku(), new Object[0]);
}
}
}
} finally {
}
}
purchase = null;
}
if (googlePlayTransaction == null) {
Log.Helper.LOGD(this, "Transaction record could not be found for purchase", new Object[0]);
new ItemRestorer().restoreItems();
return;
}
if (billingResult.getResponseCode() != 0) {
Log.Helper.LOGD(this, "Google Play purchase error", new Object[0]);
if (purchase != null) {
updateAdditionalInfoBundleFromBillingPurchase(googlePlayTransaction, purchase);
}
googlePlayTransaction.mError = createNimbleMTXErrorWithGooglePlayError(createGooglePlayErrorFromBillingResult(billingResult), "Google Play purchase error");
googlePlayTransaction.mFailedState = googlePlayTransaction.mGooglePlayTransactionState;
updateGooglePlayTransactionRecordState(googlePlayTransaction, GooglePlayTransaction.GooglePlayTransactionState.COMPLETE);
INimbleMTX.PurchaseTransactionCallback purchaseTransactionCallback = googlePlayTransaction.mPurchaseCallback;
if (purchaseTransactionCallback != null) {
try {
purchaseTransactionCallback.purchaseComplete(googlePlayTransaction);
return;
} catch (Exception e) {
Log.Helper.LOGE(this, "MTX_GOOGLE: Unhandled exception in mPurchaseCallback: " + e, new Object[0]);
e.printStackTrace();
return;
}
}
return;
}
Log.Helper.LOGD(this, "GooglePlay Purchase successful.", new Object[0]);
String signature = purchase.getSignature();
googlePlayTransaction.mReceipt = signature;
if (signature == null || signature.length() == 0) {
Log.Helper.LOGW(this, "Purchase has an empty signature string. Setting to \"xxxxx\" for test.", new Object[0]);
googlePlayTransaction.mReceipt = "xxxxxxxxxxxxxxxxxxxxxxxxx";
}
updateAdditionalInfoBundleFromBillingPurchase(googlePlayTransaction, purchase);
if (purchase.getPurchaseState() != 1) {
googlePlayTransaction.mError = new NimbleMTXError(NimbleMTXError.Code.TRANSACTION_DEFERRED, "Google Play Purchase still pending");
googlePlayTransaction.mFailedState = googlePlayTransaction.mGooglePlayTransactionState;
updateGooglePlayTransactionRecordState(googlePlayTransaction, GooglePlayTransaction.GooglePlayTransactionState.COMPLETE);
INimbleMTX.PurchaseTransactionCallback purchaseTransactionCallback2 = googlePlayTransaction.mPurchaseCallback;
if (purchaseTransactionCallback2 != null) {
purchaseTransactionCallback2.purchaseComplete(googlePlayTransaction);
return;
} else {
Log.Helper.LOGE(this, "Transaction missing callback, cannot notify game of completed purchase", new Object[0]);
return;
}
}
if (this.m_verificationEnabled) {
updateGooglePlayTransactionRecordState(googlePlayTransaction, GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_SYNERGY_VERIFICATION);
INimbleMTX.PurchaseTransactionCallback purchaseTransactionCallback3 = googlePlayTransaction.mPurchaseCallback;
if (purchaseTransactionCallback3 != null) {
purchaseTransactionCallback3.unverifiedReceiptReceived(googlePlayTransaction);
} else {
Log.Helper.LOGE(this, "Transaction missing callback, cannot notify game of completed purchase", new Object[0]);
}
new PurchaseTransactionVerifier().verifyTransaction(googlePlayTransaction);
return;
}
if (!this.m_reportingEnabled) {
this.mUnrecordedTransactions.remove(googlePlayTransaction);
}
updateGooglePlayTransactionRecordState(googlePlayTransaction, GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_GAME_TO_CONFIRM_ITEM_GRANT);
INimbleMTX.PurchaseTransactionCallback purchaseTransactionCallback4 = googlePlayTransaction.mPurchaseCallback;
if (purchaseTransactionCallback4 != null) {
purchaseTransactionCallback4.purchaseComplete(googlePlayTransaction);
} else {
Log.Helper.LOGE(this, "Transaction missing callback, cannot notify game of completed purchase", new Object[0]);
}
}
@Override // com.ea.nimble.mtx.INimbleMTX
public Error itemGranted(String str, NimbleCatalogItem.ItemType itemType, INimbleMTX.ItemGrantedCallback itemGrantedCallback) {
GooglePlayTransaction googlePlayTransaction;
Log.Helper.LOGV(this, "itemGranted() call with transactionId(%s) and type (%s)", str, itemType.toString());
synchronized (this) {
googlePlayTransaction = this.mPendingTransactions.get(str);
}
if (googlePlayTransaction == null) {
Log.Helper.LOGE(this, "Could not find transaction by Id to perform item grant, id: " + str, new Object[0]);
return new NimbleMTXError(NimbleMTXError.Code.UNRECOGNIZED_TRANSACTION_ID, "Could not find transaction to perform item grant.");
}
BillingHelper billingHelper = this.m_billingHelper;
if (billingHelper == null || !billingHelper.isBillingAvailable()) {
refreshBillingClient();
Log.Helper.LOGE(this, "Billing service is disconnected or not available", new Object[0]);
return new NimbleMTXError(NimbleMTXError.Code.BILLING_NOT_AVAILABLE, "Billing service disconnected or not available");
}
GooglePlayTransaction.GooglePlayTransactionState googlePlayTransactionState = googlePlayTransaction.mGooglePlayTransactionState;
if (googlePlayTransactionState != GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_GAME_TO_CONFIRM_ITEM_GRANT) {
Log.Helper.LOGW(this, "Transaction in unexpected state for item grant. Transaction state: %s", googlePlayTransactionState);
}
if (itemGrantedCallback == null) {
Log.Helper.LOGE(this, "itemGranted called with empty callback parameter.", new Object[0]);
return new Error(Error.Code.MISSING_CALLBACK, "Missing callback in itemGranted call.");
}
googlePlayTransaction.mItemGrantedCallback = itemGrantedCallback;
GooglePlayCatalogItem googlePlayCatalogItem = googlePlayTransaction.mCatalogItem;
if (googlePlayCatalogItem != null) {
NimbleCatalogItem.ItemType itemType2 = googlePlayCatalogItem.getItemType();
NimbleCatalogItem.ItemType itemType3 = NimbleCatalogItem.ItemType.CONSUMABLE;
if (itemType2 == itemType3 && itemType != itemType3) {
Log.Helper.LOGW(this, "Game called item grant for SKU, %s, and indicated NOT consumable, though cached catalog data indicates the item is a consumable.", googlePlayTransaction.getItemSku());
}
}
if (googlePlayTransaction.getError() != null) {
Log.Helper.LOGW(this, "Transaction for item SKU, %s, granted by game, despite an error. Clearing error from transaction.", googlePlayTransaction.getItemSku());
googlePlayTransaction.mError = null;
}
updateGooglePlayTransactionRecordState(googlePlayTransaction, GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_GOOGLEPLAY_CONSUMPTION);
if (itemType == NimbleCatalogItem.ItemType.CONSUMABLE) {
googlePlayConsumeItem(googlePlayTransaction);
} else {
googlePlayAcknowledgePurchase(googlePlayTransaction);
}
return null;
}
@Override // com.ea.nimble.mtx.INimbleMTX
public Error finalizeTransaction(String str, INimbleMTX.FinalizeTransactionCallback finalizeTransactionCallback) {
GooglePlayTransaction googlePlayTransaction;
String currencyCode;
Log.Helper.LOGV(this, "finalizeTransaction() call with transactionId(%s)", str);
synchronized (this) {
googlePlayTransaction = this.mPendingTransactions.get(str);
}
boolean z = false;
if (googlePlayTransaction == null) {
String str2 = "Could not find transaction by Id to perform finalize, id: " + str;
Log.Helper.LOGE(this, str2, new Object[0]);
return new NimbleMTXError(NimbleMTXError.Code.UNRECOGNIZED_TRANSACTION_ID, str2);
}
GooglePlayTransaction.GooglePlayTransactionState googlePlayTransactionState = googlePlayTransaction.mGooglePlayTransactionState;
GooglePlayTransaction.GooglePlayTransactionState googlePlayTransactionState2 = GooglePlayTransaction.GooglePlayTransactionState.COMPLETE;
if (googlePlayTransactionState != googlePlayTransactionState2) {
Log.Helper.LOGW(this, "Finalize called on unfinished transaction, for sku, %s.", googlePlayTransaction.getItemSku());
}
googlePlayTransaction.mFinalizeCallback = finalizeTransactionCallback;
if (googlePlayTransaction.getError() == null && googlePlayTransaction.mTransactionType == NimbleMTXTransaction.TransactionType.PURCHASE) {
String itemSku = googlePlayTransaction.getItemSku();
String format = String.format(Locale.US, "%.2f", Float.valueOf(googlePlayTransaction.getPriceDecimal()));
Object obj = googlePlayTransaction.getAdditionalInfo().get(SynergyCatalog.MTX_INFO_KEY_CURRENCY);
if (obj != null) {
currencyCode = obj.toString();
} else {
Log.Helper.LOGD(this, "Currency information not currently available; using local currency instead.", new Object[0]);
currencyCode = ApplicationEnvironment.getComponent().getCurrencyCode();
}
String sellIdFromSku = this.m_synergyCatalog.getSellIdFromSku(itemSku);
if (sellIdFromSku == null) {
GooglePlayCatalogItem catalogItem = googlePlayTransaction.getCatalogItem();
if (catalogItem == null) {
catalogItem = this.mCatalogItems.get(itemSku);
}
if (catalogItem != null) {
sellIdFromSku = catalogItem.getSellId();
}
}
Object component = Base.getComponent(Tracking.COMPONENT_ID);
if (component != null && sellIdFromSku != null) {
HashMap hashMap = new HashMap();
hashMap.put(Tracking.KEY_MTX_SELLID, sellIdFromSku);
hashMap.put(Tracking.KEY_MTX_PRICE, format);
hashMap.put(Tracking.KEY_MTX_CURRENCY, currencyCode);
((ITracking) component).logEvent(Tracking.EVENT_MTX_ITEM_PURCHASED, hashMap);
}
HashMap hashMap2 = new HashMap();
hashMap2.put("en", "mtx");
Bundle bundle = new Bundle();
bundle.putSerializable("core", hashMap2);
bundle.putString("action", "purchased");
if (sellIdFromSku != null) {
bundle.putString("itemSellId", sellIdFromSku);
} else {
bundle.putString("skuAlias", itemSku);
}
bundle.putString("price", format);
bundle.putString("currency", currencyCode);
bundle.putString("eatid", str);
Object obj2 = googlePlayTransaction.getAdditionalInfo().get(GOOGLEPLAY_ADDITIONALINFO_KEY_ORDERID);
if (obj2 != null) {
bundle.putString("fptid", obj2.toString());
}
Intent intent = new Intent();
intent.setAction(NOTIFICATION_TRACKING2_LOG_EVENT);
intent.putExtras(bundle);
LocalBroadcastManager.getInstance(ApplicationEnvironment.getComponent().getApplicationContext()).sendBroadcast(intent);
}
synchronized (this) {
this.mPendingTransactions.remove(str);
}
updateGooglePlayTransactionRecordState(googlePlayTransaction, googlePlayTransactionState2);
GooglePlayCatalogItem catalogItem2 = googlePlayTransaction.getCatalogItem();
if (googlePlayTransaction.getError() == null && (catalogItem2 == null || catalogItem2.getItemType() != NimbleCatalogItem.ItemType.CONSUMABLE)) {
synchronized (this) {
this.mPurchasedTransactions.put(str, googlePlayTransaction);
}
savePurchasedTransactionsToPersistence();
}
if (this.m_reportingEnabled && !googlePlayTransaction.mIsRecorded && googlePlayTransaction.mError == null) {
z = true;
}
if (z) {
synchronized (this) {
this.mUnrecordedTransactions.add(googlePlayTransaction);
}
saveUnrecordedTransactionsToPersistence();
}
INimbleMTX.FinalizeTransactionCallback finalizeTransactionCallback2 = googlePlayTransaction.mFinalizeCallback;
if (finalizeTransactionCallback2 != null) {
finalizeTransactionCallback2.finalizeComplete(googlePlayTransaction);
}
if (!z) {
return null;
}
this.m_transactionRecorder.recordTransactions();
return null;
}
@Override // com.ea.nimble.mtx.INimbleMTX
public void restorePurchasedTransactions() {
Log.Helper.LOGV(this, "restorePurchasedTransactions()", new Object[0]);
restorePurchasedTransactionsImpl(true);
}
/* JADX INFO: Access modifiers changed from: private */
public void restorePurchasedTransactionsImpl(boolean z) {
Log.Helper.LOGFUNC(this);
if (this.m_restoreInProgress) {
Log.Helper.LOGD(this, "restorePurchasedTransactions called while restore already in progress. Aborting.", new Object[0]);
return;
}
if (isTransactionPending(z)) {
Log.Helper.LOGD(this, "restorePurchasedTransactions called while transactions still pending.", new Object[0]);
synchronized (this) {
Log.Helper.LOGD(this, "pendingTransactions: " + this.mPendingTransactions, new Object[0]);
Log.Helper.LOGD(this, "recoveredTransactions: " + this.mRecoveredTransactions, new Object[0]);
}
broadcastLocalEvent(INimbleMTX.NIMBLE_NOTIFICATION_MTX_RESTORE_PURCHASED_TRANSACTIONS_FINISHED, new NimbleMTXError(NimbleMTXError.Code.TRANSACTION_PENDING, "Can't restore purchases while transaction is pending"), null, null);
return;
}
Log.Helper.LOGD(this, "restorePurchasedTransactions called.", new Object[0]);
BillingHelper billingHelper = this.m_billingHelper;
if (billingHelper == null || !billingHelper.isBillingAvailable()) {
refreshBillingClient();
broadcastLocalEvent(INimbleMTX.NIMBLE_NOTIFICATION_MTX_RESTORE_PURCHASED_TRANSACTIONS_FINISHED, new NimbleMTXError(NimbleMTXError.Code.BILLING_NOT_AVAILABLE, "Billing not available"), null, null);
} else {
this.m_restoreInProgress = true;
this.m_billingHelper.queryPurchasesAsync(new PurchasesResponseListener() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.4
@Override // com.android.billingclient.api.PurchasesResponseListener
public void onQueryPurchasesResponse(@NonNull BillingResult billingResult, @NonNull final List<Purchase> list) {
GooglePlayError googlePlayError;
Log.Helper.LOGD(GooglePlay.this, "restorePurchasedTransactions onQueryPurchasesResponse", new Object[0]);
if (billingResult.getResponseCode() != 0) {
googlePlayError = GooglePlay.this.createGooglePlayErrorFromBillingResult(billingResult);
Log.Helper.LOGE(this, "Error with GooglePlay purchased item query. %s", googlePlayError.getMessage());
} else {
googlePlayError = null;
}
ArrayList arrayList = new ArrayList();
ArrayList arrayList2 = new ArrayList();
final HashMap hashMap = new HashMap();
if (list.size() > 0) {
Iterator<Purchase> it = list.iterator();
while (it.hasNext()) {
String str = (String) it.next().getProducts().get(0);
GooglePlayCatalogItem googlePlayCatalogItem = GooglePlay.this.mCatalogItems.get(str);
if (googlePlayCatalogItem != null && Utility.validString(googlePlayCatalogItem.mAdditionalInfo.get(SynergyCatalog.MTX_INFO_KEY_CURRENCY).toString())) {
hashMap.put(str, googlePlayCatalogItem.mAdditionalInfo.get(SynergyCatalog.MTX_INFO_KEY_CURRENCY).toString());
} else {
arrayList.add(QueryProductDetailsParams.Product.newBuilder().setProductId(str).setProductType(Consts.ITEM_TYPE_SUBSCRIPTION).build());
arrayList2.add(QueryProductDetailsParams.Product.newBuilder().setProductId(str).setProductType("inapp").build());
}
}
if (arrayList.isEmpty() || arrayList2.isEmpty()) {
GooglePlay.this.processQueryPurchasesResponse(list, hashMap);
} else {
GooglePlay.this.m_billingHelper.queryProductDetailsAsync(arrayList, arrayList2, new ProductDetailsResponseListener() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.4.1
@Override // com.android.billingclient.api.ProductDetailsResponseListener
public void onProductDetailsResponse(@NonNull BillingResult billingResult2, @Nullable List<ProductDetails> list2) {
if (billingResult2.getResponseCode() == 0) {
for (ProductDetails productDetails : list2) {
if (Consts.ITEM_TYPE_SUBSCRIPTION.equals(productDetails.getProductType())) {
hashMap.put(productDetails.getProductId(), ((ProductDetails.PricingPhase) ((ProductDetails.SubscriptionOfferDetails) productDetails.getSubscriptionOfferDetails().get(0)).getPricingPhases().getPricingPhaseList().get(0)).getPriceCurrencyCode());
} else {
hashMap.put(productDetails.getProductId(), productDetails.getOneTimePurchaseOfferDetails().getPriceCurrencyCode());
}
}
}
GooglePlay.this.processQueryPurchasesResponse(list, hashMap);
}
});
}
}
if (googlePlayError != null || list.isEmpty()) {
GooglePlay.this.mPurchasedTransactions.clear();
GooglePlay.this.m_restoreInProgress = false;
GooglePlay.this.broadcastLocalEvent(INimbleMTX.NIMBLE_NOTIFICATION_MTX_RESTORE_PURCHASED_TRANSACTIONS_FINISHED, googlePlayError != null ? GooglePlay.this.createNimbleMTXErrorWithGooglePlayError(googlePlayError, "Error with GooglePlay purchased item query") : null, null, null);
}
}
});
}
}
/* JADX INFO: Access modifiers changed from: private */
public void processQueryPurchasesResponse(List<Purchase> list, HashMap<String, String> hashMap) {
ArrayList arrayList = new ArrayList();
HashSet hashSet = new HashSet();
for (Purchase purchase : list) {
if (purchase.getPurchaseState() != 1) {
Log.Helper.LOGD(this, "Skipping processing a pending purchase", new Object[0]);
} else {
String str = (String) purchase.getProducts().get(0);
hashSet.add(Utility.safeString(str));
GooglePlayTransaction googlePlayTransaction = new GooglePlayTransaction();
googlePlayTransaction.mTransactionType = NimbleMTXTransaction.TransactionType.RESTORE;
googlePlayTransaction.mTransactionId = generateTransactionId();
String safeString = Utility.safeString(str);
googlePlayTransaction.mItemSku = safeString;
GooglePlayCatalogItem googlePlayCatalogItem = this.mCatalogItems.get(safeString);
if (googlePlayCatalogItem != null) {
if (googlePlayCatalogItem.getItemType() == NimbleCatalogItem.ItemType.CONSUMABLE) {
Log.Helper.LOGDS("CatalogItem: ", "CONSUMABLE", new Object[0]);
} else if (googlePlayCatalogItem.getItemType() == NimbleCatalogItem.ItemType.NONCONSUMABLE) {
Log.Helper.LOGDS("CatalogItem: ", "NONCONSUMABLE", new Object[0]);
} else if (googlePlayCatalogItem.getItemType() == NimbleCatalogItem.ItemType.SUBSCRIPTION) {
Log.Helper.LOGDS("CatalogItem: ", "SUBSCRIPTION", new Object[0]);
} else {
Log.Helper.LOGDS("CatalogItem: ", "UNKNOWN", new Object[0]);
}
googlePlayTransaction.mAdditionalInfo.put(SynergyCatalog.MTX_INFO_KEY_CURRENCY, googlePlayCatalogItem.getAdditionalInfo().get(SynergyCatalog.MTX_INFO_KEY_CURRENCY).toString());
} else {
Log.Helper.LOGDS("CatalogItem: ", "UNKNOWN", new Object[0]);
googlePlayTransaction.mAdditionalInfo.put(SynergyCatalog.MTX_INFO_KEY_CURRENCY, hashMap.get(str));
}
googlePlayTransaction.mNonce = Utility.safeString(purchase.getDeveloperPayload());
googlePlayTransaction.mReceipt = Utility.safeString(purchase.getSignature());
googlePlayTransaction.mGooglePlayTransactionState = GooglePlayTransaction.GooglePlayTransactionState.UNDEFINED;
updateAdditionalInfoBundleFromBillingPurchase(googlePlayTransaction, purchase);
googlePlayTransaction.mTimeStamp = new Date();
arrayList.add(googlePlayTransaction);
}
}
Iterator<String> it = this.mRecoveredTransactions.keySet().iterator();
while (it.hasNext()) {
GooglePlayTransaction googlePlayTransaction2 = this.mRecoveredTransactions.get(it.next());
if (hashSet.contains(googlePlayTransaction2.mItemSku) && googlePlayTransaction2.mGooglePlayTransactionState == GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_GOOGLEPLAY_ACTIVITY_RESPONSE) {
if (this.m_verificationEnabled) {
updateGooglePlayTransactionRecordState(googlePlayTransaction2, GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_SYNERGY_VERIFICATION);
} else {
updateGooglePlayTransactionRecordState(googlePlayTransaction2, GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_GAME_TO_CONFIRM_ITEM_GRANT);
}
}
}
HashMap hashMap2 = new HashMap();
for (String str2 : this.mPurchasedTransactions.keySet()) {
hashMap2.put(this.mPurchasedTransactions.get(str2).getItemSku(), str2);
}
Set keySet = hashMap2.keySet();
keySet.removeAll(hashSet);
Iterator it2 = keySet.iterator();
while (it2.hasNext()) {
String str3 = (String) hashMap2.get((String) it2.next());
synchronized (this) {
this.mPurchasedTransactions.remove(str3);
this.mPendingTransactions.remove(str3);
}
}
if (arrayList.size() == 0) {
Log.Helper.LOGDS(TAG, "No restored transactions to verify. Raising NIMBLE_NOTIFICATION_MTX_RESTORE_PURCHASED_TRANSACTIONS_FINISHED notification.", new Object[0]);
this.m_restoreInProgress = false;
broadcastLocalEvent(INimbleMTX.NIMBLE_NOTIFICATION_MTX_RESTORE_PURCHASED_TRANSACTIONS_FINISHED, null, null, null);
} else {
if (this.m_verificationEnabled) {
new RestoreTransactionVerifier().verifyTransactions(arrayList);
return;
}
if (!this.m_reportingEnabled) {
this.mUnrecordedTransactions.remove(arrayList);
}
onRestoreComplete(arrayList);
}
}
@Override // com.ea.nimble.mtx.INimbleMTX
public List<NimbleMTXTransaction> getPurchasedTransactions() {
ArrayList arrayList;
Log.Helper.LOGPUBLICFUNC(this);
synchronized (this) {
arrayList = new ArrayList(this.mPurchasedTransactions.values());
}
return arrayList;
}
public NimbleMTXTransaction getTransaction(String str) {
GooglePlayTransaction googlePlayTransaction;
Log.Helper.LOGPUBLICFUNC(this);
if (this.mPendingTransactions == null) {
return null;
}
synchronized (this) {
googlePlayTransaction = this.mPendingTransactions.get(str);
}
return googlePlayTransaction;
}
@Override // com.ea.nimble.mtx.INimbleMTX
public List<NimbleMTXTransaction> getPendingTransactions() {
ArrayList arrayList;
Log.Helper.LOGPUBLICFUNC(this);
if (this.mPendingTransactions == null) {
return null;
}
synchronized (this) {
arrayList = new ArrayList(this.mPendingTransactions.values());
}
return arrayList;
}
@Override // com.ea.nimble.mtx.INimbleMTX
public Error resumeTransaction(String str, INimbleMTX.PurchaseTransactionCallback purchaseTransactionCallback, INimbleMTX.ItemGrantedCallback itemGrantedCallback, INimbleMTX.FinalizeTransactionCallback finalizeTransactionCallback) {
GooglePlayTransaction remove;
Log.Helper.LOGV(this, "Resuming transaction id, %s.", Utility.safeString(str));
if (str == null) {
return new NimbleMTXError(NimbleMTXError.Code.UNRECOGNIZED_TRANSACTION_ID, "Null transaction ID");
}
if (this.m_restoreInProgress) {
Log.Helper.LOGD(this, "resumeTransaction called while restore is in progress.", new Object[0]);
return new NimbleMTXError(NimbleMTXError.Code.TRANSACTION_PENDING, "Can't resume transaction while restore is in progress.");
}
synchronized (this) {
try {
if (this.mPendingTransactions.size() > 0) {
remove = this.mPendingTransactions.get(str);
if (remove == null) {
Log.Helper.LOGD(this, "Resume called while transactions are pending: " + this.mPendingTransactions, new Object[0]);
return new NimbleMTXError(NimbleMTXError.Code.TRANSACTION_PENDING, "Another transaction is pending. It needs to finish and finalize first.");
}
if (remove.mError == null) {
return new Error(Error.Code.INVALID_ARGUMENT, "Cannot resume a pending transaction with no error");
}
} else {
remove = this.mRecoveredTransactions.remove(str);
if (remove == null) {
return new NimbleMTXError(NimbleMTXError.Code.UNRECOGNIZED_TRANSACTION_ID, "No transaction for given transaction ID.");
}
this.mPendingTransactions.put(remove.getTransactionId(), remove);
}
Exception exc = remove.mError;
if (exc != null && (!(exc instanceof Error) || ((Error) exc).getCode() != NimbleMTXError.Code.TRANSACTION_SUPERSEDED.intValue())) {
Log.Helper.LOGD(this, "Resuming transaction that failed in state " + remove.mFailedState + " with error " + remove.mError, new Object[0]);
remove.mGooglePlayTransactionState = remove.mFailedState;
remove.mFailedState = null;
remove.mError = null;
}
GooglePlayTransaction.GooglePlayTransactionState googlePlayTransactionState = remove.mGooglePlayTransactionState;
if (googlePlayTransactionState == GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_PREPURCHASE_INFO || googlePlayTransactionState == GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_GOOGLEPLAY_ACTIVITY_RESPONSE) {
remove.mFailedState = googlePlayTransactionState;
remove.mGooglePlayTransactionState = GooglePlayTransaction.GooglePlayTransactionState.COMPLETE;
remove.mError = new NimbleMTXError(NimbleMTXError.Code.NON_CRITICAL_INTERRUPTION, "MTX transaction interrupted before account charged.");
}
remove.mPurchaseCallback = purchaseTransactionCallback;
remove.mFinalizeCallback = finalizeTransactionCallback;
remove.mItemGrantedCallback = itemGrantedCallback;
savePendingTransactionsToPersistence();
GooglePlayTransaction.GooglePlayTransactionState googlePlayTransactionState2 = remove.mGooglePlayTransactionState;
if (googlePlayTransactionState2 == GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_NONCE || googlePlayTransactionState2 == GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_SYNERGY_VERIFICATION) {
new PurchaseTransactionVerifier().verifyTransaction(remove);
} else if (googlePlayTransactionState2 == GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_GAME_TO_CONFIRM_ITEM_GRANT) {
INimbleMTX.PurchaseTransactionCallback purchaseTransactionCallback2 = remove.mPurchaseCallback;
if (purchaseTransactionCallback2 != null) {
purchaseTransactionCallback2.purchaseComplete(remove);
} else {
return new Error(Error.Code.MISSING_CALLBACK, "Resumed transaction not given purchase callback.");
}
} else if (googlePlayTransactionState2 == GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_GOOGLEPLAY_CONSUMPTION) {
if (remove.mItemGrantedCallback != null) {
if (remove.getCatalogItem() != null && remove.getCatalogItem().getItemType() != null && remove.getCatalogItem().getItemType() != NimbleCatalogItem.ItemType.CONSUMABLE) {
googlePlayAcknowledgePurchase(remove);
} else {
googlePlayConsumeItem(remove);
}
} else {
return new Error(Error.Code.MISSING_CALLBACK, "Resumed transaction not given item granted callback.");
}
} else if (googlePlayTransactionState2 == GooglePlayTransaction.GooglePlayTransactionState.COMPLETE) {
finalizeTransaction(str, remove.mFinalizeCallback);
} else {
Log.Helper.LOGE(this, "ResumeTransaction called on a transaction that can't be resumed: " + remove, new Object[0]);
return new NimbleMTXError(NimbleMTXError.Code.TRANSACTION_NOT_RESUMABLE, "Transaction not in a resumable state.");
}
return null;
} catch (Throwable th) {
throw th;
}
}
}
@Override // com.ea.nimble.mtx.INimbleMTX
public List<NimbleMTXTransaction> getRecoveredTransactions() {
ArrayList arrayList;
Log.Helper.LOGPUBLICFUNC(this);
if (this.mRecoveredTransactions == null) {
return null;
}
synchronized (this) {
arrayList = new ArrayList(this.mRecoveredTransactions.values());
}
return arrayList;
}
@Override // com.ea.nimble.mtx.INimbleMTX
public void refreshAvailableCatalogItems() {
Log.Helper.LOGPUBLICFUNC(this);
BillingHelper billingHelper = this.m_billingHelper;
if (billingHelper == null || !billingHelper.isBillingAvailable()) {
refreshBillingClient();
Log.Helper.LOGW(this, "refreshAvailable returning because billing is unavailable ", new Object[0]);
Error.Code code = Error.Code.NOT_AVAILABLE;
broadcastLocalEvent(INimbleMTX.NIMBLE_NOTIFICATION_MTX_REFRESH_CATALOG_FINISHED, new Error(code, String.valueOf(code)), null, null);
return;
}
if (Network.getComponent().getStatus() != Network.Status.OK) {
Log.Helper.LOGW(this, "refreshAvailable returning because there is no network connection", new Object[0]);
Error.Code code2 = Error.Code.NETWORK_NO_CONNECTION;
broadcastLocalEvent(INimbleMTX.NIMBLE_NOTIFICATION_MTX_REFRESH_CATALOG_FINISHED, new Error(code2, String.valueOf(code2)), null, null);
return;
}
networkCallGetAvailableItems();
}
public void networkCallGetAvailableItems() {
Log.Helper.LOGFUNC(this);
try {
this.m_synergyCatalog.getItemCatalog(new SynergyCatalog.ItemCallback() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.5
@Override // com.ea.nimble.mtx.catalog.synergy.SynergyCatalog.ItemCallback
public void callback(List<SynergyCatalogItem> list, Exception exc) {
Log.Helper.LOGFUNC(this);
if (exc == null) {
LinkedList linkedList = new LinkedList();
for (SynergyCatalogItem synergyCatalogItem : list) {
GooglePlayCatalogItem googlePlayCatalogItem = new GooglePlayCatalogItem();
googlePlayCatalogItem.mItemType = synergyCatalogItem.getItemType();
googlePlayCatalogItem.mAdditionalInfo = synergyCatalogItem.getAdditionalInfo();
googlePlayCatalogItem.mDescription = synergyCatalogItem.getDescription();
googlePlayCatalogItem.mSku = synergyCatalogItem.getSku();
googlePlayCatalogItem.mTitle = synergyCatalogItem.getTitle();
googlePlayCatalogItem.mUrl = synergyCatalogItem.getMetaDataUrl();
googlePlayCatalogItem.mIsFree = synergyCatalogItem.isFree();
linkedList.add(googlePlayCatalogItem);
}
if (Base.getConfiguration() != NimbleConfiguration.LIVE) {
GooglePlayCatalogItem googlePlayCatalogItem2 = new GooglePlayCatalogItem();
googlePlayCatalogItem2.mSku = "android.test.purchased";
googlePlayCatalogItem2.mTitle = "GP Purchased";
googlePlayCatalogItem2.mDescription = "GP Purchased Desc";
googlePlayCatalogItem2.mUrl = "";
NimbleCatalogItem.ItemType itemType = NimbleCatalogItem.ItemType.NONCONSUMABLE;
googlePlayCatalogItem2.mItemType = itemType;
linkedList.add(googlePlayCatalogItem2);
GooglePlayCatalogItem googlePlayCatalogItem3 = new GooglePlayCatalogItem();
googlePlayCatalogItem3.mSku = "android.test.canceled";
googlePlayCatalogItem3.mTitle = "GP Canceled";
googlePlayCatalogItem3.mDescription = "GP Canceled Desc";
googlePlayCatalogItem3.mUrl = "";
googlePlayCatalogItem3.mItemType = itemType;
linkedList.add(googlePlayCatalogItem3);
GooglePlayCatalogItem googlePlayCatalogItem4 = new GooglePlayCatalogItem();
googlePlayCatalogItem4.mSku = "android.test.refunded";
googlePlayCatalogItem4.mTitle = "GP Refunded";
googlePlayCatalogItem4.mDescription = "GP Refunded Desc";
googlePlayCatalogItem4.mUrl = "";
googlePlayCatalogItem4.mItemType = itemType;
linkedList.add(googlePlayCatalogItem4);
GooglePlayCatalogItem googlePlayCatalogItem5 = new GooglePlayCatalogItem();
googlePlayCatalogItem5.mSku = "android.test.item_unavailable";
googlePlayCatalogItem5.mTitle = "GP Unavailable";
googlePlayCatalogItem5.mDescription = "GP Unavailable Desc";
googlePlayCatalogItem5.mUrl = "";
googlePlayCatalogItem5.mItemType = itemType;
linkedList.add(googlePlayCatalogItem5);
}
GooglePlay.this.getGooglePlayPricingForPendingCatalogItems(linkedList, new CatalogItemCallback() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.5.1
@Override // com.ea.nimble.mtx.googleplay.GooglePlay.CatalogItemCallback
public void onCatalogItemsRetrieved(List<GooglePlayCatalogItem> list2, Exception exc2) {
GooglePlay.this.onGooglePlayCatalogItemsRefreshed(list2, exc2);
}
});
return;
}
Log.Helper.LOGE(this, "GetAvailableItems error: " + exc, new Object[0]);
GooglePlay.this.broadcastLocalEvent(INimbleMTX.NIMBLE_NOTIFICATION_MTX_REFRESH_CATALOG_FINISHED, new Error(Error.Code.UNKNOWN, exc.toString(), exc), null, null);
}
});
} catch (Exception e) {
e.printStackTrace();
}
}
@Override // com.ea.nimble.mtx.INimbleMTX
public List<NimbleCatalogItem> getAvailableCatalogItems() {
Log.Helper.LOGPUBLICFUNC(this);
synchronized (this) {
if (this.mCatalogItems != null && !isCacheExpired()) {
ArrayList arrayList = new ArrayList(this.mCatalogItems.values());
Collections.sort(arrayList, new Comparator<NimbleCatalogItem>() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.1SkuComparator
@Override // java.util.Comparator
public int compare(NimbleCatalogItem nimbleCatalogItem, NimbleCatalogItem nimbleCatalogItem2) {
return nimbleCatalogItem.getSku().compareTo(nimbleCatalogItem2.getSku());
}
});
return arrayList;
}
return null;
}
}
@Override // com.ea.nimble.mtx.INimbleMTX
public void setPlatformParameters(Map<String, String> map) {
String str;
Log.Helper.LOGPUBLICFUNC(this);
if (map == null || (str = map.get(GOOGLEPLAY_PLATFORM_PARAMETER_APPLICATION_PUBLIC_KEY)) == null) {
return;
}
this.m_appPublicKey = str;
}
/* JADX INFO: Access modifiers changed from: private */
public void getGooglePlayPricingForPendingCatalogItems(final List<GooglePlayCatalogItem> list, final CatalogItemCallback catalogItemCallback) {
Log.Helper.LOGFUNC(this);
if (list == null || list.isEmpty()) {
broadcastLocalEvent(INimbleMTX.NIMBLE_NOTIFICATION_MTX_REFRESH_CATALOG_FINISHED, new Error(Error.Code.UNKNOWN, "Empty catalog item list for GooglePlay catalog query."), null, null);
return;
}
ArrayList arrayList = new ArrayList();
ArrayList arrayList2 = new ArrayList();
for (GooglePlayCatalogItem googlePlayCatalogItem : list) {
arrayList.add(QueryProductDetailsParams.Product.newBuilder().setProductId(googlePlayCatalogItem.mSku).setProductType(Consts.ITEM_TYPE_SUBSCRIPTION).build());
arrayList2.add(QueryProductDetailsParams.Product.newBuilder().setProductId(googlePlayCatalogItem.mSku).setProductType("inapp").build());
}
this.m_billingHelper.queryProductDetailsAsync(arrayList, arrayList2, new ProductDetailsResponseListener() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.6
@Override // com.android.billingclient.api.ProductDetailsResponseListener
public void onProductDetailsResponse(@NonNull BillingResult billingResult, @Nullable List<ProductDetails> list2) {
NimbleMTXError nimbleMTXError;
Log.Helper.LOGD(this, "GooglePlaySkuDetailsResponseListener onSkuDetailsResponse: " + billingResult.getResponseCode(), new Object[0]);
List<GooglePlayCatalogItem> arrayList3 = new ArrayList<>(list);
if (billingResult.getResponseCode() != 0) {
Log.Helper.LOGD(this, "Query inventory error: " + billingResult.getDebugMessage(), new Object[0]);
nimbleMTXError = GooglePlay.this.createNimbleMTXErrorWithGooglePlayError(GooglePlay.this.createGooglePlayErrorFromBillingResult(billingResult), "GooglePlay catalog query error");
} else {
HashMap hashMap = new HashMap();
for (ProductDetails productDetails : list2) {
hashMap.put(productDetails.getProductId(), productDetails);
}
HashSet hashSet = new HashSet();
for (GooglePlayCatalogItem googlePlayCatalogItem2 : arrayList3) {
ProductDetails productDetails2 = (ProductDetails) hashMap.get(googlePlayCatalogItem2.getSku());
if (productDetails2 != null) {
googlePlayCatalogItem2.mTitle = productDetails2.getTitle();
googlePlayCatalogItem2.mDescription = productDetails2.getDescription();
if (Consts.ITEM_TYPE_SUBSCRIPTION.equals(productDetails2.getProductType())) {
googlePlayCatalogItem2.mPriceWithCurrencyAndFormat = ((ProductDetails.PricingPhase) ((ProductDetails.SubscriptionOfferDetails) productDetails2.getSubscriptionOfferDetails().get(0)).getPricingPhases().getPricingPhaseList().get(0)).getFormattedPrice();
googlePlayCatalogItem2.mPriceDecimal = ((ProductDetails.PricingPhase) ((ProductDetails.SubscriptionOfferDetails) productDetails2.getSubscriptionOfferDetails().get(0)).getPricingPhases().getPricingPhaseList().get(0)).getPriceAmountMicros() / 1000000.0f;
googlePlayCatalogItem2.mAdditionalInfo.put(SynergyCatalog.MTX_INFO_KEY_CURRENCY, ((ProductDetails.PricingPhase) ((ProductDetails.SubscriptionOfferDetails) productDetails2.getSubscriptionOfferDetails().get(0)).getPricingPhases().getPricingPhaseList().get(0)).getPriceCurrencyCode());
} else {
googlePlayCatalogItem2.mPriceWithCurrencyAndFormat = productDetails2.getOneTimePurchaseOfferDetails().getFormattedPrice();
googlePlayCatalogItem2.mPriceDecimal = productDetails2.getOneTimePurchaseOfferDetails().getPriceAmountMicros() / 1000000.0f;
googlePlayCatalogItem2.mAdditionalInfo.put(SynergyCatalog.MTX_INFO_KEY_CURRENCY, productDetails2.getOneTimePurchaseOfferDetails().getPriceCurrencyCode());
}
if (productDetails2.getProductType().equals(Consts.ITEM_TYPE_SUBSCRIPTION)) {
NimbleCatalogItem.ItemType itemType = googlePlayCatalogItem2.mItemType;
NimbleCatalogItem.ItemType itemType2 = NimbleCatalogItem.ItemType.SUBSCRIPTION;
if (itemType != itemType2) {
Log.Helper.LOGW(this, "EA Catalog failed to recognize " + googlePlayCatalogItem2.getSku() + " as subscription. Updating item type based on First Party response.", new Object[0]);
googlePlayCatalogItem2.mItemType = itemType2;
}
}
} else {
hashSet.add(googlePlayCatalogItem2);
}
}
if (hashSet.size() > 0) {
arrayList3.removeAll(hashSet);
}
nimbleMTXError = arrayList3.size() == 0 ? new NimbleMTXError(NimbleMTXError.Code.EMPTY_BILLING_CATALOG, "Billing platform returned no matching items") : null;
}
catalogItemCallback.onCatalogItemsRetrieved(arrayList3, nimbleMTXError);
}
});
}
/* JADX INFO: Access modifiers changed from: private */
public void onGooglePlayCatalogItemsRefreshed(List<GooglePlayCatalogItem> list, Exception exc) {
Log.Helper.LOGFUNC(this);
if (exc == null) {
Log.Helper.LOGD(this, "GooglePlayCatalog Updated.", new Object[0]);
synchronized (this) {
try {
this.mCatalogItems.clear();
for (GooglePlayCatalogItem googlePlayCatalogItem : list) {
this.mCatalogItems.put(googlePlayCatalogItem.getSku(), googlePlayCatalogItem);
}
} catch (Throwable th) {
throw th;
}
}
saveCatalogToPersistence();
} else {
Log.Helper.LOGE(this, "Error updating GooglePlay Catalog: " + exc, new Object[0]);
}
broadcastLocalEvent(INimbleMTX.NIMBLE_NOTIFICATION_MTX_REFRESH_CATALOG_FINISHED, exc != null ? new Error(Error.Code.UNKNOWN, exc.toString(), exc) : null, null, null);
}
/* JADX INFO: Access modifiers changed from: private */
public void broadcastLocalEvent(String str, Error error, String str2, Bundle bundle) {
Log.Helper.LOGFUNC(this);
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(ApplicationEnvironment.getComponent().getApplicationContext());
Intent intent = new Intent();
intent.setAction(str);
Bundle bundle2 = bundle != null ? new Bundle(bundle) : new Bundle();
if (error == null) {
bundle2.putString("result", "1");
} else {
bundle2.putParcelable("error", error);
bundle2.putString("result", "0");
}
if (str2 != null) {
bundle2.putString(INimbleMTX.NOTIFICATION_DICTIONARY_KEY_TRANSACTIONID, str2);
}
intent.putExtras(bundle2);
localBroadcastManager.sendBroadcast(intent);
}
/* JADX INFO: Access modifiers changed from: private */
public void networkCallGetNonceFromSynergy(final GooglePlayTransaction googlePlayTransaction, final GetNonceCallback getNonceCallback) {
Log.Helper.LOGFUNC(this);
try {
this.m_synergyCatalog.getNonce(new SynergyCatalog.StringCallback() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.7
@Override // com.ea.nimble.mtx.catalog.synergy.SynergyCatalog.StringCallback
public void callback(String str, Exception exc) {
Log.Helper.LOGFUNC(this);
if (exc == null) {
getNonceCallback.onGetNonceComplete(googlePlayTransaction, str, null);
} else {
getNonceCallback.onGetNonceComplete(googlePlayTransaction, null, new NimbleMTXError(NimbleMTXError.Code.GET_NONCE_ERROR, "Synergy getNonce request error.", exc));
}
}
});
} catch (Exception e) {
e.printStackTrace();
getNonceCallback.onGetNonceComplete(googlePlayTransaction, null, new NimbleMTXError(NimbleMTXError.Code.GET_NONCE_ERROR, "Error making Synergy getNonce request", e));
}
}
/* JADX INFO: Access modifiers changed from: private */
public boolean updateTransactionRecordWithNonce(GooglePlayTransaction googlePlayTransaction, String str, Error error) {
NimbleMTXError nimbleMTXError;
Log.Helper.LOGFUNC(this);
if (error == null && str != null && str.length() != 0) {
googlePlayTransaction.mNonce = str;
return true;
}
if (error != null) {
Log.Helper.LOGE(this, "Error making getNonce call to Synergy: " + error, new Object[0]);
nimbleMTXError = new NimbleMTXError(NimbleMTXError.Code.VERIFICATION_ERROR, "Synergy getNonce error", error);
} else {
Log.Helper.LOGE(this, "No nonce in Synergy response for getNonce.", new Object[0]);
nimbleMTXError = new NimbleMTXError(NimbleMTXError.Code.VERIFICATION_ERROR, "No nonce in Synergy response");
}
if (googlePlayTransaction != null) {
googlePlayTransaction.mError = nimbleMTXError;
googlePlayTransaction.mFailedState = googlePlayTransaction.mGooglePlayTransactionState;
updateGooglePlayTransactionRecordState(googlePlayTransaction, GooglePlayTransaction.GooglePlayTransactionState.COMPLETE);
} else {
Log.Helper.LOGE(this, "No transaction record in getNonce error handling. No callback to call.", new Object[0]);
}
return false;
}
public class PurchaseTransactionVerifier {
private PurchaseTransactionVerifier() {
}
public void verifyTransaction(GooglePlayTransaction googlePlayTransaction) {
Log.Helper.LOGFUNC(this);
GooglePlay.this.updateGooglePlayTransactionRecordState(googlePlayTransaction, GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_NONCE);
GooglePlay.this.networkCallGetNonceFromSynergy(googlePlayTransaction, new GetNonceCallback() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.PurchaseTransactionVerifier.1
@Override // com.ea.nimble.mtx.googleplay.GooglePlay.GetNonceCallback
public void onGetNonceComplete(final GooglePlayTransaction googlePlayTransaction2, String str, Error error) {
Log.Helper.LOGFUNC(this);
if (googlePlayTransaction2.mGooglePlayTransactionState != GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_NONCE) {
return;
}
if (GooglePlay.this.updateTransactionRecordWithNonce(googlePlayTransaction2, str, error)) {
GooglePlay.this.networkCallRecordPurchase(googlePlayTransaction2, new VerifyCallback() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.PurchaseTransactionVerifier.1.1
@Override // com.ea.nimble.mtx.googleplay.GooglePlay.VerifyCallback
public void onVerificationComplete(Exception exc) {
INimbleMTX.PurchaseTransactionCallback purchaseTransactionCallback;
Log.Helper.LOGFUNC(this);
GooglePlayTransaction googlePlayTransaction3 = googlePlayTransaction2;
if (googlePlayTransaction3.mGooglePlayTransactionState != GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_SYNERGY_VERIFICATION) {
return;
}
if (exc == null) {
GooglePlay.this.updateGooglePlayTransactionRecordState(googlePlayTransaction3, GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_GAME_TO_CONFIRM_ITEM_GRANT);
} else {
Log.Helper.LOGE(this, "Error making recordPurchase call to Synergy: " + exc, new Object[0]);
googlePlayTransaction2.mError = new NimbleMTXError(NimbleMTXError.Code.VERIFICATION_ERROR, "Synergy verification error", exc);
GooglePlayTransaction googlePlayTransaction4 = googlePlayTransaction2;
googlePlayTransaction4.mFailedState = googlePlayTransaction4.mGooglePlayTransactionState;
GooglePlay.this.updateGooglePlayTransactionRecordState(googlePlayTransaction4, GooglePlayTransaction.GooglePlayTransactionState.COMPLETE);
}
GooglePlayTransaction googlePlayTransaction5 = googlePlayTransaction2;
if (googlePlayTransaction5 == null || (purchaseTransactionCallback = googlePlayTransaction5.mPurchaseCallback) == null) {
return;
}
purchaseTransactionCallback.purchaseComplete(googlePlayTransaction5);
}
});
return;
}
INimbleMTX.PurchaseTransactionCallback purchaseTransactionCallback = googlePlayTransaction2.mPurchaseCallback;
if (purchaseTransactionCallback != null) {
purchaseTransactionCallback.purchaseComplete(googlePlayTransaction2);
}
}
});
}
}
public class RestoreTransactionVerifier {
private AtomicInteger m_transactionsVerifying;
private ArrayList<GooglePlayTransaction> m_verifiedTransactions;
private RestoreTransactionVerifier() {
}
public void verifyTransactions(List<GooglePlayTransaction> list) {
Log.Helper.LOGFUNC(this);
this.m_transactionsVerifying = new AtomicInteger(0);
this.m_verifiedTransactions = new ArrayList<>();
if (list.size() == 0) {
GooglePlay.this.onRestoreComplete(this.m_verifiedTransactions);
return;
}
for (GooglePlayTransaction googlePlayTransaction : list) {
this.m_transactionsVerifying.incrementAndGet();
synchronized (GooglePlay.this) {
GooglePlay.this.mPendingTransactions.put(googlePlayTransaction.getTransactionId(), googlePlayTransaction);
}
GooglePlay.this.updateGooglePlayTransactionRecordState(googlePlayTransaction, GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_NONCE);
GooglePlay.this.networkCallGetNonceFromSynergy(googlePlayTransaction, new GetNonceCallback() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.RestoreTransactionVerifier.1
@Override // com.ea.nimble.mtx.googleplay.GooglePlay.GetNonceCallback
public void onGetNonceComplete(final GooglePlayTransaction googlePlayTransaction2, String str, Error error) {
if (GooglePlay.this.updateTransactionRecordWithNonce(googlePlayTransaction2, str, error)) {
GooglePlay.this.networkCallRecordPurchase(googlePlayTransaction2, new VerifyCallback() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.RestoreTransactionVerifier.1.1
@Override // com.ea.nimble.mtx.googleplay.GooglePlay.VerifyCallback
public void onVerificationComplete(Exception exc) {
if (exc != null) {
googlePlayTransaction2.mError = new NimbleMTXError(NimbleMTXError.Code.VERIFICATION_ERROR, "Synergy verification error", exc);
}
RestoreTransactionVerifier.this.m_verifiedTransactions.add(googlePlayTransaction2);
if (RestoreTransactionVerifier.this.m_transactionsVerifying.decrementAndGet() == 0) {
RestoreTransactionVerifier restoreTransactionVerifier = RestoreTransactionVerifier.this;
GooglePlay.this.onRestoreComplete(restoreTransactionVerifier.m_verifiedTransactions);
}
}
});
return;
}
synchronized (GooglePlay.this) {
GooglePlay.this.mPendingTransactions.remove(googlePlayTransaction2.getTransactionId());
}
if (RestoreTransactionVerifier.this.m_transactionsVerifying.decrementAndGet() == 0) {
RestoreTransactionVerifier restoreTransactionVerifier = RestoreTransactionVerifier.this;
GooglePlay.this.onRestoreComplete(restoreTransactionVerifier.m_verifiedTransactions);
}
}
});
}
}
}
/* JADX INFO: Access modifiers changed from: private */
/* JADX WARN: Removed duplicated region for block: B:39:0x01bb A[EXC_TOP_SPLITTER, SYNTHETIC] */
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public void onRestoreComplete(java.util.List<com.ea.nimble.mtx.googleplay.GooglePlayTransaction> r11) {
/*
Method dump skipped, instructions count: 491
To view this dump add '--comments-level debug' option
*/
throw new UnsupportedOperationException("Method not decompiled: com.ea.nimble.mtx.googleplay.GooglePlay.onRestoreComplete(java.util.List):void");
}
/* JADX INFO: Access modifiers changed from: private */
public void networkCallRecordPurchase(final GooglePlayTransaction googlePlayTransaction, final VerifyCallback verifyCallback) {
Log.Helper.LOGFUNC(this);
updateGooglePlayTransactionRecordState(googlePlayTransaction, GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_SYNERGY_VERIFICATION);
SynergyRequest.SynergyRequestPreparingCallback synergyRequestPreparingCallback = new SynergyRequest.SynergyRequestPreparingCallback() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.8
@Override // com.ea.nimble.SynergyRequest.SynergyRequestPreparingCallback
public void prepareRequest(final SynergyRequest synergyRequest) {
Log.Helper.LOGFUNC(this);
final IApplicationEnvironment component = ApplicationEnvironment.getComponent();
component.retrieveAdvertisingId(new IApplicationEnvironment.AdvertisingIdCalback() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.8.1
@Override // com.ea.nimble.IApplicationEnvironment.AdvertisingIdCalback
public void onCallback(String str, boolean z) {
Map<String, String> playerIdMap;
ISynergyEnvironment component2 = SynergyEnvironment.getComponent();
ISynergyIdManager component3 = SynergyIdManager.getComponent();
HashMap hashMap = new HashMap();
boolean z2 = googlePlayTransaction.getCatalogItem() != null && googlePlayTransaction.getCatalogItem().isFree();
hashMap.put("transactionId", googlePlayTransaction.getAdditionalInfo().get(GooglePlay.GOOGLEPLAY_ADDITIONALINFO_KEY_ORDERID));
hashMap.put("price", Integer.valueOf((int) (googlePlayTransaction.getPriceDecimal() * 100.0f)));
hashMap.put("currency", googlePlayTransaction.getAdditionalInfo().get(SynergyCatalog.MTX_INFO_KEY_CURRENCY));
hashMap.put("restore", Boolean.valueOf(googlePlayTransaction.getTransactionType() == NimbleMTXTransaction.TransactionType.RESTORE));
try {
hashMap.put("receipt", googlePlayTransaction.getAdditionalInfo().get(GooglePlay.GOOGLEPLAY_ADDITIONALINFO_KEY_PURCHASEDATA));
} catch (Exception unused) {
Log.Helper.LOGE(this, "Exception creating JSON body for /recordPurchase", new Object[0]);
hashMap.put("receipt", "");
}
String itemSku = googlePlayTransaction.getItemSku();
String sellIdFromSku = GooglePlay.this.m_synergyCatalog.getSellIdFromSku(itemSku);
if (sellIdFromSku != null) {
hashMap.put("itemSellId", sellIdFromSku);
} else {
hashMap.put("skuAlias", itemSku);
GooglePlayCatalogItem googlePlayCatalogItem = GooglePlay.this.mCatalogItems.get(itemSku);
if (googlePlayCatalogItem != null) {
hashMap.put("itemSellId", googlePlayCatalogItem.getSellId());
}
}
hashMap.put("masterSellId", component2.getSellId());
hashMap.put("hwId", component2.getEAHardwareId());
hashMap.put(InAppPurchaseMetaData.KEY_SIGNATURE, googlePlayTransaction.getReceipt());
hashMap.put("nonce", googlePlayTransaction.getNonce());
hashMap.put("isFree", Boolean.valueOf(z2));
String synergyId = component3.getSynergyId();
if (synergyId != null && synergyId != "") {
hashMap.put("synergyUid", Utility.safeString(synergyId));
}
HashMap hashMap2 = new HashMap();
String bool = Boolean.toString(z);
hashMap2.put("eaDeviceId", Utility.safeString(component2.getEADeviceId()));
hashMap2.put(ApplicationEnvironment.NIMBLE_PARAMETER_ANDROID_ID, component.getAndroidId());
hashMap2.put("advertiserId", Utility.safeString(str));
hashMap2.put(ApplicationEnvironment.NIMBLE_PARAMETER_LIMIT_AD_TRACKING, Utility.safeString(bool));
hashMap2.put("aut", Utility.safeString(""));
hashMap.put("didMap", Utility.convertObjectToJSONString(hashMap2));
IApplicationEnvironment iApplicationEnvironment = component;
if (iApplicationEnvironment != null && (playerIdMap = iApplicationEnvironment.getPlayerIdMap()) != null && playerIdMap.size() > 0) {
hashMap.put("pidMap", Utility.convertObjectToJSONString(playerIdMap));
}
HashMap hashMap3 = new HashMap();
hashMap3.put("timestamp", Utility.safeString(Utility.getUTCDateStringFormat(googlePlayTransaction.getTimeStamp())));
hashMap3.put("bundleId", Utility.safeString(component.getApplicationBundleId()));
hashMap3.put("appName", Utility.safeString(component.getApplicationName()));
hashMap3.put(v8.i.W, Utility.safeString(component.getApplicationVersion()));
hashMap3.put("appLanguage", Utility.safeString(ApplicationEnvironment.getComponent().getShortApplicationLanguageCode()));
hashMap3.put(ApplicationEnvironment.NIMBLE_PARAMETER_COUNTRY_CODE, Utility.safeString(Locale.getDefault().getCountry()));
String configValueAsString = NimbleApplicationConfiguration.getConfigValueAsString(FacebookSdk.APPLICATION_ID_PROPERTY);
if (Utility.validString(configValueAsString)) {
hashMap3.put("fbAppId", configValueAsString);
}
String parameter = component.getParameter(ApplicationEnvironment.NIMBLE_PARAMETER_FB_ATTR_ID);
if (Utility.validString(parameter)) {
hashMap3.put(ApplicationEnvironment.NIMBLE_PARAMETER_FB_ATTR_ID, parameter);
}
hashMap.put("appInfo", Utility.convertObjectToJSONString(hashMap3));
HashMap hashMap4 = new HashMap();
hashMap4.put(ApplicationEnvironment.NIMBLE_PARAMETER_SYSTEM_NAME, v8.d);
hashMap4.put(ApplicationEnvironment.NIMBLE_PARAMETER_LIMIT_AD_TRACKING, bool);
hashMap.put("deviceInfo", Utility.convertObjectToJSONString(hashMap4));
hashMap.put("schemaVer", "2");
hashMap.put("clientApiVersion", "2.0.0");
synergyRequest.jsonData = GooglePlay.this.new JsonData(hashMap);
synergyRequest.baseUrl = component2.getServerUrlWithKey(SynergyEnvironment.SERVER_URL_KEY_SYNERGY_DRM);
synergyRequest.send();
}
});
}
};
SynergyNetworkConnectionCallback synergyNetworkConnectionCallback = new SynergyNetworkConnectionCallback() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.9
@Override // com.ea.nimble.SynergyNetworkConnectionCallback
public void callback(SynergyNetworkConnectionHandle synergyNetworkConnectionHandle) {
Exception error = synergyNetworkConnectionHandle.getResponse().getError();
if (error == null) {
Log.Helper.LOGD(this, "recordPurchase response: " + synergyNetworkConnectionHandle.getResponse().getJsonData().toString(), new Object[0]);
googlePlayTransaction.mIsRecorded = true;
} else if (error instanceof Error) {
Error error2 = (Error) error;
if (error2.getDomain().equals(SynergyServerError.ERROR_DOMAIN) && error2.getCode() != SynergyServerError.Code.AMAZON_SERVER_CONNECTION_ERROR.intValue() && error2.getCode() != SynergyServerError.Code.APPLE_SERVER_CONNECTION_ERROR.intValue()) {
Log.Helper.LOGD(GooglePlay.this, "Transaction " + googlePlayTransaction.mTransactionId + " failed to record with error: " + error2, new Object[0]);
googlePlayTransaction.mIsRecorded = true;
}
}
if (verifyCallback == null || !ApplicationEnvironment.isMainApplicationActive()) {
return;
}
verifyCallback.onVerificationComplete(error);
}
};
SynergyNetwork.getComponent().sendRequest(new SynergyRequest(SYNERGY_API_VERIFY_AND_RECORD_GOOGLEPLAY_PURCHASE, IHttpRequest.Method.POST, synergyRequestPreparingCallback), synergyNetworkConnectionCallback);
}
private void googlePlayConsumeItem(GooglePlayTransaction googlePlayTransaction) {
Serializable serializable = googlePlayTransaction.mAdditionalInfo.get(GOOGLEPLAY_ADDITIONALINFO_KEY_ACKNOWLEDGED);
Serializable serializable2 = googlePlayTransaction.mAdditionalInfo.get(GOOGLEPLAY_ADDITIONALINFO_KEY_TOKEN);
if (serializable == null || serializable2 == null) {
Log.Helper.LOGD(this, "Purchase token is null", new Object[0]);
googlePlayTransaction.mError = new NimbleMTXError(NimbleMTXError.Code.UNABLE_TO_CONSTRUCT_REQUEST, "Unable to construct Purchase object from GooglePlayTransaction.");
googlePlayTransaction.mFailedState = googlePlayTransaction.mGooglePlayTransactionState;
updateGooglePlayTransactionRecordState(googlePlayTransaction, GooglePlayTransaction.GooglePlayTransactionState.COMPLETE);
INimbleMTX.ItemGrantedCallback itemGrantedCallback = googlePlayTransaction.mItemGrantedCallback;
if (itemGrantedCallback != null) {
itemGrantedCallback.itemGrantedComplete(googlePlayTransaction);
return;
} else {
Log.Helper.LOGE(this, "Transaction does not have a consume callback to notify game of the finalize error.", new Object[0]);
return;
}
}
this.m_billingHelper.consumeAsync(serializable2.toString(), new ConsumeResponseListener() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.10
@Override // com.android.billingclient.api.ConsumeResponseListener
public void onConsumeResponse(@NonNull BillingResult billingResult, @NonNull String str) {
GooglePlayTransaction googlePlayTransaction2;
Log.Helper.LOGFUNC(this);
synchronized (GooglePlay.this) {
try {
googlePlayTransaction2 = null;
for (GooglePlayTransaction googlePlayTransaction3 : GooglePlay.this.mPendingTransactions.values()) {
if (googlePlayTransaction3.mAdditionalInfo.get(GooglePlay.GOOGLEPLAY_ADDITIONALINFO_KEY_TOKEN).toString() == str) {
googlePlayTransaction2 = googlePlayTransaction3;
}
}
} catch (Throwable th) {
throw th;
}
}
if (billingResult.getResponseCode() == 0) {
if (googlePlayTransaction2 != null) {
Log.Helper.LOGD(this, "GooglePlay consume item success, item SKU: " + googlePlayTransaction2.getItemSku(), new Object[0]);
GooglePlay.this.updateGooglePlayTransactionRecordState(googlePlayTransaction2, GooglePlayTransaction.GooglePlayTransactionState.COMPLETE);
INimbleMTX.ItemGrantedCallback itemGrantedCallback2 = googlePlayTransaction2.mItemGrantedCallback;
if (itemGrantedCallback2 != null) {
itemGrantedCallback2.itemGrantedComplete(googlePlayTransaction2);
return;
} else {
Log.Helper.LOGE(this, "Transaction does not have a consume callback to notify game.", new Object[0]);
return;
}
}
Log.Helper.LOGE(this, "Unable to find consumed transaction to remove.", new Object[0]);
return;
}
if (googlePlayTransaction2 != null) {
Log.Helper.LOGE(this, "GooglePlay consume item failed, item SKU: " + googlePlayTransaction2.getItemSku(), new Object[0]);
googlePlayTransaction2.mError = GooglePlay.this.createNimbleMTXErrorWithGooglePlayError(GooglePlay.this.createGooglePlayErrorFromBillingResult(billingResult), "GooglePlay item consumption error.");
googlePlayTransaction2.mFailedState = googlePlayTransaction2.mGooglePlayTransactionState;
GooglePlay.this.updateGooglePlayTransactionRecordState(googlePlayTransaction2, GooglePlayTransaction.GooglePlayTransactionState.COMPLETE);
INimbleMTX.ItemGrantedCallback itemGrantedCallback3 = googlePlayTransaction2.mItemGrantedCallback;
if (itemGrantedCallback3 != null) {
itemGrantedCallback3.itemGrantedComplete(googlePlayTransaction2);
} else {
Log.Helper.LOGE(this, "Transaction does not have a consume callback to notify game of the finalize error.", new Object[0]);
}
}
}
});
}
private String generateTransactionId() {
return UUID.randomUUID().toString();
}
private void updateAdditionalInfoBundleFromBillingPurchase(GooglePlayTransaction googlePlayTransaction, Purchase purchase) {
Log.Helper.LOGFUNC(this);
if (purchase != null) {
googlePlayTransaction.mAdditionalInfo.put(GOOGLEPLAY_ADDITIONALINFO_KEY_ORDERID, purchase.getOrderId());
googlePlayTransaction.mAdditionalInfo.put(GOOGLEPLAY_ADDITIONALINFO_KEY_PURCHASETIME, Long.valueOf(purchase.getPurchaseTime()));
googlePlayTransaction.mAdditionalInfo.put(GOOGLEPLAY_ADDITIONALINFO_KEY_PURCHASESTATE, Integer.valueOf(purchase.getPurchaseState()));
googlePlayTransaction.mAdditionalInfo.put(GOOGLEPLAY_ADDITIONALINFO_KEY_TOKEN, purchase.getPurchaseToken());
googlePlayTransaction.mAdditionalInfo.put(GOOGLEPLAY_ADDITIONALINFO_KEY_PURCHASEDATA, purchase.getOriginalJson());
googlePlayTransaction.mAdditionalInfo.put(GOOGLEPLAY_ADDITIONALINFO_KEY_RECEIPT, purchase.getSignature());
googlePlayTransaction.mAdditionalInfo.put(GOOGLEPLAY_ADDITIONALINFO_KEY_ACKNOWLEDGED, Boolean.valueOf(purchase.isAcknowledged()));
}
}
/* JADX INFO: Access modifiers changed from: private */
public void updateGooglePlayTransactionRecordState(GooglePlayTransaction googlePlayTransaction, GooglePlayTransaction.GooglePlayTransactionState googlePlayTransactionState) {
Log.Helper.LOGFUNC(this);
googlePlayTransaction.mGooglePlayTransactionState = googlePlayTransactionState;
googlePlayTransaction.mTimeStamp = new Date();
savePendingTransactionsToPersistence();
}
private void savePendingTransactionsToPersistence() {
HashMap hashMap;
HashMap hashMap2;
Log.Helper.LOGFUNC(this);
synchronized (this) {
hashMap = new HashMap(this.mPendingTransactions);
hashMap2 = new HashMap(this.mRecoveredTransactions);
}
Persistence persistenceForNimbleComponent = PersistenceService.getPersistenceForNimbleComponent(COMPONENT_ID, Persistence.Storage.DOCUMENT);
Log.Helper.LOGD(this, "Saving %d pending and %d previously recovered transactions to persistence.", Integer.valueOf(hashMap.size()), Integer.valueOf(hashMap2.size()));
persistenceForNimbleComponent.setValue(PERSISTENCE_PENDING_TRANSACTIONS, hashMap);
persistenceForNimbleComponent.setValue(PERSISTENCE_RECOVERED_TRANSACTIONS, hashMap2);
persistenceForNimbleComponent.lambda$new$0();
}
private void saveCatalogToPersistence() {
HashMap hashMap;
Log.Helper.LOGFUNC(this);
synchronized (this) {
hashMap = new HashMap(this.mCatalogItems);
}
Persistence persistenceForNimbleComponent = PersistenceService.getPersistenceForNimbleComponent(COMPONENT_ID, Persistence.Storage.DOCUMENT);
Log.Helper.LOGD(this, "Saving %d catalog items to persistence.", Integer.valueOf(hashMap.size()));
persistenceForNimbleComponent.setValue(PERSISTENCE_CATALOG_ITEMS, hashMap);
Long valueOf = Long.valueOf(System.currentTimeMillis());
this.m_cacheTimestamp = valueOf;
persistenceForNimbleComponent.setValue(CACHE_TIMESTAMP_KEY, valueOf);
persistenceForNimbleComponent.lambda$new$0();
}
private void savePurchasedTransactionsToPersistence() {
HashMap hashMap;
Log.Helper.LOGFUNC(this);
synchronized (this) {
hashMap = new HashMap(this.mPurchasedTransactions);
}
Persistence persistenceForNimbleComponent = PersistenceService.getPersistenceForNimbleComponent(COMPONENT_ID, Persistence.Storage.DOCUMENT);
Log.Helper.LOGD(this, "Saving %d purchased transactions to persistence.", Integer.valueOf(hashMap.size()));
persistenceForNimbleComponent.setValue(PERSISTENCE_PURCHASED_TRANSACTIONS, hashMap);
persistenceForNimbleComponent.lambda$new$0();
}
/* JADX INFO: Access modifiers changed from: private */
public void saveUnrecordedTransactionsToPersistence() {
ArrayList arrayList;
Log.Helper.LOGFUNC(this);
synchronized (this) {
arrayList = new ArrayList(this.mUnrecordedTransactions);
}
Persistence persistenceForNimbleComponent = PersistenceService.getPersistenceForNimbleComponent(COMPONENT_ID, Persistence.Storage.DOCUMENT);
Log.Helper.LOGD(this, "Saving %d unrecorded transactions to persistence.", Integer.valueOf(arrayList.size()));
persistenceForNimbleComponent.setValue(PERSISTENCE_UNRECORDED_TRANSACTIONS, arrayList);
persistenceForNimbleComponent.lambda$new$0();
}
private HashMap<String, GooglePlayTransaction> filterForResumablePurchaseTransactions(HashMap<String, GooglePlayTransaction> hashMap) {
Log.Helper.LOGFUNC(this);
HashMap<String, GooglePlayTransaction> hashMap2 = new HashMap<>();
if (hashMap == null) {
return hashMap2;
}
for (GooglePlayTransaction googlePlayTransaction : hashMap.values()) {
GooglePlayTransaction.GooglePlayTransactionState googlePlayTransactionState = googlePlayTransaction.mGooglePlayTransactionState;
if (googlePlayTransactionState == GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_NONCE || googlePlayTransactionState == GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_GOOGLEPLAY_ACTIVITY_RESPONSE || googlePlayTransactionState == GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_SYNERGY_VERIFICATION || googlePlayTransactionState == GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_GAME_TO_CONFIRM_ITEM_GRANT || googlePlayTransactionState == GooglePlayTransaction.GooglePlayTransactionState.WAITING_FOR_GOOGLEPLAY_CONSUMPTION || googlePlayTransactionState == GooglePlayTransaction.GooglePlayTransactionState.COMPLETE) {
hashMap2.put(googlePlayTransaction.getTransactionId(), googlePlayTransaction);
}
}
return hashMap2;
}
private List<GooglePlayTransaction> findRecoveredTransactionsWithItemSku(String str) {
Log.Helper.LOGFUNC(this);
ArrayList arrayList = new ArrayList();
if (str == null) {
return arrayList;
}
synchronized (this) {
try {
for (GooglePlayTransaction googlePlayTransaction : this.mRecoveredTransactions.values()) {
if (googlePlayTransaction.getItemSku().equals(str)) {
arrayList.add(googlePlayTransaction);
}
}
} catch (Throwable th) {
throw th;
}
}
return arrayList;
}
private boolean isTransactionPending() {
Log.Helper.LOGFUNC(this);
return isTransactionPending(true);
}
private boolean isTransactionPending(boolean z) {
Log.Helper.LOGFUNC(this);
synchronized (this) {
try {
if (this.mPendingTransactions.size() == 0 && (!z || this.mRecoveredTransactions.size() == 0)) {
return false;
}
return true;
} finally {
}
}
}
private void loadFromPersistence() {
Log.Helper.LOGFUNC(this);
Persistence persistenceForNimbleComponent = PersistenceService.getPersistenceForNimbleComponent(COMPONENT_ID, Persistence.Storage.DOCUMENT);
Serializable value = persistenceForNimbleComponent.getValue(PERSISTENCE_CATALOG_ITEMS);
if (value != null && value.getClass() == HashMap.class) {
HashMap<String, GooglePlayCatalogItem> hashMap = new HashMap<>((HashMap) value);
synchronized (this) {
this.mCatalogItems = hashMap;
Log.Helper.LOGD(this, "Restored %d catalog items from persistence.", Integer.valueOf(hashMap.size()));
}
}
Serializable value2 = persistenceForNimbleComponent.getValue(PERSISTENCE_PURCHASED_TRANSACTIONS);
if (value2 != null && value2.getClass() == HashMap.class) {
HashMap<String, GooglePlayTransaction> hashMap2 = new HashMap<>((HashMap) value2);
synchronized (this) {
this.mPurchasedTransactions = hashMap2;
Log.Helper.LOGD(this, "%d purchased transactions restored from persistence.", Integer.valueOf(hashMap2.size()));
}
} else {
Log.Helper.LOGD(this, "No purchased transactions to restore.", new Object[0]);
}
Serializable value3 = persistenceForNimbleComponent.getValue(PERSISTENCE_RECOVERED_TRANSACTIONS);
if (value3 != null && value3.getClass() == HashMap.class) {
HashMap<String, GooglePlayTransaction> hashMap3 = new HashMap<>((HashMap) value3);
synchronized (this) {
this.mRecoveredTransactions = hashMap3;
Log.Helper.LOGD(this, "%d recovered transactions restored from persistence.", Integer.valueOf(hashMap3.size()));
}
} else {
Log.Helper.LOGD(this, "No recovered transactions to restore.", new Object[0]);
}
Serializable value4 = persistenceForNimbleComponent.getValue(PERSISTENCE_PENDING_TRANSACTIONS);
if (value4 != null && value4.getClass() == HashMap.class) {
HashMap<String, GooglePlayTransaction> hashMap4 = new HashMap<>((HashMap) value4);
Log.Helper.LOGD(this, "%d pending transactions restored from persistence.", Integer.valueOf(hashMap4.size()));
synchronized (this) {
try {
if (this.mRecoveredTransactions == null) {
this.mRecoveredTransactions = new HashMap<>();
}
this.mRecoveredTransactions.putAll(filterForResumablePurchaseTransactions(hashMap4));
Iterator<GooglePlayTransaction> it = this.mRecoveredTransactions.values().iterator();
while (it.hasNext()) {
this.mPendingTransactions.remove(it.next().getTransactionId());
}
} finally {
}
}
} else {
Log.Helper.LOGD(this, "No pending transactions to restore.", new Object[0]);
}
Serializable value5 = persistenceForNimbleComponent.getValue(PERSISTENCE_UNRECORDED_TRANSACTIONS);
if (value5 != null && (value5 instanceof ArrayList)) {
ArrayList<GooglePlayTransaction> arrayList = (ArrayList) value5;
synchronized (this) {
this.mUnrecordedTransactions = arrayList;
}
this.m_transactionRecorder.recordTransactions();
}
this.m_cacheTimestamp = (Long) persistenceForNimbleComponent.getValue(CACHE_TIMESTAMP_KEY);
synchronized (this) {
try {
HashMap<String, GooglePlayTransaction> hashMap5 = this.mRecoveredTransactions;
if (hashMap5 != null && hashMap5.size() > 0) {
Log.Helper.LOGD(this, "Recovered transactions: " + this.mRecoveredTransactions, new Object[0]);
broadcastLocalEvent(INimbleMTX.NIMBLE_NOTIFICATION_MTX_TRANSACTIONS_RECOVERED, null, null, null);
}
} finally {
}
}
}
private void googlePlayAcknowledgePurchase(final GooglePlayTransaction googlePlayTransaction) {
boolean z;
Log.Helper.LOGFUNC(this);
Serializable serializable = googlePlayTransaction.mAdditionalInfo.get(GOOGLEPLAY_ADDITIONALINFO_KEY_ACKNOWLEDGED);
Serializable serializable2 = googlePlayTransaction.mAdditionalInfo.get(GOOGLEPLAY_ADDITIONALINFO_KEY_TOKEN);
if (serializable == null || serializable2 == null) {
Log.Helper.LOGD(this, "Purchase token is null", new Object[0]);
googlePlayTransaction.mError = new NimbleMTXError(NimbleMTXError.Code.UNABLE_TO_CONSTRUCT_REQUEST, "Unable to construct Purchase object from GooglePlayTransaction.");
googlePlayTransaction.mFailedState = googlePlayTransaction.mGooglePlayTransactionState;
z = true;
} else {
z = false;
}
if (serializable != null && Utility.validString(serializable.toString()) && serializable.toString() == "true") {
Log.Helper.LOGD(this, "Purchase has already been acknowledged triggering callback", new Object[0]);
} else if (!z) {
this.m_billingHelper.acknowledgeAsync(serializable2.toString(), new AcknowledgePurchaseResponseListener() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.11
@Override // com.android.billingclient.api.AcknowledgePurchaseResponseListener
public void onAcknowledgePurchaseResponse(@NonNull BillingResult billingResult) {
if (billingResult.getResponseCode() != 0) {
NimbleMTXError createNimbleMTXErrorWithGooglePlayError = GooglePlay.this.createNimbleMTXErrorWithGooglePlayError(GooglePlay.this.createGooglePlayErrorFromBillingResult(billingResult), "GooglePlay item consumption error.");
GooglePlayTransaction googlePlayTransaction2 = googlePlayTransaction;
googlePlayTransaction2.mError = createNimbleMTXErrorWithGooglePlayError;
googlePlayTransaction2.mFailedState = googlePlayTransaction2.mGooglePlayTransactionState;
}
GooglePlay.this.updateGooglePlayTransactionRecordState(googlePlayTransaction, GooglePlayTransaction.GooglePlayTransactionState.COMPLETE);
GooglePlayTransaction googlePlayTransaction3 = googlePlayTransaction;
INimbleMTX.ItemGrantedCallback itemGrantedCallback = googlePlayTransaction3.mItemGrantedCallback;
if (itemGrantedCallback != null) {
itemGrantedCallback.itemGrantedComplete(googlePlayTransaction3);
} else {
Log.Helper.LOGE(this, "Transaction does not have a consume callback to notify game of the finalize error.", new Object[0]);
}
}
});
return;
}
updateGooglePlayTransactionRecordState(googlePlayTransaction, GooglePlayTransaction.GooglePlayTransactionState.COMPLETE);
INimbleMTX.ItemGrantedCallback itemGrantedCallback = googlePlayTransaction.mItemGrantedCallback;
if (itemGrantedCallback != null) {
itemGrantedCallback.itemGrantedComplete(googlePlayTransaction);
} else {
Log.Helper.LOGE(this, "Transaction does not have a consume callback to notify game of the finalize error.", new Object[0]);
}
}
/* JADX INFO: Access modifiers changed from: private */
public GooglePlayError createGooglePlayErrorFromBillingResult(BillingResult billingResult) {
GooglePlayError.Code code;
String str;
String str2;
Log.Helper.LOGFUNC(this);
if (billingResult == null || billingResult.getResponseCode() == 0) {
return null;
}
int responseCode = billingResult.getResponseCode();
if (responseCode == -2) {
code = GooglePlayError.Code.BILLING_RESPONSE_RESULT_FEATURE_NOT_SUPPORTED;
str = "Requested feature is not supported by Play Store on the current device";
} else if (responseCode != -1) {
str = "Network connection is down";
if (responseCode != 12) {
switch (responseCode) {
case 1:
code = GooglePlayError.Code.BILLING_RESPONSE_RESULT_USER_CANCELED;
str = "User pressed back or canceled a dialog";
break;
case 2:
code = GooglePlayError.Code.BILLING_RESPONSE_RESULT_SERVICE_UNAVAILABLE;
break;
case 3:
code = GooglePlayError.Code.BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE;
str = "Billing API version is not supported for the type requested";
break;
case 4:
code = GooglePlayError.Code.BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE;
str = "Requested product is not available for purchase";
break;
case 5:
code = GooglePlayError.Code.BILLING_RESPONSE_RESULT_DEVELOPER_ERROR;
str = "Invalid arguments provided to the API. This error can also indicate that the application was not correctly signed or properly set up for In-app Billing in Google Play, or does not have the necessary permissions in its manifest";
break;
case 6:
code = GooglePlayError.Code.BILLING_RESPONSE_RESULT_ERROR;
str = "error during the API action";
break;
case 7:
code = GooglePlayError.Code.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED;
str = "Failure to purchase since item is already owned";
break;
case 8:
code = GooglePlayError.Code.BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED;
str = "Failure to consume since item is not owned";
break;
default:
code = GooglePlayError.Code.UNKNOWN;
str = "Unknown message";
break;
}
} else {
code = GooglePlayError.Code.BILLING_RESPONSE_RESULT_NETWORK_ERROR;
}
} else {
code = GooglePlayError.Code.BILLING_RESPONSE_RESULT_SERVICE_DISCONNECTED;
str = "Play Store service is not connected now - potentially transient state. Play Store could have been updated in the background while your app was still running";
}
StringBuilder sb = new StringBuilder();
sb.append(str);
if (Utility.validString(billingResult.getDebugMessage())) {
str2 = ", Google Play debug message: " + billingResult.getDebugMessage();
} else {
str2 = "";
}
sb.append(str2);
return new GooglePlayError(code, sb.toString());
}
/* JADX INFO: Access modifiers changed from: private */
public NimbleMTXError createNimbleMTXErrorWithGooglePlayError(GooglePlayError googlePlayError, String str) {
Log.Helper.LOGFUNC(this);
NimbleMTXError.Code code = NimbleMTXError.Code.PLATFORM_ERROR;
if (googlePlayError != null) {
int code2 = googlePlayError.getCode();
if (code2 == GooglePlayError.Code.BILLING_RESPONSE_RESULT_USER_CANCELED.intValue()) {
code = NimbleMTXError.Code.USER_CANCELED;
} else if (code2 == GooglePlayError.Code.BILLING_RESPONSE_RESULT_BILLING_UNAVAILABLE.intValue()) {
code = NimbleMTXError.Code.BILLING_NOT_AVAILABLE;
} else if (code2 == GooglePlayError.Code.BILLING_RESPONSE_RESULT_ITEM_UNAVAILABLE.intValue()) {
code = NimbleMTXError.Code.ITEM_UNAVAILABLE;
} else if (code2 == GooglePlayError.Code.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED.intValue()) {
code = NimbleMTXError.Code.ITEM_ALREADY_OWNED;
} else if (code2 == GooglePlayError.Code.BILLING_RESPONSE_RESULT_ITEM_NOT_OWNED.intValue()) {
code = NimbleMTXError.Code.ITEM_NOT_OWNED;
}
}
return new NimbleMTXError(code, str, googlePlayError);
}
/* JADX INFO: Access modifiers changed from: private */
public String generateDeveloperPayloadForTransaction(GooglePlayTransaction googlePlayTransaction) {
Log.Helper.LOGFUNC(this);
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MMddHHmmss", Locale.US);
simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
return simpleDateFormat.format(new Date());
}
public class TransactionRecorder extends BroadcastReceiver implements Runnable, GetNonceCallback {
private double m_requestRetryDelay;
private final Timer m_timer;
private TransactionRecorder() {
this.m_requestRetryDelay = 1.0d;
this.m_timer = new Timer(this);
}
public void recordTransactions() {
Log.Helper.LOGFUNC(this);
synchronized (GooglePlay.this) {
ArrayList<GooglePlayTransaction> arrayList = GooglePlay.this.mUnrecordedTransactions;
if (arrayList != null && arrayList.size() != 0) {
Log.Helper.LOGD(GooglePlay.this, "Attempting to record transactions", new Object[0]);
if (!ApplicationEnvironment.isMainApplicationActive()) {
Log.Helper.LOGD(GooglePlay.this, "Main application not running, ignoring record", new Object[0]);
return;
}
if (Network.getComponent().getStatus() != Network.Status.OK) {
Log.Helper.LOGD(GooglePlay.this, "Waiting for Network connectivity", new Object[0]);
Utility.registerReceiver(Global.NOTIFICATION_NETWORK_STATUS_CHANGE, this);
return;
}
synchronized (GooglePlay.this) {
try {
Iterator<GooglePlayTransaction> it = GooglePlay.this.mUnrecordedTransactions.iterator();
while (it.hasNext()) {
GooglePlay.this.networkCallGetNonceFromSynergy(it.next(), this);
}
} finally {
}
}
return;
}
Log.Helper.LOGD(GooglePlay.this, "No transactions to record", new Object[0]);
}
}
@Override // com.ea.nimble.mtx.googleplay.GooglePlay.GetNonceCallback
public void onGetNonceComplete(final GooglePlayTransaction googlePlayTransaction, String str, Error error) {
Log.Helper.LOGFUNC(this);
if (GooglePlay.this.isCancelledError(error)) {
return;
}
if (GooglePlay.this.updateTransactionRecordWithNonce(googlePlayTransaction, str, error)) {
GooglePlay.this.networkCallRecordPurchase(googlePlayTransaction, new VerifyCallback() { // from class: com.ea.nimble.mtx.googleplay.GooglePlay.TransactionRecorder.1
@Override // com.ea.nimble.mtx.googleplay.GooglePlay.VerifyCallback
public void onVerificationComplete(Exception exc) {
Log.Helper.LOGFUNC(this);
if (GooglePlay.this.isCancelledError(exc)) {
return;
}
if (!googlePlayTransaction.mIsRecorded) {
if (TransactionRecorder.this.m_timer.isRunning()) {
return;
}
TransactionRecorder.this.m_timer.schedule(TransactionRecorder.this.m_requestRetryDelay, false);
} else {
synchronized (GooglePlay.this) {
GooglePlay.this.mUnrecordedTransactions.remove(googlePlayTransaction);
}
GooglePlay.this.saveUnrecordedTransactionsToPersistence();
TransactionRecorder.this.m_requestRetryDelay = 1.0d;
}
}
});
} else {
if (this.m_timer.isRunning()) {
return;
}
this.m_timer.schedule(this.m_requestRetryDelay, false);
}
}
@Override // java.lang.Runnable
public void run() {
this.m_requestRetryDelay = Math.min(this.m_requestRetryDelay * 2.0d, 300.0d);
recordTransactions();
}
@Override // android.content.BroadcastReceiver
public void onReceive(Context context, Intent intent) {
Log.Helper.LOGD(GooglePlay.this, "Received network notification", new Object[0]);
if (Network.getComponent().getStatus() == Network.Status.OK) {
Log.Helper.LOGD(GooglePlay.this, "Network status is OK, unregistering receiver and attempting to record transactions", new Object[0]);
Utility.unregisterReceiver(this);
recordTransactions();
return;
}
Log.Helper.LOGD(GooglePlay.this, "Attempted to recordTransaction but network state was not OK. Aborting and eating my transaction.", new Object[0]);
}
public void cancel() {
this.m_timer.cancel();
this.m_requestRetryDelay = 1.0d;
Utility.unregisterReceiver(this);
}
}
/* JADX INFO: Access modifiers changed from: private */
public boolean isCancelledError(Throwable th) {
Log.Helper.LOGFUNC(this);
if (!(th instanceof Error)) {
return false;
}
Error error = (Error) th;
return (error.getDomain().equals(Error.ERROR_DOMAIN) && error.getCode() == Error.Code.NETWORK_OPERATION_CANCELLED.intValue()) || isCancelledError(error.getCause());
}
private boolean isCacheExpired() {
Log.Helper.LOGFUNC(this);
return this.m_cacheTimestamp == null || ((double) (System.currentTimeMillis() - this.m_cacheTimestamp.longValue())) > 3600000.0d;
}
}