package com.seewo.libmcuservice;

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

/* JADX INFO: loaded from: classes.dex */
public class FactoryBox extends AbstractMailbox {
    private static final String TAG = "FactoryBox";
    private AbsFactoryCallback mCallback;
    private Runnable mFTGetResultRunnable;
    private Runnable mFTGetVersionRunnable;
    private Runnable mFTReTestRunnable;
    private Runnable mResetMcuRunnable;
    private IFactoryService mService;
    private IServiceCallback mServiceCallback = new IServiceCallback.Stub() { // from class: com.seewo.libmcuservice.FactoryBox.1
        @Override // com.seewo.libmcuservice.aidl.IServiceCallback
        public void onCallback(int i, Bundle bundle) throws RemoteException {
            if (FactoryBox.this.mCallback == null) {
                return;
            }
            if (i == 1) {
                FactoryBox.this.mCallback.onResetMcu();
                return;
            }
            if (i == 2) {
                FactoryBox.this.mCallback.onFTGetResult(bundle.getByteArray(IFactoryConstants.KEY_FT_GET_RESULT));
            } else if (i == 3) {
                FactoryBox.this.mCallback.onFTReTest(bundle.getBoolean(IFactoryConstants.KEY_FT_RE_TEST));
            } else if (i == 5) {
                FactoryBox.this.mCallback.onFTGetVersion(bundle.getByteArray(IFactoryConstants.KEY_FT_GET_VERSION));
            }
        }
    };
    private Runnable mSysRebootRunnable;

    public static abstract class AbsFactoryCallback {
        protected void onFTGetResult(byte[] bArr) {
        }

        protected void onFTGetVersion(byte[] bArr) {
        }

        protected void onFTReTest(boolean z) {
        }

        protected void onResetMcu() {
        }
    }

    FactoryBox(AbsFactoryCallback absFactoryCallback) {
        this.mCallback = absFactoryCallback;
    }

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

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

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

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

    /* JADX INFO: Access modifiers changed from: private */
    public void sendSysReboot() {
        try {
            this.mService.sendMessage(McuMailboxes.getID(), 4, 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 {
            IFactoryService factoryService = iMcuService.getFactoryService();
            this.mService = factoryService;
            if (this.mCallback != null) {
                factoryService.registerCallback(this.mServiceCallback);
            }
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

    @Override // com.seewo.libmcuservice.AbstractMailbox
    protected void onWorkDone() {
        this.mResetMcuRunnable = null;
        this.mFTGetResultRunnable = null;
        this.mFTReTestRunnable = null;
        this.mSysRebootRunnable = null;
    }

    public void postFTGetResult() {
        if (this.mService != null) {
            sendFTGetResult();
        } else if (this.mFTGetResultRunnable == null) {
            Runnable runnable = new Runnable() { // from class: com.seewo.libmcuservice.FactoryBox.4
                @Override // java.lang.Runnable
                public void run() {
                    FactoryBox.this.sendFTGetResult();
                }
            };
            this.mFTGetResultRunnable = runnable;
            this.mConnection.post(runnable);
        }
    }

    public void postFTGetVersion() {
        if (this.mService != null) {
            sendFTGetVersion();
        } else if (this.mFTGetVersionRunnable == null) {
            Runnable runnable = new Runnable() { // from class: com.seewo.libmcuservice.FactoryBox.3
                @Override // java.lang.Runnable
                public void run() {
                    FactoryBox.this.sendFTGetVersion();
                }
            };
            this.mFTGetVersionRunnable = runnable;
            this.mConnection.post(runnable);
        }
    }

    public void postFTReTest() {
        if (this.mService != null) {
            sendFTReTest();
        } else if (this.mFTReTestRunnable == null) {
            Runnable runnable = new Runnable() { // from class: com.seewo.libmcuservice.FactoryBox.5
                @Override // java.lang.Runnable
                public void run() {
                    FactoryBox.this.sendFTReTest();
                }
            };
            this.mFTReTestRunnable = runnable;
            this.mConnection.post(runnable);
        }
    }

    public void postResetMcu() {
        if (this.mService != null) {
            sendResetMcu();
        } else if (this.mResetMcuRunnable == null) {
            Runnable runnable = new Runnable() { // from class: com.seewo.libmcuservice.FactoryBox.2
                @Override // java.lang.Runnable
                public void run() {
                    FactoryBox.this.sendResetMcu();
                }
            };
            this.mResetMcuRunnable = runnable;
            this.mConnection.post(runnable);
        }
    }

    public void postSysReboot() {
        if (this.mService != null) {
            sendSysReboot();
        } else if (this.mSysRebootRunnable == null) {
            Runnable runnable = new Runnable() { // from class: com.seewo.libmcuservice.FactoryBox.6
                @Override // java.lang.Runnable
                public void run() {
                    FactoryBox.this.sendSysReboot();
                }
            };
            this.mSysRebootRunnable = runnable;
            this.mConnection.post(runnable);
        }
    }

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