package com.mbridge.msdk.newreward.a.c;

import android.os.Handler;
import android.os.HandlerThread;
import android.text.TextUtils;
import com.mbridge.msdk.MBridgeConstans;
import com.mbridge.msdk.foundation.tools.af;
import java.util.HashMap;
import java.util.Map;
/* compiled from: MBridgeTimer.java */
/* loaded from: classes5.dex */
public class a {

    /* renamed from: a  reason: collision with root package name */
    private static volatile a f4015a;
    private Map<String, c> b;
    private Handler c;

    /* compiled from: MBridgeTimer.java */
    /* renamed from: com.mbridge.msdk.newreward.a.c.a$a  reason: collision with other inner class name */
    /* loaded from: classes5.dex */
    public interface InterfaceC0292a {
        void a(String str, long j);
    }

    public a() {
        HandlerThread handlerThread = new HandlerThread("MBridgeTimerThread");
        handlerThread.start();
        this.c = new Handler(handlerThread.getLooper());
        this.b = new HashMap();
    }

    public static a a() {
        if (f4015a == null) {
            synchronized (a.class) {
                if (f4015a == null) {
                    f4015a = new a();
                }
            }
        }
        return f4015a;
    }

    public final void a(String str, long j, InterfaceC0292a interfaceC0292a) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        if (MBridgeConstans.DEBUG) {
            af.a("MBridgeTimer", "startTimer taskID: " + str + " timeout: " + j);
        }
        if (this.b.containsKey(str)) {
            return;
        }
        c cVar = new c(new b(str, j), interfaceC0292a);
        this.b.put(str, cVar);
        this.c.postDelayed(cVar, j);
    }

    public final void a(String str) {
        if (TextUtils.isEmpty(str)) {
            return;
        }
        c remove = this.b.remove(str);
        if (MBridgeConstans.DEBUG) {
            af.a("MBridgeTimer", "stopTimer taskID: " + str);
        }
        if (remove != null) {
            remove.f4017a.c = true;
            if (remove == null) {
                return;
            }
            this.c.removeCallbacks(remove);
        }
    }

    /* compiled from: MBridgeTimer.java */
    /* loaded from: classes5.dex */
    public static class c implements Runnable {

        /* renamed from: a  reason: collision with root package name */
        private final b f4017a;
        private final InterfaceC0292a b;

        public c(b bVar, InterfaceC0292a interfaceC0292a) {
            this.f4017a = bVar;
            this.b = interfaceC0292a;
        }

        @Override // java.lang.Runnable
        public final void run() {
            InterfaceC0292a interfaceC0292a;
            if (MBridgeConstans.DEBUG) {
                af.a("MBridgeTimer", "TimerTask run taskID: " + this.f4017a.f4016a + " isStop: " + this.f4017a.c);
            }
            if (this.f4017a.c || (interfaceC0292a = this.b) == null) {
                return;
            }
            try {
                interfaceC0292a.a(this.f4017a.f4016a, this.f4017a.b);
            } catch (Exception unused) {
            }
        }
    }

    /* compiled from: MBridgeTimer.java */
    /* loaded from: classes5.dex */
    private static final class b {

        /* renamed from: a  reason: collision with root package name */
        private final String f4016a;
        private final long b;
        private boolean c;

        public b(String str, long j) {
            this.f4016a = str;
            this.b = j;
        }
    }
}
