package com.bytedance.sdk.openadsdk.utils;

import android.os.Looper;
import android.text.TextUtils;
import androidx.media3.common.MimeTypes;
import com.bytedance.sdk.component.wu.ro.wsy;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import org.json.JSONObject;

/* JADX INFO: loaded from: classes2.dex */
public class xgn {
    private static volatile com.bytedance.sdk.component.wu.ro.wsy ajl;
    private static volatile com.bytedance.sdk.component.wu.ro.wsy dsz;
    private static volatile com.bytedance.sdk.component.wu.ro.wsy duv;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private static volatile com.bytedance.sdk.component.wu.ro.wsy f7571ef;
    private static volatile ScheduledExecutorService fm;
    private static volatile com.bytedance.sdk.component.wu.ro.wsy jnr;
    private static volatile com.bytedance.sdk.component.wu.ro.wsy ku;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private static volatile boolean f7572lb;
    private static volatile com.bytedance.sdk.component.wu.ro.wsy onz;
    private static volatile ThreadPoolExecutor ro;
    private static volatile com.bytedance.sdk.component.wu.ro.wsy vt;
    private static volatile com.bytedance.sdk.component.wu.ro.wsy wsy;
    private static volatile com.bytedance.sdk.component.wu.ro.wsy wu;
    private static volatile com.bytedance.sdk.component.wu.ro.wsy yz;

    static {
        com.bytedance.sdk.component.wu.ro.yz.fm(new com.bytedance.sdk.component.wu.ro.fm() { // from class: com.bytedance.sdk.openadsdk.utils.xgn.1
            @Override // com.bytedance.sdk.component.wu.ro.fm
            public void fm(com.bytedance.sdk.component.wu.ro.wsy wsyVar, com.bytedance.sdk.component.wu.ro.lb lbVar) {
                lbVar.getName();
                new RuntimeException();
            }
        });
        com.bytedance.sdk.component.wu.fm.fm(new com.bytedance.sdk.component.fm() { // from class: com.bytedance.sdk.openadsdk.utils.xgn.2
            @Override // com.bytedance.sdk.component.fm
            public void fm(Runnable runnable) {
                xgn.lb(runnable);
            }
        });
        ro = null;
        f7572lb = false;
    }

    public static boolean ajl() {
        return Looper.getMainLooper() == Looper.myLooper();
    }

    public static com.bytedance.sdk.component.wu.ro.wsy dsz() {
        com.bytedance.sdk.component.wu.ro.wsy wsyVar;
        com.bytedance.sdk.component.wu.ro.wsy wsyVar2 = vt;
        if (!fm(wsyVar2)) {
            return wsyVar2;
        }
        synchronized (xgn.class) {
            try {
                if (fm(vt)) {
                    try {
                        vt = fm("net", vt);
                    } catch (Throwable th) {
                        th.getMessage();
                    }
                    if (vt == null) {
                        vt = gqi();
                    }
                }
                wsyVar = vt;
            } catch (Throwable th2) {
                throw th2;
            }
        }
        return wsyVar;
    }

    public static com.bytedance.sdk.component.wu.ro.wsy duv() {
        com.bytedance.sdk.component.wu.ro.wsy wsyVar;
        com.bytedance.sdk.component.wu.ro.wsy wsyVar2 = dsz;
        if (!fm(wsyVar2)) {
            return wsyVar2;
        }
        synchronized (xgn.class) {
            try {
                if (fm(dsz)) {
                    try {
                        dsz = fm("ad_log_up", dsz);
                    } catch (Throwable th) {
                        th.getMessage();
                    }
                    if (dsz == null) {
                        dsz = gqi();
                    }
                }
                wsyVar = dsz;
            } catch (Throwable th2) {
                throw th2;
            }
        }
        return wsyVar;
    }

    public static com.bytedance.sdk.component.wu.ro.wsy ef() {
        com.bytedance.sdk.component.wu.ro.wsy wsyVar;
        com.bytedance.sdk.component.wu.ro.wsy wsyVar2 = ajl;
        if (!fm(wsyVar2)) {
            return wsyVar2;
        }
        synchronized (xgn.class) {
            try {
                if (fm(ajl)) {
                    try {
                        ajl = fm("cache", ajl);
                    } catch (Throwable th) {
                        th.getMessage();
                    }
                    if (ajl == null) {
                        ajl = gqi();
                    }
                }
                wsyVar = ajl;
            } catch (Throwable th2) {
                throw th2;
            }
        }
        return wsyVar;
    }

