package I2;

import android.app.Activity;
import android.app.PendingIntent;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.ServiceInfo;
import android.os.Build;
import android.os.Bundle;
import android.os.DeadObjectException;
import android.os.Handler;
import android.os.Looper;
import android.text.TextUtils;
import com.android.billingclient.api.ProxyBillingActivity;
import com.google.android.gms.internal.play_billing.zzam;
import com.google.android.gms.internal.play_billing.zzaz;
import com.google.android.gms.internal.play_billing.zzbi;
import com.google.android.gms.internal.play_billing.zzbl;
import com.google.android.gms.internal.play_billing.zzbt;
import com.google.android.gms.internal.play_billing.zzby;
import com.google.android.gms.internal.play_billing.zzc;
import com.google.android.gms.internal.play_billing.zzcu;
import com.google.android.gms.internal.play_billing.zzcz;
import com.google.android.gms.internal.play_billing.zzdj;
import com.google.android.gms.internal.play_billing.zzdk;
import com.google.android.gms.internal.play_billing.zzhv;
import com.google.android.gms.internal.play_billing.zzhx;
import com.google.android.gms.internal.play_billing.zzhz;
import com.google.android.gms.internal.play_billing.zzib;
import com.google.android.gms.internal.play_billing.zzic;
import com.google.android.gms.internal.play_billing.zzie;
import com.google.android.gms.internal.play_billing.zzig;
import com.google.android.gms.internal.play_billing.zzil;
import com.google.android.gms.internal.play_billing.zziq;
import com.google.android.gms.internal.play_billing.zzis;
import com.google.android.gms.internal.play_billing.zziw;
import com.google.android.gms.internal.play_billing.zziz;
import com.google.android.gms.internal.play_billing.zzjt;
import com.google.android.gms.internal.play_billing.zzjv;
import com.revenuecat.purchases.api.BuildConfig;
import com.revenuecat.purchases.google.history.BillingConstants;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.Random;
import java.util.concurrent.Callable;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

