package K.K.㸾.K;

import ai.advance.core.LServiceParent;
import ai.advance.liveness.lib.Detector;
import ai.advance.liveness.lib.http.entity.ResultEntity;
import ai.advance.liveness.lib.l;
import android.content.Context;
import android.text.TextUtils;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ArrayBlockingQueue;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import ඓ.K.K.K.C1293;
import K.K.ʬ.AbstractC2357;
import K.K.K.ʬ.C2367;

/* renamed from: K.K.㸾.K.ᕣ  reason: contains not printable characters */
public class C2386 extends AbstractC2357 {

    /* renamed from: ᓆ  reason: contains not printable characters */
    public static int f8259;

    /* renamed from: 㶋  reason: contains not printable characters */
    public static int f8260;

    /* renamed from: Ԕ  reason: contains not printable characters */
    public JSONArray f8261;

    /* renamed from: Ԛ  reason: contains not printable characters */
    public boolean f8262;

    /* renamed from: ؿ  reason: contains not printable characters */
    public Detector.ActionStatus f8263;

    /* renamed from: ݜ  reason: contains not printable characters */
    public Map<String, Integer> f8264;

    /* renamed from: ᓣ  reason: contains not printable characters */
    public long f8265;

    /* renamed from: ᕣ  reason: contains not printable characters */
    public Detector.DetectionType f8266;

    /* renamed from: 㑃  reason: contains not printable characters */
    public boolean f8267 = false;

    /* renamed from: 㗗  reason: contains not printable characters */
    public int f8268 = 0;

    /* renamed from: 㗽  reason: contains not printable characters */
    public long f8269;

    /* renamed from: 㳳  reason: contains not printable characters */
    public List<JSONObject> f8270;

    /* renamed from: 䀟  reason: contains not printable characters */
    public ArrayBlockingQueue<C2385> f8271;

    /* renamed from: 䁗  reason: contains not printable characters */
    public long f8272;

    /* JADX INFO: super call moved to the top of the method (can break code semantics) */
    public C2386(Context context) {
        super(context, "LIVENESS_DETECTION", "1.2.9");
        C2388.m6423();
    }

    @Override // K.K.ʬ.AbstractC2357
    /* renamed from: ʬ  reason: contains not printable characters */
    public String m6390() {
        return C2387.m6420();
    }

    @Override // K.K.ʬ.AbstractC2357
    /* renamed from: ඓ  reason: contains not printable characters */
    public String m6391() {
        C2388.m6428();
        return "1.2.9";
    }

    /* renamed from: ᕣ  reason: contains not printable characters */
    public final void m6392() {
        List<JSONObject> list;
        if (this.f8170 != null) {
            Map<String, Integer> map = this.f8264;
            if (map != null) {
                JSONObject jSONObject = new JSONObject();
                if (map != null && !map.isEmpty()) {
                    for (String str : map.keySet()) {
                        Integer num = map.get(str);
                        try {
                            JSONArray r5 = C2367.m6263(num);
                            if (r5 == null) {
                                jSONObject.put(str.toString(), num);
                            } else {
                                jSONObject.put(str.toString(), r5);
                            }
                        } catch (JSONException e) {
                            e.getMessage();
                        }
                    }
                }
                try {
                    this.f8170.putOpt("prepare_log", jSONObject);
                } catch (JSONException unused) {
                }
            }
            if (!this.f8262 && (list = this.f8270) != null && list.size() > 0) {
                JSONArray jSONArray = new JSONArray();
                for (int i = 0; i < this.f8270.size(); i++) {
                    jSONArray.put(this.f8270.get(i));
                }
                try {
                    this.f8170.putOpt("action_log", jSONArray);
                } catch (JSONException unused2) {
                }
            }
        }
    }

    /* renamed from: ᨨ  reason: contains not printable characters */
    public final void m6393() {
        if (this.f8272 != 0) {
            m6183("upload_picture_duration", Long.valueOf(System.currentTimeMillis() - this.f8272));
        }
    }

    /* renamed from: ⁱ  reason: contains not printable characters */
    public JSONObject m6394() {
        ArrayBlockingQueue<C2385> arrayBlockingQueue;
        JSONObject r0 = super.m6180(this.f8170);
        if (r0 == null) {
            return new JSONObject();
        }
        try {
            m6392();
            Detector.ActionStatus actionStatus = this.f8263;
            if (actionStatus != null && actionStatus.isFaceNotReady() && (arrayBlockingQueue = this.f8271) != null && arrayBlockingQueue.size() > 0) {
                C2394.f8285.addAll(0, this.f8271);
                this.f8271.clear();
            }
            if (this.f8270 != null) {
                this.f8270.clear();
            }
            if (this.f8264 != null) {
                this.f8264.clear();
            }
        } catch (Exception unused) {
        }
        return r0;
    }

    @Override // K.K.ʬ.AbstractC2357, ai.advance.event.GuardianEvents
    @Deprecated
    /* renamed from: K  reason: contains not printable characters */
    public JSONObject m6395(JSONObject jSONObject) {
        return super.m6180(jSONObject);
    }