    private static com.bytedance.sdk.component.wu.ro.wsy fhx() {
        com.bytedance.sdk.component.wu.ro.wsy wsyVar;
        com.bytedance.sdk.component.wu.ro.wsy wsyVar2 = jnr;
        if (!fm(wsyVar2)) {
            return wsyVar2;
        }
        synchronized (xgn.class) {
            try {
                if (fm(jnr)) {
                    try {
                        jnr = fm("log", jnr);
                    } catch (Throwable th) {
                        th.getMessage();
                    }
                    if (jnr == null) {
                        jnr = gqi();
                    }
                }
                wsyVar = jnr;
            } catch (Throwable th2) {
                throw th2;
            }
        }
        return wsyVar;
    }

    public static ScheduledExecutorService fm() {
        if (fm == null) {
            synchronized (xgn.class) {
                try {
                    if (fm == null) {
                        fm = Executors.newSingleThreadScheduledExecutor(new com.bytedance.sdk.component.wu.ro.jnr("scheduled"));
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
        return fm;
    }

    private static com.bytedance.sdk.component.wu.ro.wsy gof() {
        com.bytedance.sdk.component.wu.ro.wsy wsyVar;
        com.bytedance.sdk.component.wu.ro.wsy wsyVar2 = ku;
        if (!fm(wsyVar2)) {
            return wsyVar2;
        }
        synchronized (xgn.class) {
            try {
                if (fm(ku)) {
                    try {
                        ku = fm("imgdisk", ku);
                    } catch (Throwable th) {
                        th.getMessage();
                    }
                    if (ku == null) {
                        ku = gqi();
                    }
                }
                wsyVar = ku;
            } catch (Throwable th2) {
                throw th2;
            }
        }
        return wsyVar;
    }

    private static com.bytedance.sdk.component.wu.ro.wsy gqi() {
        com.bytedance.sdk.component.wu.ro.wsy wsyVar;
        com.bytedance.sdk.component.wu.ro.wsy wsyVar2 = duv;
        if (wsyVar2 != null) {
            return wsyVar2;
        }
        synchronized (xgn.class) {
            try {
                if (duv == null) {
                    try {
                        duv = ro("default").fm();
                    } catch (Throwable th) {
                        th.getMessage();
                    }
                }
                wsyVar = duv;
            } catch (Throwable th2) {
                throw th2;
            }
        }
        return wsyVar;
    }

    private static com.bytedance.sdk.component.wu.ro.wsy irt() {
        com.bytedance.sdk.component.wu.ro.wsy wsyVar;
        com.bytedance.sdk.component.wu.ro.wsy wsyVar2 = wu;
        if (!fm(wsyVar2)) {
            return wsyVar2;
        }
        synchronized (xgn.class) {
            try {
                if (fm(wu)) {
                    try {
                        wu = fm(MimeTypes.BASE_TYPE_IMAGE, wu);
                    } catch (Throwable th) {
                        th.getMessage();
                    }
                    if (wu == null) {
                        wu = gqi();
                    }
                }
                wsyVar = wu;
            } catch (Throwable th2) {
                throw th2;
            }
        }
        return wsyVar;
    }

    public static ExecutorService jnr() {
        return ef();
    }

    public static ExecutorService ku() {
        com.bytedance.sdk.component.wu.ro.wsy wsyVar;
        com.bytedance.sdk.component.wu.ro.wsy wsyVar2 = onz;
        if (!fm(wsyVar2)) {
            return wsyVar2;
        }
        synchronized (xgn.class) {
            try {
                if (fm(onz)) {
                    try {
                        onz = fm("ad_log_save", onz);
                    } catch (Throwable th) {
                        th.getMessage();
                    }
                    if (onz == null) {
                        onz = gqi();
                    }
                }
                wsyVar = onz;
            } catch (Throwable th2) {
                throw th2;
            }
        }
        return wsyVar;
    }

    public static ExecutorService lb() {
        return gof();
    }

    private static ThreadPoolExecutor onz() {
        com.bytedance.sdk.component.wu.ro.wsy wsyVar;
        com.bytedance.sdk.component.wu.ro.wsy wsyVar2 = yz;
        if (!fm(wsyVar2)) {
            return wsyVar2;
        }
        synchronized (xgn.class) {
            try {
                if (fm(yz)) {
                    try {
                        yz = fm("ad", yz);
                    } catch (Throwable th) {
                        th.getMessage();
                    }
                    if (yz == null) {
                        yz = gqi();
                    }
                }
                wsyVar = yz;
            } catch (Throwable th2) {
                throw th2;
            }
        }
        return wsyVar;
    }

    private static com.bytedance.sdk.component.wu.ro.wsy qhl() {
        com.bytedance.sdk.component.wu.ro.wsy wsyVar;
        com.bytedance.sdk.component.wu.ro.wsy wsyVar2 = wsy;
        if (!fm(wsyVar2)) {
            return wsyVar2;
        }
        synchronized (xgn.class) {
            try {
                if (fm(wsy)) {
                    try {
                        wsy = fm("io", wsy);
                    } catch (Throwable th) {
                        th.getMessage();
                    }
                    if (wsy == null) {
                        wsy = gqi();
                    }
                }
                wsyVar = wsy;
            } catch (Throwable th2) {
                throw th2;
            }
        }
        return wsyVar;
    }

    public static ExecutorService ro() {
        return irt();
    }

    public static com.bytedance.sdk.component.wu.ro.wsy vt() {
        com.bytedance.sdk.component.wu.ro.wsy wsyVar;
        com.bytedance.sdk.component.wu.ro.wsy wsyVar2 = f7571ef;
        if (!fm(wsyVar2)) {
            return wsyVar2;
        }
        synchronized (xgn.class) {
            try {
                if (fm(f7571ef)) {
                    try {
                        f7571ef = fm("express", f7571ef);
                    } catch (Throwable th) {
                        th.getMessage();
                    }
                    if (f7571ef == null) {
                        f7571ef = gqi();
                    }
                }
                wsyVar = f7571ef;
            } catch (Throwable th2) {
                throw th2;
            }
        }
        return wsyVar;
    }

    public static boolean wsy() {
        String name = Thread.currentThread().getName();
        if (TextUtils.isEmpty(name)) {
            return false;
        }
        return name.startsWith("pag_log");
    }

    public static ExecutorService wu() {
        return qhl();
    }

    public static ExecutorService yz() {
        return fhx();
    }

    public static void jnr(com.bytedance.sdk.component.wu.ro.lb lbVar) {
        dsz().execute(lbVar);
    }

    public static void lb(Runnable runnable) {
        if (hxv.fm) {
            return;
        }
        qhl().execute(runnable);
    }

    public static void ro(Runnable runnable) {
        if (runnable == null) {
            return;
        }
        com.bytedance.sdk.openadsdk.core.fhx.lb().removeCallbacks(runnable);
    }

    public static void yz(com.bytedance.sdk.component.wu.ro.lb lbVar) {
        if (hxv.fm) {
            return;
        }
        onz().execute(lbVar);
    }

    public static void lb(com.bytedance.sdk.component.wu.ro.lb lbVar) {
        if (lbVar == null || hxv.fm) {
            return;
        }
        onz().execute(lbVar);
    }

    public static void ro(com.bytedance.sdk.component.wu.ro.lb lbVar) {
        if (lbVar == null || hxv.fm) {
            return;
        }
        fhx().execute(lbVar);
    }

    public static void fm(Runnable runnable) {
        if (runnable == null || hxv.fm) {
            return;
        }
        if (ajl()) {
            runnable.run();
        } else {
            com.bytedance.sdk.openadsdk.core.fhx.lb().post(runnable);
        }
    }

    public static void ro(com.bytedance.sdk.component.wu.ro.lb lbVar, int i10) {
        if (lbVar == null || hxv.fm) {
            return;
        }
        lbVar.setPriority(i10);
        fhx().execute(lbVar);
    }

    private static wsy.fm ro(String str) {
        wsy.fm fmVar;
        if (TextUtils.isEmpty(str)) {
            str = "unknown";
        }
        fmVar = new wsy.fm();
        str.getClass();
        switch (str) {
            case "express":
                return fmVar.fm(str).fm(2).ro(4).lb(0).fm(10000L).fm(true).jnr(-1).yz(10).ro(false);
            case "ad":
                return fmVar.fm(str).fm(4).ro(4).lb(0).fm(20000L).fm(true).jnr(-1).yz(10).ro(false);
            case "io":
                return fmVar.fm(str).fm(4).ro(10).lb(0).fm(20000L).fm(true).jnr(-1).yz(10).ro(false);
            case "log":
                return fmVar.fm(str).fm(4).ro(6).lb(2).fm(20000L).fm(true).jnr(-1).yz(10).ro(false);
            case "net":
                return fmVar.fm(str).fm(10).ro(10).lb(0).fm(10000L).fm(true).jnr(-1).yz(10).ro(false);
            case "aidl":
                return fmVar.fm(str).fm(2).ro(4).lb(0).fm(10000L).fm(true).jnr(-1).yz(10).ro(false);
            case "cache":
                return fmVar.fm(str).fm(0).ro(0).lb(0).fm(5000L).fm(true).jnr(-1).yz(20).ro(false);
            case "image":
                return fmVar.fm(str).fm(3).ro(3).lb(0).fm(20000L).fm(true).jnr(-1).yz(10).ro(false);
            case "ad_log_up":
                return fmVar.fm(str).fm(1).ro(4).lb(0).fm(10000L).fm(true).jnr(-1).yz(10).ro(false);
            case "monitor":
                return fmVar.fm(str).fm(2).ro(2).lb(0).fm(10000L).fm(true).jnr(-1).yz(10).ro(false);
            case "ad_log_save":
                return fmVar.fm(str).fm(1).ro(4).lb(0).fm(10000L).fm(new PriorityBlockingQueue()).fm(true).jnr(-1).yz(10).ro(false);
            case "imgdisk":
                return fmVar.fm(str).fm(1).ro(2).lb(3).fm(10000L).fm(true).jnr(-1).yz(10).ro(false);
            default:
                return fmVar.fm(str).fm(8).ro(16).lb(2).fm(20000L).fm(true).jnr(-1).yz(10).ro(false);
        }
    }

    public static void fm(com.bytedance.sdk.component.wu.ro.lb lbVar) {
        if (hxv.fm) {
            return;
        }
        ef().execute(lbVar);
    }

    public static void fm(com.bytedance.sdk.component.wu.ro.lb lbVar, int i10) {
        if (lbVar == null || hxv.fm) {
            return;
        }
        lbVar.setPriority(i10);
        qhl().execute(lbVar);
    }

    private static boolean fm(com.bytedance.sdk.component.wu.ro.wsy wsyVar) {
        if (wsyVar != null) {
            return !wsyVar.ro() && com.bytedance.sdk.openadsdk.core.settings.ku.zh();
        }
        return true;
    }

    private static com.bytedance.sdk.component.wu.ro.wsy fm(String str, com.bytedance.sdk.component.wu.ro.wsy wsyVar) {
        wsy.fm fmVarFm = fm(str);
        if (wsyVar == null) {
            return fmVarFm.fm();
        }
        wsyVar.fm(fmVarFm);
        return wsyVar;
    }

    private static wsy.fm fm(String str) {
        wsy.fm fmVarRo = ro(str);
        try {
            if (com.bytedance.sdk.openadsdk.core.settings.ku.zh()) {
                fmVarRo.ro(true);
                JSONObject jSONObjectXca = com.bytedance.sdk.openadsdk.core.settings.ku.ro().xca();
                JSONObject jSONObjectOptJSONObject = jSONObjectXca != null ? jSONObjectXca.optJSONObject(str) : null;
                if (jSONObjectOptJSONObject != null) {
                    fmVarRo.ro(true);
                    if (jSONObjectOptJSONObject.has("coreSize")) {
                        fmVarRo.fm(jSONObjectOptJSONObject.optInt("coreSize"));
                    }
                    if (jSONObjectOptJSONObject.has("maxSize")) {
                        fmVarRo.ro(jSONObjectOptJSONObject.optInt("maxSize"));
                    }
                    if (jSONObjectOptJSONObject.has("createSize")) {
                        fmVarRo.lb(jSONObjectOptJSONObject.optInt("createSize"));
                    }
                    if (jSONObjectOptJSONObject.has("keepAlive")) {
                        fmVarRo.fm(jSONObjectOptJSONObject.optInt("keepAlive"));
                    }
                    if (jSONObjectOptJSONObject.has("allowCoreTimeOut")) {
                        fmVarRo.fm(jSONObjectOptJSONObject.optBoolean("allowCoreTimeOut"));
                    }
                    if (jSONObjectOptJSONObject.has("reportLogThreshold")) {
                        jSONObjectOptJSONObject.optInt("reportLogThreshold");
                    }
                    if (jSONObjectOptJSONObject.has("logTaskCount")) {
                        jSONObjectOptJSONObject.optInt("logTaskCount");
                    }
                }
            }
        } catch (Throwable th) {
            th.getMessage();
        }
        return fmVarRo;
    }
}
