package com.facetec.sdk; import android.app.Activity; import android.app.PendingIntent; import android.content.Intent; import android.nfc.NfcAdapter; import android.nfc.NfcManager; import android.nfc.Tag; import android.nfc.tech.IsoDep; import android.os.Build; import com.facetec.sdk.dl; import com.facetec.sdk.dm; import java.io.IOException; import java.lang.ref.WeakReference; import o.nMh; import org.bouncycastle.asn1.cmp.PKIFailureInfo; import org.json.JSONObject; /* loaded from: classes.dex */ public final class dl { private static boolean g = true; private final NfcAdapter c; private IsoDep d; private final WeakReference e; private String f; private c h; private Exception a = null; private dm b = null; private String j = ""; /* loaded from: classes.dex */ public static final class c { public final String b; public final String c; public final String e; } /* loaded from: classes.dex */ public interface d { void c(dm dmVar, String str); void e(); } final native String nativeStartReading(String str, String str2, String str3); final native String nativeStartReadingWithKey(String str); final native void nativeUpdateErrorHistory(String str, String str2); public static dl d(Activity activity) { NfcAdapter c2 = c(activity); if (c2 == null) { return null; } return new dl(c2, activity); } public static boolean e(Activity activity) { return nMh.checkSelfPermission(activity, "android.permission.NFC") == 0 && c(activity) != null; } public static boolean a(Activity activity) { NfcAdapter c2; return nMh.checkSelfPermission(activity, "android.permission.NFC") == 0 && (c2 = c(activity)) != null && c2.isEnabled(); } private static NfcAdapter c(Activity activity) { NfcManager nfcManager = (NfcManager) activity.getSystemService("nfc"); if (nfcManager == null) { return null; } return nfcManager.getDefaultAdapter(); } private dl(NfcAdapter nfcAdapter, Activity activity) { this.c = nfcAdapter; this.e = new WeakReference<>(activity); } public final boolean b(Class cls, String str) { Activity activity = this.e.get(); if (activity == null) { return false; } this.f = str; Intent intent = new Intent(activity, cls); intent.addFlags(PKIFailureInfo.duplicateCertReq); this.c.enableForegroundDispatch(activity, PendingIntent.getActivity(activity, 0, intent, Build.VERSION.SDK_INT >= 31 ? 167772160 : 134217728), null, new String[][]{new String[]{"android.nfc.tech.IsoDep"}}); return true; } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void d(d dVar, dm dmVar) { dVar.c(dmVar, this.j); } public final boolean b(Intent intent, final d dVar) { if (!"android.nfc.action.TECH_DISCOVERED".equals(intent.getAction())) { return false; } this.d = IsoDep.get((Tag) intent.getExtras().getParcelable("android.nfc.extra.TAG")); new Thread(new Runnable(this, dVar) { // from class: com.facetec.sdk.dl$$ExternalSyntheticLambda2 public final dl f$0; public final dl.d f$1; @Override // java.lang.Runnable public final void run() { this.f$0.a(this.f$1); } { this.f$0 = this; this.f$1 = dVar; } }).start(); return true; } public final void e() { Activity activity = this.e.get(); if (activity != null) { this.c.disableForegroundDispatch(activity); } } final byte[] sendCommand(byte[] bArr) { this.a = null; try { if (!this.d.isConnected()) { this.d.connect(); } return this.d.transceive(bArr); } catch (IOException e2) { this.a = e2; return null; } } final void setNativeError(int i, String str) { this.j = str; if (i == 1) { this.b = dm.Unknown; return; } if (i == 2) { this.b = dm.InvalidMrzKey; return; } if (i == 3) { this.b = dm.ResponseError; return; } if (i == 4) { this.b = dm.UnknownRetry; } else if (i == 5) { this.b = dm.IncompatibleDoc; } else { if (!g) { throw new AssertionError(); } this.b = dm.Unknown; } } /* loaded from: classes.dex */ public static final class e { private JSONObject c; public e(JSONObject jSONObject) { this.c = jSONObject; } } /* JADX INFO: Access modifiers changed from: private */ public /* synthetic */ void a(final d dVar) { final dm dmVar; String nativeStartReading; Activity activity = this.e.get(); if (activity != null) { this.a = null; this.b = null; this.j = ""; try { String str = this.f; if (str != null && !str.isEmpty()) { nativeStartReading = nativeStartReadingWithKey(this.f); } else { nativeStartReading = nativeStartReading(this.h.b, this.h.c, this.h.e); } } catch (Throwable unused) { dmVar = dm.Unknown; } if (nativeStartReading != null) { final e eVar = new e(new JSONObject(nativeStartReading)); activity.runOnUiThread(new Runnable(dVar, eVar) { // from class: com.facetec.sdk.dl$$ExternalSyntheticLambda0 public final dl.d f$0; public final dl.e f$1; @Override // java.lang.Runnable public final void run() { dl.d dVar2 = this.f$0; dl.e eVar2 = this.f$1; dVar2.e(); } { this.f$0 = dVar; this.f$1 = eVar; } }); return; } if (this.a != null) { dmVar = dm.ConnectionError; } else { dmVar = this.b; if (dmVar == null) { dmVar = dm.Unknown; } } int i = dm.AnonymousClass3.b[dmVar.ordinal()]; nativeUpdateErrorHistory(i != 2 ? i != 3 ? i != 4 ? i != 5 ? i != 6 ? "Unknown" : "IncompatibleDoc" : "UnknownRetry" : "ConnectionError" : "ResponseError" : "InvalidMrzKey", this.j); activity.runOnUiThread(new Runnable(this, dVar, dmVar) { // from class: com.facetec.sdk.dl$$ExternalSyntheticLambda1 public final dl f$0; public final dl.d f$1; public final dm f$2; @Override // java.lang.Runnable public final void run() { this.f$0.d(this.f$1, this.f$2); } { this.f$0 = this; this.f$1 = dVar; this.f$2 = dmVar; } }); } } }