package com.seewo.libmcuservice;

import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
import com.seewo.libmcuservice.aidl.IMcuService;
import com.seewo.libmcuservice.aidl.IServiceCallback;
import com.seewo.libmcuservice.aidl.IVideoRecorderService;
import com.seewo.libmcuservice.constant.IVideoRecorderConstants;

/* JADX INFO: loaded from: classes.dex */
public class VideoRecorderBox extends AbstractMailbox {
    private static final String TAG = "VideoRecorderBox";
    private AbsRecorderCallback mCallback;
    private IVideoRecorderService mService;
    private IServiceCallback mServiceCallback = new IServiceCallback.Stub() { // from class: com.seewo.libmcuservice.VideoRecorderBox.1
        @Override // com.seewo.libmcuservice.aidl.IServiceCallback
        public void onCallback(int i, Bundle bundle) throws RemoteException {
            switch (i) {
                case 1:
                    VideoRecorderBox.this.mCallback.onVRFunctionControl(bundle.getInt(IVideoRecorderConstants.VR_FUNCTION_KEY, 0));
                    break;
                case 2:
                    VideoRecorderBox.this.mCallback.onVRLockControl(bundle.getInt(IVideoRecorderConstants.VR_FUNCTION_KEY, 0));
                    break;
                case 3:
                    VideoRecorderBox.this.mCallback.onVRPowerOff();
                    break;
                case 4:
                    VideoRecorderBox.this.mCallback.onVRBooting();
                    break;
                case 5:
                    VideoRecorderBox.this.mCallback.onVRBootOK();
                    break;
                case 6:
                    VideoRecorderBox.this.mCallback.onVRStart();
                    break;
                case 7:
                    VideoRecorderBox.this.mCallback.onVRPause();
                    break;
                case 8:
                    VideoRecorderBox.this.mCallback.onVRFinish();
                    break;
                case 9:
                    VideoRecorderBox.this.mCallback.onVRLock();
                    break;
                case 10:
                    VideoRecorderBox.this.mCallback.onVRUnLock();
                    break;
                case 11:
                    VideoRecorderBox.this.mCallback.onVRStateBack(bundle.getInt(IVideoRecorderConstants.VR_POWER_STATUS));
                    break;
                case 12:
                    VideoRecorderBox.this.mCallback.onRecordStateBack(bundle.getInt(IVideoRecorderConstants.VR_RECORDER_STATUS), bundle.getInt(IVideoRecorderConstants.VR_LOCK_STATUS));
                    break;
                case 13:
                    VideoRecorderBox.this.mCallback.onVRIpBack(bundle.getString(IVideoRecorderConstants.VR_NET_IP), bundle.getString(IVideoRecorderConstants.VR_NET_MASK), bundle.getString(IVideoRecorderConstants.VR_NET_GATEWAY));
                    break;
            }
        }
    };
    private VRIpRunnable mVRIpRunnable;
    private VRStateRunnable mVRStateRunnable;

    public static abstract class AbsRecorderCallback {
        protected void onRecordStateBack(int i, int i2) {
        }

        protected void onVRBootOK() {
        }

        protected void onVRBooting() {
        }

        protected void onVRFinish() {
        }

        protected void onVRFunctionControl(int i) {
        }

        protected void onVRIpBack(String str, String str2, String str3) {
        }

        protected void onVRLock() {
        }

        protected void onVRLockControl(int i) {
        }

        protected void onVRPause() {
        }

        protected void onVRPowerOff() {
        }

        protected void onVRStart() {
        }

        protected void onVRStateBack(int i) {
        }

        protected void onVRUnLock() {
        }
    }

    private class VRIpRunnable implements Runnable {
        private VRIpRunnable() {
        }

        @Override // java.lang.Runnable
        public void run() {
            VideoRecorderBox.this.sendGetVRIp();
        }
    }

    private class VRStateRunnable implements Runnable {
        private VRStateRunnable() {
        }

        @Override // java.lang.Runnable
        public void run() {
            VideoRecorderBox.this.sendGetVRState();
        }
    }

