APK反编译源代码展示 - 南明离火平台提供

应用版本信息
应用名称:Electrical Cost
版本号:6.0.5
包名称:it.Ettore.spesaelettrica

MD5 校验值:facd8e3913e14e36e7daf9e69fbd45cb

反编译源代码说明

BillingWrapper.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。


package com.revenuecat.purchases.google;

import L.AbstractC0058b;
import L.C0059c;
import L.C0063g;
import L.C0065i;
import L.C0066j;
import L.C0067k;
import L.C0068l;
import L.InterfaceC0060d;
import L.r;
import L.t;
import L.u;
import L.v;
import L.y;
import L.z;
import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import androidx.room.migration.aPQ.ZgDYSIg;
import androidx.viewpager2.widget.Dk.cLduOWqDt;
import com.android.billingclient.api.Purchase;
import com.google.android.gms.internal.play_billing.zzx;
import com.google.android.material.internal.FB.ffxCxHAgR;
import com.revenuecat.purchases.ProductType;
import com.revenuecat.purchases.PurchasesError;
import com.revenuecat.purchases.PurchasesErrorCode;
import com.revenuecat.purchases.ReplacementMode;
import com.revenuecat.purchases.common.BillingAbstract;
import com.revenuecat.purchases.common.DateProvider;
import com.revenuecat.purchases.common.DefaultDateProvider;
import com.revenuecat.purchases.common.DurationExtensionsKt;
import com.revenuecat.purchases.common.HTTPClient;
import com.revenuecat.purchases.common.LogIntent;
import com.revenuecat.purchases.common.LogUtilsKt;
import com.revenuecat.purchases.common.LogWrapperKt;
import com.revenuecat.purchases.common.PurchaseExtensionsKt;
import com.revenuecat.purchases.common.ReplaceProductInfo;
import com.revenuecat.purchases.common.UtilsKt;
import com.revenuecat.purchases.common.caching.DeviceCache;
import com.revenuecat.purchases.common.diagnostics.DiagnosticsTracker;
import com.revenuecat.purchases.google.usecase.GetBillingConfigUseCase;
import com.revenuecat.purchases.google.usecase.QueryProductDetailsUseCase;
import com.revenuecat.purchases.google.usecase.QueryProductDetailsUseCaseParams;
import com.revenuecat.purchases.google.usecase.QueryPurchaseHistoryUseCase;
import com.revenuecat.purchases.google.usecase.QueryPurchaseHistoryUseCaseParams;
import com.revenuecat.purchases.google.usecase.QueryPurchasesUseCase;
import com.revenuecat.purchases.google.usecase.QueryPurchasesUseCaseParams;
import com.revenuecat.purchases.models.GooglePurchasingData;
import com.revenuecat.purchases.models.GoogleReplacementMode;
import com.revenuecat.purchases.models.InAppMessageType;
import com.revenuecat.purchases.models.PurchaseState;
import com.revenuecat.purchases.models.PurchasingData;
import com.revenuecat.purchases.models.StoreTransaction;
import com.revenuecat.purchases.strings.BillingStrings;
import com.revenuecat.purchases.strings.OfferingStrings;
import com.revenuecat.purchases.strings.PurchaseStrings;
import com.revenuecat.purchases.strings.RestoreStrings;
import com.revenuecat.purchases.utils.Result;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.atomic.AtomicBoolean;
import k2.C0320D;
import kotlin.NoWhenBranchMatchedException;
import kotlin.jvm.functions.Function0;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.uH.YpIkwCgYXfGh;
import l2.j;
import m1.CWT.TOhAhwcHW;
import p3.g;
import v2.InterfaceC0424k;
import v2.InterfaceC0428o;

public final class BillingWrapper extends BillingAbstract implements v, InterfaceC0060d {
    private volatile AbstractC0058b billingClient;
    private final ClientFactory clientFactory;
    private final DateProvider dateProvider;
    private final DeviceCache deviceCache;
    private final DiagnosticsTracker diagnosticsTrackerIfEnabled;
    private final Handler mainHandler;
    private final Map<String, PurchaseContext> purchaseContext;
    private long reconnectMilliseconds;
    private boolean reconnectionAlreadyScheduled;
    private final ConcurrentLinkedQueue<InterfaceC0424k> serviceRequests;

    public static final class ClientFactory {
        private final Context context;

        public ClientFactory(Context context) {
            k.e(context, "context");
            this.context = context;
        }

        public final AbstractC0058b buildClient(v listener) {
            k.e(listener, "listener");
            Context context = this.context;
            if (context != null) {
                return new C0059c(context, listener);
            }
            throw new IllegalArgumentException("Please provide a valid Context.");
        }
    }

    public BillingWrapper(ClientFactory clientFactory, Handler mainHandler, DeviceCache deviceCache, DiagnosticsTracker diagnosticsTracker, DateProvider dateProvider) {
        k.e(clientFactory, "clientFactory");
        k.e(mainHandler, "mainHandler");
        k.e(deviceCache, "deviceCache");
        k.e(dateProvider, "dateProvider");
        this.clientFactory = clientFactory;
        this.mainHandler = mainHandler;
        this.deviceCache = deviceCache;
        this.diagnosticsTrackerIfEnabled = diagnosticsTracker;
        this.dateProvider = dateProvider;
        this.purchaseContext = new LinkedHashMap();
        this.serviceRequests = new ConcurrentLinkedQueue<>();
        this.reconnectMilliseconds = 1000L;
    }

