package com.ss.android.ugc.aweme.commercialize.log;

import X.0Gf;
import X.0Gp;
import X.0HH;
import X.7he;
import X.86a;
import X.8BD;
import X.8eL;
import X.8qg;
import X.8ql;
import X.C3263LEo;
import X.C3273LEy;
import X.Crj;
import X.FNX;
import X.HkP;
import X.IUt;
import X.JLr;
import X.L6E;
import X.LF1;
import X.LFC;
import X.M12;
import X.PTf;
import X.SfZ;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.webkit.WebSettings;
import android.webkit.WebView;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import java.util.List;
import kotlin.h.b.n;

public final class RawURLGetter {
    public static final RawURLGetter LIZ = new RawURLGetter();
    public static final Crj LIZIZ = 7he.LIZ(C3273LEy.LIZ);
    public static final Crj LIZJ = 7he.LIZ(LF1.LIZ);
    public static final Crj LIZLLL = 7he.LIZ(LFC.LIZ);
    public static String LJ;
    public static boolean LJFF;

    public interface RawUrlApi {
        static {
            Covode.recordClassIndex(59125);
        }

        @IUt
        @PTf(LIZ = "vas_ad_track")
        JLr<String> doGet(@8qg String str, @8ql List<8BD> list);
    }

    public final RawUrlApi LIZ() {
        return (RawUrlApi) LIZIZ.getValue();
    }

    public final String LIZIZ() {
        return (String) LIZJ.getValue();
    }

    public final SharedPreferences LIZJ() {
        return (SharedPreferences) LIZLLL.getValue();
    }

    public static final void LIZLLL() {
        SfZ.LJIJ.LJI().LIZLLL(FNX.LIZ);
    }

    static {
        Covode.recordClassIndex(59124);
    }

    public final String LIZ(Context context) {
        MethodCollector.i(15960);
        if (!86a.LIZ(LJ)) {
            String str = LJ;
            MethodCollector.o(15960);
            return str;
        }
        String LIZ2 = HkP.LIZ.LIZ(context);
        LJ = LIZ2;
        if (!86a.LIZ(LIZ2)) {
            String str2 = LJ;
            MethodCollector.o(15960);
            return str2;
        }
        if (!LJFF && context != null && (context instanceof Activity)) {
            LJFF = true;
            try {
                WebView webView = new WebView(context);
                WebSettings settings = webView.getSettings();
                n.LIZIZ(settings, "");
                LJ = settings.getUserAgentString();
                webView.destroy();
            } catch (Throwable unused) {
            }
        }
        String str3 = LJ;
        MethodCollector.o(15960);
        return str3;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:9:0x0051, code lost:
        if (r1 == false) goto L_0x0053;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public static final java.lang.String LIZ(java.lang.String r9) {
        /*
            X.M12.LIZ((java.lang.Object) r9)
            com.ss.android.ugc.aweme.commercialize.log.RawURLGetter r8 = LIZ
            android.content.SharedPreferences r1 = r8.LIZJ()
            java.lang.String r5 = "ad_user_agent_sp"
            r0 = 0
            java.lang.String r3 = r1.getString(r5, r0)
            r7 = 0
            r6 = 1
            if (r3 == 0) goto L_0x001a
            int r0 = r3.length()
            if (r0 != 0) goto L_0x005b
        L_0x001a:
            java.lang.Thread r1 = java.lang.Thread.currentThread()
            android.os.Looper r0 = android.os.Looper.getMainLooper()
            java.lang.String r3 = ""
            kotlin.h.b.n.LIZIZ(r0, r3)
            java.lang.Thread r0 = r0.getThread()
            boolean r0 = kotlin.h.b.n.LIZ(r1, r0)
            if (r0 != 0) goto L_0x0053
            android.content.SharedPreferences r4 = r8.LIZJ()
            kotlin.h.b.n.LIZIZ(r4, r3)
            java.lang.String r0 = "feed"
            boolean r0 = android.text.TextUtils.equals(r9, r0)
            if (r0 == 0) goto L_0x0061
            java.lang.String r2 = "ad_user_agent_has_read_sp"
            boolean r1 = r4.getBoolean(r2, r7)
            android.content.SharedPreferences$Editor r0 = r4.edit()
            android.content.SharedPreferences$Editor r0 = r0.putBoolean(r2, r6)
            r0.apply()
            if (r1 != 0) goto L_0x0061
        L_0x0053:
            java.lang.String r0 = "http.agent"
            java.lang.String r0 = java.lang.System.getProperty(r0)
            if (r0 != 0) goto L_0x005f
        L_0x005b:
            LIZLLL()
        L_0x005e:
            return r3
        L_0x005f:
            r3 = r0
            goto L_0x005b
        L_0x0061:
            java.lang.Boolean r0 = X.7xA.LIZIZ()
            kotlin.h.b.n.LIZIZ(r0, r3)
            boolean r0 = r0.booleanValue()
            if (r0 == 0) goto L_0x0075
            boolean r0 = X.9a1.LIZ()
            if (r0 == 0) goto L_0x0075
            goto L_0x0053
        L_0x0075:
            java.lang.String r3 = r8.LIZIZ()
            android.content.SharedPreferences r0 = r8.LIZJ()
            android.content.SharedPreferences$Editor r1 = r0.edit()
            java.lang.String r0 = r8.LIZIZ()
            android.content.SharedPreferences$Editor r0 = r1.putString(r5, r0)
            r0.apply()
            goto L_0x005e
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.commercialize.log.RawURLGetter.LIZ(java.lang.String):java.lang.String");
    }

    public static final void LIZ(String str, L6E l6e) {
        M12.LIZ((Object) str);
        0Gp.LIZ(new C3263LEo(str, l6e), 8eL.LIZ(), (0Gf) null);
    }

    public final void LIZ(L6E l6e, int i, boolean z, Exception exc) {
        if (l6e != null) {
            try {
                l6e.LIZ(i, z, exc);
            } catch (Exception e) {
                0HH.LIZ(e);
            }
        }
    }
}
