package com.bytedance.sdk.openadsdk.core.ef;

import android.os.Handler;
import android.os.Looper;
import com.bytedance.sdk.openadsdk.core.gof;
import com.bytedance.sdk.openadsdk.core.settings.ku;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Queue;

/* JADX INFO: loaded from: classes2.dex */
public class fm {
    private static volatile fm fm;

    /* JADX INFO: renamed from: lb, reason: collision with root package name */
    private static volatile long f7080lb;
    private static volatile boolean ro;
    private Handler jnr;
    private final Queue<C0068fm> yz = new LinkedList();
    private final ku ajl = gof.yz();

    /* JADX INFO: renamed from: com.bytedance.sdk.openadsdk.core.ef.fm$fm, reason: collision with other inner class name */
    public static class C0068fm {
        private final long fm;
        private final String ro;

        private C0068fm(long j10, String str) {
            this.fm = j10;
            this.ro = str;
        }
    }

    private fm() {
    }

    private synchronized boolean ro(String str) {
        long jCurrentTimeMillis = System.currentTimeMillis();
        int iWbw = this.ajl.wbw();
        long jOl = this.ajl.ol();
        if (this.yz.size() <= 0 || this.yz.size() < iWbw) {
            this.yz.offer(new C0068fm(jCurrentTimeMillis, str));
        } else {
            long jAbs = Math.abs(jCurrentTimeMillis - this.yz.peek().fm);
            if (jAbs <= jOl) {
                ro(jOl - jAbs);
                return true;
            }
            this.yz.poll();
            this.yz.offer(new C0068fm(jCurrentTimeMillis, str));
        }
        return false;
    }

    public synchronized String lb() {
        String str;
        try {
            HashMap map = new HashMap();
            for (C0068fm c0068fm : this.yz) {
                if (map.containsKey(c0068fm.ro)) {
                    map.put(c0068fm.ro, Integer.valueOf(((Integer) map.get(c0068fm.ro)).intValue() + 1));
                } else {
                    map.put(c0068fm.ro, 1);
                }
            }
            str = "";
            int i10 = Integer.MIN_VALUE;
            for (String str2 : map.keySet()) {
                int iIntValue = ((Integer) map.get(str2)).intValue();
                if (i10 < iIntValue) {
                    str = str2;
                    i10 = iIntValue;
                }
            }
        } catch (Throwable th) {
            throw th;
        }
        return str;
    }

    public static fm fm() {
        if (fm == null) {
            synchronized (fm.class) {
                try {
                    if (fm == null) {
                        fm = new fm();
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
        return fm;
    }

    public synchronized boolean fm(String str) {
        try {
            if (ro(str)) {
                fm(true);
                fm(f7080lb);
            } else {
                fm(false);
            }
        } catch (Throwable th) {
            throw th;
        }
        return ro;
    }

    private synchronized void fm(long j10) {
        try {
            if (this.jnr == null) {
                this.jnr = new Handler(Looper.getMainLooper());
            }
            this.jnr.postDelayed(new Runnable() { // from class: com.bytedance.sdk.openadsdk.core.ef.fm.1
                @Override // java.lang.Runnable
                public void run() {
                    fm.this.fm(false);
                }
            }, j10);
        } catch (Throwable th) {
            throw th;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public synchronized void fm(boolean z10) {
        ro = z10;
    }

    public synchronized boolean ro() {
        return ro;
    }

    private synchronized void ro(long j10) {
        f7080lb = j10;
    }
}