    @Override // ai.advance.event.GuardianEvents
    /* renamed from: K  reason: contains not printable characters */
    public void m6396() {
        this.f8269 = System.currentTimeMillis();
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m6397(Detector.DetectionFailedType detectionFailedType) {
        f8260++;
        m6183("failed_times", Integer.valueOf(f8260));
        m6402();
        m6183("failed_reason", (m6401() + "_" + detectionFailedType.name()).toLowerCase());
        m6183("sdk_detection_success", false);
        m6183("final_success", false);
        this.f8268 = 0;
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m6400(boolean z) {
        m6183("ui_callback_result", Boolean.valueOf(z));
    }

    /* renamed from: 㑃  reason: contains not printable characters */
    public final String m6401() {
        Detector.DetectionType detectionType = this.f8266;
        return detectionType != null ? detectionType.name().toLowerCase() : "";
    }

    /* renamed from: 㳳  reason: contains not printable characters */
    public final void m6402() {
        String r0 = m6401();
        m6183(C1293.m3412(r0, "_detection_frame_count"), Integer.valueOf(this.f8268));
        m6183(r0 + "_duration", Long.valueOf(System.currentTimeMillis() - this.f8265));
    }

    /* renamed from: 㴹  reason: contains not printable characters */
    public void m6403() {
        m6183("prepare_duration", Long.valueOf(System.currentTimeMillis() - this.f8269));
    }

    @Override // K.K.ʬ.AbstractC2357
    /* renamed from: 㸾  reason: contains not printable characters */
    public String m6404() {
        return C2388.m6422();
    }

    /* renamed from: 㿎  reason: contains not printable characters */
    public void m6405() {
        f8259++;
        m6183("give_up_times", Integer.valueOf(f8259));
        Detector.ActionStatus actionStatus = this.f8263;
        if (actionStatus == null || !actionStatus.isFaceNotReady()) {
            C2383.m6379(this.f8266);
            m6183("failed_reason", m6401() + "_give_up");
            m6402();
            return;
        }
        C2383.m6381(l.PREPARE);
        m6183("prepare_duration", Long.valueOf(System.currentTimeMillis() - this.f8269));
        m6183("failed_reason", "prepare_give_up");
    }

    /* renamed from: 䁗  reason: contains not printable characters */
    public void m6406() {
        try {
            m6393();
            if (this.f8169 != 0) {
                m6183("auth_duration", Long.valueOf(System.currentTimeMillis() - this.f8169));
            }
            if (this.f8171) {
                m6183("failed_reason", "auth_give_up");
                C2383.m6381(l.AUTH);
            }
            if (this.f8261 != null) {
                m6183("success_action_list", this.f8261);
            }
            if (this.f8267) {
                C2383.m6381(l.CHECKING);
                m6183("failed_reason", "upload_picture_give_up");
            }
            if (this.f8170 != null) {
                JSONObject r0 = C2387.m6408();
                Iterator<String> keys = r0.keys();
                while (keys.hasNext()) {
                    String next = keys.next();
                    this.f8170.put(next, r0.optString(next));
                }
            }
        } catch (Exception unused) {
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m6398(ResultEntity resultEntity) {
        try {
            m6183("failed_times", Integer.valueOf(f8260));
            f8260 = 0;
            m6183("server_detection_success", Boolean.valueOf(resultEntity.f8209));
            m6183("final_success", Boolean.valueOf(resultEntity.f8209));
            m6183("liveness_id", C2383.f8244);
            if ("NO_RESPONSE".equals(resultEntity.f8212)) {
                m6183("failed_reason", "picture_upload_failed");
            } else if (!resultEntity.f8209) {
                m6183("server_detection_failed_message", resultEntity.f8214);
            }
            m6393();
        } catch (Exception unused) {
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m6399(JSONObject jSONObject, C2385 r5, Detector.ActionStatus actionStatus, int i) {
        ArrayBlockingQueue<C2385> arrayBlockingQueue;
        this.f8263 = actionStatus;
        if (actionStatus != null) {
            Detector.ActionStatus actionStatus2 = this.f8263;
            if (actionStatus2 != null && actionStatus2.isFaceNotReady()) {
                if (this.f8264 == null) {
                    this.f8264 = new HashMap();
                }
                String lowerCase = this.f8263.name().toLowerCase();
                this.f8264.put(lowerCase, Integer.valueOf((this.f8264.containsKey(lowerCase) ? this.f8264.get(lowerCase).intValue() : 0) + 1));
            }
            boolean isFaceNotReady = this.f8263.isFaceNotReady();
            if (jSONObject != null) {
                String optString = jSONObject.optString("log");
                if (!TextUtils.isEmpty(optString)) {
                    try {
                        if (C2367.m6265(optString) && !isFaceNotReady) {
                            JSONObject jSONObject2 = new JSONObject(optString);
                            jSONObject2.putOpt("det_time", Integer.valueOf(i));
                            if (this.f8270 == null) {
                                this.f8270 = new ArrayList();
                            }
                            this.f8270.add(jSONObject2);
                            this.f8268++;
                        }
                    } catch (Exception unused) {
                    }
                }
                boolean optBoolean = jSONObject.optBoolean("snapshot", false);
                if (LServiceParent.f37) {
                    if (optBoolean && r5 != null) {
                        Detector.ActionStatus actionStatus3 = this.f8263;
                        if (actionStatus3 == null || !actionStatus3.isFaceNotReady()) {
                            C2394.f8285.add(r5);
                        } else {
                            if (this.f8271 == null) {
                                this.f8271 = new ArrayBlockingQueue<>(20);
                            }
                            if (this.f8271.size() >= 20) {
                                this.f8271.poll();
                            }
                            this.f8271.add(r5);
                        }
                    }
                    Detector.ActionStatus actionStatus4 = this.f8263;
                    if (actionStatus4 != null && !actionStatus4.isFaceNotReady() && (arrayBlockingQueue = this.f8271) != null) {
                        arrayBlockingQueue.clear();
                    }
                }
            }
        }
    }
}