    public BillingWrapper(ClientFactory clientFactory, Handler handler, DeviceCache deviceCache, DiagnosticsTracker diagnosticsTracker, DateProvider dateProvider, int i, kotlin.jvm.internal.f fVar) {
        this(clientFactory, handler, deviceCache, diagnosticsTracker, (i & 16) != 0 ? new DefaultDateProvider() : dateProvider);
    }

    private final Result<C0065i, PurchasesError> buildOneTimePurchaseParams(GooglePurchasingData.InAppProduct inAppProduct, String str, Boolean bool) {
        A1.e eVar = new A1.e(6);
        r productDetails = inAppProduct.getProductDetails();
        eVar.f12b = productDetails;
        if (productDetails.a() != null) {
            productDetails.a().getClass();
            eVar.f13c = productDetails.a().f642d;
        }
        zzx.zzc((r) eVar.f12b, "ProductDetails is required for constructing ProductDetailsParams.");
        zzx.zzc((String) eVar.f13c, "offerToken is required for constructing ProductDetailsParams.");
        C0063g c0063g = new C0063g(eVar);
        ?? obj = new Object();
        ?? obj2 = new Object();
        obj2.f627d = 0;
        obj2.e = 0;
        obj2.f626c = true;
        obj.f621d = obj2;
        obj.f619b = new ArrayList(g.n(c0063g));
        obj.f618a = UtilsKt.sha256(str);
        if (bool != null) {
            obj.f620c = bool.booleanValue();
        }
        return new Result.Success(obj.a());
    }

    public final Result<C0065i, PurchasesError> buildPurchaseParams(GooglePurchasingData googlePurchasingData, ReplaceProductInfo replaceProductInfo, String str, Boolean bool) {
        if (googlePurchasingData instanceof GooglePurchasingData.InAppProduct) {
            return buildOneTimePurchaseParams((GooglePurchasingData.InAppProduct) googlePurchasingData, str, bool);
        }
        if (googlePurchasingData instanceof GooglePurchasingData.Subscription) {
            return buildSubscriptionPurchaseParams((GooglePurchasingData.Subscription) googlePurchasingData, replaceProductInfo, str, bool);
        }
        throw new NoWhenBranchMatchedException();
    }

    private final Result<C0065i, PurchasesError> buildSubscriptionPurchaseParams(GooglePurchasingData.Subscription subscription, ReplaceProductInfo replaceProductInfo, String str, Boolean bool) {
        A1.e eVar = new A1.e(6);
        eVar.f13c = subscription.getToken();
        r productDetails = subscription.getProductDetails();
        eVar.f12b = productDetails;
        if (productDetails.a() != null) {
            productDetails.a().getClass();
            eVar.f13c = productDetails.a().f642d;
        }
        zzx.zzc((r) eVar.f12b, "ProductDetails is required for constructing ProductDetailsParams.");
        zzx.zzc((String) eVar.f13c, "offerToken is required for constructing ProductDetailsParams.");
        C0063g c0063g = new C0063g(eVar);
        ?? obj = new Object();
        ?? obj2 = new Object();
        obj2.f627d = 0;
        obj2.e = 0;
        obj2.f626c = true;
        obj.f621d = obj2;
        obj.f619b = new ArrayList(g.n(c0063g));
        if (replaceProductInfo != null) {
            BillingFlowParamsExtensionsKt.setUpgradeInfo(obj, replaceProductInfo);
        } else {
            obj.f618a = UtilsKt.sha256(str);
        }
        if (bool != null) {
            obj.f620c = bool.booleanValue();
        }
        return new Result.Success(obj.a());
    }

