package com.bytedance.sdk.openadsdk.yz;

import android.content.Context;
import android.graphics.Bitmap;
import android.os.SystemClock;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.webkit.JavascriptInterface;
import android.webkit.WebBackForwardList;
import android.webkit.WebView;
import androidx.media3.common.MimeTypes;
import androidx.media3.exoplayer.rtsp.SessionDescription;
import androidx.media3.exoplayer.upstream.CmcdConfiguration;
import com.bytedance.sdk.openadsdk.TTAdConstant;
import com.bytedance.sdk.openadsdk.core.model.ai;
import com.bytedance.sdk.openadsdk.core.model.lse;
import com.bytedance.sdk.openadsdk.core.model.wey;
import com.bytedance.sdk.openadsdk.core.widget.fm.wsy;
import com.bytedance.sdk.openadsdk.utils.bx;
import com.bytedance.sdk.openadsdk.utils.xgn;
import com.bytedance.sdk.openadsdk.utils.zan;
import java.io.IOException;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import org.json.JSONException;
import org.json.JSONObject;
import tv.danmaku.ijk.media.player.IjkMediaPlayer;

/* JADX INFO: loaded from: classes2.dex */
public class dsz {

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private static final int[] f7596lb = {10, 30, 50, 75, 100};
    private final AtomicBoolean ado;
    private long ai;
    private int ajl;
    private volatile long bkb;
    private String bwv;
    private boolean bx;
    private String dsz;
    private boolean duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private final AtomicBoolean f7597ef;
    private final Context fhx;
    public wsy.fm fm;

    /* JADX INFO: renamed from: gc, reason: collision with root package name */
    private WeakReference<WebView> f7598gc;
    private com.bytedance.sdk.openadsdk.maa.wu gof;
    private ef gqi;
    private long gzf;

    /* JADX INFO: renamed from: ha, reason: collision with root package name */
    private boolean f7599ha;
    private final lse hi;
    private int hlt;
    private final int[] hxv;

    /* JADX INFO: renamed from: ib, reason: collision with root package name */
    private volatile int f7600ib;
    private com.bytedance.sdk.openadsdk.core.widget.fm.wsy irt;
    private long jnr;
    private int ku;
    private volatile long kwx;
    private volatile long lmk;
    private long lse;
    private final AtomicInteger lz;
    private long maa;
    private long mj;
    private com.bytedance.sdk.openadsdk.yz.yz.jnr mon;
    private final AtomicBoolean mpp;
    private long mq;

    /* JADX INFO: renamed from: ne, reason: collision with root package name */
    private int f7601ne;
    private String nt;
    private long ol;
    private String onz;
    private final boolean pkk;

    /* JADX INFO: renamed from: qf, reason: collision with root package name */
    private final AtomicInteger f7602qf;
    private boolean qhl;
    AtomicBoolean ro;
    private int sds;
    private final AtomicBoolean si;
    private volatile long tzk;
    private final AtomicBoolean vt;
    private String vvj;
    private long wbw;
    private boolean wey;
    private final AtomicBoolean wsy;
    private final AtomicBoolean wu;
    private boolean xgn;
    private boolean ywr;
    private int yz;
    private duv zan;

    public static class fm {
        private final int[] fm;

        public fm(int[] iArr) {
            this.fm = iArr;
        }

        @JavascriptInterface
        public String getUrl() {
            return "";
        }

        @JavascriptInterface
        public void readPercent(String str) {
            int iIntValue;
            try {
                iIntValue = Float.valueOf(str).intValue();
            } catch (Throwable unused) {
            }
            if (iIntValue > 100) {
                iIntValue = 100;
            } else if (iIntValue < 0) {
                iIntValue = 0;
            }
            int[] iArr = this.fm;
            if (iArr == null || iArr.length <= 0) {
                return;
            }
            iArr[0] = iIntValue;
        }
    }

    public dsz(lse lseVar, WebView webView, duv duvVar, int i10) {
        this(lseVar, webView);
        this.zan = duvVar;
        this.f7601ne = i10;
    }

    private boolean ef() {
        lse lseVar;
        return this.bx && (lseVar = this.hi) != null && lseVar.hxv();
    }

    private int vt() {
        WeakReference<WebView> weakReference = this.f7598gc;
        WebView webView = weakReference != null ? weakReference.get() : null;
        if (webView != null) {
            try {
                WebBackForwardList webBackForwardListCopyBackForwardList = webView.copyBackForwardList();
                if (webBackForwardListCopyBackForwardList != null) {
                    if (webBackForwardListCopyBackForwardList.getCurrentIndex() == 0) {
                        return 1;
                    }
                }
            } catch (Throwable unused) {
            }
        }
        return 0;
    }

    public void ajl() {
        if (ef() && this.bkb > 0 && this.lmk > 0 && !this.mpp.getAndSet(true)) {
            lb.ro(this.lmk - this.bkb, this.hi, this.vvj, (String) null);
        }
    }

