package com.overlook.android.fing.ui.purchase; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.IntentSender; import android.util.Log; import com.huawei.hms.iap.Iap; import com.huawei.hms.iap.IapApiException; import com.huawei.hms.iap.entity.InAppPurchaseData; import com.huawei.hms.iap.entity.IsEnvReadyResult; import com.huawei.hms.iap.entity.OwnedPurchasesReq; import com.huawei.hms.iap.entity.OwnedPurchasesResult; import com.huawei.hms.iap.entity.ProductInfo; import com.huawei.hms.iap.entity.ProductInfoReq; import com.huawei.hms.iap.entity.ProductInfoResult; import com.huawei.hms.iap.entity.PurchaseIntentReq; import com.huawei.hms.iap.entity.PurchaseIntentResult; import com.huawei.hms.support.api.client.Status; import com.overlook.android.fing.engine.FingService; import com.overlook.android.fing.ui.purchase.t1; import e.e.b.a.i; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import org.json.JSONException; import org.json.JSONObject; /* compiled from: HmsStoreClient */ public class l1 extends t1 { /* renamed from: f reason: collision with root package name */ private final List<ProductInfo> f17915f = new ArrayList(); /* renamed from: g reason: collision with root package name */ private final List<InAppPurchaseData> f17916g = new ArrayList(); /* renamed from: h reason: collision with root package name */ private final List<InAppPurchaseData> f17917h = new ArrayList(); /* renamed from: i reason: collision with root package name */ private ProductInfo f17918i; private boolean j; private boolean k; private boolean l; private long m; /* access modifiers changed from: private */ /* compiled from: HmsStoreClient */ public static class a extends t1.a { /* renamed from: d reason: collision with root package name */ private final InAppPurchaseData f17919d; public a(String str, String str2, InAppPurchaseData inAppPurchaseData) { super(str, str2, inAppPurchaseData.getProductId()); this.f17919d = inAppPurchaseData; } /* access modifiers changed from: protected */ @Override // com.overlook.android.fing.ui.purchase.t1.a public JSONObject a() throws JSONException { JSONObject a2 = super.a(); a2.put("hmsAccountFlag", this.f17919d.getAccountFlag()); return a2; } } public l1(Context context, FingService fingService, List<String> list, u1 u1Var) { super(context, fingService, list, u1Var); Log.i("fing:hms-store", "Initializing HMS purchase store"); Iap.getIapClient(context).isEnvReady().addOnSuccessListener(new i0(this)).addOnFailureListener(new m0(this)); } private void G(Runnable runnable, Runnable runnable2) { w wVar = new w(this, runnable, null); h0 h0Var = new h0(this, runnable, null); Log.i("fing:hms-store", "Retrieving purchases history records..."); OwnedPurchasesReq ownedPurchasesReq = new OwnedPurchasesReq(); ownedPurchasesReq.setPriceType(2); i<OwnedPurchasesResult> obtainOwnedPurchaseRecord = Iap.getIapClient(this).obtainOwnedPurchaseRecord(ownedPurchasesReq); obtainOwnedPurchaseRecord.addOnSuccessListener(new z(this, wVar)); obtainOwnedPurchaseRecord.addOnFailureListener(new f0(h0Var)); } /* access modifiers changed from: private */ /* renamed from: H */ public void C(Runnable runnable, Runnable runnable2) { Log.i("fing:hms-store", "Retrieving purchases from Huawei store..."); OwnedPurchasesReq ownedPurchasesReq = new OwnedPurchasesReq(); ownedPurchasesReq.setPriceType(2); i<OwnedPurchasesResult> obtainOwnedPurchases = Iap.getIapClient(this).obtainOwnedPurchases(ownedPurchasesReq); obtainOwnedPurchases.addOnSuccessListener(new b0(this, runnable, runnable2)); obtainOwnedPurchases.addOnFailureListener(new k0(this, runnable2)); } private static ProductInfo u(String str, List<ProductInfo> list) { for (ProductInfo productInfo : list) { if (str.equals(productInfo.getProductId())) { return productInfo; } } return null; } public /* synthetic */ void A() { G(null, null); } public void D(Runnable runnable, ProductInfoResult productInfoResult) { List<ProductInfo> productInfoList = productInfoResult.getProductInfoList(); ArrayList arrayList = new ArrayList(); for (ProductInfo productInfo : productInfoList) { arrayList.add(productInfo.getProductId()); } Log.i("fing:hms-store", "Retrieved products from Huawei store: " + arrayList); this.f17915f.clear(); this.f17915f.addAll(productInfoList); this.f17995d.f0(s1.HUAWEI, v()); if (runnable != null) { runnable.run(); } } public /* synthetic */ void E(Runnable runnable, Exception exc) { int statusCode = exc instanceof IapApiException ? ((IapApiException) exc).getStatusCode() : -1; Log.e("fing:hms-store", "Failed to retrieve purchases from Huawei store (code=" + statusCode + ")", exc); this.m = System.currentTimeMillis() + 14400000; this.l = false; f(); if (runnable != null) { runnable.run(); } } public /* synthetic */ void F(Runnable runnable, OwnedPurchasesResult ownedPurchasesResult) { this.f17917h.clear(); ArrayList arrayList = new ArrayList(); if (!(ownedPurchasesResult == null || ownedPurchasesResult.getInAppPurchaseDataList() == null)) { for (int i2 = 0; i2 < ownedPurchasesResult.getInAppPurchaseDataList().size(); i2++) { try { InAppPurchaseData inAppPurchaseData = new InAppPurchaseData(ownedPurchasesResult.getInAppPurchaseDataList().get(i2)); arrayList.add(inAppPurchaseData.getProductId()); this.f17917h.add(inAppPurchaseData); } catch (JSONException unused) { } } } Log.i("fing:hms-store", "Retrieved purchase history records: " + arrayList); if (runnable != null) { runnable.run(); } } @Override // com.overlook.android.fing.ui.purchase.t1 public boolean a() { return this.j; } @Override // com.overlook.android.fing.ui.purchase.t1 public boolean b(String str) { return this.f17917h.isEmpty(); } @Override // com.overlook.android.fing.ui.purchase.t1 public boolean c() { return this.f17917h.isEmpty(); } @Override // com.overlook.android.fing.ui.purchase.t1 public void d(Activity activity, Intent intent) { s1 s1Var = s1.HUAWEI; ProductInfo productInfo = this.f17918i; if (productInfo != null) { this.f17918i = null; StringBuilder E = e.a.a.a.a.E("Resuming purchase workflow for product "); E.append(productInfo.getProductId()); Log.d("fing:hms-store", E.toString()); int returnCode = Iap.getIapClient(activity).parsePurchaseResultInfoFromIntent(intent).getReturnCode(); if (returnCode == -1) { StringBuilder E2 = e.a.a.a.a.E("Purchase of "); E2.append(productInfo.getProductId()); E2.append(" failed"); Log.e("fing:hms-store", E2.toString()); this.f17995d.O(s1Var, m1.p(productInfo), -1); G(null, null); } else if (returnCode == 0) { StringBuilder E3 = e.a.a.a.a.E("Purchase of "); E3.append(productInfo.getProductId()); E3.append(" completed"); Log.d("fing:hms-store", E3.toString()); G(new j0(this, productInfo), null); } else if (returnCode == 60000) { StringBuilder E4 = e.a.a.a.a.E("Purchase of "); E4.append(productInfo.getProductId()); E4.append(" has been cancelled by the user"); Log.d("fing:hms-store", E4.toString()); this.f17995d.b0(s1Var, m1.p(productInfo)); } else if (returnCode == 60051) { StringBuilder E5 = e.a.a.a.a.E("Purchase of "); E5.append(productInfo.getProductId()); E5.append(" failed because the user already owns the product"); Log.w("fing:hms-store", E5.toString()); G(null, null); } } } @Override // com.overlook.android.fing.ui.purchase.t1 public List<m1> g(List<String> list) { ArrayList arrayList = new ArrayList(); for (ProductInfo productInfo : this.f17915f) { if (list.contains(productInfo.getProductId())) { arrayList.add(m1.p(productInfo)); } } Collections.sort(arrayList, new c0(list)); return Collections.unmodifiableList(arrayList); } @Override // com.overlook.android.fing.ui.purchase.t1 public o1 h(String str) { for (InAppPurchaseData inAppPurchaseData : this.f17916g) { if (str.equals(inAppPurchaseData.getProductId())) { ProductInfo u = u(inAppPurchaseData.getProductId(), this.f17915f); if (u == null) { return null; } return o1.h(u, inAppPurchaseData); } } return null; } @Override // com.overlook.android.fing.ui.purchase.t1 public List<o1> i() { ArrayList arrayList = new ArrayList(); for (InAppPurchaseData inAppPurchaseData : this.f17916g) { ProductInfo u = u(inAppPurchaseData.getProductId(), this.f17915f); if (u != null) { arrayList.add(o1.h(u, inAppPurchaseData)); } } return Collections.unmodifiableList(arrayList); } @Override // com.overlook.android.fing.ui.purchase.t1 public s1 j() { return s1.HUAWEI; } @Override // com.overlook.android.fing.ui.purchase.t1 public String k() { return "https://app.fing.com/purchase/validate_huawei"; } @Override // com.overlook.android.fing.ui.purchase.t1 public boolean l() { return this.k; } @Override // com.overlook.android.fing.ui.purchase.t1 public void m(Activity activity, m1 m1Var) { StringBuilder E = e.a.a.a.a.E("Purchasing product product "); E.append(m1Var.c()); Log.d("fing:hms-store", E.toString()); PurchaseIntentReq purchaseIntentReq = new PurchaseIntentReq(); purchaseIntentReq.setProductId(m1Var.c()); purchaseIntentReq.setPriceType(2); Iap.getIapClient(activity).createPurchaseIntent(purchaseIntentReq).addOnSuccessListener(new a0(this, m1Var, activity)).addOnFailureListener(new e0(this, m1Var)); } @Override // com.overlook.android.fing.ui.purchase.t1 public void p() { } @Override // com.overlook.android.fing.ui.purchase.t1 public void q(boolean z) { if (this.l) { Log.v("fing:hms-store", "Not running sync because engine is already synchronizing!"); return; } if (!z) { long j2 = this.m; if (j2 != 0 && j2 > System.currentTimeMillis()) { Log.v("fing:hms-store", "Not running sync because it was run less than 240 mins ago!"); return; } } Log.d("fing:hms-store", "Running sync (force=" + z + ")"); this.m = System.currentTimeMillis() + 14400000; this.l = true; if (this.f17915f.isEmpty() || z) { g0 g0Var = new g0(this); n0 n0Var = new n0(this); StringBuilder E = e.a.a.a.a.E("Requesting products from Huawei store: "); E.append(this.f17994c); Log.i("fing:hms-store", E.toString()); ProductInfoReq productInfoReq = new ProductInfoReq(); productInfoReq.setPriceType(2); productInfoReq.setProductIds(this.f17994c); i<ProductInfoResult> obtainProductInfo = Iap.getIapClient(this).obtainProductInfo(productInfoReq); obtainProductInfo.addOnSuccessListener(new d0(this, g0Var)); obtainProductInfo.addOnFailureListener(new l0(this, n0Var)); return; } G(null, null); } public List<m1> v() { ArrayList arrayList = new ArrayList(); for (ProductInfo productInfo : this.f17915f) { arrayList.add(m1.p(productInfo)); } return Collections.unmodifiableList(arrayList); } public void w(ProductInfo productInfo) { InAppPurchaseData inAppPurchaseData; String productId = productInfo.getProductId(); Iterator<InAppPurchaseData> it = this.f17916g.iterator(); while (true) { if (!it.hasNext()) { inAppPurchaseData = null; break; } inAppPurchaseData = it.next(); if (productId.equals(inAppPurchaseData.getProductId())) { break; } } if (inAppPurchaseData != null) { this.f17995d.Y(s1.HUAWEI, o1.h(productInfo, inAppPurchaseData)); } } public /* synthetic */ void x(IsEnvReadyResult isEnvReadyResult) { this.j = isEnvReadyResult.getReturnCode() == 0; this.k = true; q(true); } public /* synthetic */ void y(Exception exc) { this.j = false; this.k = true; } public void z(m1 m1Var, Activity activity, PurchaseIntentResult purchaseIntentResult) { Status status = purchaseIntentResult.getStatus(); if (status.hasResolution()) { try { this.f17918i = u(m1Var.c(), this.f17915f); status.startResolutionForResult(activity, 6666); } catch (IntentSender.SendIntentException e2) { StringBuilder E = e.a.a.a.a.E("Failed to purchase product "); E.append(m1Var.c()); Log.e("fing:hms-store", E.toString(), e2); this.f17995d.O(s1.HUAWEI, m1Var, -1); } } } }