/* JADX INFO: renamed from: I2.d, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public class C0320d extends AbstractC0319c {

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public boolean f2584A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public boolean f2585B;

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public final C0331o f2586C;

    /* JADX INFO: renamed from: D, reason: collision with root package name */
    public final boolean f2587D;

    /* JADX INFO: renamed from: E, reason: collision with root package name */
    public ExecutorService f2588E;

    /* JADX INFO: renamed from: F, reason: collision with root package name */
    public final Long f2589F;

    /* JADX INFO: renamed from: G, reason: collision with root package name */
    public final zzbl f2590G;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final String f2593c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final String f2594d;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public volatile G.B f2596f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final Context f2597g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final T.p f2598h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public volatile zzam f2599i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public volatile L f2600j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public boolean f2601k;
    public boolean l;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public boolean f2603n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public boolean f2604o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public boolean f2605p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public boolean f2606q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public boolean f2607r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public boolean f2608s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public boolean f2609t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public boolean f2610u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public boolean f2611v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public boolean f2612w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public boolean f2613x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public boolean f2614y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public boolean f2615z;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Object f2591a = new Object();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public volatile int f2592b = 0;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final Handler f2595e = new Handler(Looper.getMainLooper());

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public int f2602m = 0;

    public C0320d(C0331o c0331o, Context context, InterfaceC0339x interfaceC0339x, C0318b c0318b) {
        long jNextLong = new Random().nextLong();
        this.f2589F = Long.valueOf(jNextLong);
        this.f2590G = zzaz.zza();
        this.f2593c = BuildConfig.BILLING_CLIENT_VERSION;
        String strF = F();
        this.f2594d = strF;
        this.f2597g = context.getApplicationContext();
        zziq zziqVarZzc = zzis.zzc();
        zziqVarZzc.zzs(BuildConfig.BILLING_CLIENT_VERSION);
        if (strF != null) {
            zziqVarZzc.zzt(strF);
        }
        zziqVarZzc.zzq(this.f2597g.getPackageName());
        zziqVarZzc.zzn(jNextLong);
        c0318b.getClass();
        zziqVarZzc.zzr(false);
        zziqVarZzc.zza(Build.VERSION.SDK_INT);
        zziqVarZzc.zzp(772604006L);
        try {
            zziqVarZzc.zzl(this.f2597g.getPackageManager().getPackageInfo(this.f2597g.getPackageName(), 0).versionCode);
        } catch (Throwable th) {
            zzc.zzo("BillingClient", "Error getting app version code.", th);
        }
        this.f2598h = new T.p(this.f2597g, (zzis) zziqVarZzc.zze());
        if (interfaceC0339x == null) {
            zzc.zzn("BillingClient", "Billing client should have a valid listener but the provided is null.");
        }
        this.f2596f = new G.B(this.f2597g, interfaceC0339x, this.f2598h);
        this.f2586C = c0331o;
        this.f2587D = false;
        this.f2597g.getPackageName();
    }

    public static String F() {
        try {
            return (String) Class.forName("com.android.billingclient.ktx.BuildConfig").getField("VERSION_NAME").get(null);
        } catch (Exception unused) {
            return null;
        }
    }

    public static Future j(Callable callable, long j4, Runnable runnable, Handler handler, ExecutorService executorService) {
        try {
            Future futureSubmit = executorService.submit(callable);
            handler.postDelayed(new C1.a(5, futureSubmit, runnable), (long) (j4 * 0.95d));
            return futureSubmit;
        } catch (Exception e6) {
            zzc.zzo("BillingClient", "Async task throws exception!", e6);
            return null;
        }
    }

    public static /* bridge */ /* synthetic */ void x(C0320d c0320d, int i6) {
        c0320d.f2602m = i6;
        c0320d.f2585B = i6 >= 26;
        c0320d.f2584A = i6 >= 24;
        c0320d.f2615z = i6 >= 23;
        c0320d.f2614y = i6 >= 21;
        c0320d.f2613x = i6 >= 20;
        c0320d.f2612w = i6 >= 19;
        c0320d.f2611v = i6 >= 18;
        c0320d.f2610u = i6 >= 17;
        c0320d.f2609t = i6 >= 16;
        c0320d.f2608s = i6 >= 15;
        c0320d.f2607r = i6 >= 14;
        c0320d.f2606q = i6 >= 12;
        c0320d.f2605p = i6 >= 9;
        c0320d.f2604o = i6 >= 8;
        c0320d.f2603n = i6 >= 6;
    }

    public static void y(C0320d c0320d, int i6) {
        if (i6 != 0) {
            c0320d.r(0);
            return;
        }
        synchronized (c0320d.f2591a) {
            try {
                if (c0320d.f2592b == 3) {
                    return;
                }
                c0320d.r(2);
                G.B b5 = c0320d.f2596f != null ? c0320d.f2596f : null;
                if (b5 != null) {
                    boolean z6 = c0320d.f2614y;
                    IntentFilter intentFilter = new IntentFilter("com.android.vending.billing.PURCHASES_UPDATED");
                    IntentFilter intentFilter2 = new IntentFilter("com.android.vending.billing.LOCAL_BROADCAST_PURCHASES_UPDATED");
                    intentFilter2.addAction("com.android.vending.billing.ALTERNATIVE_BILLING");
                    b5.f1644a = z6;
                    Y y6 = (Y) b5.f1649f;
                    Context context = (Context) b5.f1645b;
                    y6.a(context, intentFilter2);
                    if (!b5.f1644a) {
                        ((Y) b5.f1648e).a(context, intentFilter);
                        return;
                    }
                    Y y7 = (Y) b5.f1648e;
                    synchronized (y7) {
                        try {
                            if (y7.f2571a) {
                                return;
                            }
                            if (Build.VERSION.SDK_INT >= 33) {
                                context.registerReceiver(y7, intentFilter, "com.google.android.finsky.permission.PLAY_BILLING_LIBRARY_BROADCAST", null, true != y7.f2572b ? 4 : 2);
                            } else {
                                context.registerReceiver(y7, intentFilter, "com.google.android.finsky.permission.PLAY_BILLING_LIBRARY_BROADCAST", null);
                            }
                            y7.f2571a = true;
                        } finally {
                        }
                    }
                }
            } finally {
            }
        }
    }

    public final O A(C0328l c0328l, zzie zzieVar, String str, Exception exc) {
        zzc.zzo("BillingClient", str, exc);
        K(zzieVar, 7, c0328l, T.a(exc));
        return new O(c0328l.f2636a, c0328l.f2638c, new ArrayList(), new ArrayList());
    }

    public final C0328l B(int i6) {
        zzc.zzm("BillingClient", "Service connection is valid. No need to re-initialize.");
        zzhz zzhzVarZzc = zzib.zzc();
        zzhzVarZzc.zzo(6);
        zzjt zzjtVarZzc = zzjv.zzc();
        zzjtVarZzc.zzn(true);
        zzjtVarZzc.zza(i6 > 0);
        zzjtVarZzc.zzl(i6);
        zzhzVarZzc.zzn(zzjtVarZzc);
        p((zzib) zzhzVarZzc.zze());
        return V.f2550i;
    }

    public final C0328l C() {
        int[] iArr = {0, 3};
        synchronized (this.f2591a) {
            for (int i6 = 0; i6 < 2; i6++) {
                if (this.f2592b == iArr[i6]) {
                    return V.f2551j;
                }
            }
            return V.f2549h;
        }
    }

    public final zzcz D(int i6) {
        zzc.zzm("BillingClient", "Already connected or not opted into auto reconnection.");
        return zzcu.zza(V.f2550i);
    }

    public final void E() {
        if (TextUtils.isEmpty(null)) {
            this.f2597g.getPackageName();
        }
    }

    public final T.p G(C0328l c0328l, zzie zzieVar, String str, Exception exc) {
        K(zzieVar, 9, c0328l, T.a(exc));
        zzc.zzo("BillingClient", str, exc);
        return new T.p(c0328l, (ArrayList) null);
    }

    public final void H(int i6, C0328l c0328l, zzie zzieVar) {
        zzib zzibVar = null;
        zzhx zzhxVar = null;
        if (c0328l.f2636a == 0) {
            int i7 = T.f2535a;
            try {
                zzhz zzhzVarZzc = zzib.zzc();
                zzhzVarZzc.zzo(5);
                zziw zziwVarZzc = zziz.zzc();
                zziwVarZzc.zza(i6);
                zzhzVarZzc.zzl((zziz) zziwVarZzc.zze());
                zzibVar = (zzib) zzhzVarZzc.zze();
            } catch (Exception e6) {
                zzc.zzo("BillingLogger", "Unable to create logging payload", e6);
            }
            p(zzibVar);
            return;
        }
        int i8 = T.f2535a;
        try {
            zzhv zzhvVarZzc = zzhx.zzc();
            zzic zzicVarZzc = zzig.zzc();
            zzicVarZzc.zzo(c0328l.f2636a);
            zzicVarZzc.zzl(c0328l.f2638c);
            zzicVarZzc.zzn(zzieVar);
            zzhvVarZzc.zzl(zzicVarZzc);
            zzhvVarZzc.zzp(5);
            zziw zziwVarZzc2 = zziz.zzc();
            zziwVarZzc2.zza(i6);
            zzhvVarZzc.zzm((zziz) zziwVarZzc2.zze());
            zzhxVar = (zzhx) zzhvVarZzc.zze();
        } catch (Exception e7) {
            zzc.zzo("BillingLogger", "Unable to create logging payload", e7);
        }
        o(zzhxVar);
    }

    public final void I(int i6, C0328l c0328l, zzie zzieVar) {
        try {
            int i7 = T.f2535a;
            o(T.b(zzieVar, i6, c0328l, null, zzil.BROADCAST_ACTION_UNSPECIFIED));
        } catch (Throwable th) {
            zzc.zzo("BillingClient", "Unable to log.", th);
        }
    }

    public final void J(zzie zzieVar, C0328l c0328l, long j4) {
        try {
            int i6 = T.f2535a;
            try {
                this.f2598h.A(T.b(zzieVar, 2, c0328l, null, zzil.BROADCAST_ACTION_UNSPECIFIED), this.f2602m, j4);
            } catch (Throwable th) {
                zzc.zzo("BillingClient", "Unable to log.", th);
            }
        } catch (Throwable th2) {
            zzc.zzo("BillingClient", "Unable to log.", th2);
        }
    }

    public final void K(zzie zzieVar, int i6, C0328l c0328l, String str) {
        try {
            int i7 = T.f2535a;
            o(T.b(zzieVar, i6, c0328l, str, zzil.BROADCAST_ACTION_UNSPECIFIED));
        } catch (Throwable th) {
            zzc.zzo("BillingClient", "Unable to log.", th);
        }
    }

    public final void L(zzie zzieVar, C0328l c0328l, long j4, boolean z6) {
        try {
            int i6 = T.f2535a;
            try {
                this.f2598h.C(T.b(zzieVar, 2, c0328l, null, zzil.BROADCAST_ACTION_UNSPECIFIED), this.f2602m, j4, z6);
            } catch (Throwable th) {
                zzc.zzo("BillingClient", "Unable to log.", th);
            }
        } catch (Throwable th2) {
            zzc.zzo("BillingClient", "Unable to log.", th2);
        }
    }

    public final void M(zzie zzieVar, C0328l c0328l, String str, long j4, boolean z6) {
        try {
            int i6 = T.f2535a;
            try {
                this.f2598h.C(T.b(zzieVar, 2, c0328l, str, zzil.BROADCAST_ACTION_UNSPECIFIED), this.f2602m, j4, z6);
            } catch (Throwable th) {
                zzc.zzo("BillingClient", "Unable to log.", th);
            }
        } catch (Throwable th2) {
            zzc.zzo("BillingClient", "Unable to log.", th2);
        }
    }

    public final void N(C0328l c0328l) {
        if (Thread.interrupted()) {
            return;
        }
        this.f2595e.post(new C1.a(3, this, c0328l));
    }

    @Override // I2.AbstractC0319c
    public void a(C0317a c0317a, com.revenuecat.purchases.google.usecase.a aVar) {
        if (j(new E(this, aVar, c0317a, 0), 30000L, new C1.a(2, this, aVar), z(), i()) == null) {
            C0328l c0328lC = C();
            I(3, c0328lC, zzie.MISSING_RESULT_FROM_EXECUTE_ASYNC);
            aVar.c(c0328lC);
        }
    }

    @Override // I2.AbstractC0319c
    public void b(C0317a c0317a, com.revenuecat.purchases.google.usecase.a aVar) {
        int i6 = 1;
        if (j(new E(this, aVar, c0317a, i6), 30000L, new C1.o(this, (Object) aVar, (Object) c0317a, i6), z(), i()) == null) {
            C0328l c0328lC = C();
            I(4, c0328lC, zzie.MISSING_RESULT_FROM_EXECUTE_ASYNC);
            aVar.d(c0328lC, c0317a.f2580b);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:50:0x0050 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    @Override // I2.AbstractC0319c
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void c() {
        try {
            int i6 = T.f2535a;
            p(T.c(12, zzil.BROADCAST_ACTION_UNSPECIFIED));
        } catch (Throwable th) {
            zzc.zzo("BillingClient", "Unable to log.", th);
        }
        synchronized (this.f2591a) {
            try {
            } finally {
            }
            if (this.f2596f != null) {
                G.B b5 = this.f2596f;
                Y y6 = (Y) b5.f1648e;
                Context context = (Context) b5.f1645b;
                y6.b(context);
                ((Y) b5.f1649f).b(context);
                try {
                    zzc.zzm("BillingClient", "Unbinding from service.");
                    t();
                } catch (Throwable th2) {
                    zzc.zzo("BillingClient", "There was an exception while unbinding from the service while ending connection!", th2);
                }
                try {
                    synchronized (this) {
                        ExecutorService executorService = this.f2588E;
                        if (executorService != null) {
                            executorService.shutdownNow();
                            this.f2588E = null;
                        }
                    }
                } finally {
                    try {
                    } finally {
                    }
                }
            } else {
                zzc.zzm("BillingClient", "Unbinding from service.");
                t();
                synchronized (this) {
                }
            }
        }
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Removed duplicated region for block: B:67:0x00fd  */
    @Override // I2.AbstractC0319c
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final C0328l d(String str) {
        C0328l c0328l;
        if (!u()) {
            c0328l = V.f2551j;
            zzie zzieVar = zzie.SERVICE_CONNECTION_NOT_READY;
            if (c0328l.f2636a != 0) {
                I(5, c0328l, zzieVar);
                return c0328l;
            }
            try {
                int i6 = T.f2535a;
                p(T.c(5, zzil.BROADCAST_ACTION_UNSPECIFIED));
                return c0328l;
            } catch (Throwable th) {
                zzc.zzo("BillingClient", "Unable to log.", th);
                return c0328l;
            }
        }
        C0328l c0328l2 = V.f2542a;
        switch (str) {
            case "subscriptions":
                C0328l c0328l3 = this.f2601k ? V.f2550i : V.l;
                H(2, c0328l3, zzie.SUBSCRIPTIONS_NOT_SUPPORTED);
                break;
            case "subscriptionsUpdate":
                C0328l c0328l4 = this.l ? V.f2550i : V.f2553m;
                H(3, c0328l4, zzie.SUBSCRIPTIONS_UPDATE_NOT_SUPPORTED);
                break;
            case "priceChangeConfirmation":
                C0328l c0328l5 = this.f2604o ? V.f2550i : V.f2554n;
                H(4, c0328l5, zzie.PRICE_CHANGE_CONFIRMATION_NOT_SUPPORTED);
                break;
            case "bbb":
                C0328l c0328l6 = this.f2606q ? V.f2550i : V.f2559s;
                H(5, c0328l6, zzie.IN_APP_MESSAGE_NOT_SUPPORTED);
                break;
            case "aaa":
                C0328l c0328l7 = this.f2608s ? V.f2550i : V.f2555o;
                H(6, c0328l7, zzie.CROSS_APP_NOT_SUPPORTED);
                break;
            case "ddd":
                C0328l c0328l8 = this.f2607r ? V.f2550i : V.f2557q;
                H(7, c0328l8, zzie.OFFER_ID_TOKEN_NOT_SUPPORTED);
                break;
            case "ccc":
                C0328l c0328l9 = this.f2609t ? V.f2550i : V.f2556p;
                H(8, c0328l9, zzie.MULTI_ITEM_NOT_SUPPORTED);
                break;
            case "eee":
                C0328l c0328l10 = this.f2609t ? V.f2550i : V.f2556p;
                H(9, c0328l10, zzie.PBL_FOR_PAYMENTS_GATEWAY_BUYFLOW_NOT_SUPPORTED);
                break;
            case "fff":
                C0328l c0328l11 = this.f2610u ? V.f2550i : V.f2558r;
                H(10, c0328l11, zzie.PRODUCT_DETAILS_NOT_SUPPORTED);
                break;
            case "ggg":
                C0328l c0328l12 = this.f2611v ? V.f2550i : V.f2564x;
                H(11, c0328l12, zzie.GET_BILLING_CONFIG_NOT_SUPPORTED);
                break;
            case "hhh":
                C0328l c0328l13 = this.f2611v ? V.f2550i : V.f2565y;
                H(12, c0328l13, zzie.QUERY_PRODUCT_DETAILS_WITH_SERIALIZED_DOCID_NOT_SUPPORTED);
                break;
            case "iii":
                C0328l c0328l14 = this.f2613x ? V.f2550i : V.f2538B;
                H(13, c0328l14, zzie.QUERY_PRODUCT_DETAILS_WITH_DEVELOPER_SPECIFIED_ACCOUNT_NOT_SUPPORTED);
                break;
            case "jjj":
                C0328l c0328l15 = this.f2614y ? V.f2550i : V.f2539C;
                H(14, c0328l15, zzie.ALTERNATIVE_BILLING_ONLY_NOT_SUPPORTED);
                break;
            case "kkk":
                C0328l c0328l16 = this.f2584A ? V.f2550i : V.f2566z;
                H(18, c0328l16, zzie.LAUNCH_EXTERNAL_OFFER_FLOW_NOT_SUPPORTED);
                break;
            case "lll":
                C0328l c0328l17 = this.f2615z ? V.f2550i : V.f2560t;
                H(19, c0328l17, zzie.MULTI_ITEM_WITH_SEASON_PASS_NOT_SUPPORTED);
                break;
            case "mmm":
                C0328l c0328l18 = this.f2584A ? V.f2550i : V.f2561u;
                H(20, c0328l18, zzie.AUTO_PAY_NOT_SUPPORTED);
                break;
            case "nnn":
                C0328l c0328l19 = this.f2585B ? V.f2550i : V.f2562v;
                H(21, c0328l19, zzie.INCLUDE_SUSPENDED_SUBSCRIPTIONS_NOT_SUPPORTED);
                break;
            default:
                zzc.zzn("BillingClient", "Unsupported feature: ".concat(str));
                C0328l c0328l20 = V.f2563w;
                H(1, c0328l20, zzie.UNKNOWN_FEATURE);
                break;
        }
        return c0328l;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:116:0x026a  */
    /* JADX WARN: Removed duplicated region for block: B:44:0x00b8  */
    /* JADX WARN: Type inference failed for: r29v0, types: [I2.d] */
    /* JADX WARN: Type inference failed for: r2v10, types: [I2.q] */
    /* JADX WARN: Type inference failed for: r2v7 */
    /* JADX WARN: Type inference failed for: r2v8, types: [I2.q] */
    /* JADX WARN: Type inference failed for: r4v12 */
    /* JADX WARN: Type inference failed for: r4v14 */
    /* JADX WARN: Type inference failed for: r4v16 */
    /* JADX WARN: Type inference failed for: r4v17 */
    /* JADX WARN: Type inference failed for: r4v21 */
    /* JADX WARN: Type inference failed for: r4v22 */
    /* JADX WARN: Type inference failed for: r4v53 */
    /* JADX WARN: Type inference failed for: r4v54 */
    /* JADX WARN: Type inference failed for: r4v55 */
    /* JADX WARN: Type inference failed for: r5v7, types: [long] */
    /* JADX WARN: Type inference failed for: r5v8, types: [long] */
    /* JADX WARN: Type inference failed for: r6v10 */
    /* JADX WARN: Type inference failed for: r6v11 */
    /* JADX WARN: Type inference failed for: r6v12 */
    /* JADX WARN: Type inference failed for: r6v13 */
    /* JADX WARN: Type inference failed for: r6v14 */
    /* JADX WARN: Type inference failed for: r6v17 */
    /* JADX WARN: Type inference failed for: r6v18 */
    /* JADX WARN: Type inference failed for: r6v26 */
    /* JADX WARN: Type inference failed for: r6v27 */
    /* JADX WARN: Type inference failed for: r6v28 */
    /* JADX WARN: Type inference failed for: r6v29 */
    /* JADX WARN: Type inference failed for: r6v30 */
    /* JADX WARN: Type inference failed for: r7v1, types: [boolean] */
    /* JADX WARN: Type inference failed for: r7v2, types: [boolean] */
    @Override // I2.AbstractC0319c
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public C0328l e(Activity activity, final C0326j c0326j) {
        boolean z6;
        String str;
        boolean z7;
        String str2;
        long j4;
        boolean z8;
        String str3;
        C0328l c0328lA;
        ?? r22;
        C0328l c0328l;
        C0328l c0328lA2;
        long j6;
        boolean z9;
        String string;
        Future futureJ;
        ?? r6;
        String str4;
        ?? r62;
        ?? r42;
        ?? r63;
        ?? r43;
        zzie zzieVarZzb;
        Object obj;
        String str5;
        boolean z10;
        boolean z11;
        boolean z12;
        boolean z13 = true;
        long jNextLong = new Random().nextLong();
        if (this.f2596f == null || ((InterfaceC0339x) this.f2596f.f1646c) == null) {
            zzie zzieVar = zzie.MISSING_LISTENER;
            C0328l c0328l2 = V.f2540D;
            J(zzieVar, c0328l2, jNextLong);
            return c0328l2;
        }
        if (!u()) {
            zzie zzieVar2 = zzie.SERVICE_CONNECTION_NOT_READY;
            C0328l c0328l3 = V.f2551j;
            J(zzieVar2, c0328l3, jNextLong);
            N(c0328l3);
            return c0328l3;
        }
        synchronized (this.f2591a) {
            try {
                z6 = this.f2600j != null && this.f2600j.f2516d > 0;
            } finally {
            }
        }
        c0326j.getClass();
        ArrayList arrayList = new ArrayList();
        arrayList.addAll(c0326j.f2631e);
        zzbt zzbtVar = c0326j.f2630d;
        if (zzby.zza(arrayList, null) != null) {
            throw new ClassCastException();
        }
        C0324h c0324h = (C0324h) zzby.zza(zzbtVar, null);
        C0336u c0336u = c0324h.f2621a;
        String str6 = c0336u.f2667c;
        String str7 = c0336u.f2668d;
        if (str7.equals("subs") && !this.f2601k) {
            zzc.zzn("BillingClient", "Current client doesn't support subscriptions.");
            zzie zzieVar3 = zzie.SUBSCRIPTIONS_NOT_SUPPORTED;
            C0328l c0328l4 = V.l;
            L(zzieVar3, c0328l4, jNextLong, z6);
            N(c0328l4);
            return c0328l4;
        }
        boolean z14 = z6;
        if (c0326j.f2628b == null) {
            C1.k kVar = c0326j.f2629c;
            kVar.getClass();
            if (kVar.f690b != 0 || c0326j.f2627a || c0326j.f2632f) {
                str = null;
                if (!this.f2603n) {
                    zzc.zzn("BillingClient", "Current client doesn't support extra params for buy intent.");
                    zzie zzieVar4 = zzie.EXTRA_PARAMS_NOT_SUPPORTED;
                    C0328l c0328l5 = V.f2547f;
                    L(zzieVar4, c0328l5, jNextLong, z14);
                    N(c0328l5);
                    return c0328l5;
                }
            } else {
                zzbt zzbtVar2 = c0326j.f2630d;
                if (zzbtVar2 != null) {
                    int size = zzbtVar2.size();
                    str = null;
                    for (int i6 = 0; i6 < size; i6++) {
                    }
                } else {
                    str = null;
                }
            }
        }
        if (arrayList.size() > 1 && !this.f2609t) {
            zzc.zzn("BillingClient", "Current client doesn't support multi-item purchases.");
            zzie zzieVar5 = zzie.MULTI_ITEM_NOT_SUPPORTED;
            C0328l c0328l6 = V.f2556p;
            L(zzieVar5, c0328l6, jNextLong, z14);
            N(c0328l6);
            return c0328l6;
        }
        if (!zzbtVar.isEmpty() && !this.f2610u) {
            zzc.zzn("BillingClient", "Current client doesn't support purchases with ProductDetails.");
            zzie zzieVar6 = zzie.PRODUCT_DETAILS_NOT_SUPPORTED;
            C0328l c0328l7 = V.f2558r;
            L(zzieVar6, c0328l7, jNextLong, z14);
            N(c0328l7);
            return c0328l7;
        }
        if (c0326j.f2630d.isEmpty()) {
            c0328lA2 = V.f2550i;
            z7 = true;
        } else {
            C0324h c0324h2 = (C0324h) c0326j.f2630d.get(0);
            int i7 = 1;
            while (true) {
                z7 = z13;
                if (i7 < c0326j.f2630d.size()) {
                    C0324h c0324h3 = (C0324h) c0326j.f2630d.get(i7);
                    if (!c0324h3.f2621a.f2668d.equals(c0324h2.f2621a.f2668d) && !c0324h3.f2621a.f2668d.equals("play_pass_subs")) {
                        c0328lA2 = V.a(5, "All products should have same ProductType.");
                        break;
                    }
                    i7++;
                    z13 = z7;
                } else {
                    String strOptString = c0324h2.f2621a.f2666b.optString("packageName");
                    HashMap map = new HashMap();
                    HashSet hashSet = new HashSet();
                    str2 = str6;
                    zzbt zzbtVar3 = c0326j.f2630d;
                    j4 = jNextLong;
                    int size2 = zzbtVar3.size();
                    z8 = z14;
                    int i8 = 0;
                    while (true) {
                        str3 = str7;
                        C0336u c0336u2 = c0324h2.f2621a;
                        if (i8 < size2) {
                            zzbt zzbtVar4 = zzbtVar3;
                            C0324h c0324h4 = (C0324h) zzbtVar3.get(i8);
                            int i9 = size2;
                            C0336u c0336u3 = c0324h4.f2621a;
                            int i10 = i8;
                            ArrayList arrayList2 = c0336u3.f2674j;
                            String str8 = c0336u3.f2667c;
                            if (arrayList2 != null && c0324h4.f2622b == null) {
                                c0328lA = V.a(5, "offerToken is required for constructing ProductDetailsParams for subscriptions. Missing value for product id: " + str8);
                                break;
                            }
                            boolean zContainsKey = map.containsKey(str8);
                            C0336u c0336u4 = c0324h4.f2621a;
                            if (zContainsKey) {
                                c0328lA = V.a(5, "ProductId can not be duplicated. Invalid product id: " + c0336u4.f2667c + ".");
                                break;
                            }
                            map.put(c0336u4.f2667c, c0324h4);
                            if (!c0336u2.f2668d.equals("play_pass_subs") && !c0336u4.f2668d.equals("play_pass_subs") && !strOptString.equals(c0336u4.f2666b.optString("packageName"))) {
                                c0328lA = V.a(5, "All products must have the same package name.");
                                break;
                            }
                            i8 = i10 + 1;
                            str7 = str3;
                            size2 = i9;
                            zzbtVar3 = zzbtVar4;
                        } else {
                            Iterator it = hashSet.iterator();
                            while (true) {
                                if (it.hasNext()) {
                                    String str9 = (String) it.next();
                                    if (map.containsKey(str9)) {
                                        c0328lA = V.a(5, "OldProductId must not be one of the products to be purchased. Invalid old product id: " + str9 + ".");
                                        break;
                                    }
                                } else {
                                    ArrayList arrayList3 = c0336u2.f2675k;
                                    String str10 = c0324h2.f2622b;
                                    if (str10 == null || arrayList3 == null) {
                                        c0328lA = V.f2550i;
                                    } else {
                                        Iterator it2 = arrayList3.iterator();
                                        while (true) {
                                            if (!it2.hasNext()) {
                                                r22 = str;
                                                break;
                                            }
                                            r22 = (C0333q) it2.next();
                                            if (str10.equals(r22.f2647d)) {
                                                break;
                                            }
                                        }
                                        if (r22 != 0 && r22.f2650g != null) {
                                            c0328lA = V.a(5, "Both autoPayDetails and autoPayBalanceThreshold is required for constructing ProductDetailsParams for autopay.");
                                        }
                                    }
                                }
                            }
                        }
                    }
                    c0328l = c0328lA;
                }
            }
        }
        str2 = str6;
        j4 = jNextLong;
        z8 = z14;
        c0328l = c0328lA2;
        str3 = str7;
        if (c0328l != V.f2550i) {
            L(zzie.INVALID_BILLING_FLOW_PARAMS, c0328l, j4, z8);
            N(c0328l);
            return c0328l;
        }
        long j7 = j4;
        boolean z15 = z8;
        if (this.f2603n) {
            boolean z16 = this.f2605p;
            boolean z17 = this.f2612w;
            this.f2586C.getClass();
            boolean z18 = this.f2586C.f2641a;
            boolean z19 = this.f2587D;
            String str11 = this.f2593c;
            String str12 = this.f2594d;
            long jLongValue = this.f2589F.longValue();
            this.f2597g.getPackageName();
            int i11 = zzc.zza;
            boolean z20 = z15;
            final Bundle bundle = new Bundle();
            zzc.zzc(bundle, str11, str12, jLongValue);
            bundle.putLong("billingClientTransactionId", j7);
            int i12 = c0326j.f2629c.f690b;
            if (i12 != 0) {
                bundle.putInt("prorationMode", i12);
            }
            if (!TextUtils.isEmpty(c0326j.f2628b)) {
                bundle.putString("accountId", c0326j.f2628b);
            }
            if (TextUtils.isEmpty(str)) {
                str5 = str;
            } else {
                str5 = str;
                bundle.putString("obfuscatedProfileId", str5);
            }
            if (c0326j.f2632f) {
                bundle.putBoolean("isOfferPersonalizedByDeveloper", z7);
            }
            if (!TextUtils.isEmpty(str5)) {
                bundle.putStringArrayList("skusToReplace", new ArrayList<>(Arrays.asList(str5)));
            }
            if (!TextUtils.isEmpty((String) c0326j.f2629c.f691c)) {
                bundle.putString("oldSkuPurchaseToken", (String) c0326j.f2629c.f691c);
            }
            if (!TextUtils.isEmpty(null)) {
                bundle.putString("oldSkuPurchaseId", null);
            }
            c0326j.f2629c.getClass();
            if (!TextUtils.isEmpty(null)) {
                c0326j.f2629c.getClass();
                bundle.putString("originalExternalTransactionId", null);
            }
            if (!TextUtils.isEmpty(null)) {
                bundle.putString("paymentsPurchaseParams", null);
            }
            if (z16) {
                z10 = true;
                bundle.putBoolean("enablePendingPurchases", true);
            } else {
                z10 = true;
            }
            if (z17 && z18) {
                bundle.putBoolean("enablePendingPurchaseForSubscriptions", z10);
            }
            if (z19) {
                bundle.putBoolean("enableAlternativeBilling", z10);
            }
            ArrayList arrayList4 = new ArrayList();
            for (C0324h c0324h5 : c0326j.f2630d) {
            }
            if (!arrayList4.isEmpty()) {
                zzdj zzdjVarZza = zzdk.zza();
                zzdjVarZza.zza(arrayList4);
                bundle.putByteArray("subscriptionProductReplacementParamsList", ((zzdk) zzdjVarZza.zze()).zzM());
            }
            if (arrayList.isEmpty()) {
                ArrayList<String> arrayList5 = new ArrayList<>(zzbtVar.size() - 1);
                ArrayList<String> arrayList6 = new ArrayList<>(zzbtVar.size() - 1);
                ArrayList<String> arrayList7 = new ArrayList<>();
                ArrayList<String> arrayList8 = new ArrayList<>();
                ArrayList<String> arrayList9 = new ArrayList<>();
                ArrayList<Integer> arrayList10 = new ArrayList<>();
                int i13 = 0;
                while (i13 < zzbtVar.size()) {
                    C0324h c0324h6 = (C0324h) zzbtVar.get(i13);
                    long j8 = j7;
                    C0336u c0336u5 = c0324h6.f2621a;
                    if (!c0336u5.f2672h.isEmpty()) {
                        arrayList7.add(c0336u5.f2672h);
                    }
                    arrayList8.add(c0324h6.f2622b);
                    String str13 = c0336u5.f2673i;
                    ArrayList arrayList11 = c0336u5.f2675k;
                    if (arrayList11 != null && !arrayList11.isEmpty()) {
                        Iterator it3 = c0336u5.f2675k.iterator();
                        while (true) {
                            if (!it3.hasNext()) {
                                break;
                            }
                            C0333q c0333q = (C0333q) it3.next();
                            Iterator it4 = it3;
                            if (!TextUtils.isEmpty(c0333q.f2649f)) {
                                str13 = c0333q.f2649f;
                                break;
                            }
                            it3 = it4;
                        }
                    }
                    if (!TextUtils.isEmpty(str13)) {
                        arrayList9.add(str13);
                    }
                    if (i13 > 0) {
                        arrayList5.add(((C0324h) zzbtVar.get(i13)).f2621a.f2667c);
                        arrayList6.add(((C0324h) zzbtVar.get(i13)).f2621a.f2668d);
                    }
                    i13++;
                    j7 = j8;
                }
                j6 = j7;
                z11 = true;
                bundle.putStringArrayList("SKU_OFFER_ID_TOKEN_LIST", arrayList8);
                if (!arrayList10.isEmpty()) {
                    bundle.putIntegerArrayList("autoPayBalanceThresholdList", arrayList10);
                }
                if (!arrayList7.isEmpty()) {
                    bundle.putStringArrayList("skuDetailsTokens", arrayList7);
                }
                if (!arrayList9.isEmpty()) {
                    bundle.putStringArrayList("SKU_SERIALIZED_DOCID_LIST", arrayList9);
                }
                if (!arrayList5.isEmpty()) {
                    bundle.putStringArrayList("additionalSkus", arrayList5);
                    bundle.putStringArrayList("additionalSkuTypes", arrayList6);
                }
            } else {
                ArrayList<String> arrayList12 = new ArrayList<>();
                new ArrayList();
                new ArrayList();
                new ArrayList();
                new ArrayList();
                Iterator it5 = arrayList.iterator();
                if (it5.hasNext()) {
                    it5.next().getClass();
                    throw new ClassCastException();
                }
                if (!arrayList12.isEmpty()) {
                    bundle.putStringArrayList("skuDetailsTokens", arrayList12);
                }
                if (arrayList.size() > 1) {
                    ArrayList<String> arrayList13 = new ArrayList<>(arrayList.size() - 1);
                    ArrayList<String> arrayList14 = new ArrayList<>(arrayList.size() - 1);
                    if (1 < arrayList.size()) {
                        arrayList.get(1).getClass();
                        throw new ClassCastException();
                    }
                    bundle.putStringArrayList("additionalSkus", arrayList13);
                    bundle.putStringArrayList("additionalSkuTypes", arrayList14);
                }
                j6 = j7;
                z11 = true;
            }
            if (bundle.containsKey("SKU_OFFER_ID_TOKEN_LIST") && !this.f2607r) {
                zzie zzieVar7 = zzie.OFFER_ID_TOKEN_NOT_SUPPORTED;
                C0328l c0328l8 = V.f2557q;
                L(zzieVar7, c0328l8, j6, z20);
                N(c0328l8);
                return c0328l8;
            }
            if (TextUtils.isEmpty(c0324h.f2621a.f2666b.optString("packageName"))) {
                z12 = false;
            } else {
                bundle.putString("skuPackageName", c0324h.f2621a.f2666b.optString("packageName"));
                z12 = z11;
            }
            string = null;
            if (!TextUtils.isEmpty(null)) {
                bundle.putString("accountName", null);
            }
            Intent intent = activity.getIntent();
            if (intent == null) {
                zzc.zzn("BillingClient", "Activity's intent is null.");
            } else if (!TextUtils.isEmpty(intent.getStringExtra("PROXY_PACKAGE"))) {
                String stringExtra = intent.getStringExtra("PROXY_PACKAGE");
                bundle.putString("proxyPackage", stringExtra);
                try {
                    bundle.putString("proxyPackageVersion", this.f2597g.getPackageManager().getPackageInfo(stringExtra, 0).versionName);
                } catch (PackageManager.NameNotFoundException unused) {
                    bundle.putString("proxyPackageVersion", "package not found");
                }
            }
            final int i14 = (!this.f2610u || zzbtVar.isEmpty()) ? (this.f2608s && z12) ? 15 : this.f2605p ? 9 : 6 : 17;
            final String str14 = str2;
            final String str15 = str3;
            futureJ = j(new Callable(i14, str14, str15, c0326j, bundle) { // from class: I2.Z

                /* JADX INFO: renamed from: b, reason: collision with root package name */
                public final /* synthetic */ int f2575b;

                /* JADX INFO: renamed from: c, reason: collision with root package name */
                public final /* synthetic */ String f2576c;

                /* JADX INFO: renamed from: d, reason: collision with root package name */
                public final /* synthetic */ String f2577d;

                /* JADX INFO: renamed from: e, reason: collision with root package name */
                public final /* synthetic */ Bundle f2578e;

                {
                    this.f2578e = bundle;
                }

                @Override // java.util.concurrent.Callable
                public final Object call() {
                    zzam zzamVar;
                    C0320d c0320d = this.f2574a;
                    int i15 = this.f2575b;
                    String str16 = this.f2576c;
                    String str17 = this.f2577d;
                    Bundle bundle2 = this.f2578e;
                    c0320d.getClass();
                    try {
                        synchronized (c0320d.f2591a) {
                            zzamVar = c0320d.f2599i;
                        }
                        return zzamVar == null ? zzc.zzd(V.f2551j, zzie.SERVICE_RESET_TO_NULL) : zzamVar.zzg(i15, c0320d.f2597g.getPackageName(), str16, str17, null, bundle2);
                    } catch (DeadObjectException e6) {
                        return zzc.zze(V.f2551j, zzie.LAUNCH_BILLING_FLOW_EXCEPTION, T.a(e6));
                    } catch (Exception e7) {
                        return zzc.zze(V.f2549h, zzie.LAUNCH_BILLING_FLOW_EXCEPTION, T.a(e7));
                    }
                }
            }, 5000L, null, this.f2595e, i());
            str4 = str15;
            r6 = bundle;
            z9 = z20;
        } else {
            j6 = j7;
            z9 = z15;
            string = str;
            String str16 = str3;
            futureJ = j(new E(this, str2, str16, 4), 5000L, null, this.f2595e, i());
            str4 = str16;
            r6 = z15;
        }
        try {
            if (futureJ == null) {
                try {
                    zzie zzieVar8 = zzie.MISSING_RESULT_FROM_EXECUTE_ASYNC;
                    C0328l c0328l9 = V.f2544c;
                    L(zzieVar8, c0328l9, j6, z9);
                    N(c0328l9);
                    return c0328l9;
                } catch (CancellationException e6) {
                    e = e6;
                    r43 = j6;
                    r63 = z9;
                    zzc.zzo("BillingClient", "Time out while launching billing flow. Try to reconnect", e);
                    zzie zzieVar9 = zzie.LAUNCH_BILLING_FLOW_TIMEOUT;
                    C0328l c0328l10 = V.f2552k;
                    M(zzieVar9, c0328l10, T.a(e), r43, r63);
                    N(c0328l10);
                    return c0328l10;
                } catch (TimeoutException e7) {
                    e = e7;
                    r43 = j6;
                    r63 = z9;
                    zzc.zzo("BillingClient", "Time out while launching billing flow. Try to reconnect", e);
                    zzie zzieVar92 = zzie.LAUNCH_BILLING_FLOW_TIMEOUT;
                    C0328l c0328l102 = V.f2552k;
                    M(zzieVar92, c0328l102, T.a(e), r43, r63);
                    N(c0328l102);
                    return c0328l102;
                } catch (Exception e8) {
                    e = e8;
                    r42 = j6;
                    r62 = z9;
                    zzc.zzo("BillingClient", "Exception while launching billing flow. Try to reconnect", e);
                    zzie zzieVar10 = zzie.LAUNCH_BILLING_FLOW_EXCEPTION;
                    C0328l c0328l11 = V.f2551j;
                    M(zzieVar10, c0328l11, T.a(e), r42, r62);
                    N(c0328l11);
                    return c0328l11;
                }
            }
            long j9 = j6;
            boolean z21 = z9;
            Bundle bundle2 = (Bundle) futureJ.get(5000L, TimeUnit.MILLISECONDS);
            int iZzb = zzc.zzb(bundle2, "BillingClient");
            String strZzj = zzc.zzj(bundle2, "BillingClient");
            if (iZzb == 0) {
                Intent intent2 = new Intent(activity, (Class<?>) ProxyBillingActivity.class);
                intent2.putExtra("BUY_INTENT", (PendingIntent) bundle2.getParcelable("BUY_INTENT"));
                intent2.putExtra("billingClientTransactionId", j9);
                intent2.putExtra("wasServiceAutoReconnected", z21);
                activity.startActivity(intent2);
                return V.f2550i;
            }
            zzc.zzn("BillingClient", "Unable to buy item, Error response code: " + iZzb);
            C0328l c0328lA3 = V.a(iZzb, strZzj);
            try {
                if (bundle2 == null || (obj = bundle2.get("LOG_REASON")) == null) {
                    zzieVarZzb = zzie.REASON_UNSPECIFIED;
                } else if (obj instanceof Integer) {
                    zzieVarZzb = zzie.zzb(((Integer) obj).intValue());
                } else {
                    zzc.zzn("BillingClient", "Unexpected type for bundle log reason: " + obj.getClass().getName());
                    zzieVarZzb = zzie.REASON_UNSPECIFIED;
                }
            } catch (Throwable th) {
                zzc.zzn("BillingClient", "Failed to get log reason from bundle: ".concat(String.valueOf(th.getMessage())));
                zzieVarZzb = zzie.REASON_UNSPECIFIED;
            }
            if (zzieVarZzb == zzie.REASON_UNSPECIFIED) {
                zzieVarZzb = zzie.BILLING_RESULT_RECEIVED_FROM_PHONESKY;
            }
            zzie zzieVar11 = zzieVarZzb;
            if (bundle2 != null) {
                try {
                    string = bundle2.getString("ADDITIONAL_LOG_DETAILS");
                } catch (Throwable th2) {
                    zzc.zzn("BillingClient", "Failed to get additional log details from bundle: ".concat(String.valueOf(th2.getMessage())));
                }
            }
            try {
                M(zzieVar11, c0328lA3, string, j9, z21);
                N(c0328lA3);
                return c0328lA3;
            } catch (CancellationException e9) {
                e = e9;
                r43 = j9;
                r63 = z21 ? 1 : 0;
                zzc.zzo("BillingClient", "Time out while launching billing flow. Try to reconnect", e);
                zzie zzieVar922 = zzie.LAUNCH_BILLING_FLOW_TIMEOUT;
                C0328l c0328l1022 = V.f2552k;
                M(zzieVar922, c0328l1022, T.a(e), r43, r63);
                N(c0328l1022);
                return c0328l1022;
            } catch (TimeoutException e10) {
                e = e10;
                r43 = j9;
                r63 = z21 ? 1 : 0;
                zzc.zzo("BillingClient", "Time out while launching billing flow. Try to reconnect", e);
                zzie zzieVar9222 = zzie.LAUNCH_BILLING_FLOW_TIMEOUT;
                C0328l c0328l10222 = V.f2552k;
                M(zzieVar9222, c0328l10222, T.a(e), r43, r63);
                N(c0328l10222);
                return c0328l10222;
            } catch (Exception e11) {
                e = e11;
                r42 = j9;
                r62 = z21 ? 1 : 0;
                zzc.zzo("BillingClient", "Exception while launching billing flow. Try to reconnect", e);
                zzie zzieVar102 = zzie.LAUNCH_BILLING_FLOW_EXCEPTION;
                C0328l c0328l112 = V.f2551j;
                M(zzieVar102, c0328l112, T.a(e), r42, r62);
                N(c0328l112);
                return c0328l112;
            }
        } catch (CancellationException e12) {
            e = e12;
        } catch (TimeoutException e13) {
            e = e13;
            r43 = str4;
            r63 = r6;
        } catch (Exception e14) {
            e = e14;
        }
    }

    @Override // I2.AbstractC0319c
    public void f(C0341z c0341z, com.revenuecat.purchases.google.usecase.c cVar) {
        if (j(new E(this, cVar, c0341z, 2), 30000L, new C1.a(6, this, cVar), z(), i()) == null) {
            C0328l c0328lC = C();
            I(7, c0328lC, zzie.MISSING_RESULT_FROM_EXECUTE_ASYNC);
            cVar.a(c0328lC, new A(zzbt.zzk(), zzbt.zzk()));
        }
    }

    @Override // I2.AbstractC0319c
    public final void g(C c6, InterfaceC0338w interfaceC0338w) {
        if (j(new E(this, interfaceC0338w, c6.f2490a), 30000L, new C1.a(7, this, interfaceC0338w), z(), i()) == null) {
            C0328l c0328lC = C();
            I(9, c0328lC, zzie.MISSING_RESULT_FROM_EXECUTE_ASYNC);
            interfaceC0338w.b(c0328lC, zzbt.zzk());
        }
    }

    @Override // I2.AbstractC0319c
    public void h(InterfaceC0321e interfaceC0321e) {
        s(interfaceC0321e, 0);
    }

    public final synchronized ExecutorService i() {
        try {
            if (this.f2588E == null) {
                this.f2588E = Executors.newFixedThreadPool(zzc.zza, new H(this));
            }
        } catch (Throwable th) {
            throw th;
        }
        return this.f2588E;
    }

    public final void k(com.revenuecat.purchases.google.usecase.a aVar, C0328l c0328l, zzie zzieVar, Exception exc) {
        zzc.zzo("BillingClient", "Error in acknowledge purchase!", exc);
        K(zzieVar, 3, c0328l, T.a(exc));
        aVar.c(c0328l);
    }

    public final void l(com.revenuecat.purchases.google.usecase.a aVar, String str, C0328l c0328l, zzie zzieVar, String str2, Exception exc) {
        zzc.zzo("BillingClient", str2, exc);
        K(zzieVar, 4, c0328l, T.a(exc));
        aVar.d(c0328l, str);
    }

    public final void m(com.revenuecat.purchases.google.usecase.b bVar, C0328l c0328l, zzie zzieVar, Exception exc) {
        zzc.zzo("BillingClient", "getBillingConfig got an exception.", exc);
        K(zzieVar, 13, c0328l, T.a(exc));
        bVar.a(c0328l, null);
    }

    public final void n(int i6, zzie zzieVar, Exception exc) {
        zzhx zzhxVar;
        zzc.zzo("BillingClient", "showInAppMessages error.", exc);
        T.p pVar = this.f2598h;
        String strA = T.a(exc);
        try {
            zzic zzicVarZzc = zzig.zzc();
            zzicVarZzc.zzo(i6);
            if (zzieVar != null) {
                zzicVarZzc.zzn(zzieVar);
            }
            if (strA != null) {
                zzicVarZzc.zza(strA);
            }
            zzhv zzhvVarZzc = zzhx.zzc();
            zzhvVarZzc.zzl(zzicVarZzc);
            zzhvVarZzc.zzp(30);
            zzhxVar = (zzhx) zzhvVarZzc.zze();
        } catch (Throwable th) {
            zzc.zzo("BillingLogger", "Unable to create logging payload", th);
            zzhxVar = null;
        }
        pVar.y(zzhxVar);
    }

    public final void o(zzhx zzhxVar) {
        try {
            this.f2598h.z(zzhxVar, this.f2602m);
        } catch (Throwable th) {
            zzc.zzo("BillingClient", "Unable to log.", th);
        }
    }

    public final void p(zzib zzibVar) {
        try {
            T.p pVar = this.f2598h;
            int i6 = this.f2602m;
            pVar.getClass();
            try {
                zziq zziqVar = (zziq) ((zzis) pVar.f6345b).zzm();
                zziqVar.zzm(i6);
                zzis zzisVar = (zzis) zziqVar.zze();
                pVar.f6345b = zzisVar;
                try {
                    pVar.F(zzibVar, zzisVar);
                } catch (Throwable th) {
                    zzc.zzo("BillingLogger", "Unable to log.", th);
                }
            } catch (Throwable th2) {
                zzc.zzo("BillingLogger", "Unable to log.", th2);
            }
        } catch (Throwable th3) {
            zzc.zzo("BillingClient", "Unable to log.", th3);
        }
    }

    public final void q(int i6, C0328l c0328l, zzie zzieVar) {
        try {
            int i7 = T.f2535a;
            zzhv zzhvVar = (zzhv) T.b(zzieVar, 6, c0328l, null, zzil.BROADCAST_ACTION_UNSPECIFIED).zzm();
            zzjt zzjtVarZzc = zzjv.zzc();
            zzjtVarZzc.zza(i6 > 0);
            zzjtVarZzc.zzl(i6);
            zzhvVar.zzo(zzjtVarZzc);
            o((zzhx) zzhvVar.zze());
        } catch (Throwable th) {
            zzc.zzo("BillingClient", "Unable to log.", th);
        }
    }

    public final void r(int i6) {
        synchronized (this.f2591a) {
            try {
                if (this.f2592b == 3) {
                    return;
                }
                int i7 = this.f2592b;
                zzc.zzm("BillingClient", "Setting clientState from " + (i7 != 0 ? i7 != 1 ? i7 != 2 ? "CLOSED" : "CONNECTED" : "CONNECTING" : "DISCONNECTED") + " to " + (i6 != 0 ? i6 != 1 ? i6 != 2 ? "CLOSED" : "CONNECTED" : "CONNECTING" : "DISCONNECTED"));
                this.f2592b = i6;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    public final void s(InterfaceC0321e interfaceC0321e, int i6) {
        zzie zzieVar;
        C0328l c0328lB;
        C0328l c0328l;
        synchronized (this.f2591a) {
            try {
                if (w()) {
                    c0328lB = B(i6);
                } else {
                    if (this.f2592b == 1) {
                        zzc.zzn("BillingClient", "Client is already in the process of connecting to billing service.");
                        zzie zzieVar2 = zzie.BILLING_CLIENT_CONNECTING;
                        c0328l = V.f2545d;
                        q(i6, c0328l, zzieVar2);
                    } else if (this.f2592b == 3) {
                        zzc.zzn("BillingClient", "Client was already closed and can't be reused. Please create another instance.");
                        zzie zzieVar3 = zzie.BILLING_CLIENT_CLOSED;
                        c0328l = V.f2551j;
                        q(i6, c0328l, zzieVar3);
                    } else {
                        r(1);
                        if (i6 == 0) {
                            i6 = 0;
                        }
                        t();
                        zzc.zzm("BillingClient", "Starting in-app billing setup.");
                        this.f2600j = new L(this, interfaceC0321e, i6);
                        zzbi zzbiVar = this.f2600j.f2514b;
                        zzbiVar.zzd();
                        zzbiVar.zze();
                        Intent intent = new Intent(BillingConstants.BILLING_SERVICE_ACTION);
                        intent.setPackage("com.android.vending");
                        List<ResolveInfo> listQueryIntentServices = this.f2597g.getPackageManager().queryIntentServices(intent, 0);
                        if (listQueryIntentServices == null || listQueryIntentServices.isEmpty()) {
                            zzieVar = zzie.INTENT_SERVICE_NOT_FOUND;
                        } else {
                            ServiceInfo serviceInfo = listQueryIntentServices.get(0).serviceInfo;
                            if (serviceInfo != null) {
                                String str = serviceInfo.packageName;
                                String str2 = serviceInfo.name;
                                if (!Objects.equals(str, "com.android.vending") || str2 == null) {
                                    zzieVar = zzie.INVALID_PHONESKY_PACKAGE;
                                    zzc.zzn("BillingClient", "The device doesn't have valid Play Store.");
                                } else {
                                    ComponentName componentName = new ComponentName(str, str2);
                                    Intent intent2 = new Intent(intent);
                                    intent2.setComponent(componentName);
                                    intent2.putExtra("playBillingLibraryVersion", this.f2593c);
                                    synchronized (this.f2591a) {
                                        try {
                                            if (this.f2592b == 2) {
                                                c0328lB = B(i6);
                                            } else if (this.f2592b != 1) {
                                                zzc.zzn("BillingClient", "Client state no longer CONNECTING, returning service disconnected.");
                                                zzie zzieVar4 = zzie.BILLING_CLIENT_TRANSITIONED_OUT_OF_CONNECTING;
                                                c0328l = V.f2551j;
                                                q(i6, c0328l, zzieVar4);
                                            } else {
                                                L l = this.f2600j;
                                                if ((i6 <= 0 || Build.VERSION.SDK_INT < 29) ? this.f2597g.bindService(intent2, l, 1) : this.f2597g.bindService(intent2, 1, i(), l)) {
                                                    zzc.zzm("BillingClient", "Service was bonded successfully.");
                                                    c0328lB = null;
                                                } else {
                                                    zzieVar = zzie.BILLING_SERVICE_BLOCKED;
                                                    zzc.zzn("BillingClient", "Connection to Billing service is blocked.");
                                                }
                                            }
                                        } finally {
                                        }
                                    }
                                }
                            } else {
                                zzieVar = zzie.INVALID_PHONESKY_PACKAGE;
                                zzc.zzn("BillingClient", "The device doesn't have valid Play Store.");
                            }
                        }
                        r(0);
                        zzc.zzm("BillingClient", "Billing service unavailable on device.");
                        C0328l c0328l2 = V.f2543b;
                        q(i6, c0328l2, zzieVar);
                        c0328lB = c0328l2;
                    }
                    c0328lB = c0328l;
                }
            } finally {
            }
        }
        if (c0328lB != null) {
            interfaceC0321e.onBillingSetupFinished(c0328lB);
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final void t() {
        synchronized (this.f2591a) {
            if (this.f2600j != null) {
                try {
                    this.f2597g.unbindService(this.f2600j);
                } catch (Throwable th) {
                    try {
                        zzc.zzo("BillingClient", "There was an exception while unbinding service!", th);
                        this.f2599i = null;
                        this.f2600j = null;
                    } finally {
                        this.f2599i = null;
                        this.f2600j = null;
                    }
                }
            }
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final boolean u() {
        try {
            int i6 = ((C0328l) D(1).get(Build.VERSION.SDK_INT < 29 ? 0L : androidx.media3.common.C.DEFAULT_MAX_SEEK_TO_PREVIOUS_POSITION_MS, TimeUnit.MILLISECONDS)).f2636a;
            if (i6 == 0) {
                zzc.zzm("BillingClient", "Reconnection succeeded with result: " + i6);
            } else {
                zzc.zzn("BillingClient", "Reconnection failed with result: " + i6);
            }
        } catch (Exception e6) {
            if (e6 instanceof InterruptedException) {
                Thread.currentThread().interrupt();
            }
            zzc.zzo("BillingClient", "Error during reconnection attempt: ", e6);
        }
        return w();
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final boolean v() {
        long jMax;
        zzbi zzbiVarZzb = zzbi.zzb(this.f2590G);
        long jZza = 30000;
        for (int i6 = 1; i6 <= 3; i6++) {
            try {
                jMax = Math.max(0L, jZza);
            } catch (Exception e6) {
                if (e6 instanceof InterruptedException) {
                    Thread.currentThread().interrupt();
                }
                zzc.zzo("BillingClient", "Error during reconnection attempt: ", e6);
            }
            if (jMax <= 0) {
                zzc.zzn("BillingClient", "No time remaining for reconnection attempt.");
                return w();
            }
            int i7 = ((C0328l) D(i6).get(jMax, TimeUnit.MILLISECONDS)).f2636a;
            if (i7 == 0) {
                zzc.zzm("BillingClient", "Reconnection succeeded with result: " + i7);
                return w();
            }
            zzc.zzn("BillingClient", "Reconnection failed with result: " + i7);
            TimeUnit timeUnit = TimeUnit.MILLISECONDS;
            jZza = 30000 - zzbiVarZzb.zza(timeUnit);
            long jPow = ((long) Math.pow(2.0d, i6 - 1)) * 1000;
            if (jZza < jPow) {
                zzc.zzn("BillingClient", "Reconnection failed due to timeout limit reached.");
                return w();
            }
            if (i6 < 3 && jPow > 0) {
                try {
                    Thread.sleep(jPow);
                    jZza = 30000 - zzbiVarZzb.zza(timeUnit);
                } catch (InterruptedException e7) {
                    Thread.currentThread().interrupt();
                    zzc.zzo("BillingClient", "Error sleeping during reconnection attempt: ", e7);
                }
            }
        }
        zzc.zzn("BillingClient", "Max retries reached.");
        return w();
    }

    public final boolean w() {
        boolean z6;
        synchronized (this.f2591a) {
            try {
                z6 = false;
                if (this.f2592b == 2 && this.f2599i != null && this.f2600j != null) {
                    z6 = true;
                }
            } finally {
            }
        }
        return z6;
    }

    public final Handler z() {
        return Looper.myLooper() == null ? this.f2595e : new Handler(Looper.myLooper());
    }

    public C0320d(C0331o c0331o, Context context, C0318b c0318b) {
        long jNextLong = new Random().nextLong();
        this.f2589F = Long.valueOf(jNextLong);
        this.f2590G = zzaz.zza();
        this.f2593c = BuildConfig.BILLING_CLIENT_VERSION;
        String strF = F();
        this.f2594d = strF;
        this.f2597g = context.getApplicationContext();
        zziq zziqVarZzc = zzis.zzc();
        zziqVarZzc.zzs(BuildConfig.BILLING_CLIENT_VERSION);
        if (strF != null) {
            zziqVarZzc.zzt(strF);
        }
        zziqVarZzc.zzq(this.f2597g.getPackageName());
        zziqVarZzc.zzn(jNextLong);
        c0318b.getClass();
        zziqVarZzc.zzr(false);
        zziqVarZzc.zza(Build.VERSION.SDK_INT);
        zziqVarZzc.zzp(772604006L);
        try {
            zziqVarZzc.zzl(this.f2597g.getPackageManager().getPackageInfo(this.f2597g.getPackageName(), 0).versionCode);
        } catch (Throwable th) {
            zzc.zzo("BillingClient", "Error getting app version code.", th);
        }
        this.f2598h = new T.p(this.f2597g, (zzis) zziqVarZzc.zze());
        zzc.zzn("BillingClient", "Billing client should have a valid listener but the provided is null.");
        this.f2596f = new G.B(this.f2597g, (InterfaceC0339x) null, this.f2598h);
        this.f2586C = c0331o;
        this.f2597g.getPackageName();
    }
}
