package com.seewo.libmcuservice;

import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
import com.seewo.libmcuservice.aidl.IBootChannelService;
import com.seewo.libmcuservice.aidl.IMcuService;
import com.seewo.libmcuservice.constant.IBootChannelConstants;

/* JADX INFO: loaded from: classes.dex */
public class BootChannelBox extends AbstractMailbox {
    private static final String TAG = "BootChannelBox";
    private ChannelChoiceRunnable mChannelRunnable;
    private PCChoiceRunnable mPCRunnable;
    private IBootChannelService mService;

    private class ChannelChoiceRunnable implements Runnable {
        byte mForceChannel;

        private ChannelChoiceRunnable() {
        }

        @Override // java.lang.Runnable
        public void run() {
            BootChannelBox.this.sendBootChannelChoice(this.mForceChannel);
        }
    }

    private class PCChoiceRunnable implements Runnable {
        private byte mBootWay;

        private PCChoiceRunnable() {
        }

        @Override // java.lang.Runnable
        public void run() {
            BootChannelBox.this.sendBootPCChoice(this.mBootWay);
        }
    }

    BootChannelBox() {
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void sendBootChannelChoice(byte b2) {
        Bundle bundle = new Bundle();
        bundle.putByte(IBootChannelConstants.KEY_FORCE_CHANNEL, b2);
        try {
            this.mService.sendMessage(McuMailboxes.getID(), 0, bundle);
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void sendBootPCChoice(byte b2) {
        Bundle bundle = new Bundle();
        bundle.putByte(IBootChannelConstants.KEY_PC_BOOT_CHOICE, b2);
        try {
            this.mService.sendMessage(McuMailboxes.getID(), 1, 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 {
            this.mService = iMcuService.getBootChannelService();
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

    @Override // com.seewo.libmcuservice.AbstractMailbox
    protected void onWorkDone() {
        this.mChannelRunnable = null;
        this.mPCRunnable = null;
    }

    public void postBootChannelChoice(byte b2) {
        if (this.mService != null) {
            sendBootChannelChoice(b2);
            return;
        }
        if (this.mChannelRunnable == null) {
            ChannelChoiceRunnable channelChoiceRunnable = new ChannelChoiceRunnable();
            this.mChannelRunnable = channelChoiceRunnable;
            this.mConnection.post(channelChoiceRunnable);
        }
        this.mChannelRunnable.mForceChannel = b2;
    }

    public void postBootPCChoice(byte b2) {
        if (this.mService != null) {
            sendBootPCChoice(b2);
            return;
        }
        if (this.mPCRunnable == null) {
            PCChoiceRunnable pCChoiceRunnable = new PCChoiceRunnable();
            this.mPCRunnable = pCChoiceRunnable;
            this.mConnection.post(pCChoiceRunnable);
        }
        this.mPCRunnable.mBootWay = b2;
    }

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