package com.seewo.libmcuservice;

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

/* JADX INFO: loaded from: classes.dex */
public class KeyLockerBox extends AbstractMailbox {
    private static final String TAG = "KeyLockerBox";
    private AbsKeyLockerCallback mCallback;
    private ChildLockRunnable mChildLockRunnable;
    private Runnable mClearKeypadRunnable;
    private RemoteControlRunnable mRemoteControlRunnable;
    private IKeyLockerService mService;
    private IServiceCallback mServiceCallback = new IServiceCallback.Stub() { // from class: com.seewo.libmcuservice.KeyLockerBox.1
        @Override // com.seewo.libmcuservice.aidl.IServiceCallback
        public void onCallback(int i, Bundle bundle) throws RemoteException {
            if (KeyLockerBox.this.mCallback == null) {
                return;
            }
            if (i == 1) {
                KeyLockerBox.this.mCallback.onTouchBack();
            } else if (i == 2) {
                KeyLockerBox.this.mCallback.onRemoteControlStateBack(bundle.getInt(IKeyLockerConstants.KEY_GET_REMOTE_CONTROL, 1));
            }
        }
    };
    private Runnable mSetKeypadRunnable;

    public static abstract class AbsKeyLockerCallback {
        protected void onRemoteControlStateBack(int i) {
        }

        protected void onTouchBack() {
        }
    }

    private class ChildLockRunnable implements Runnable {
        boolean mState;

        private ChildLockRunnable() {
        }

        @Override // java.lang.Runnable
        public void run() {
            KeyLockerBox.this.sendSetChildLockState(this.mState);
        }
    }

    private class RemoteControlRunnable implements Runnable {
        int mState;

        private RemoteControlRunnable() {
        }

        @Override // java.lang.Runnable
        public void run() {
            KeyLockerBox.this.sendRemoteControlState(this.mState);
        }
    }

    KeyLockerBox(AbsKeyLockerCallback absKeyLockerCallback) {
        this.mCallback = absKeyLockerCallback;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void sendClearKeypadLock() {
        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 sendRemoteControlState(int i) {
        try {
            Bundle bundle = new Bundle();
            bundle.putInt(IKeyLockerConstants.KEY_SET_REMOTE_CONTROL, i);
            this.mService.sendMessage(McuMailboxes.getID(), 4, bundle);
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void sendSetChildLockState(boolean z) {
        try {
            Bundle bundle = new Bundle();
            bundle.putBoolean(IKeyLockerConstants.KEY_SET_CHILD_LOCK, z);
            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 sendSetKeypadLock() {
        try {
            this.mService.sendMessage(McuMailboxes.getID(), 1, 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 {
            IKeyLockerService keyLockerService = iMcuService.getKeyLockerService();
            this.mService = keyLockerService;
            if (this.mCallback != null) {
                keyLockerService.registerCallback(this.mServiceCallback);
            }
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

    @Override // com.seewo.libmcuservice.AbstractMailbox
    protected void onWorkDone() {
        this.mSetKeypadRunnable = null;
        this.mClearKeypadRunnable = null;
        this.mChildLockRunnable = null;
        this.mRemoteControlRunnable = null;
    }

    public void postClearChildLock() {
        if (this.mService != null) {
            sendSetChildLockState(false);
            return;
        }
        if (this.mChildLockRunnable == null) {
            ChildLockRunnable childLockRunnable = new ChildLockRunnable();
            this.mChildLockRunnable = childLockRunnable;
            this.mConnection.post(childLockRunnable);
        }
        this.mChildLockRunnable.mState = false;
    }

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

    public void postGetRemoteControl() {
        IKeyLockerService iKeyLockerService = this.mService;
        if (iKeyLockerService != null) {
            try {
                iKeyLockerService.sendMessage(McuMailboxes.getID(), 5, new Bundle());
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postSetChildLock() {
        if (this.mService != null) {
            sendSetChildLockState(true);
            return;
        }
        if (this.mChildLockRunnable == null) {
            ChildLockRunnable childLockRunnable = new ChildLockRunnable();
            this.mChildLockRunnable = childLockRunnable;
            this.mConnection.post(childLockRunnable);
        }
        this.mChildLockRunnable.mState = true;
    }

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

    public void postSetRemoteControl(int i) {
        if (this.mService != null) {
            sendRemoteControlState(i);
            return;
        }
        if (this.mRemoteControlRunnable == null) {
            this.mRemoteControlRunnable = new RemoteControlRunnable();
        }
        RemoteControlRunnable remoteControlRunnable = this.mRemoteControlRunnable;
        remoteControlRunnable.mState = i;
        this.mConnection.post(remoteControlRunnable);
    }

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