    public lse fm() {
        return this.hi;
    }

    public void jnr(boolean z10) {
        this.ywr = z10;
    }

    public void lb(boolean z10) {
        this.bx = z10;
    }

    public dsz ro(boolean z10) {
        this.xgn = z10;
        return this;
    }

    public void wsy() {
        if (this.wbw == 0) {
            this.wbw = System.currentTimeMillis();
        }
        this.mq = System.currentTimeMillis();
        if ("landingpage".equals(this.nt) || "landingpage_endcard".equals(this.nt) || "landingpage_split_screen".equals(this.nt) || "landingpage_direct".equals(this.nt) || "aggregate_page".equals(this.nt)) {
            if (this.ado.compareAndSet(false, true)) {
                com.bytedance.sdk.openadsdk.ajl.ro.fm().fm("landingStart", this.hi, this.bwv);
            } else {
                com.bytedance.sdk.openadsdk.ajl.ro.fm().fm("landingContinue", this.hi, this.bwv);
            }
        }
        if (wey.ef(this.hi) || wey.ro(this.hi)) {
            fm(true, SystemClock.elapsedRealtime());
        }
    }

    public void wu() {
        if (("landingpage".equals(this.nt) || "landingpage_endcard".equals(this.nt) || "landingpage_split_screen".equals(this.nt) || "landingpage_direct".equals(this.nt) || "aggregate_page".equals(this.nt) || "landingpage_split_ceiling".equals(this.nt)) && this.ajl == 2) {
            if (this.gzf > 0 || !lb()) {
                long jCurrentTimeMillis = System.currentTimeMillis() - Math.max(this.mq, this.gzf);
                JSONObject jSONObject = new JSONObject();
                try {
                    jSONObject.put("load_status", this.ajl);
                    jSONObject.put("max_scroll_percent", this.hxv[0]);
                    jSONObject.put("jump_times", this.lz.getAndSet(0));
                    jSONObject.put("click_times", this.f7602qf.getAndSet(0));
                    jSONObject.putOpt("render_type", "h5");
                    jSONObject.putOpt("render_type_2", 0);
                } catch (JSONException unused) {
                }
                this.vt.set(true);
                fm("stay_page", jSONObject, Math.min(jCurrentTimeMillis, TTAdConstant.AD_MAX_EVENT_TIME));
                com.bytedance.sdk.openadsdk.ajl.ro.fm().fm("landingPause", this.hi, this.bwv);
            }
        }
    }

    public dsz(lse lseVar, WebView webView) {
        this(lseVar, webView, false);
    }

    public void fm(int i10) {
        this.f7601ne = i10;
    }

    public boolean lb() {
        return this.bx;
    }

    public com.bytedance.sdk.openadsdk.yz.yz.jnr ro() {
        return this.mon;
    }

    public void yz() {
        if (ef()) {
            this.kwx = SystemClock.elapsedRealtime();
            lb.fm(this.hi, this.vvj);
        }
    }

    public dsz(lse lseVar, WebView webView, boolean z10) {
        this.yz = 0;
        this.jnr = -1L;
        this.ajl = 1;
        this.wsy = new AtomicBoolean(false);
        this.wu = new AtomicBoolean(false);
        this.f7597ef = new AtomicBoolean(false);
        this.vt = new AtomicBoolean(false);
        this.ku = -1;
        this.wey = false;
        this.sds = 0;
        this.ro = new AtomicBoolean(false);
        this.nt = "landingpage";
        this.mq = 0L;
        this.gzf = 0L;
        this.ai = 0L;
        this.ol = 0L;
        this.wbw = 0L;
        this.f7599ha = false;
        this.pkk = false;
        int[] iArr = {0};
        this.hxv = iArr;
        this.xgn = false;
        this.bx = false;
        this.tzk = 0L;
        this.lz = new AtomicInteger(0);
        this.f7602qf = new AtomicInteger(0);
        this.si = new AtomicBoolean(false);
        this.f7600ib = 0;
        this.f7601ne = -1;
        this.mpp = new AtomicBoolean(false);
        this.ado = new AtomicBoolean(false);
        this.ywr = false;
        Context contextFm = com.bytedance.sdk.openadsdk.core.gof.fm();
        this.fhx = contextFm;
        this.hi = lseVar;
        if (webView == null) {
            return;
        }
        this.wey = z10;
        WeakReference<WebView> weakReference = new WeakReference<>(webView);
        this.f7598gc = weakReference;
        WebView webView2 = weakReference.get();
        if (webView2 == null) {
            return;
        }
        if (lseVar != null && lseVar.kc()) {
            com.bytedance.sdk.openadsdk.core.widget.fm.wsy wsyVar = new com.bytedance.sdk.openadsdk.core.widget.fm.wsy(webView2, lseVar, contextFm, this.wey);
            this.irt = wsyVar;
            this.fm = wsyVar.lb();
        }
        if (lseVar != null && lseVar.ug() && com.bytedance.sdk.openadsdk.core.settings.ku.ro().lse()) {
            this.gqi = new ef(lseVar, webView, this.wey);
        }
        if (webView instanceof com.bytedance.sdk.component.ef.ajl) {
            this.mj = ((com.bytedance.sdk.component.ef.ajl) webView2).fm;
        } else {
            this.mj = System.currentTimeMillis();
        }
        try {
            webView2.addJavascriptInterface(new fm(iArr), "JS_LANDING_PAGE_LOG_OBJ");
        } catch (Exception e10) {
            com.bytedance.sdk.component.utils.wey.fm("LandingPageLog", "addJavascriptInterface exception", e10);
        }
        if (lseVar != null && lseVar.olu() != null) {
            this.jnr = lseVar.olu().optLong("page_id", -1L);
        }
        this.bwv = String.valueOf(SystemClock.elapsedRealtime());
    }

