package p138.p139.p140.p141;

import android.os.Bundle;
import android.os.RemoteException;
import android.text.TextUtils;
import java.util.ArrayList;
import java.util.concurrent.Callable;
import org.json.JSONException;
import org.json.JSONObject;
import p000.p001.p002.p003.p004.C0567;
import p138.p139.p140.p141.C2759;
import p138.p139.p140.p142.C2802;

/* JADX INFO: renamed from: ދ.֏.֏.֏.ޟ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class CallableC2795 implements Callable<Void> {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final /* synthetic */ String f8615;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final /* synthetic */ InterfaceC2769 f8616;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final /* synthetic */ C2759 f8617;

    public CallableC2795(C2759 c2759, String str, InterfaceC2769 interfaceC2769) {
        this.f8617 = c2759;
        this.f8615 = str;
        this.f8616 = interfaceC2769;
    }

    @Override // java.util.concurrent.Callable
    public final /* synthetic */ Void call() {
        C2759.C2761 c2761;
        C2759 c2759 = this.f8617;
        String str = this.f8615;
        if (c2759 == null) {
            throw null;
        }
        String strValueOf = String.valueOf(str);
        C2802.m4857("BillingClient", strValueOf.length() != 0 ? "Querying purchase history, item type: ".concat(strValueOf) : new String("Querying purchase history, item type: "));
        ArrayList arrayList = new ArrayList();
        boolean z = c2759.f8520;
        boolean z2 = c2759.f8524;
        String str2 = c2759.f8508;
        Bundle bundle = new Bundle();
        bundle.putString("playBillingLibraryVersion", str2);
        if (z && z2) {
            bundle.putBoolean("enablePendingPurchases", true);
        }
        String string = null;
        while (true) {
            if (!c2759.f8518) {
                C2802.m4859("BillingClient", "getPurchaseHistory is not supported on current device");
                c2761 = new C2759.C2761(C2785.f8589, null);
                break;
            }
            try {
                Bundle bundleMo7910 = c2759.f8514.mo7910(6, c2759.f8511.getPackageName(), str, string, bundle);
                C2764 c2764M1868 = C0567.m1868(bundleMo7910, "BillingClient", "getPurchaseHistory()");
                if (c2764M1868 != C2785.f8594) {
                    c2761 = new C2759.C2761(c2764M1868, null);
                    break;
                }
                ArrayList<String> stringArrayList = bundleMo7910.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
                ArrayList<String> stringArrayList2 = bundleMo7910.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
                ArrayList<String> stringArrayList3 = bundleMo7910.getStringArrayList("INAPP_DATA_SIGNATURE_LIST");
                for (int i = 0; i < stringArrayList2.size(); i++) {
                    String str3 = stringArrayList2.get(i);
                    String str4 = stringArrayList3.get(i);
                    String strValueOf2 = String.valueOf(stringArrayList.get(i));
                    C2802.m4857("BillingClient", strValueOf2.length() != 0 ? "Purchase record found for sku : ".concat(strValueOf2) : new String("Purchase record found for sku : "));
                    try {
                        C2768 c2768 = new C2768(str3, str4);
                        JSONObject jSONObject = c2768.f8553;
                        if (TextUtils.isEmpty(jSONObject.optString("token", jSONObject.optString("purchaseToken")))) {
                            C2802.m4859("BillingClient", "BUG: empty/null token!");
                        }
                        arrayList.add(c2768);
                    } catch (JSONException e) {
                        String strValueOf3 = String.valueOf(e);
                        StringBuilder sb = new StringBuilder(strValueOf3.length() + 48);
                        sb.append("Got an exception trying to decode the purchase: ");
                        sb.append(strValueOf3);
                        C2802.m4859("BillingClient", sb.toString());
                        c2761 = new C2759.C2761(C2785.f8591, null);
                    }
                }
                string = bundleMo7910.getString("INAPP_CONTINUATION_TOKEN");
                String strValueOf4 = String.valueOf(string);
                C2802.m4857("BillingClient", strValueOf4.length() != 0 ? "Continuation token: ".concat(strValueOf4) : new String("Continuation token: "));
                if (TextUtils.isEmpty(string)) {
                    c2761 = new C2759.C2761(C2785.f8594, arrayList);
                    break;
                }
            } catch (RemoteException e2) {
                String strValueOf5 = String.valueOf(e2);
                StringBuilder sb2 = new StringBuilder(strValueOf5.length() + 64);
                sb2.append("Got exception trying to get purchase history: ");
                sb2.append(strValueOf5);
                sb2.append("; try to reconnect");
                C2802.m4859("BillingClient", sb2.toString());
                c2761 = new C2759.C2761(C2785.f8595, null);
            }
        }
        C2759.m4833(this.f8617, new RunnableC2794(this, c2761));
        return null;
    }
}
