package c.d.a.a; 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.Bundle; import android.os.Handler; import android.os.Looper; import android.text.TextUtils; import androidx.annotation.Nullable; import androidx.annotation.UiThread; import c.i.a.f.h.n.d; import com.android.billingclient.api.BillingClient; import com.android.billingclient.api.BillingFlowParams; import com.android.billingclient.api.BillingResult; import com.android.billingclient.api.ProxyBillingActivity; import com.android.billingclient.api.Purchase; import com.android.billingclient.api.SkuDetails; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Objects; 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; import org.json.JSONException; import org.json.JSONObject; /* compiled from: com.android.billingclient:billing@@3.0.3 */ public class a extends BillingClient { public int a; public final String b; /* renamed from: c reason: collision with root package name */ public final Handler f351c; public u d; public Context e; public d f; public o g; public boolean h; public boolean i; public int j; public boolean k; public boolean l; public boolean m; public boolean n; public boolean o; public boolean p; public boolean q; public ExecutorService r; @UiThread public a(@Nullable String str, Context context, e eVar) { String str2; try { str2 = (String) Class.forName("c.d.a.b.a").getField("VERSION_NAME").get(null); } catch (Exception unused) { str2 = "3.0.3"; } this.a = 0; this.f351c = new Handler(Looper.getMainLooper()); this.j = 0; this.b = str2; Context applicationContext = context.getApplicationContext(); this.e = applicationContext; this.d = new u(applicationContext, eVar); this.q = true; } @Override // com.android.billingclient.api.BillingClient public final void a(c cVar, d dVar) { if (!c()) { dVar.onConsumeResponse(q.j, cVar.a); } else if (j(new w(this, cVar, dVar), 30000, new x(dVar, cVar)) == null) { dVar.onConsumeResponse(i(), cVar.a); } } @Override // com.android.billingclient.api.BillingClient public final void b() { int i = 3; try { this.d.a(); o oVar = this.g; if (oVar != null) { synchronized (oVar.i) { oVar.k = null; oVar.j = true; } } if (!(this.g == null || this.f == null)) { c.i.a.f.h.n.a.a("BillingClient", "Unbinding from service."); this.e.unbindService(this.g); this.g = null; } this.f = null; ExecutorService executorService = this.r; if (executorService != null) { executorService.shutdownNow(); this.r = null; } } catch (Exception e) { String valueOf = String.valueOf(e); StringBuilder sb = new StringBuilder(valueOf.length() + 48); sb.append("There was an exception while ending connection: "); sb.append(valueOf); c.i.a.f.h.n.a.b("BillingClient", sb.toString()); } finally { this.a = i; } } @Override // com.android.billingclient.api.BillingClient public final boolean c() { return (this.a != 2 || this.f == null || this.g == null) ? false : true; } /* JADX WARNING: Code restructure failed: missing block: B:155:0x03f1, code lost: r1 = r24; */ /* JADX WARNING: Code restructure failed: missing block: B:159:0x03f8, code lost: r1 = r24; */ /* JADX WARNING: Failed to process nested try/catch */ /* JADX WARNING: Removed duplicated region for block: B:160:? A[ExcHandler: Exception (unused java.lang.Exception), SYNTHETIC, Splitter:B:142:0x0399] */ @Override // com.android.billingclient.api.BillingClient public final BillingResult d(Activity activity, BillingFlowParams billingFlowParams) { String str; String str2; String str3; String str4; Future future; long j; String str5; String str6; String str7; int i; boolean z2; String str8; String str9; String str10 = "BUY_INTENT"; if (!c()) { BillingResult billingResult = q.j; this.d.b.a.onPurchasesUpdated(billingResult, null); return billingResult; } Objects.requireNonNull(billingFlowParams); ArrayList arrayList = new ArrayList(); arrayList.addAll(billingFlowParams.g); SkuDetails skuDetails = (SkuDetails) arrayList.get(0); String e = skuDetails.e(); String str11 = "BillingClient"; if (!e.equals("subs") || this.h) { String str12 = billingFlowParams.f1552c; if (str12 != null && !this.i) { c.i.a.f.h.n.a.b(str11, "Current client doesn't support subscriptions update."); BillingResult billingResult2 = q.m; this.d.b.a.onPurchasesUpdated(billingResult2, null); return billingResult2; } else if (((!billingFlowParams.h && billingFlowParams.b == null && billingFlowParams.e == null && billingFlowParams.f == 0 && !billingFlowParams.a) ? false : true) && !this.k) { c.i.a.f.h.n.a.b(str11, "Current client doesn't support extra params for buy intent."); BillingResult billingResult3 = q.f; this.d.b.a.onPurchasesUpdated(billingResult3, null); return billingResult3; } else if (arrayList.size() <= 1 || this.p) { String str13 = ""; int i2 = 0; String str14 = str13; while (i2 < arrayList.size()) { String valueOf = String.valueOf(str14); String valueOf2 = String.valueOf(arrayList.get(i2)); String H = c.d.b.a.a.H(new StringBuilder(valueOf.length() + valueOf2.length()), valueOf, valueOf2); if (i2 < arrayList.size() - 1) { H = String.valueOf(H).concat(", "); } str14 = H; i2++; str13 = str13; } StringBuilder sb = new StringBuilder(String.valueOf(str14).length() + 41 + e.length()); sb.append("Constructing buy intent for "); sb.append(str14); sb.append(", item type: "); sb.append(e); c.i.a.f.h.n.a.a(str11, sb.toString()); if (this.k) { boolean z3 = this.l; boolean z4 = this.q; String str15 = this.b; Bundle bundle = new Bundle(); bundle.putString("playBillingLibraryVersion", str15); int i3 = billingFlowParams.f; if (i3 != 0) { bundle.putInt("prorationMode", i3); } if (!TextUtils.isEmpty(billingFlowParams.b)) { bundle.putString("accountId", billingFlowParams.b); } if (!TextUtils.isEmpty(billingFlowParams.e)) { bundle.putString("obfuscatedProfileId", billingFlowParams.e); } if (billingFlowParams.h) { i = 1; bundle.putBoolean("vr", true); } else { i = 1; } if (!TextUtils.isEmpty(billingFlowParams.f1552c)) { String[] strArr = new String[i]; str4 = "; try to reconnect"; strArr[0] = billingFlowParams.f1552c; bundle.putStringArrayList("skusToReplace", new ArrayList<>(Arrays.asList(strArr))); } else { str4 = "; try to reconnect"; } if (!TextUtils.isEmpty(billingFlowParams.d)) { bundle.putString("oldSkuPurchaseToken", billingFlowParams.d); } if (!TextUtils.isEmpty(null)) { bundle.putString("oldSkuPurchaseId", null); } if (!TextUtils.isEmpty(null)) { bundle.putString("paymentsPurchaseParams", null); } if (z3 && z4) { bundle.putBoolean("enablePendingPurchases", true); } ArrayList arrayList2 = new ArrayList<>(); ArrayList arrayList3 = new ArrayList<>(); ArrayList arrayList4 = new ArrayList<>(); ArrayList arrayList5 = new ArrayList<>(); int size = arrayList.size(); boolean z5 = false; boolean z6 = false; boolean z7 = false; str2 = str14; int i4 = 0; while (i4 < size) { SkuDetails skuDetails2 = (SkuDetails) arrayList.get(i4); if (!skuDetails2.b.optString("skuDetailsToken").isEmpty()) { arrayList2.add(skuDetails2.b.optString("skuDetailsToken")); } try { str9 = new JSONObject(skuDetails2.a).optString("offer_id_token"); } catch (JSONException unused) { str9 = str13; } String optString = skuDetails2.b.optString("offer_id"); int optInt = skuDetails2.b.optInt("offer_type"); arrayList3.add(str9); z5 |= !TextUtils.isEmpty(str9); arrayList4.add(optString); z6 |= !TextUtils.isEmpty(optString); arrayList5.add(Integer.valueOf(optInt)); z7 |= optInt != 0; i4++; str10 = str10; size = size; str11 = str11; } str3 = str10; str = str11; if (!arrayList2.isEmpty()) { bundle.putStringArrayList("skuDetailsTokens", arrayList2); } if (z5) { if (!this.n) { BillingResult billingResult4 = q.g; this.d.b.a.onPurchasesUpdated(billingResult4, null); return billingResult4; } bundle.putStringArrayList("SKU_OFFER_ID_TOKEN_LIST", arrayList3); } if (z6) { bundle.putStringArrayList("SKU_OFFER_ID_LIST", arrayList4); } if (z7) { bundle.putIntegerArrayList("SKU_OFFER_TYPE_LIST", arrayList5); } if (!TextUtils.isEmpty(skuDetails.f())) { bundle.putString("skuPackageName", skuDetails.f()); str8 = null; z2 = true; } else { str8 = null; z2 = false; } if (!TextUtils.isEmpty(str8)) { bundle.putString("accountName", str8); } if (arrayList.size() > 1) { ArrayList arrayList6 = new ArrayList<>(arrayList.size() - 1); ArrayList arrayList7 = new ArrayList<>(arrayList.size() - 1); for (int i5 = 1; i5 < arrayList.size(); i5++) { arrayList6.add(((SkuDetails) arrayList.get(i5)).d()); arrayList7.add(((SkuDetails) arrayList.get(i5)).e()); } bundle.putStringArrayList("additionalSkus", arrayList6); bundle.putStringArrayList("additionalSkuTypes", arrayList7); } if (!TextUtils.isEmpty(activity.getIntent().getStringExtra("PROXY_PACKAGE"))) { String stringExtra = activity.getIntent().getStringExtra("PROXY_PACKAGE"); bundle.putString("proxyPackage", stringExtra); try { bundle.putString("proxyPackageVersion", this.e.getPackageManager().getPackageInfo(stringExtra, 0).versionName); } catch (PackageManager.NameNotFoundException unused2) { bundle.putString("proxyPackageVersion", "package not found"); } } j = 5000; future = j(new d0(this, (!this.o || !z2) ? this.l ? 9 : billingFlowParams.h ? 7 : 6 : 15, skuDetails, e, billingFlowParams, bundle), 5000, null); } else { str3 = str10; str4 = "; try to reconnect"; str = str11; str2 = str14; j = 5000; future = str12 != null ? j(new e0(this, billingFlowParams, skuDetails), 5000, null) : j(new h(this, skuDetails, e), 5000, null); } try { Bundle bundle2 = (Bundle) future.get(j, TimeUnit.MILLISECONDS); str6 = str; try { int d = c.i.a.f.h.n.a.d(bundle2, str6); String e2 = c.i.a.f.h.n.a.e(bundle2, str6); if (d != 0) { StringBuilder sb2 = new StringBuilder(52); sb2.append("Unable to buy item, Error response code: "); sb2.append(d); c.i.a.f.h.n.a.b(str6, sb2.toString()); BillingResult billingResult5 = new BillingResult(); billingResult5.a = d; billingResult5.b = e2; this.d.b.a.onPurchasesUpdated(billingResult5, null); return billingResult5; } Intent intent = new Intent(activity, ProxyBillingActivity.class); intent.putExtra(str3, (PendingIntent) bundle2.getParcelable(str3)); activity.startActivity(intent); return q.i; } catch (CancellationException | TimeoutException unused3) { str7 = str4; str5 = str2; StringBuilder sb3 = new StringBuilder(String.valueOf(str5).length() + 68); sb3.append("Time out while launching billing flow: ; for sku: "); sb3.append(str5); sb3.append(str7); c.i.a.f.h.n.a.b(str6, sb3.toString()); BillingResult billingResult6 = q.k; this.d.b.a.onPurchasesUpdated(billingResult6, null); return billingResult6; } catch (Exception unused4) { StringBuilder sb4 = new StringBuilder(String.valueOf(str2).length() + 69); sb4.append("Exception while launching billing flow: ; for sku: "); sb4.append(str2); sb4.append(str4); c.i.a.f.h.n.a.b(str6, sb4.toString()); BillingResult billingResult7 = q.j; this.d.b.a.onPurchasesUpdated(billingResult7, null); return billingResult7; } } catch (CancellationException | TimeoutException unused5) { str7 = str4; str5 = str2; str6 = str; StringBuilder sb3 = new StringBuilder(String.valueOf(str5).length() + 68); sb3.append("Time out while launching billing flow: ; for sku: "); sb3.append(str5); sb3.append(str7); c.i.a.f.h.n.a.b(str6, sb3.toString()); BillingResult billingResult6 = q.k; this.d.b.a.onPurchasesUpdated(billingResult6, null); return billingResult6; } catch (Exception unused6) { } } else { c.i.a.f.h.n.a.b(str11, "Current client doesn't support multi-item purchases."); BillingResult billingResult8 = q.n; this.d.b.a.onPurchasesUpdated(billingResult8, null); return billingResult8; } } else { c.i.a.f.h.n.a.b(str11, "Current client doesn't support subscriptions."); BillingResult billingResult9 = q.l; this.d.b.a.onPurchasesUpdated(billingResult9, null); return billingResult9; } } @Override // com.android.billingclient.api.BillingClient public final Purchase.a e(String str) { if (!c()) { return new Purchase.a(q.j, null); } if (TextUtils.isEmpty(str)) { c.i.a.f.h.n.a.b("BillingClient", "Please provide a valid SKU type."); return new Purchase.a(q.e, null); } try { return (Purchase.a) j(new i(this, str), 5000, null).get(5000, TimeUnit.MILLISECONDS); } catch (CancellationException | TimeoutException unused) { return new Purchase.a(q.k, null); } catch (Exception unused2) { return new Purchase.a(q.h, null); } } @Override // com.android.billingclient.api.BillingClient public final void f(f fVar, g gVar) { if (!c()) { gVar.onSkuDetailsResponse(q.j, null); return; } String str = fVar.a; List list = fVar.b; if (TextUtils.isEmpty(str)) { c.i.a.f.h.n.a.b("BillingClient", "Please fix the input params. SKU type can't be empty."); gVar.onSkuDetailsResponse(q.e, null); } else if (list != null) { ArrayList arrayList = new ArrayList(); for (String str2 : list) { if (!TextUtils.isEmpty(str2)) { arrayList.add(new s(str2)); } else { throw new IllegalArgumentException("SKU must be set."); } } if (j(new k(this, str, arrayList, gVar), 30000, new v(gVar)) == null) { gVar.onSkuDetailsResponse(i(), null); } } else { c.i.a.f.h.n.a.b("BillingClient", "Please fix the input params. The list of SKUs can't be empty - set SKU list or SkuWithOffer list."); gVar.onSkuDetailsResponse(q.d, null); } } @Override // com.android.billingclient.api.BillingClient public final void g(b bVar) { ServiceInfo serviceInfo; if (c()) { c.i.a.f.h.n.a.a("BillingClient", "Service connection is valid. No need to re-initialize."); bVar.onBillingSetupFinished(q.i); return; } int i = this.a; if (i == 1) { c.i.a.f.h.n.a.b("BillingClient", "Client is already in the process of connecting to billing service."); bVar.onBillingSetupFinished(q.f352c); } else if (i == 3) { c.i.a.f.h.n.a.b("BillingClient", "Client was already closed and can't be reused. Please create another instance."); bVar.onBillingSetupFinished(q.j); } else { this.a = 1; u uVar = this.d; t tVar = uVar.b; Context context = uVar.a; IntentFilter intentFilter = new IntentFilter("com.android.vending.billing.PURCHASES_UPDATED"); if (!tVar.b) { context.registerReceiver(tVar.f354c.b, intentFilter); tVar.b = true; } c.i.a.f.h.n.a.a("BillingClient", "Starting in-app billing setup."); this.g = new o(this, bVar); Intent intent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); intent.setPackage("com.android.vending"); List queryIntentServices = this.e.getPackageManager().queryIntentServices(intent, 0); if (!(queryIntentServices == null || queryIntentServices.isEmpty() || (serviceInfo = queryIntentServices.get(0).serviceInfo) == null)) { String str = serviceInfo.packageName; String str2 = serviceInfo.name; if (!"com.android.vending".equals(str) || str2 == null) { c.i.a.f.h.n.a.b("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.b); if (this.e.bindService(intent2, this.g, 1)) { c.i.a.f.h.n.a.a("BillingClient", "Service was bonded successfully."); return; } c.i.a.f.h.n.a.b("BillingClient", "Connection to Billing service is blocked."); } } this.a = 0; c.i.a.f.h.n.a.a("BillingClient", "Billing service unavailable on device."); bVar.onBillingSetupFinished(q.b); } } public final void h(Runnable runnable) { if (!Thread.interrupted()) { this.f351c.post(runnable); } } public final BillingResult i() { int i = this.a; return (i == 0 || i == 3) ? q.j : q.h; } @Nullable public final Future j(Callable callable, long j, @Nullable Runnable runnable) { long j2 = (long) (((double) j) * 0.95d); if (this.r == null) { this.r = Executors.newFixedThreadPool(c.i.a.f.h.n.a.a, new y(this)); } try { Future submit = this.r.submit(callable); this.f351c.postDelayed(new z(submit, runnable), j2); return submit; } catch (Exception e) { String valueOf = String.valueOf(e); StringBuilder sb = new StringBuilder(valueOf.length() + 28); sb.append("Async task throws exception "); sb.append(valueOf); c.i.a.f.h.n.a.b("BillingClient", sb.toString()); return null; } } }