package defpackage;

import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import java.util.concurrent.Callable;

/* renamed from: ᵧˁˇ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class CallableC3631 implements Callable {

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final /* synthetic */ int f13524;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final /* synthetic */ Object f13525;

    public /* synthetic */ CallableC3631(int i, Object obj) {
        this.f13524 = i;
        this.f13525 = obj;
    }

    public CallableC3631(BinderC0769 binderC0769, C2850 c2850, String str) {
        this.f13524 = 3;
        this.f13525 = binderC0769;
    }

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    private final Object m8229() {
        synchronized (((C4035) this.f13525)) {
            try {
                C4035 c4035 = (C4035) this.f13525;
                if (c4035.f15153 == null) {
                    return null;
                }
                c4035.m8887();
                if (((C4035) this.f13525).m8890()) {
                    ((C4035) this.f13525).m8892();
                    ((C4035) this.f13525).f15161 = 0;
                }
                return null;
            } finally {
            }
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    private final Object m8230() throws InterruptedException {
        int i;
        Bundle bundle;
        InterfaceC0233 interfaceC0233;
        ServiceConnectionC2349 serviceConnectionC2349 = (ServiceConnectionC2349) this.f13525;
        C3768 c3768 = serviceConnectionC2349.f9193;
        synchronized (c3768.f14080) {
            try {
                if (c3768.f14062 == 3) {
                    return null;
                }
                int i2 = 1;
                boolean z = false;
                if (c3768.f14062 == 1) {
                    i = 0;
                    z = true;
                } else {
                    i = 0;
                }
                if (TextUtils.isEmpty(null)) {
                    bundle = null;
                } else {
                    bundle = new Bundle();
                    bundle.putString("accountName", null);
                    AbstractC1845.m5212(bundle, c3768.f14079, c3768.f14084.longValue());
                }
                synchronized (c3768.f14080) {
                    interfaceC0233 = c3768.f14055;
                }
                C3768 c37682 = serviceConnectionC2349.f9193;
                if (interfaceC0233 == null) {
                    c37682.m8414(i);
                    int i3 = serviceConnectionC2349.f9195;
                    C3297 c3297 = AbstractC5497.f20622;
                    c37682.m8405(107, i3, c3297);
                    serviceConnectionC2349.m6096(c3297);
                    return null;
                }
                String packageName = c37682.f14072.getPackageName();
                try {
                    C0157 c0157 = (C0157) interfaceC0233;
                    if (c0157.m1319(25, packageName, "inapp") != 0) {
                        int i4 = 28;
                        int iM1319 = 3;
                        int i5 = 28;
                        while (true) {
                            if (i5 < 3) {
                                i5 = i;
                                break;
                            }
                            try {
                                AbstractC1845.m5207("BillingClient", "trying subs apiVersion: " + i5);
                                iM1319 = bundle == null ? c0157.m1319(i5, packageName, "subs") : c0157.m1321(i5, packageName, "subs", bundle);
                                if (iM1319 == 0) {
                                    AbstractC1845.m5207("BillingClient", "highestLevelSupportedForSubs: " + i5);
                                    break;
                                }
                                i5--;
                            } catch (Exception e) {
                                serviceConnectionC2349.m6097(e, z);
                            }
                        }
                        C3768 c37683 = serviceConnectionC2349.f9193;
                        c37683.getClass();
                        c37683.f14078 = i5 >= 3 ? 1 : i;
                        if (i5 < 3) {
                            AbstractC1845.m5207("BillingClient", "In-app billing API does not support subscription on this device.");
                            i2 = 9;
                        }
                        while (true) {
                            if (i4 < 3) {
                                break;
                            }
                            AbstractC1845.m5207("BillingClient", "trying inapp apiVersion: " + i4);
                            iM1319 = bundle == null ? c0157.m1319(i4, packageName, "inapp") : c0157.m1321(i4, packageName, "inapp", bundle);
                            if (iM1319 == 0) {
                                c37683.f14063 = i4;
                                AbstractC1845.m5207("BillingClient", "mHighestLevelSupportedForInApp: " + i4);
                                break;
                            }
                            i4--;
                        }
                        C3768.m8392(c37683, c37683.f14063);
                        if (c37683.f14063 < 3) {
                            int i6 = AbstractC1845.f7462;
                            Log.isLoggable("BillingClient", 5);
                            i2 = 36;
                        }
                        int i7 = i2;
                        C3768.m8396(c37683, iM1319);
                        if (iM1319 == 0) {
                            serviceConnectionC2349.m6102(i, z);
                            serviceConnectionC2349.m6096(AbstractC5497.f20614);
                            return null;
                        }
                        C3297 c32972 = AbstractC5497.f20621;
                        serviceConnectionC2349.m6099(c32972, i7, null, z, 0);
                        serviceConnectionC2349.m6096(c32972);
                        return null;
                    }
                    C3768 c37684 = serviceConnectionC2349.f9193;
                    Context context = c37684.f14072;
                    ᵙᵛᵯ.ˑᵝﹳᵜ();
                    ᵙᵛᵯ.ˊᵸˊ();
                    ᵙᵛᵯ.ᵙᵢᵨᵳ();
                    ᵙᵛᵯ.ˀᵗᵩ();
                    long jMin = 100;
                    int i8 = i;
                    Exception e2 = null;
                    while (true) {
                        long j = i8;
                        if (j > 3) {
                            break;
                        }
                        try {
                            Boolean boolValueOf = Boolean.valueOf(z);
                            Bundle bundle2 = new Bundle();
                            bundle2.putString("callingPackage", c37684.f14072.getPackageName());
                            AbstractC1845.m5212(bundle2, c37684.f14079, c37684.f14084.longValue());
                            if (c37684.f14073 != null) {
                                bundle2.putBoolean("enablePendingPurchases", true);
                            }
                            c0157.m1322(c37684.f14072.getPackageName(), bundle2, new BinderC2066(c37684, serviceConnectionC2349, boolValueOf, i8));
                            break;
                        } catch (SecurityException e3) {
                            serviceConnectionC2349.m6098(e3, z, i8);
                        } catch (Exception e4) {
                            e2 = e4;
                            if (j == 3) {
                                break;
                            }
                            AbstractC1845.m5213("BillingClient");
                            try {
                                Thread.sleep(jMin);
                                jMin = (long) Math.min(jMin * 2.0d, 60000.0d);
                                i8++;
                            } catch (InterruptedException e5) {
                                Thread.currentThread().interrupt();
                                serviceConnectionC2349.m6098(e5, z, i8);
                            }
                        }
                    }
                    serviceConnectionC2349.m6098(e2, z, i8);
                } catch (Exception e6) {
                    serviceConnectionC2349.m6097(e6, z);
                }
                return null;
            } finally {
            }
        }
    }

    @Override // java.util.concurrent.Callable
    public final Object call() {
        switch (this.f13524) {
            case 0:
                return m8229();
            case 1:
                return m8230();
            case 2:
                return new C3233(((C3245) this.f13525).f12216);
            case 3:
                BinderC0769 binderC0769 = (BinderC0769) this.f13525;
                binderC0769.f3656.m2263();
                C5034 c5034 = binderC0769.f3656.f2722;
                C0524.m2252(c5034);
                c5034.ˀᵗᵝᵭ();
                throw new IllegalStateException("Unexpected call on client side");
            default:
                C1557 c1557 = (C1557) this.f13525;
                synchronized (((C3953) c1557.f6204).f14920) {
                    c1557.f6205 = null;
                }
                return null;
        }
    }
}
