package com.seewo.libmcuservice;

import a.b.c.a.a;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
import com.seewo.libmcuservice.aidl.IMcuService;
import com.seewo.libmcuservice.aidl.IPowerService;
import com.seewo.libmcuservice.aidl.IServiceCallback;
import com.seewo.libmcuservice.constant.IPowerConstants;

/* JADX INFO: loaded from: classes.dex */
public class PowerBox extends AbstractMailbox {
    private static final String TAG = "PCStateBox";
    private AbsPowerCallback mCallback;
    private Context mContext;
    private IPowerService mService;
    private BroadcastReceiver mReceiver = new BroadcastReceiver() { // from class: com.seewo.libmcuservice.PowerBox.1
        @Override // android.content.BroadcastReceiver
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals("com.cvte.newmcuto901.ACTION_BROADCAST_BACKLIGHT_CONTROL")) {
                PowerBox.this.mCallback.onBacklightControl(intent.getBooleanExtra("KEY_BACKLIGHT_CONTROL", true));
            }
        }
    };
    private IServiceCallback mServiceCallback = new IServiceCallback.Stub() { // from class: com.seewo.libmcuservice.PowerBox.2
        @Override // com.seewo.libmcuservice.aidl.IServiceCallback
        public void onCallback(int i2, Bundle bundle) {
            switch (i2) {
                case 1:
                    PowerBox.this.mCallback.onPowerControl(bundle.getString(IPowerConstants.KEY_POWEROFF_ORIGIN, ""), bundle.getInt(IPowerConstants.KEY_MCU_TO_OUTSIDE_VALUE), bundle.getBoolean(IPowerConstants.KEY_POWER_CONTROL));
                    break;
                case 3:
                    PowerBox.this.mCallback.onDetectPCSleep(bundle.getInt(IPowerConstants.KEY_MCU_TO_OUTSIDE_VALUE));
                    break;
                case 4:
                    PowerBox.this.mCallback.onDetectPCCrash();
                    break;
                case 5:
                    PowerBox.this.mCallback.onResetAP();
                    break;
                case 7:
                    PowerBox.this.mCallback.onRemoteSwitchChange(bundle.getBoolean(IPowerConstants.KEY_REMOTE_SWITCH_CHANGED));
                    break;
                case 8:
                    PowerBox.this.mCallback.onRemoteDummyStandbySwitch();
                    break;
                case 9:
                    PowerBox.this.mCallback.onDetectPCOff();
                    break;
                case 10:
                    PowerBox.this.mCallback.onGetProwiseSleepTime();
                    break;
                case 11:
                    PowerBox.this.mCallback.onSetProwiseSleepTime(bundle.getInt(IPowerConstants.KEY_SLEEPTIME));
                    break;
                case 12:
                    PowerBox.this.mCallback.onRemoteSwitchChange(bundle.getInt(IPowerConstants.KEY_REMOTE_DUMMY_SWITCH) == 1);
                    break;
                case 14:
                    PowerBox.this.mCallback.onDetectPowerState(bundle.getInt(IPowerConstants.KEY_ACTION_POWER_STATE));
                    break;
            }
        }
    };

    public static abstract class AbsPowerCallback {
        public void onBacklightControl(boolean z) {
        }

        public void onDetectPCCrash() {
        }

        public void onDetectPCOff() {
        }

        public void onDetectPCSleep(int i2) {
        }

        public void onDetectPowerState(int i2) {
        }

        public void onGetProwiseSleepTime() {
        }

        public void onPowerControl(String str, int i2, boolean z) {
        }

        public void onRemoteDummyStandbySwitch() {
        }

        public void onRemoteSwitchChange(boolean z) {
        }

        public void onResetAP() {
        }

        public void onSetProwiseSleepTime(int i2) {
        }
    }

    public PowerBox(Context context, AbsPowerCallback absPowerCallback) {
        this.mContext = context;
        this.mCallback = absPowerCallback;
        if (absPowerCallback != null) {
            registerBroadcast();
        }
    }

    private void registerBroadcast() {
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.cvte.newmcuto901.ACTION_BROADCAST_BACKLIGHT_CONTROL");
        this.mContext.registerReceiver(this.mReceiver, intentFilter);
    }

    private void unregisterBroadcast() {
        this.mContext.unregisterReceiver(this.mReceiver);
    }

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

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

    public void notifyAndroidReboot() {
        IPowerService iPowerService = this.mService;
        if (iPowerService != null) {
            try {
                iPowerService.sendMessage(McuMailboxes.getID(), 19, new Bundle());
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

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

    public void postClearCECAutoBoot() {
        IPowerService iPowerService = this.mService;
        if (iPowerService != null) {
            try {
                iPowerService.sendMessage(McuMailboxes.getID(), 4, new Bundle());
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postCloseSystem() {
        IPowerService iPowerService = this.mService;
        if (iPowerService != null) {
            try {
                iPowerService.sendMessage(McuMailboxes.getID(), 1, new Bundle());
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postCloseWithPCOn() {
        IPowerService iPowerService = this.mService;
        if (iPowerService != null) {
            try {
                iPowerService.sendMessage(McuMailboxes.getID(), 2, new Bundle());
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postCloseWithPCOnInPC() {
        IPowerService iPowerService = this.mService;
        if (iPowerService != null) {
            try {
                iPowerService.sendMessage(McuMailboxes.getID(), 6, new Bundle());
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postEnterFakeStandby() {
        IPowerService iPowerService = this.mService;
        if (iPowerService != null) {
            try {
                iPowerService.sendMessage(McuMailboxes.getID(), 17, new Bundle());
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postLeaveFakeStandby() {
        IPowerService iPowerService = this.mService;
        if (iPowerService != null) {
            try {
                iPowerService.sendMessage(McuMailboxes.getID(), 18, new Bundle());
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postPowerState(int i2) {
        if (this.mService != null) {
            try {
                Bundle bundle = new Bundle();
                bundle.putInt(IPowerConstants.KEY_ACTION_POWER_STATE, i2);
                this.mService.sendMessage(McuMailboxes.getID(), 14, bundle);
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postPressPower(String str, int i2) {
        if (this.mService != null) {
            Bundle bundle = new Bundle();
            bundle.putString(IPowerConstants.KEY_POWEROFF_ORIGIN, str);
            bundle.putInt(IPowerConstants.KEY_SHUTDOWN_TIMER_TIME, i2);
            try {
                this.mService.sendMessage(McuMailboxes.getID(), 10, bundle);
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postPressPower(String str, int i2, boolean z) {
        if (this.mService != null) {
            Bundle bundle = new Bundle();
            bundle.putBoolean(IPowerConstants.KEY_INTERCEPT_SHUTDOWN, z);
            bundle.putString(IPowerConstants.KEY_POWEROFF_ORIGIN, str);
            bundle.putInt(IPowerConstants.KEY_SHUTDOWN_TIMER_TIME, i2);
            try {
                this.mService.sendMessage(McuMailboxes.getID(), 10, bundle);
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postRemoteSwitchChange(int i2) {
        if (this.mService != null) {
            try {
                Bundle bundle = new Bundle();
                bundle.putInt(IPowerConstants.KEY_REMOTE_DUMMY_SWITCH, i2);
                this.mService.sendMessage(McuMailboxes.getID(), 12, bundle);
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postReplyCurrentSleepTime(int i2) {
        if (this.mService != null) {
            try {
                Bundle bundle = new Bundle();
                bundle.putInt(IPowerConstants.KEY_SLEEPTIME, i2);
                this.mService.sendMessage(McuMailboxes.getID(), 15, bundle);
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postSetCECAutoBoot() {
        IPowerService iPowerService = this.mService;
        if (iPowerService != null) {
            try {
                iPowerService.sendMessage(McuMailboxes.getID(), 3, new Bundle());
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postShutdownScreen() {
        a.h0("com.cvte.newmcuto901.ACTION_ACTION_SHUTDOWN_SCREEN", this.mContext);
    }

    public void postWakeupActiveSourceChange(boolean z) {
        if (this.mService != null) {
            try {
                Bundle bundle = new Bundle();
                bundle.putBoolean(IPowerConstants.KEY_WAKEUP_ACTIVE_SOURCE_SWITCH, z);
                this.mService.sendMessage(McuMailboxes.getID(), 16, bundle);
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }

    public void postWakeupScreen() {
        a.h0("com.cvte.newmcuto901.ACTION_WAKEUP_SCREEN", this.mContext);
    }

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