    public void fm(long j10) {
        this.gzf = j10;
    }

    public void jnr() {
        if (ef()) {
            this.bkb = SystemClock.elapsedRealtime();
            ajl();
        }
    }

    public void fm(com.bytedance.sdk.openadsdk.maa.wu wuVar) {
        this.gof = wuVar;
    }

    public void lb(String str) {
        if (!this.xgn || this.hi == null) {
            return;
        }
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.putOpt("render_type", "h5");
            jSONObject.putOpt("render_type_2", 0);
            int i10 = this.f7601ne;
            if (i10 >= 0) {
                jSONObject.putOpt("preload_status", Integer.valueOf(i10));
            }
            if (TextUtils.isEmpty(str)) {
                str = this.hi.rbn();
            }
            jSONObject.put(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL, str);
        } catch (Exception unused) {
        }
        fm("load_start", jSONObject);
    }

    public void ro(String str) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        this.vvj = str;
    }

    private void ro(String str, String str2, long j10) {
        if (this.f7597ef.compareAndSet(false, true)) {
            JSONObject jSONObject = new JSONObject();
            try {
                if (str.length() > 200) {
                    int iIndexOf = str.indexOf(38, 200);
                    int i10 = 300;
                    if (iIndexOf == -1 || iIndexOf > 300) {
                        iIndexOf = str.indexOf(63);
                    }
                    if (iIndexOf != -1 && iIndexOf <= 300) {
                        i10 = iIndexOf;
                    }
                    str = str.substring(0, i10);
                }
                jSONObject.put(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL, str);
                jSONObject.put("type", str2);
            } catch (Throwable unused) {
            }
            fm("load_finish_progress", jSONObject, j10);
        }
    }

    public void fm(duv duvVar) {
        this.zan = duvVar;
    }

    public void yz(boolean z10) {
        WeakReference<WebView> weakReference = this.f7598gc;
        WebView webView = weakReference != null ? weakReference.get() : null;
        if (webView != null) {
            try {
                webView.removeJavascriptInterface("JS_LANDING_PAGE_LOG_OBJ");
            } catch (Exception e10) {
                com.bytedance.sdk.component.utils.wey.fm("LandingPageLog", "removeJavascriptInterface exception", e10);
            }
        }
        if (this.wu.compareAndSet(false, true)) {
            fm(z10, "1");
            if (this.xgn) {
                lb.fm(this.hi, this.nt, System.currentTimeMillis() - this.wbw, this.f7601ne, vt());
            }
        } else if (this.ajl == 2 && !this.vt.get()) {
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.put("load_status", this.ajl);
                jSONObject.put("max_scroll_percent", this.hxv[0]);
                jSONObject.put("jump_times", this.lz.getAndSet(0));
                jSONObject.put("click_times", this.f7602qf.getAndSet(0));
                jSONObject.putOpt("render_type", "h5");
                jSONObject.putOpt("render_type_2", 0);
            } catch (JSONException unused) {
            }
            fm("stay_page", jSONObject, 0L);
        }
        if ("landingpage".equals(this.nt) || "landingpage_endcard".equals(this.nt) || "landingpage_split_screen".equals(this.nt) || "landingpage_direct".equals(this.nt) || "aggregate_page".equals(this.nt) || "landingpage_split_ceiling".equals(this.nt)) {
            com.bytedance.sdk.openadsdk.ajl.ro.fm().fm("landingFinish", this.hi, this.bwv);
        }
    }

    private String jnr(String str) {
        return "javascript:".concat(String.valueOf(str));
    }

    public void fm(com.bytedance.sdk.openadsdk.yz.yz.jnr jnrVar) {
        this.mon = jnrVar;
    }

    public void fm(boolean z10) {
        if (z10) {
            this.sds = 1;
        }
    }

    public void fm(String str) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        com.bytedance.sdk.openadsdk.core.widget.fm.wsy wsyVar = this.irt;
        if (wsyVar != null) {
            wsyVar.fm(str);
        }
        ef efVar = this.gqi;
        if (efVar != null) {
            efVar.lb(str);
        }
        this.nt = str;
    }

    public void fm(WebView webView, int i10) {
        if (webView == null) {
            return;
        }
        if (this.tzk == 0) {
            this.tzk = SystemClock.elapsedRealtime();
        }
        if (this.ai == 0 && i10 > 0) {
            this.ai = System.currentTimeMillis();
        } else if (this.ol == 0 && i10 == 100) {
            this.ol = System.currentTimeMillis();
        }
        if (this.yz != f7596lb.length && ("landingpage".equals(this.nt) || "landingpage_endcard".equals(this.nt) || "landingpage_split_screen".equals(this.nt) || "landingpage_direct".equals(this.nt) || "aggregate_page".equals(this.nt))) {
            int i11 = this.yz;
            while (true) {
                int[] iArr = f7596lb;
                if (i11 >= iArr.length || i10 < iArr[this.yz]) {
                    break;
                }
                int i12 = i11 + 1;
                this.yz = i12;
                JSONObject jSONObject = new JSONObject();
                try {
                    jSONObject.put(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL, webView.getUrl());
                    long j10 = this.jnr;
                    if (j10 != -1) {
                        jSONObject.put("page_id", j10);
                    }
                    jSONObject.putOpt("render_type", "h5");
                    jSONObject.putOpt("render_type_2", 0);
                    jSONObject.put("pct", iArr[i11]);
                } catch (Exception unused) {
                }
                fm("progress_load_finish", jSONObject);
                i11 = i12;
            }
        }
        if (i10 == 100) {
            fm(false, SystemClock.elapsedRealtime());
            ro(webView.getUrl(), "progress", Math.min(this.ol - this.ai, TTAdConstant.AD_MAX_EVENT_TIME));
        }
    }

    public void ro(WebView webView, String str, boolean z10) {
        ef efVar = this.gqi;
        if (efVar == null || !z10) {
            return;
        }
        efVar.fm(webView, str);
    }

    public void ro(int i10) {
        com.bytedance.sdk.openadsdk.core.widget.fm.wsy wsyVar = this.irt;
        if (wsyVar == null || !this.qhl) {
            return;
        }
        wsyVar.fm(i10);
    }

    public void yz(String str) {
        if (!this.xgn || this.hi == null) {
            return;
        }
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.putOpt("render_type", "h5");
            jSONObject.putOpt("render_type_2", 0);
            int i10 = this.f7601ne;
            if (i10 >= 0) {
                jSONObject.putOpt("preload_status", Integer.valueOf(i10));
            }
            if (TextUtils.isEmpty(str)) {
                str = this.hi.rbn();
            }
            jSONObject.put(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL, str);
        } catch (Exception unused) {
        }
        fm("progress_load_finish", jSONObject);
    }

    public void fm(WebView webView, String str, Bitmap bitmap, boolean z10, int i10) {
        this.qhl = z10;
        this.hlt++;
        com.bytedance.sdk.openadsdk.core.widget.fm.wsy wsyVar = this.irt;
        if (wsyVar != null && z10) {
            wsyVar.ro(str);
            this.irt.ro();
        }
        ef efVar = this.gqi;
        if (efVar != null && z10) {
            efVar.fm(str, i10);
        }
        WeakReference<WebView> weakReference = this.f7598gc;
        WebView webView2 = weakReference != null ? weakReference.get() : null;
        if (webView2 != null) {
            try {
                WebBackForwardList webBackForwardListCopyBackForwardList = webView2.copyBackForwardList();
                if (webBackForwardListCopyBackForwardList != null && webBackForwardListCopyBackForwardList.getCurrentIndex() > this.f7600ib) {
                    this.lz.incrementAndGet();
                }
                this.f7600ib = webBackForwardListCopyBackForwardList.getCurrentIndex();
            } catch (Exception e10) {
                com.bytedance.sdk.component.utils.wey.fm("LandingPageLog", "copyBackForwardList exception", e10);
            }
        }
        if (this.tzk == 0) {
            this.tzk = SystemClock.elapsedRealtime();
        }
        com.bytedance.sdk.openadsdk.yz.yz.jnr jnrVar = this.mon;
        if (jnrVar != null) {
            jnrVar.yz();
        }
        if (this.wsy.compareAndSet(false, true)) {
            JSONObject jSONObject = new JSONObject();
            try {
                jSONObject.putOpt("render_type", "h5");
                jSONObject.putOpt("render_type_2", 0);
                int i11 = this.f7601ne;
                if (i11 >= 0) {
                    jSONObject.putOpt("preload_status", Integer.valueOf(i11));
                }
            } catch (Exception unused) {
            }
            fm("load_start", jSONObject);
        }
    }

    public void fm(WebView webView, String str, boolean z10) {
        fm(false, SystemClock.elapsedRealtime());
        com.bytedance.sdk.openadsdk.core.widget.fm.wsy wsyVar = this.irt;
        if (wsyVar != null && z10) {
            wsyVar.fm();
        }
        com.bytedance.sdk.openadsdk.yz.yz.jnr jnrVar = this.mon;
        if (jnrVar != null) {
            jnrVar.jnr();
        }
        ef efVar = this.gqi;
        if (efVar != null && z10) {
            efVar.fm(str);
        }
        if (webView != null && !this.f7599ha && this.xgn) {
            this.f7599ha = true;
            com.bytedance.sdk.component.utils.onz.fm(webView, "javascript:\nfunction sendScroll(){\n   var totalH = document.body.scrollHeight || document.documentElement.scrollHeight;\n   var clientH = window.innerHeight || document.documentElement.clientHeight;\n   var scrollH = document.body.scrollTop || document.documentElement.scrollTop;\n   var validH = scrollH + clientH;\n   var result = (validH/totalH*100).toFixed(2);\n   console.log('LandingPageLogscroll status: (' + scrollH + '+' + clientH + ')/' + totalH + '=' + result);\n   window.JS_LANDING_PAGE_LOG_OBJ.readPercent(result);\n}\nsendScroll();\nwindow.addEventListener('scroll', function(e){\n    sendScroll();\n});");
        }
        if (this.wu.compareAndSet(false, true)) {
            if (this.ajl != 3) {
                this.ajl = 2;
            }
            this.mq = System.currentTimeMillis();
            boolean z11 = this.ajl == 2;
            int iVt = vt();
            if (z11) {
                long j10 = this.ol - this.ai;
                JSONObject jSONObject = new JSONObject();
                try {
                    jSONObject.put("error_code", this.ku);
                    jSONObject.put("error_msg", this.dsz);
                    jSONObject.put("error_url", this.onz);
                    int i10 = this.f7601ne;
                    if (i10 >= 0) {
                        jSONObject.put("preload_status", i10);
                    }
                    jSONObject.put("first_page", iVt);
                    jSONObject.putOpt("render_type", "h5");
                    jSONObject.putOpt("render_type_2", 0);
                    jSONObject.put(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL, this.hi.rbn());
                    jSONObject.put("preload_h5_type", this.hi.mon());
                } catch (Exception unused) {
                }
                fm(z10, SessionDescription.SUPPORTED_SDP_VERSION);
                long jMin = Math.min(j10, TTAdConstant.AD_MAX_EVENT_TIME);
                fm("load_finish", jSONObject, jMin);
                if (ef()) {
                    this.lmk = SystemClock.elapsedRealtime();
                    ajl();
                    lb.fm(this.hi, this.vvj, this.lmk - this.kwx);
                }
                ro(str, "load_finish", jMin);
                duv duvVar = this.zan;
                if (duvVar != null) {
                    duvVar.fm(iVt);
                    return;
                }
                return;
            }
            JSONObject jSONObject2 = new JSONObject();
            try {
                jSONObject2.put("error_code", this.ku);
                jSONObject2.put("error_msg", this.dsz);
                jSONObject2.put("error_url", this.onz);
                jSONObject2.put("first_page", iVt);
                int i11 = this.f7601ne;
                if (i11 >= 0) {
                    jSONObject2.put("preload_status", i11);
                }
                jSONObject2.putOpt("render_type", "h5");
                jSONObject2.putOpt("render_type_2", 0);
                jSONObject2.put(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL, this.hi.rbn());
                jSONObject2.put("preload_h5_type", this.hi.mon());
            } catch (Exception unused2) {
            }
            fm(z10, "2");
            fm("load_fail", jSONObject2);
            if (ef()) {
                lb.fm(this.hi, this.vvj, SystemClock.elapsedRealtime() - this.kwx, this.ku, this.dsz, this.onz);
            }
            if (this.duv) {
                jSONObject2.remove("render_type");
                jSONObject2.remove("render_type_2");
                fm("load_fail_main", jSONObject2);
            }
        }
    }

    public void fm(WebView webView, int i10, String str, String str2, String str3, boolean z10) {
        com.bytedance.sdk.openadsdk.yz.yz.jnr jnrVar = this.mon;
        if (jnrVar != null) {
            jnrVar.fm((JSONObject) null);
        }
        if ((str3 == null || !str3.startsWith(MimeTypes.BASE_TYPE_IMAGE)) && this.ajl != 2) {
            this.ajl = 3;
        }
        this.ku = i10;
        this.dsz = str;
        this.onz = str2;
        this.duv = z10;
    }

    public void fm(com.bytedance.sdk.component.ef.wsy wsyVar) {
        int iRka;
        Bitmap bitmapFm;
        lse lseVar;
        if ((!"landingpage".equals(this.nt) && !"landingpage_endcard".equals(this.nt) && !"landingpage_split_screen".equals(this.nt) && !"landingpage_direct".equals(this.nt) && !"aggregate_page".equals(this.nt)) || (iRka = com.bytedance.sdk.openadsdk.core.gof.yz().rka()) == 0 || new Random().nextInt(100) + 1 > iRka || wsyVar == null || wsyVar.getWebView() == null || wsyVar.getVisibility() != 0 || (bitmapFm = zan.fm(wsyVar)) == null || (lseVar = this.hi) == null) {
            return;
        }
        zan.fm(lseVar, this.nt, "landing_page_blank", bitmapFm, wsyVar.getUrl(), this.jnr);
    }

    private void fm(String str, JSONObject jSONObject) {
        fm(str, jSONObject, -1L);
    }

    private void fm(final String str, final JSONObject jSONObject, final long j10) {
        if (!this.xgn || this.hi == null || TextUtils.isEmpty(str)) {
            return;
        }
        com.bytedance.sdk.openadsdk.maa.wu wuVar = this.gof;
        final int iXgn = wuVar != null ? wuVar.xgn() : -1;
        lb.fm(System.currentTimeMillis(), this.hi, this.nt, str, new com.bytedance.sdk.openadsdk.irt.ro.fm() { // from class: com.bytedance.sdk.openadsdk.yz.dsz.1
            @Override // com.bytedance.sdk.openadsdk.irt.ro.fm, com.bytedance.sdk.openadsdk.irt.ro.ro
            public JSONObject fm() {
                try {
                    JSONObject jSONObject2 = new JSONObject();
                    if ("load_start".equals(str) || "load_finish".equals(str) || "progress_load_finish".equals(str)) {
                        jSONObject2.put("is_reused", dsz.this.ywr ? 1 : 0);
                    }
                    if (com.bytedance.sdk.openadsdk.onz.lb.lb(dsz.this.hi)) {
                        jSONObject2.put("is_lp_pre_render", dsz.this.sds);
                    }
                    return jSONObject2;
                } catch (Throwable unused) {
                    return null;
                }
            }

            @Override // com.bytedance.sdk.openadsdk.irt.ro.fm, com.bytedance.sdk.openadsdk.irt.ro.ro
            public JSONObject lb() {
                if (jSONObject != null) {
                    try {
                        boolean zRo = ai.ro(dsz.this.hi);
                        int i10 = 0;
                        jSONObject.put("is_playable", zRo ? 1 : 0);
                        jSONObject.put("usecache", com.bytedance.sdk.openadsdk.core.fhx.lb.fm.fm().fm(dsz.this.hi) ? 1 : 0);
                        if (zRo && ("load_finish".equals(str) || "load_fail".equals(str))) {
                            jSONObject.put("playable_has_show", iXgn);
                        }
                        if ("stay_page".equals(str)) {
                            JSONObject jSONObject2 = jSONObject;
                            if (dsz.this.hlt <= 1) {
                                i10 = 1;
                            }
                            jSONObject2.put("first_page", i10);
                        }
                    } catch (JSONException unused) {
                    }
                }
                String unused2 = dsz.this.nt;
                return jSONObject;
            }

            @Override // com.bytedance.sdk.openadsdk.irt.ro.fm, com.bytedance.sdk.openadsdk.irt.ro.ro
            public JSONObject ro() {
                JSONObject jSONObject2 = new JSONObject();
                try {
                    long j11 = j10;
                    if (j11 > 0) {
                        jSONObject2.put("duration", j11);
                    }
                } catch (Throwable unused) {
                }
                return jSONObject2;
            }
        });
    }

    public void fm(MotionEvent motionEvent) {
        com.bytedance.sdk.openadsdk.core.widget.fm.wsy wsyVar = this.irt;
        if (wsyVar != null && this.qhl) {
            wsyVar.fm(motionEvent);
        }
        int actionMasked = motionEvent.getActionMasked();
        if (this.tzk != 0) {
            if (actionMasked == 1 || actionMasked == 3) {
                this.f7602qf.incrementAndGet();
                this.f7602qf.get();
                if (this.si.getAndSet(true)) {
                    return;
                }
                JSONObject jSONObject = new JSONObject();
                try {
                    jSONObject.put(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL, this.hi.rbn());
                } catch (JSONException unused) {
                }
                fm("click_time", jSONObject, Math.max(SystemClock.elapsedRealtime() - this.tzk, 0L));
            }
        }
    }

    public void fm(String str, boolean z10) {
        com.bytedance.sdk.openadsdk.core.widget.fm.wsy wsyVar = this.irt;
        if (wsyVar != null && z10) {
            wsyVar.lb(str);
        }
        ef efVar = this.gqi;
        if (efVar == null || !z10) {
            return;
        }
        efVar.ro(str);
    }

    private void fm(boolean z10, final String str) {
        if (z10) {
            final int iVt = vt();
            lb.fm(new com.bytedance.sdk.component.wu.ro.lb("sendPrefLog") { // from class: com.bytedance.sdk.openadsdk.yz.dsz.2
                @Override // java.lang.Runnable
                public void run() {
                    try {
                        com.bytedance.sdk.openadsdk.core.settings.ajl ajlVarHa = com.bytedance.sdk.openadsdk.core.gof.yz().ha();
                        boolean zFm = dsz.this.fm(ajlVarHa, str);
                        if (zFm) {
                            if (!TextUtils.isEmpty(com.bytedance.sdk.openadsdk.core.settings.ajl.ro)) {
                                dsz.this.fm(iVt, str);
                                return;
                            }
                            if (TextUtils.isEmpty(ajlVarHa.f7276lb) || !zFm) {
                                return;
                            }
                            String str2 = ajlVarHa.f7276lb;
                            com.bytedance.sdk.component.wsy.ro.ro roVarLb = com.bytedance.sdk.openadsdk.wey.ro.ro().lb().lb();
                            roVarLb.lb(str2);
                            HashMap map = new HashMap();
                            map.put("content-type", "application/json; charset=utf-8");
                            roVarLb.yz(map);
                            roVarLb.fm(9);
                            roVarLb.ro("sendPrefLog");
                            roVarLb.ro(new com.bytedance.sdk.component.wsy.fm.fm() { // from class: com.bytedance.sdk.openadsdk.yz.dsz.2.1
                                @Override // com.bytedance.sdk.component.wsy.fm.fm
                                public void fm(com.bytedance.sdk.component.wsy.ro.lb lbVar, IOException iOException) {
                                }

                                @Override // com.bytedance.sdk.component.wsy.fm.fm
                                public void fm(com.bytedance.sdk.component.wsy.ro.lb lbVar, com.bytedance.sdk.component.wsy.ro roVar) {
                                    try {
                                        com.bytedance.sdk.openadsdk.core.settings.ajl.ro = roVar.yz();
                                        AnonymousClass2 anonymousClass2 = AnonymousClass2.this;
                                        dsz.this.fm(iVt, str);
                                    } catch (Exception e10) {
                                        com.bytedance.sdk.component.utils.wey.fm("LandingPageLog", "TTWebViewClient : onPageFinished", e10);
                                    }
                                }
                            });
                        }
                    } catch (Throwable th) {
                        com.bytedance.sdk.component.utils.wey.lb(th.getMessage(), new Object[0]);
                    }
                }
            });
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void fm(int i10, String str) {
        try {
            if (TextUtils.isEmpty(com.bytedance.sdk.openadsdk.core.settings.ajl.ro)) {
                return;
            }
            JSONObject jSONObject = new JSONObject();
            StringBuilder sb = new StringBuilder(com.bytedance.sdk.openadsdk.core.settings.ajl.ro);
            jSONObject.putOpt(CmcdConfiguration.KEY_CONTENT_ID, fm().eo());
            jSONObject.putOpt("ad_id", fm().eo());
            jSONObject.put("log_extra", fm().gt());
            bx.fm(sb, "\"/** adInfo **/\"", jSONObject.toString());
            bx.fm(sb, "\"/** first_page **/\"", String.valueOf(i10));
            long j10 = this.jnr;
            String str2 = SessionDescription.SUPPORTED_SDP_VERSION;
            bx.fm(sb, "\"/** ix_to_externalurl **/\"", j10 != -1 ? "1" : SessionDescription.SUPPORTED_SDP_VERSION);
            if (this.f7601ne == 2) {
                str2 = "2";
            }
            bx.fm(sb, "\"/** preload_status **/\"", str2);
            bx.fm(sb, "\"/** scene_state **/\"", str);
            bx.fm(sb, "\"/** web_init_time **/\"", String.valueOf(this.mj));
            bx.fm(sb, "\"/** channel_name **/\"", "\"" + fm().kec() + "\"");
            bx.fm(sb, "\"/** session_id **/\"", "\"" + UUID.randomUUID().toString() + "\"");
            bx.fm(sb, "\"/** web_url **/\"", "\"" + fm().rbn() + "\"");
            String string = sb.toString();
            if (TextUtils.isEmpty(string)) {
                return;
            }
            final String strJnr = jnr(string);
            WeakReference<WebView> weakReference = this.f7598gc;
            final WebView webView = weakReference != null ? weakReference.get() : null;
            if (TextUtils.isEmpty(strJnr) || webView == null) {
                return;
            }
            xgn.fm(new Runnable() { // from class: com.bytedance.sdk.openadsdk.yz.dsz.3
                @Override // java.lang.Runnable
                public void run() {
                    com.bytedance.sdk.component.utils.onz.fm(webView, strJnr);
                }
            });
        } catch (Throwable th) {
            com.bytedance.sdk.component.utils.wey.lb(th.getMessage(), new Object[0]);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public boolean fm(com.bytedance.sdk.openadsdk.core.settings.ajl ajlVar, String str) {
        str.getClass();
        switch (str) {
            case "0":
                return ajlVar.yz;
            case "1":
                return ajlVar.jnr;
            case "2":
                return ajlVar.ajl;
            default:
                return false;
        }
    }

    public void fm(boolean z10, long j10) {
        if (z10) {
            this.maa = j10;
        } else {
            this.lse = j10;
        }
        if (this.maa <= 0 || this.lse <= 0 || !this.qhl || !this.ro.compareAndSet(false, true)) {
            return;
        }
        fm(this.hi, this.nt, this.lse - this.maa, this.sds, this.ywr);
    }

    public static void fm(final lse lseVar, final String str, final long j10, final int i10, final boolean z10) {
        lb.fm(System.currentTimeMillis(), lseVar, str, "lp_feeling_duration", new com.bytedance.sdk.openadsdk.irt.ro.fm() { // from class: com.bytedance.sdk.openadsdk.yz.dsz.4
            @Override // com.bytedance.sdk.openadsdk.irt.ro.fm, com.bytedance.sdk.openadsdk.irt.ro.ro
            public JSONObject fm() {
                JSONObject jSONObject = new JSONObject();
                try {
                    jSONObject.put("is_lp_pre_render", i10);
                    jSONObject.put("meta_pre_render", lseVar.dbt() ? 1 : 0);
                    com.bytedance.sdk.openadsdk.core.model.gqi gqiVarNt = lseVar.nt();
                    if (gqiVarNt == null) {
                        gqiVarNt = new com.bytedance.sdk.openadsdk.core.model.gqi();
                    }
                    jSONObject.put("pre_render_status", gqiVarNt.lb());
                    jSONObject.put("pre_render_use_gecko", gqiVarNt.ro());
                    jSONObject.put("pre_render_add_type", gqiVarNt.fm());
                    jSONObject.put("is_reused", z10 ? 1 : 0);
                } catch (Throwable unused) {
                }
                return jSONObject;
            }

            @Override // com.bytedance.sdk.openadsdk.irt.ro.fm, com.bytedance.sdk.openadsdk.irt.ro.ro
            public JSONObject ro() {
                JSONObject jSONObject = new JSONObject();
                try {
                    jSONObject.put("duration", j10);
                } catch (Throwable unused) {
                }
                return jSONObject;
            }
        });
    }

    public void fm(String str, long j10) {
        if (!this.xgn || this.hi == null) {
            return;
        }
        JSONObject jSONObject = new JSONObject();
        try {
            jSONObject.put("error_code", this.ku);
            jSONObject.put("error_msg", this.dsz);
            jSONObject.put("error_url", this.onz);
            int i10 = this.f7601ne;
            if (i10 >= 0) {
                jSONObject.put("preload_status", i10);
            }
            jSONObject.put("first_page", vt());
            jSONObject.putOpt("render_type", "h5");
            jSONObject.putOpt("render_type_2", 0);
            if (TextUtils.isEmpty(str)) {
                str = this.hi.rbn();
            }
            jSONObject.put(IjkMediaPlayer.OnNativeInvokeListener.ARG_URL, str);
            jSONObject.put("preload_h5_type", this.hi.mon());
        } catch (Exception unused) {
        }
        fm("load_finish", jSONObject, Math.min(j10, TTAdConstant.AD_MAX_EVENT_TIME));
    }

    public void fm(final String str, final String str2, final long j10) {
        if (!this.xgn || this.hi == null) {
            return;
        }
        lb.fm(System.currentTimeMillis(), this.hi, this.nt, "lp_redirect_duration", new com.bytedance.sdk.openadsdk.irt.ro.fm() { // from class: com.bytedance.sdk.openadsdk.yz.dsz.5
            @Override // com.bytedance.sdk.openadsdk.irt.ro.fm, com.bytedance.sdk.openadsdk.irt.ro.ro
            public JSONObject fm() {
                JSONObject jSONObject = new JSONObject();
                try {
                    String str3 = "";
                    jSONObject.put("first_url", TextUtils.isEmpty(str) ? "" : str);
                    if (!TextUtils.isEmpty(str2)) {
                        str3 = str2;
                    }
                    jSONObject.put("current_url", str3);
                    jSONObject.put("time_since_last_touch", j10);
                } catch (Exception unused) {
                }
                return jSONObject;
            }
        });
    }
}