    VideoRecorderBox(AbsRecorderCallback absRecorderCallback) {
        this.mCallback = absRecorderCallback;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void sendGetVRIp() {
        try {
            this.mService.sendMessage(McuMailboxes.getID(), IVideoRecorderConstants.ActionIn.GET_VR_IP.ordinal(), new Bundle());
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void sendGetVRState() {
        try {
            this.mService.sendMessage(McuMailboxes.getID(), IVideoRecorderConstants.ActionIn.VR_STATE.ordinal(), new Bundle());
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

    @Override // com.seewo.libmcuservice.AbstractMailbox
    protected void clearService() {
        this.mService = null;
    }

    @Override // com.seewo.libmcuservice.AbstractMailbox
    protected void initService(IMcuService iMcuService) {
        try {
            IVideoRecorderService videoRecorderService = iMcuService.getVideoRecorderService();
            this.mService = videoRecorderService;
            if (this.mCallback != null) {
                videoRecorderService.registerCallback(this.mServiceCallback);
            }
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

    @Override // com.seewo.libmcuservice.AbstractMailbox
    protected void onWorkDone() {
    }

    public void postGetVRIp() {
        if (this.mService != null) {
            sendGetVRIp();
        } else if (this.mVRIpRunnable == null) {
            VRIpRunnable vRIpRunnable = new VRIpRunnable();
            this.mVRIpRunnable = vRIpRunnable;
            this.mConnection.post(vRIpRunnable);
        }
    }

    public void postLockStateChange(byte b2) {
        if (this.mService != null) {
            Bundle bundle = new Bundle();
            bundle.putByte(IVideoRecorderConstants.KEY_LOCK_STATE_CHANGE, b2);
            try {
                this.mService.sendMessage(McuMailboxes.getID(), IVideoRecorderConstants.ActionIn.LOCK_STATE_CHANGE.ordinal(), bundle);
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postSetVRIp(String str, String str2, String str3, String str4) {
        if (this.mService != null) {
            Bundle bundle = new Bundle();
            bundle.putString(IVideoRecorderConstants.VR_NET_IP, str);
            bundle.putString(IVideoRecorderConstants.VR_NET_MASK, str2);
            bundle.putString(IVideoRecorderConstants.VR_NET_GATEWAY, str3);
            bundle.putString(IVideoRecorderConstants.VR_NET_DNS, str4);
            try {
                this.mService.sendMessage(McuMailboxes.getID(), IVideoRecorderConstants.ActionIn.SET_VR_ETH.ordinal(), bundle);
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postVRCompleted() {
        if (this.mService != null) {
            try {
                this.mService.sendMessage(McuMailboxes.getID(), IVideoRecorderConstants.ActionIn.FINISH_RECORDER.ordinal(), new Bundle());
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postVRLock() {
        if (this.mService != null) {
            try {
                this.mService.sendMessage(McuMailboxes.getID(), IVideoRecorderConstants.ActionIn.LOCK_VR.ordinal(), new Bundle());
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postVRPause() {
        if (this.mService != null) {
            try {
                this.mService.sendMessage(McuMailboxes.getID(), IVideoRecorderConstants.ActionIn.PAUSE_RECORDER.ordinal(), new Bundle());
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postVRPowerOff() {
        if (this.mService != null) {
            try {
                this.mService.sendMessage(McuMailboxes.getID(), IVideoRecorderConstants.ActionIn.CLOSE_VR.ordinal(), new Bundle());
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postVRPowerOn() {
        if (this.mService != null) {
            try {
                this.mService.sendMessage(McuMailboxes.getID(), IVideoRecorderConstants.ActionIn.WAKEUP_VR.ordinal(), new Bundle());
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postVRStart() {
        if (this.mService != null) {
            try {
                this.mService.sendMessage(McuMailboxes.getID(), IVideoRecorderConstants.ActionIn.START_RECORDER.ordinal(), new Bundle());
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postVRState() {
        if (this.mService != null) {
            sendGetVRState();
        } else if (this.mVRStateRunnable == null) {
            VRStateRunnable vRStateRunnable = new VRStateRunnable();
            this.mVRStateRunnable = vRStateRunnable;
            this.mConnection.post(vRStateRunnable);
        }
    }

    public void postVRStateChange(byte b2) {
        if (this.mService != null) {
            Bundle bundle = new Bundle();
            bundle.putByte(IVideoRecorderConstants.KEY_VR_STATE_CHANGE, b2);
            try {
                this.mService.sendMessage(McuMailboxes.getID(), IVideoRecorderConstants.ActionIn.VR_STATE_CHANGE.ordinal(), bundle);
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postVRUnLock() {
        if (this.mService != null) {
            try {
                this.mService.sendMessage(McuMailboxes.getID(), IVideoRecorderConstants.ActionIn.UNLOCK_VR.ordinal(), new Bundle());
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    @Override // com.seewo.libmcuservice.AbstractMailbox
    protected void release() {
        IVideoRecorderService iVideoRecorderService;
        if (this.mCallback == null || (iVideoRecorderService = this.mService) == null) {
            return;
        }
        try {
            iVideoRecorderService.unregisterCallback(this.mServiceCallback);
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }
}
