package com.cvte.vman;

import android.util.SparseArray;
import android.view.KeyEvent;
import android.view.MotionEvent;
import com.cvte.vman.listener.KeyEventListener;
import com.cvte.vman.listener.MotionEventListener;
import com.cvte.vman.utils.CLog;

/* JADX INFO: loaded from: classes.dex */
public class VmInputManager {
    public static final String TAG = "Cvte@VmInputManager";
    private static SparseArray<KeyEventListener> mKeyListnerMap;
    private static SparseArray<MotionEventListener> mMotionListnerMap;
    private static VmInputManager mVmInputManager;
    private static final Object mkeyLockNotify = new Object();
    private static final Object mMotionLockNotify = new Object();

    private VmInputManager() {
    }

    public static synchronized VmInputManager getInstance() {
        if (mVmInputManager == null) {
            synchronized (VmInputManager.class) {
                if (mVmInputManager == null) {
                    mVmInputManager = new VmInputManager();
                }
            }
        }
        return mVmInputManager;
    }

    private static void postKeyEventMsg(KeyEvent keyEvent) {
        synchronized (mkeyLockNotify) {
            if (mKeyListnerMap.size() > 0) {
                int size = mKeyListnerMap.size();
                for (int i = 0; i < size; i++) {
                    KeyEventListener keyEventListenerValueAt = mKeyListnerMap.valueAt(i);
                    if (keyEventListenerValueAt != null) {
                        try {
                            keyEventListenerValueAt.onKeyEvent(keyEvent);
                        } catch (Exception unused) {
                            CLog.e("Exception, postKeyEventMsg failed !");
                        }
                    } else {
                        CLog.e("listener is null, postKeyEventMsg failed !");
                    }
                }
            } else {
                CLog.e("Exception, postKeyEventMsg failed !");
            }
        }
    }

    private static void postMotionEventMsg(MotionEvent motionEvent) {
        synchronized (mMotionLockNotify) {
            if (mMotionListnerMap.size() > 0) {
                int size = mMotionListnerMap.size();
                for (int i = 0; i < size; i++) {
                    MotionEventListener motionEventListenerValueAt = mMotionListnerMap.valueAt(i);
                    if (motionEventListenerValueAt != null) {
                        try {
                            motionEventListenerValueAt.onMotionEvent(motionEvent);
                        } catch (Exception unused) {
                            CLog.e("Exception, postMotionEventMsg failed !");
                        }
                    } else {
                        CLog.e("listener is null, postMotionEventMsg failed !");
                    }
                }
            } else {
                CLog.e("Exception, postMotionEventMsg failed !");
            }
        }
    }

    public static void registerKeyEventListener(KeyEventListener keyEventListener) {
        synchronized (mkeyLockNotify) {
            mKeyListnerMap.put(System.identityHashCode(keyEventListener), keyEventListener);
        }
    }

    public static void registerMotionEventListener(MotionEventListener motionEventListener) {
        synchronized (mMotionLockNotify) {
            mMotionListnerMap.put(System.identityHashCode(motionEventListener), motionEventListener);
        }
    }

    public static void unregisterKeyEventListener(KeyEventListener keyEventListener) {
        synchronized (mkeyLockNotify) {
            mKeyListnerMap.remove(System.identityHashCode(keyEventListener));
        }
    }

    public static void unregisterMotionEventListener(MotionEventListener motionEventListener) {
        synchronized (mMotionLockNotify) {
            mMotionListnerMap.remove(System.identityHashCode(motionEventListener));
        }
    }
}
