package com.bytedance.adsdk.ro;

import android.content.Context;
import android.os.Trace;
import com.google.android.gms.measurement.internal.u1;
import defpackage.e;
import java.io.File;

/* JADX INFO: loaded from: classes.dex */
public class jnr {
    private static long[] ajl = null;
    private static volatile com.bytedance.adsdk.ro.yz.wsy duv = null;

    /* JADX INFO: renamed from: ef, reason: collision with root package name */
    private static com.bytedance.adsdk.ro.yz.ajl f6233ef = null;
    public static boolean fm = false;
    private static String[] jnr = null;
    private static volatile com.bytedance.adsdk.ro.yz.wu ku = null;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private static boolean f6234lb = true;
    private static boolean ro = false;
    private static com.bytedance.adsdk.ro.yz.jnr vt = null;
    private static int wsy = 0;
    private static int wu = 0;
    private static boolean yz = true;

    public static boolean fm() {
        return yz;
    }

    public static float ro(String str) {
        int i10 = wu;
        if (i10 > 0) {
            wu = i10 - 1;
            return 0.0f;
        }
        if (!ro) {
            return 0.0f;
        }
        int i11 = wsy - 1;
        wsy = i11;
        if (i11 == -1) {
            throw new IllegalStateException("Can't end trace section. There are none.");
        }
        if (!str.equals(jnr[i11])) {
            throw new IllegalStateException(e.o(u1.n("Unbalanced trace call ", str, ". Expected "), jnr[wsy], "."));
        }
        Trace.endSection();
        return (System.nanoTime() - ajl[wsy]) / 1000000.0f;
    }

    public static void fm(String str) {
        if (ro) {
            int i10 = wsy;
            if (i10 == 20) {
                wu++;
                return;
            }
            jnr[i10] = str;
            ajl[i10] = System.nanoTime();
            Trace.beginSection(str);
            wsy++;
        }
    }

    public static com.bytedance.adsdk.ro.yz.wu fm(Context context) {
        com.bytedance.adsdk.ro.yz.wu wuVar;
        com.bytedance.adsdk.ro.yz.wu wuVar2 = ku;
        if (wuVar2 != null) {
            return wuVar2;
        }
        synchronized (com.bytedance.adsdk.ro.yz.wu.class) {
            try {
                wuVar = ku;
                if (wuVar == null) {
                    com.bytedance.adsdk.ro.yz.wsy wsyVarRo = ro(context);
                    com.bytedance.adsdk.ro.yz.ajl roVar = f6233ef;
                    if (roVar == null) {
                        roVar = new com.bytedance.adsdk.ro.yz.ro();
                    }
                    wuVar = new com.bytedance.adsdk.ro.yz.wu(wsyVarRo, roVar);
                    ku = wuVar;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        return wuVar;
    }

    public static com.bytedance.adsdk.ro.yz.wsy ro(Context context) {
        com.bytedance.adsdk.ro.yz.wsy wsyVar;
        if (!f6234lb) {
            return null;
        }
        final Context applicationContext = context.getApplicationContext();
        com.bytedance.adsdk.ro.yz.wsy wsyVar2 = duv;
        if (wsyVar2 != null) {
            return wsyVar2;
        }
        synchronized (com.bytedance.adsdk.ro.yz.wsy.class) {
            try {
                wsyVar = duv;
                if (wsyVar == null) {
                    com.bytedance.adsdk.ro.yz.jnr jnrVar = vt;
                    if (jnrVar == null) {
                        jnrVar = new com.bytedance.adsdk.ro.yz.jnr() { // from class: com.bytedance.adsdk.ro.jnr.1
                            @Override // com.bytedance.adsdk.ro.yz.jnr
                            public File fm() {
                                return new File(applicationContext.getCacheDir(), "lottie_network_cache");
                            }
                        };
                    }
                    wsyVar = new com.bytedance.adsdk.ro.yz.wsy(jnrVar);
                    duv = wsyVar;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        return wsyVar;
    }
}
