package com.seewo.libmcuservice;

import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
import com.seewo.libmcuservice.aidl.IChannelService;
import com.seewo.libmcuservice.aidl.IMcuService;
import com.seewo.libmcuservice.aidl.IServiceCallback;
import com.seewo.libmcuservice.command.CmdChannel;
import com.seewo.libmcuservice.constant.IChannelConstants;
import com.seewo.libmcuservice.constant.ITouchConstants;
import java.util.ArrayList;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class ChannelBox extends AbstractMailbox {
    private static final String TAG = "ChannelBox";
    private AbsChannelCallback mCallback;
    private ChannelConfirmRunnable mConfirmRunnable;
    private ChannelInfoRunnable mInfoRunnable;
    private IChannelService mService;
    private IServiceCallback mServiceCallback = new IServiceCallback.Stub() { // from class: com.seewo.libmcuservice.ChannelBox.1
        @Override // com.seewo.libmcuservice.aidl.IServiceCallback
        public void onCallback(int i2, Bundle bundle) {
            switch (i2) {
                case 1:
                    ChannelBox.this.mCallback.onChannelInfo(bundle.getInt("source"), bundle.getInt(IChannelConstants.KEY_SWITCH_SOURCE_CHANNEL_LIST));
                    break;
                case 2:
                    ChannelBox.this.mCallback.onChannelInfo(bundle.getInt(IChannelConstants.KEY_PRE_HDMI_STATUS), bundle.getInt(IChannelConstants.KEY_CURRENT_HDMI_STATUS), bundle.getInt(IChannelConstants.KEY_PRE_VGA_STATUS), bundle.getInt(IChannelConstants.KEY_CURRENT_VGA_STATUS));
                    break;
                case 4:
                    ChannelBox.this.mCallback.onUSBChannelInfo(bundle.getInt(IChannelConstants.KEY_ACT_USB_CHANNEL));
                    break;
                case 6:
                    ChannelBox.this.mCallback.onSetTouchOutChannel(bundle.getBoolean(IChannelConstants.KEY_RESULT_SET_TOUCH_OUT_CHANNEL));
                    break;
                case 7:
                    ChannelBox.this.mCallback.onGetTouchOutChannel(bundle.getByte(IChannelConstants.KEY_RESULT_GET_TOUCH_OUT_CHANNEL));
                    break;
                case 8:
                    ChannelBox.this.mCallback.onSetPressurePenChannel(bundle.getBoolean(IChannelConstants.KEY_RESULT_SET_PRESSUREPEN_CHANNEL));
                    break;
                case 9:
                    ChannelBox.this.mCallback.onGetPressurePenChannel(bundle.getByte(IChannelConstants.KEY_RESULT_GET_PRESSUREPEN_CHANNEL));
                    break;
                case 10:
                    ChannelBox.this.mCallback.onSetArrayMicChannel(bundle.getBoolean(IChannelConstants.KEY_RESULT_SET_ARRAYMIC_CHANNEL));
                    break;
                case 11:
                    ChannelBox.this.mCallback.onGetArrayMicChannel(bundle.getByte(IChannelConstants.KEY_RESULT_GET_ARRAYMIC_CHANNEL));
                    break;
                case 12:
                    ChannelBox.this.mCallback.onSetRightUSBChannel(bundle.getBoolean(IChannelConstants.KEY_RESULT_SET_RIGHT_USB_CHANNEL));
                    break;
                case 13:
                    ChannelBox.this.mCallback.onSetLeftUSBChannel(bundle.getBoolean(IChannelConstants.KEY_RESULT_SET_LEFT_USB_CHANNEL));
                    break;
                case 14:
                    ChannelBox.this.mCallback.onGetRightUSBChannel(bundle.getByte(IChannelConstants.KEY_RESULT_GET_RIGHT_USB_CHANNEL));
                    break;
                case 15:
                    ChannelBox.this.mCallback.onGetLeftUSBChannel(bundle.getByte(IChannelConstants.KEY_RESULT_GET_LEFT_USB_CHANNEL));
                    break;
            }
        }
    };
    private SwitchTouchRunnable mSwitchTouchRunnable;
    private USBChannelGetRunnable mUSBChannelGetRunnable;
    private USBChannelSetRunnable mUSBChannelSetRunnable;

    public static abstract class AbsChannelCallback {
        public void onChannelInfo(int i2, int i3) {
        }

        public void onChannelInfo(int i2, int i3, int i4, int i5) {
        }

        public void onGetArrayMicChannel(byte b2) {
        }

        public void onGetLeftUSBChannel(byte b2) {
        }

        public void onGetPressurePenChannel(byte b2) {
        }

        public void onGetRightUSBChannel(byte b2) {
        }

        public void onGetTouchOutChannel(byte b2) {
        }

        public void onSetArrayMicChannel(boolean z) {
        }

        public void onSetLeftUSBChannel(boolean z) {
        }

        public void onSetPressurePenChannel(boolean z) {
        }

        public void onSetRightUSBChannel(boolean z) {
        }

        public void onSetTouchOutChannel(boolean z) {
        }

        public void onUSBChannelInfo(int i2) {
        }
    }

    public class ChannelConfirmRunnable implements Runnable {
        public String mSourceName;

        private ChannelConfirmRunnable() {
        }

        @Override // java.lang.Runnable
        public void run() {
            ChannelBox.this.sendChannelConfirm(this.mSourceName);
        }
    }

    public class ChannelInfoRunnable implements Runnable {
        public String mSourceName;

        private ChannelInfoRunnable() {
        }

        @Override // java.lang.Runnable
        public void run() {
            ChannelBox.this.sendChannelInfo(this.mSourceName);
        }
    }

    public enum SourceSignal {
        VGA1,
        VGA2,
        VGA3,
        HDMI1,
        HDMI2,
        HDMI3,
        DP
    }

    public class SwitchTouchRunnable implements Runnable {
        public String channelName;

        public SwitchTouchRunnable(String str) {
            this.channelName = str;
        }

        @Override // java.lang.Runnable
        public void run() {
            ChannelBox.this.sendSwitchTouch(this.channelName);
        }
    }

    public class USBChannelGetRunnable implements Runnable {
        private USBChannelGetRunnable() {
        }

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

    public class USBChannelSetRunnable implements Runnable {
        public int usbChannel;

        private USBChannelSetRunnable() {
        }

        @Override // java.lang.Runnable
        public void run() {
            ChannelBox.this.sendFrontUSBSwitch(this.usbChannel);
        }
    }

    public ChannelBox(AbsChannelCallback absChannelCallback) {
        this.mCallback = absChannelCallback;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void sendChannelConfirm(String str) {
        Bundle bundle = new Bundle();
        bundle.putString(IChannelConstants.KEY_CHANNEL_INFO, str);
        try {
            this.mService.sendMessage(McuMailboxes.getID(), 2, bundle);
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void sendChannelInfo(String str) {
        Bundle bundle = new Bundle();
        bundle.putString(IChannelConstants.KEY_CHANNEL_INFO, str);
        try {
            this.mService.sendMessage(McuMailboxes.getID(), 1, bundle);
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void sendFrontUSBSwitch(int i2) {
        Bundle bundle = new Bundle();
        bundle.putInt(IChannelConstants.KEY_USB_CHANNEL_INFO, i2);
        try {
            this.mService.sendMessage(McuMailboxes.getID(), 3, bundle);
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void sendGetChannel(final int i2) {
        IChannelService iChannelService = this.mService;
        if (iChannelService == null) {
            this.mConnection.post(new Runnable() { // from class: com.seewo.libmcuservice.ChannelBox.2
                @Override // java.lang.Runnable
                public void run() {
                    ChannelBox.this.sendGetChannel(i2);
                }
            });
            return;
        }
        try {
            iChannelService.sendMessage(McuMailboxes.getID(), i2, new Bundle());
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

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

    /* JADX INFO: Access modifiers changed from: private */
    public void sendSetChannel(final int i2, final String str, final byte b2) {
        if (this.mService == null) {
            this.mConnection.post(new Runnable() { // from class: com.seewo.libmcuservice.ChannelBox.3
                @Override // java.lang.Runnable
                public void run() {
                    ChannelBox.this.sendSetChannel(i2, str, b2);
                }
            });
            return;
        }
        Bundle bundle = new Bundle();
        bundle.putByte(str, b2);
        try {
            this.mService.sendMessage(McuMailboxes.getID(), i2, bundle);
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void sendSwitchTouch(String str) {
        Bundle bundle = new Bundle();
        bundle.putString(IChannelConstants.KEY_SWITCH_CHANNEL_NAME, str);
        try {
            this.mService.sendMessage(McuMailboxes.getID(), 5, bundle);
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

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

    public List<SourceSignal> getSignal() {
        ArrayList arrayList = new ArrayList();
        IChannelService iChannelService = this.mService;
        if (iChannelService != null) {
            try {
                int signal = iChannelService.getSignal();
                if (signal == -1) {
                    return arrayList;
                }
                int i2 = 0;
                for (int i3 = 0; i3 < 8; i3++) {
                    if (((1 << i3) & signal) != 0) {
                        arrayList.add(SourceSignal.values()[i3]);
                    }
                }
                SourceSignal.values();
                int iOrdinal = SourceSignal.HDMI1.ordinal();
                while (iOrdinal < 7) {
                    if (((1 << (i2 + 8)) & signal) != 0) {
                        arrayList.add(SourceSignal.values()[iOrdinal]);
                    }
                    iOrdinal++;
                    i2++;
                }
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
        return arrayList;
    }

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

    @Override // com.seewo.libmcuservice.AbstractMailbox
    public void onWorkDone() {
        this.mInfoRunnable = null;
        this.mConfirmRunnable = null;
        this.mUSBChannelSetRunnable = null;
        this.mUSBChannelGetRunnable = null;
        this.mSwitchTouchRunnable = null;
    }

    public void postChannelConfirm(String str) {
        if (this.mService != null) {
            sendChannelConfirm(str);
            return;
        }
        if (this.mConfirmRunnable == null) {
            ChannelConfirmRunnable channelConfirmRunnable = new ChannelConfirmRunnable();
            this.mConfirmRunnable = channelConfirmRunnable;
            this.mConnection.post(channelConfirmRunnable);
        }
        this.mConfirmRunnable.mSourceName = str;
    }

    public void postChannelInfo(String str) {
        if (this.mService != null) {
            sendChannelInfo(str);
            return;
        }
        if (this.mInfoRunnable == null) {
            ChannelInfoRunnable channelInfoRunnable = new ChannelInfoRunnable();
            this.mInfoRunnable = channelInfoRunnable;
            this.mConnection.post(channelInfoRunnable);
        }
        this.mInfoRunnable.mSourceName = str;
    }

    public void postGetLeftUSBChannel() {
        sendGetChannel(15);
    }

    public void postGetRightUSBChannel() {
        sendGetChannel(13);
    }

    public void postGetUSBChannel() {
        if (this.mService != null) {
            sendGetFrontUSBSwitch();
        } else if (this.mUSBChannelGetRunnable == null) {
            USBChannelGetRunnable uSBChannelGetRunnable = new USBChannelGetRunnable();
            this.mUSBChannelGetRunnable = uSBChannelGetRunnable;
            this.mConnection.post(uSBChannelGetRunnable);
        }
    }

    public void postQueryArrayMicChannel() {
        sendGetChannel(11);
    }

    public void postQueryPressurePenChannel() {
        sendGetChannel(9);
    }

    public void postQueryTouchOutChannel() {
        sendGetChannel(7);
    }

    public void postSetArrayMicChannel(byte b2) {
        sendSetChannel(10, IChannelConstants.KEY_CHANNEL_OF_ARRAYMIC_TO_SET, b2);
    }

    public void postSetCapTouchChannel(CmdChannel.TouchChannel touchChannel) {
        if (this.mService != null) {
            try {
                Bundle bundle = new Bundle();
                bundle.putInt(ITouchConstants.KEY_TOUCH_SOURCE, touchChannel.ordinal());
                this.mService.sendMessage(McuMailboxes.getID(), 114, bundle);
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postSetLeftUSBChannel(byte b2) {
        sendSetChannel(14, IChannelConstants.KEY_SET_LEFT_USB_CHANNEL, b2);
    }

    public void postSetPressureChannel(byte b2) {
        sendSetChannel(8, IChannelConstants.KEY_CHANNEL_OF_PRESSUREPEN_TO_SET, b2);
    }

    public void postSetRightUSBChannel(byte b2) {
        sendSetChannel(12, IChannelConstants.KEY_SET_RIGHT_USB_CHANNEL, b2);
    }

    public void postSetTouchOutChannel(byte b2) {
        sendSetChannel(6, IChannelConstants.KEY_CHANNEL_OF_TOUCH_OUT_TO_SET, b2);
    }

    public void postTouchSwitch(String str) {
        if (this.mService != null) {
            sendSwitchTouch(str);
        } else if (this.mSwitchTouchRunnable == null) {
            SwitchTouchRunnable switchTouchRunnable = new SwitchTouchRunnable(str);
            this.mSwitchTouchRunnable = switchTouchRunnable;
            this.mConnection.post(switchTouchRunnable);
        }
    }

    public void postUSBChannelSwitch(int i2) {
        if (this.mService != null) {
            sendFrontUSBSwitch(i2);
            return;
        }
        if (this.mUSBChannelSetRunnable == null) {
            USBChannelSetRunnable uSBChannelSetRunnable = new USBChannelSetRunnable();
            this.mUSBChannelSetRunnable = uSBChannelSetRunnable;
            this.mConnection.post(uSBChannelSetRunnable);
        }
        this.mUSBChannelSetRunnable.usbChannel = i2;
    }

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