package com.bytedance.sdk.openadsdk.hi.ro;

import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.os.Message;
import com.bytedance.sdk.component.utils.wey;

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

    public static class fm extends Handler {
        public fm(Looper looper) {
            super(looper);
        }

        public void fm(ro roVar) {
            if (roVar == null) {
                return;
            }
            int iIntValue = roVar.ku().intValue();
            if (hasMessages(iIntValue)) {
                return;
            }
            Message messageObtain = Message.obtain();
            messageObtain.what = iIntValue;
            messageObtain.obj = roVar;
            sendMessageDelayed(messageObtain, roVar.ajl());
        }

        @Override // android.os.Handler
        public void handleMessage(Message message) {
            ro roVar = (ro) message.obj;
            if (roVar == null) {
                return;
            }
            int iRo = roVar.ro();
            if (iRo == 1) {
                roVar.wsy();
            } else {
                if (iRo != 2) {
                    jnr.ro(roVar.ku());
                    return;
                }
                roVar.wu();
            }
            if (roVar.ef()) {
                jnr.ro(roVar.ku());
            } else if (roVar.duv()) {
                fm(roVar);
            }
        }
    }

    public static void fm() {
    }

    public static void ro(ro roVar) {
        if (roVar == null || fm == null) {
            return;
        }
        try {
            int iIntValue = roVar.ku().intValue();
            if (fm.hasMessages(iIntValue)) {
                fm.removeMessages(iIntValue);
            }
        } catch (Exception unused) {
        }
    }

    public static void fm(ro roVar) {
        if (roVar == null) {
            return;
        }
        ro();
        fm fmVar = fm;
        if (fmVar != null) {
            fmVar.fm(roVar);
        }
    }

    public static void ro() {
        if (fm != null) {
            return;
        }
        try {
            HandlerThread handlerThread = ro;
            if (handlerThread != null && handlerThread.isAlive()) {
                return;
            }
            synchronized (wsy.class) {
                try {
                    HandlerThread handlerThread2 = ro;
                    if (handlerThread2 == null || !handlerThread2.isAlive()) {
                        ro = com.bytedance.sdk.component.utils.wu.fm("pag_MRC");
                        fm = new fm(ro.getLooper());
                    }
                } finally {
                }
            }
        } catch (Throwable th) {
            wey.lb("MRC", th.getMessage());
        }
    }
}