    public static final void endConnection$lambda$8(BillingWrapper this$0) {
        k.e(this$0, "this$0");
        synchronized (this$0) {
            try {
                AbstractC0058b abstractC0058b = this$0.billingClient;
                if (abstractC0058b != null) {
                    LogWrapperKt.log(LogIntent.DEBUG, String.format(BillingStrings.BILLING_CLIENT_ENDING, Arrays.copyOf(new Object[]{abstractC0058b}, 1)));
                    abstractC0058b.a();
                }
                this$0.billingClient = null;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    private final void executePendingRequests() {
        InterfaceC0424k poll;
        synchronized (this) {
            while (true) {
                AbstractC0058b abstractC0058b = this.billingClient;
                if (abstractC0058b == null || !abstractC0058b.c() || (poll = this.serviceRequests.poll()) == null) {
                    break;
                } else {
                    this.mainHandler.post(new c(poll, 2));
                }
            }
        }
    }

    public static final void executePendingRequests$lambda$2$lambda$1$lambda$0(InterfaceC0424k it2) {
        k.e(it2, "$it");
        it2.invoke(null);
    }

    public final synchronized void executeRequestOnUIThread(InterfaceC0424k interfaceC0424k) {
        try {
            if (getPurchasesUpdatedListener() != null) {
                this.serviceRequests.add(interfaceC0424k);
                AbstractC0058b abstractC0058b = this.billingClient;
                if (abstractC0058b == null || abstractC0058b.c()) {
                    executePendingRequests();
                } else {
                    BillingAbstract.startConnectionOnMainThread$default(this, 0L, 1, null);
                }
            } else {
                interfaceC0424k.invoke(new PurchasesError(PurchasesErrorCode.UnknownError, "BillingWrapper is not attached to a listener"));
            }
        } catch (Throwable th) {
            throw th;
        }
    }

    public static final void getPurchaseType$lambda$14$lambda$13(InterfaceC0424k listener, BillingWrapper this$0, AbstractC0058b client, String purchaseToken, C0067k querySubsResult, List subsPurchasesList) {
        boolean z3;
        k.e(listener, "$listener");
        k.e(this$0, "this$0");
        k.e(client, "$client");
        k.e(purchaseToken, "$purchaseToken");
        k.e(querySubsResult, "querySubsResult");
        k.e(subsPurchasesList, "subsPurchasesList");
        boolean z4 = querySubsResult.f635a == 0;
        List list = subsPurchasesList;
        if (!(list instanceof Collection) || !list.isEmpty()) {
            Iterator it2 = list.iterator();
            while (it2.hasNext()) {
                if (k.a(((Purchase) it2.next()).b(), purchaseToken)) {
                    z3 = true;
                    break;
                }
            }
        }
        z3 = false;
        if (z4 && z3) {
            listener.invoke(ProductType.SUBS);
            return;
        }
        z buildQueryPurchasesParams = BillingClientParamBuildersKt.buildQueryPurchasesParams("inapp");
        if (buildQueryPurchasesParams != null) {
            this$0.queryPurchasesAsyncWithTrackingEnsuringOneResponse(client, "inapp", buildQueryPurchasesParams, new d(listener, purchaseToken));
        } else {
            LogUtilsKt.errorLog$default(String.format(PurchaseStrings.INVALID_PRODUCT_TYPE, Arrays.copyOf(new Object[]{"getPurchaseType"}, 1)), null, 2, null);
            listener.invoke(ProductType.UNKNOWN);
        }
    }

    public static final void getPurchaseType$lambda$14$lambda$13$lambda$12(InterfaceC0424k listener, String purchaseToken, C0067k queryInAppsResult, List inAppPurchasesList) {
        k.e(listener, "$listener");
        k.e(purchaseToken, "$purchaseToken");
        k.e(queryInAppsResult, "queryInAppsResult");
        k.e(inAppPurchasesList, "inAppPurchasesList");
        boolean z3 = true;
        boolean z4 = queryInAppsResult.f635a == 0;
        List list = inAppPurchasesList;
        if (!(list instanceof Collection) || !list.isEmpty()) {
            Iterator it2 = list.iterator();
            while (it2.hasNext()) {
                if (k.a(((Purchase) it2.next()).b(), purchaseToken)) {
                    break;
                }
            }
        }
        z3 = false;
        if (z4 && z3) {
            listener.invoke(ProductType.INAPP);
        } else {
            listener.invoke(ProductType.UNKNOWN);
        }
    }

    private final String getStackTrace() {
        StringWriter stringWriter = new StringWriter();
        new Throwable().printStackTrace(new PrintWriter(stringWriter));
        String stringWriter2 = stringWriter.toString();
        k.d(stringWriter2, "stringWriter.toString()");
        return stringWriter2;
    }

    private final void getStoreTransaction(Purchase purchase, InterfaceC0424k interfaceC0424k) {
        com.google.android.gms.internal.play_billing.a.n(new Object[]{PurchaseExtensionsKt.toHumanReadableDescription(purchase)}, 1, BillingStrings.BILLING_WRAPPER_PURCHASES_UPDATED, LogIntent.DEBUG);
        synchronized (this) {
            PurchaseContext purchaseContext = this.purchaseContext.get(PurchaseExtensionsKt.getFirstProductId(purchase));
            if (purchaseContext != null && purchaseContext.getProductType() != null) {
                interfaceC0424k.invoke(StoreTransactionConversionsKt.toStoreTransaction(purchase, purchaseContext));
                return;
            }
            String b4 = purchase.b();
            k.d(b4, "purchase.purchaseToken");
            getPurchaseType$purchases_defaultsRelease(b4, new BillingWrapper$getStoreTransaction$1$2(interfaceC0424k, purchase, purchaseContext));
        }
    }

    public final void launchBillingFlow(Activity activity, C0065i c0065i) {
        if (activity.getIntent() == null) {
            LogWrapperKt.log(LogIntent.WARNING, BillingStrings.NULL_ACTIVITY_INTENT);
        }
        withConnectedClient(new BillingWrapper$launchBillingFlow$1(activity, c0065i));
    }

    public static final void onBillingSetupFinished$lambda$21(C0067k billingResult, BillingWrapper this$0) {
        PurchasesError billingResponseToPurchasesError;
        k.e(billingResult, "$billingResult");
        k.e(this$0, "this$0");
        int i = billingResult.f635a;
        if (i != 6) {
            if (i != 7 && i != 8) {
                if (i != 12) {
                    switch (i) {
                        case -2:
                        case 3:
                            String humanReadableDescription = BillingResultExtensionsKt.toHumanReadableDescription(billingResult);
                            if (k.a(billingResult.f636b, ErrorsKt.IN_APP_BILLING_LESS_THAN_3_ERROR_MESSAGE)) {
                                billingResponseToPurchasesError = new PurchasesError(PurchasesErrorCode.StoreProblemError, String.format(BillingStrings.BILLING_UNAVAILABLE_LESS_THAN_3, Arrays.copyOf(new Object[]{humanReadableDescription}, 1)));
                                LogUtilsKt.errorLog(billingResponseToPurchasesError);
                            } else {
                                billingResponseToPurchasesError = ErrorsKt.billingResponseToPurchasesError(billingResult.f635a, String.format(BillingStrings.BILLING_UNAVAILABLE, Arrays.copyOf(new Object[]{humanReadableDescription}, 1)));
                                LogUtilsKt.errorLog(billingResponseToPurchasesError);
                            }
                            this$0.sendErrorsToAllPendingRequests(billingResponseToPurchasesError);
                            return;
                        case HTTPClient.NO_STATUS_CODE:
                        case 1:
                        case 2:
                            break;
                        case 0:
                            LogIntent logIntent = LogIntent.DEBUG;
                            AbstractC0058b abstractC0058b = this$0.billingClient;
                            LogWrapperKt.log(logIntent, String.format(BillingStrings.BILLING_SERVICE_SETUP_FINISHED, Arrays.copyOf(new Object[]{abstractC0058b != null ? abstractC0058b.toString() : null}, 1)));
                            BillingAbstract.StateListener stateListener = this$0.getStateListener();
                            if (stateListener != null) {
                                stateListener.onConnected();
                            }
                            this$0.executePendingRequests();
                            this$0.reconnectMilliseconds = 1000L;
                            this$0.trackProductDetailsNotSupportedIfNeeded();
                            return;
                        case 4:
                            break;
                        default:
                            return;
                    }
                }
            }
            com.google.android.gms.internal.play_billing.a.n(new Object[]{BillingResultExtensionsKt.toHumanReadableDescription(billingResult)}, 1, BillingStrings.BILLING_CLIENT_ERROR, LogIntent.GOOGLE_WARNING);
            return;
        }
        com.google.android.gms.internal.play_billing.a.n(new Object[]{BillingResultExtensionsKt.toHumanReadableDescription(billingResult)}, 1, BillingStrings.BILLING_CLIENT_ERROR, LogIntent.GOOGLE_WARNING);
        this$0.retryBillingServiceConnectionWithExponentialBackoff();
    }

    public final void queryPurchaseHistoryAsyncEnsuringOneResponse(AbstractC0058b abstractC0058b, String str, t tVar) {
        C0320D c0320d;
        AtomicBoolean atomicBoolean = new AtomicBoolean(false);
        Date now = this.dateProvider.getNow();
        y buildQueryPurchaseHistoryParams = BillingClientParamBuildersKt.buildQueryPurchaseHistoryParams(str);
        if (buildQueryPurchaseHistoryParams != null) {
            abstractC0058b.e(buildQueryPurchaseHistoryParams, new b(atomicBoolean, this, str, now, tVar, 1));
            c0320d = C0320D.f2794a;
        } else {
            c0320d = null;
        }
        if (c0320d == null) {
            LogUtilsKt.errorLog$default(String.format(TOhAhwcHW.gBwLzl, Arrays.copyOf(new Object[]{"getPurchaseType"}, 1)), null, 2, null);
            C0066j a4 = C0067k.a();
            a4.f633b = 5;
            tVar.c(a4.a(), null);
        }
    }

    public static final void queryPurchaseHistoryAsyncEnsuringOneResponse$lambda$27$lambda$26(AtomicBoolean atomicBoolean, BillingWrapper this$0, String productType, Date requestStartTime, t listener, C0067k billingResult, List list) {
        k.e(atomicBoolean, YpIkwCgYXfGh.QcMz);
        k.e(this$0, "this$0");
        k.e(productType, "$productType");
        k.e(requestStartTime, "$requestStartTime");
        k.e(listener, "$listener");
        k.e(billingResult, "billingResult");
        if (atomicBoolean.getAndSet(true)) {
            com.google.android.gms.internal.play_billing.a.n(new Object[]{Integer.valueOf(billingResult.f635a)}, 1, RestoreStrings.EXTRA_QUERY_PURCHASE_HISTORY_RESPONSE, LogIntent.GOOGLE_ERROR);
        } else {
            this$0.trackGoogleQueryPurchaseHistoryRequestIfNeeded(productType, billingResult, requestStartTime);
            listener.c(billingResult, list);
        }
    }

    private final void queryPurchasesAsyncWithTrackingEnsuringOneResponse(AbstractC0058b abstractC0058b, String str, z zVar, u uVar) {
        abstractC0058b.f(zVar, new b(new AtomicBoolean(false), this, str, this.dateProvider.getNow(), uVar, 0));
    }

    public static final void queryPurchasesAsyncWithTrackingEnsuringOneResponse$lambda$29(AtomicBoolean hasResponded, BillingWrapper this$0, String str, Date requestStartTime, u listener, C0067k billingResult, List purchases) {
        k.e(hasResponded, "$hasResponded");
        k.e(this$0, "this$0");
        k.e(str, ffxCxHAgR.Ssb);
        k.e(requestStartTime, "$requestStartTime");
        k.e(listener, "$listener");
        k.e(billingResult, "billingResult");
        k.e(purchases, "purchases");
        if (hasResponded.getAndSet(true)) {
            com.google.android.gms.internal.play_billing.a.n(new Object[]{Integer.valueOf(billingResult.f635a)}, 1, OfferingStrings.EXTRA_QUERY_PURCHASES_RESPONSE, LogIntent.GOOGLE_ERROR);
        } else {
            this$0.trackGoogleQueryPurchasesRequestIfNeeded(str, billingResult, requestStartTime);
            listener.b(billingResult, purchases);
        }
    }

    private final void retryBillingServiceConnectionWithExponentialBackoff() {
        if (this.reconnectionAlreadyScheduled) {
            LogWrapperKt.log(LogIntent.WARNING, BillingStrings.BILLING_CLIENT_RETRY_ALREADY_SCHEDULED);
            return;
        }
        com.google.android.gms.internal.play_billing.a.n(new Object[]{Long.valueOf(this.reconnectMilliseconds)}, 1, BillingStrings.BILLING_CLIENT_RETRY, LogIntent.WARNING);
        this.reconnectionAlreadyScheduled = true;
        startConnectionOnMainThread(this.reconnectMilliseconds);
        this.reconnectMilliseconds = Math.min(this.reconnectMilliseconds * 2, 900000L);
    }

    private final synchronized void sendErrorsToAllPendingRequests(PurchasesError purchasesError) {
        while (true) {
            InterfaceC0424k poll = this.serviceRequests.poll();
            if (poll != null) {
                this.mainHandler.post(new a(1, poll, purchasesError));
            }
        }
    }

    public static final void sendErrorsToAllPendingRequests$lambda$38$lambda$37(InterfaceC0424k serviceRequest, PurchasesError error) {
        k.e(serviceRequest, "$serviceRequest");
        k.e(error, "$error");
        serviceRequest.invoke(error);
    }

    public static final void startConnectionOnMainThread$lambda$3(BillingWrapper this$0) {
        k.e(this$0, "this$0");
        this$0.startConnection();
    }

    private final void trackGoogleQueryPurchaseHistoryRequestIfNeeded(String str, C0067k c0067k, Date date) {
        DiagnosticsTracker diagnosticsTracker = this.diagnosticsTrackerIfEnabled;
        if (diagnosticsTracker != null) {
            int i = c0067k.f635a;
            String str2 = c0067k.f636b;
            k.d(str2, "billingResult.debugMessage");
            diagnosticsTracker.m55trackGoogleQueryPurchaseHistoryRequestWn2Vu4Y(str, i, str2, DurationExtensionsKt.between(E2.b.Companion, date, this.dateProvider.getNow()));
        }
    }

    private final void trackGoogleQueryPurchasesRequestIfNeeded(String str, C0067k c0067k, Date date) {
        DiagnosticsTracker diagnosticsTracker = this.diagnosticsTrackerIfEnabled;
        if (diagnosticsTracker != null) {
            int i = c0067k.f635a;
            String str2 = c0067k.f636b;
            k.d(str2, "billingResult.debugMessage");
            diagnosticsTracker.m56trackGoogleQueryPurchasesRequestWn2Vu4Y(str, i, str2, DurationExtensionsKt.between(E2.b.Companion, date, this.dateProvider.getNow()));
        }
    }

    private final void trackProductDetailsNotSupportedIfNeeded() {
        int i;
        if (this.diagnosticsTrackerIfEnabled == null) {
            return;
        }
        AbstractC0058b abstractC0058b = this.billingClient;
        C0067k b4 = abstractC0058b != null ? abstractC0058b.b("fff") : null;
        if (b4 == null || (i = b4.f635a) != -2) {
            return;
        }
        DiagnosticsTracker diagnosticsTracker = this.diagnosticsTrackerIfEnabled;
        String str = b4.f636b;
        k.d(str, "billingResult.debugMessage");
        diagnosticsTracker.trackProductDetailsNotSupported(i, str);
    }

    public final void withConnectedClient(InterfaceC0424k interfaceC0424k) {
        AbstractC0058b abstractC0058b = this.billingClient;
        C0320D c0320d = null;
        if (abstractC0058b != null) {
            if (!abstractC0058b.c()) {
                abstractC0058b = null;
            }
            if (abstractC0058b != null) {
                interfaceC0424k.invoke(abstractC0058b);
                c0320d = C0320D.f2794a;
            }
        }
        if (c0320d == null) {
            com.google.android.gms.internal.play_billing.a.n(new Object[]{getStackTrace()}, 1, BillingStrings.BILLING_CLIENT_DISCONNECTED, LogIntent.GOOGLE_WARNING);
        }
    }

    public final void acknowledge$purchases_defaultsRelease(String token, InterfaceC0428o onAcknowledged) {
        k.e(token, "token");
        k.e(onAcknowledged, "onAcknowledged");
        LogWrapperKt.log(LogIntent.PURCHASE, String.format(PurchaseStrings.ACKNOWLEDGING_PURCHASE, Arrays.copyOf(new Object[]{token}, 1)));
        executeRequestOnUIThread(new BillingWrapper$acknowledge$1(this, token, onAcknowledged));
    }

    @Override
    public void consumeAndSave(boolean z3, StoreTransaction purchase) {
        k.e(purchase, "purchase");
        if (purchase.getType() == ProductType.UNKNOWN || purchase.getPurchaseState() == PurchaseState.PENDING) {
            return;
        }
        Purchase originalGooglePurchase = StoreTransactionConversionsKt.getOriginalGooglePurchase(purchase);
        boolean optBoolean = originalGooglePurchase != null ? originalGooglePurchase.f1904c.optBoolean("acknowledged", true) : false;
        if (z3 && purchase.getType() == ProductType.INAPP) {
            consumePurchase$purchases_defaultsRelease(purchase.getPurchaseToken(), new BillingWrapper$consumeAndSave$1(this));
        } else if (!z3 || optBoolean) {
            this.deviceCache.addSuccessfullyPostedToken(purchase.getPurchaseToken());
        } else {
            acknowledge$purchases_defaultsRelease(purchase.getPurchaseToken(), new BillingWrapper$consumeAndSave$2(this));
        }
    }

    public final void consumePurchase$purchases_defaultsRelease(String token, InterfaceC0428o onConsumed) {
        k.e(token, "token");
        k.e(onConsumed, "onConsumed");
        LogWrapperKt.log(LogIntent.PURCHASE, String.format(PurchaseStrings.CONSUMING_PURCHASE, Arrays.copyOf(new Object[]{token}, 1)));
        executeRequestOnUIThread(new BillingWrapper$consumePurchase$1(this, token, onConsumed));
    }

    @Override
    public void endConnection() {
        this.mainHandler.post(new c(this, 0));
    }

    @Override
    public void findPurchaseInPurchaseHistory(String str, ProductType productType, String productId, InterfaceC0424k onCompletion, InterfaceC0424k interfaceC0424k) {
        k.e(str, ZgDYSIg.VdnrOwYojABxYdg);
        k.e(productType, "productType");
        k.e(productId, "productId");
        k.e(onCompletion, "onCompletion");
        k.e(interfaceC0424k, ffxCxHAgR.YCgbkzZUDNE);
        withConnectedClient(new BillingWrapper$findPurchaseInPurchaseHistory$1(productId, productType, interfaceC0424k, this, onCompletion));
    }

    public final synchronized AbstractC0058b getBillingClient() {
        return this.billingClient;
    }

    public final void getPurchaseType$purchases_defaultsRelease(String purchaseToken, InterfaceC0424k listener) {
        k.e(purchaseToken, "purchaseToken");
        k.e(listener, "listener");
        AbstractC0058b abstractC0058b = this.billingClient;
        C0320D c0320d = null;
        if (abstractC0058b != null) {
            z buildQueryPurchasesParams = BillingClientParamBuildersKt.buildQueryPurchasesParams("subs");
            if (buildQueryPurchasesParams == null) {
                LogUtilsKt.errorLog$default(String.format(PurchaseStrings.INVALID_PRODUCT_TYPE, Arrays.copyOf(new Object[]{"getPurchaseType"}, 1)), null, 2, null);
                listener.invoke(ProductType.UNKNOWN);
                return;
            } else {
                queryPurchasesAsyncWithTrackingEnsuringOneResponse(abstractC0058b, "subs", buildQueryPurchasesParams, new f(listener, this, abstractC0058b, purchaseToken));
                c0320d = C0320D.f2794a;
            }
        }
        if (c0320d == null) {
            listener.invoke(ProductType.UNKNOWN);
        }
    }

    @Override
    public void getStorefront(InterfaceC0424k onSuccess, InterfaceC0424k onError) {
        k.e(onSuccess, "onSuccess");
        k.e(onError, "onError");
        LogUtilsKt.verboseLog(BillingStrings.BILLING_INITIATE_GETTING_COUNTRY_CODE);
        new GetBillingConfigUseCase(this.deviceCache, new BillingWrapper$getStorefront$1(onSuccess), onError, new BillingWrapper$getStorefront$2(this), new BillingWrapper$getStorefront$3(this)).run();
    }

    @Override
    public boolean isConnected() {
        AbstractC0058b abstractC0058b = this.billingClient;
        if (abstractC0058b != null) {
            return abstractC0058b.c();
        }
        return false;
    }

    @Override
    public void makePurchaseAsync(Activity activity, String appUserID, PurchasingData purchasingData, ReplaceProductInfo replaceProductInfo, String str, Boolean bool) {
        String optionId;
        k.e(activity, "activity");
        k.e(appUserID, "appUserID");
        k.e(purchasingData, "purchasingData");
        GooglePurchasingData googlePurchasingData = purchasingData instanceof GooglePurchasingData ? (GooglePurchasingData) purchasingData : null;
        if (googlePurchasingData == null) {
            PurchasesError purchasesError = new PurchasesError(PurchasesErrorCode.UnknownError, String.format(PurchaseStrings.INVALID_PURCHASE_TYPE, Arrays.copyOf(new Object[]{"Play", "GooglePurchasingData"}, 2)));
            LogUtilsKt.errorLog(purchasesError);
            BillingAbstract.PurchasesUpdatedListener purchasesUpdatedListener = getPurchasesUpdatedListener();
            if (purchasesUpdatedListener != null) {
                purchasesUpdatedListener.onPurchasesFailedToUpdate(purchasesError);
                return;
            }
            return;
        }
        if (googlePurchasingData instanceof GooglePurchasingData.InAppProduct) {
            optionId = null;
        } else {
            if (!(googlePurchasingData instanceof GooglePurchasingData.Subscription)) {
                throw new NoWhenBranchMatchedException();
            }
            optionId = ((GooglePurchasingData.Subscription) googlePurchasingData).getOptionId();
        }
        if (replaceProductInfo != null) {
            com.google.android.gms.internal.play_billing.a.n(new Object[]{replaceProductInfo.getOldPurchase().getProductIds().get(0), googlePurchasingData.getProductId()}, 2, PurchaseStrings.UPGRADING_SKU, LogIntent.PURCHASE);
        } else {
            com.google.android.gms.internal.play_billing.a.n(new Object[]{googlePurchasingData.getProductId()}, 1, PurchaseStrings.PURCHASING_PRODUCT, LogIntent.PURCHASE);
        }
        synchronized (this) {
            try {
                String productId = googlePurchasingData.getProductId();
                Map<String, PurchaseContext> map = this.purchaseContext;
                ProductType productType = googlePurchasingData.getProductType();
                ReplacementMode replacementMode = replaceProductInfo != null ? replaceProductInfo.getReplacementMode() : null;
                map.put(productId, new PurchaseContext(productType, str, optionId, replacementMode instanceof GoogleReplacementMode ? (GoogleReplacementMode) replacementMode : null));
            } catch (Throwable th) {
                throw th;
            }
        }
        executeRequestOnUIThread(new BillingWrapper$makePurchaseAsync$2(this, purchasingData, replaceProductInfo, appUserID, bool, activity));
    }

    @Override
    public void onBillingServiceDisconnected() {
        LogIntent logIntent = LogIntent.WARNING;
        AbstractC0058b abstractC0058b = this.billingClient;
        com.google.android.gms.internal.play_billing.a.n(new Object[]{abstractC0058b != null ? abstractC0058b.toString() : null}, 1, BillingStrings.BILLING_SERVICE_DISCONNECTED_INSTANCE, logIntent);
    }

    @Override
    public void onBillingSetupFinished(C0067k billingResult) {
        k.e(billingResult, "billingResult");
        this.mainHandler.post(new a(0, billingResult, this));
    }

    @Override
    public void onPurchasesUpdated(C0067k billingResult, List<? extends Purchase> list) {
        k.e(billingResult, "billingResult");
        List<? extends Purchase> list2 = list == null ? l2.r.f2923a : list;
        if (billingResult.f635a == 0 && (!list2.isEmpty())) {
            ArrayList arrayList = new ArrayList();
            Iterator<T> it2 = list2.iterator();
            while (it2.hasNext()) {
                getStoreTransaction((Purchase) it2.next(), new BillingWrapper$onPurchasesUpdated$1$1(arrayList, list2, this));
            }
            return;
        }
        LogIntent logIntent = LogIntent.GOOGLE_ERROR;
        StringBuilder sb = new StringBuilder();
        sb.append(String.format(BillingStrings.BILLING_WRAPPER_PURCHASES_ERROR, Arrays.copyOf(new Object[]{BillingResultExtensionsKt.toHumanReadableDescription(billingResult)}, 1)));
        if (list2.isEmpty()) {
            list2 = null;
        }
        sb.append(list2 != null ? "Purchases:".concat(j.T(list2, ", ", null, null, BillingWrapper$onPurchasesUpdated$3$1.INSTANCE, 30)) : null);
        LogWrapperKt.log(logIntent, sb.toString());
        String str = "Error updating purchases. " + BillingResultExtensionsKt.toHumanReadableDescription(billingResult);
        int i = billingResult.f635a;
        if (list == null && i == 0) {
            str = "Error: onPurchasesUpdated received an OK BillingResult with a Null purchases list.";
            i = 6;
        }
        PurchasesError billingResponseToPurchasesError = ErrorsKt.billingResponseToPurchasesError(i, str);
        LogUtilsKt.errorLog(billingResponseToPurchasesError);
        BillingAbstract.PurchasesUpdatedListener purchasesUpdatedListener = getPurchasesUpdatedListener();
        if (purchasesUpdatedListener != null) {
            purchasesUpdatedListener.onPurchasesFailedToUpdate(billingResponseToPurchasesError);
        }
    }

    @Override
    public void queryAllPurchases(String appUserID, InterfaceC0424k onReceivePurchaseHistory, InterfaceC0424k onReceivePurchaseHistoryError) {
        k.e(appUserID, "appUserID");
        k.e(onReceivePurchaseHistory, "onReceivePurchaseHistory");
        k.e(onReceivePurchaseHistoryError, "onReceivePurchaseHistoryError");
        queryPurchaseHistoryAsync("subs", new BillingWrapper$queryAllPurchases$1(this, onReceivePurchaseHistoryError, onReceivePurchaseHistory), onReceivePurchaseHistoryError);
    }

    @Override
    public void queryProductDetailsAsync(ProductType productType, Set<String> productIds, InterfaceC0424k onReceive, InterfaceC0424k onError) {
        k.e(productType, "productType");
        k.e(productIds, "productIds");
        k.e(onReceive, "onReceive");
        k.e(onError, "onError");
        LogWrapperKt.log(LogIntent.DEBUG, String.format(OfferingStrings.FETCHING_PRODUCTS, Arrays.copyOf(new Object[]{j.T(productIds, null, null, null, null, 63)}, 1)));
        new QueryProductDetailsUseCase(new QueryProductDetailsUseCaseParams(this.dateProvider, this.diagnosticsTrackerIfEnabled, productIds, productType), onReceive, onError, new BillingWrapper$queryProductDetailsAsync$useCase$1(this), new BillingWrapper$queryProductDetailsAsync$useCase$2(this)).run();
    }

    public final void queryPurchaseHistoryAsync(String productType, InterfaceC0424k onReceivePurchaseHistory, InterfaceC0424k onReceivePurchaseHistoryError) {
        k.e(productType, "productType");
        k.e(onReceivePurchaseHistory, "onReceivePurchaseHistory");
        k.e(onReceivePurchaseHistoryError, "onReceivePurchaseHistoryError");
        LogWrapperKt.log(LogIntent.DEBUG, String.format(RestoreStrings.QUERYING_PURCHASE_HISTORY, Arrays.copyOf(new Object[]{productType}, 1)));
        new QueryPurchaseHistoryUseCase(new QueryPurchaseHistoryUseCaseParams(this.dateProvider, this.diagnosticsTrackerIfEnabled, productType), onReceivePurchaseHistory, onReceivePurchaseHistoryError, new BillingWrapper$queryPurchaseHistoryAsync$useCase$1(this), new BillingWrapper$queryPurchaseHistoryAsync$useCase$2(this)).run();
    }

    @Override
    public void queryPurchases(String appUserID, InterfaceC0424k onSuccess, InterfaceC0424k onError) {
        k.e(appUserID, "appUserID");
        k.e(onSuccess, "onSuccess");
        k.e(onError, "onError");
        LogWrapperKt.log(LogIntent.DEBUG, cLduOWqDt.zcgl);
        new QueryPurchasesUseCase(new QueryPurchasesUseCaseParams(this.dateProvider, this.diagnosticsTrackerIfEnabled), onSuccess, onError, new BillingWrapper$queryPurchases$useCase$1(this), new BillingWrapper$queryPurchases$useCase$2(this)).run();
    }

    public final synchronized void setBillingClient(AbstractC0058b abstractC0058b) {
        this.billingClient = abstractC0058b;
    }

    @Override
    public void showInAppMessagesIfNeeded(Activity activity, List<? extends InAppMessageType> inAppMessageTypes, Function0 subscriptionStatusChange) {
        k.e(activity, "activity");
        k.e(inAppMessageTypes, "inAppMessageTypes");
        k.e(subscriptionStatusChange, "subscriptionStatusChange");
        if (inAppMessageTypes.isEmpty()) {
            LogUtilsKt.errorLog$default(BillingStrings.BILLING_UNSPECIFIED_INAPP_MESSAGE_TYPES, null, 2, null);
            return;
        }
        HashSet hashSet = new HashSet();
        Iterator<? extends InAppMessageType> it2 = inAppMessageTypes.iterator();
        while (it2.hasNext()) {
            hashSet.add(Integer.valueOf(it2.next().getInAppMessageCategoryId$purchases_defaultsRelease()));
        }
        executeRequestOnUIThread(new BillingWrapper$showInAppMessagesIfNeeded$1(this, new WeakReference(activity), new C0068l(hashSet), subscriptionStatusChange));
    }

    @Override
    public void startConnection() {
        synchronized (this) {
            try {
                if (this.billingClient == null) {
                    this.billingClient = this.clientFactory.buildClient(this);
                }
                this.reconnectionAlreadyScheduled = false;
                AbstractC0058b abstractC0058b = this.billingClient;
                if (abstractC0058b != null && !abstractC0058b.c()) {
                    LogWrapperKt.log(LogIntent.DEBUG, String.format(BillingStrings.BILLING_CLIENT_STARTING, Arrays.copyOf(new Object[]{abstractC0058b}, 1)));
                    try {
                        abstractC0058b.g(this);
                    } catch (IllegalStateException e) {
                        LogWrapperKt.log(LogIntent.GOOGLE_ERROR, String.format(cLduOWqDt.EWmbPrqqzk, Arrays.copyOf(new Object[]{e}, 1)));
                        sendErrorsToAllPendingRequests(new PurchasesError(PurchasesErrorCode.StoreProblemError, e.getMessage()));
                    }
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override
    public void startConnectionOnMainThread(long j) {
        this.mainHandler.postDelayed(new c(this, 1), j);
    }
}