package com.seewo.libmcuservice;

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

/* JADX INFO: loaded from: classes.dex */
public class PCStateBox extends AbstractMailbox {
    private static final String TAG = "PCStateBox";
    private AbsPCStateCallback mCallback;
    private QueryPCStateRunnable mQueryPCStateRunnable;
    private IQueryPcStateService mService;
    private IServiceCallback mServiceCallback = new IServiceCallback.Stub() { // from class: com.seewo.libmcuservice.PCStateBox.1
        @Override // com.seewo.libmcuservice.aidl.IServiceCallback
        public void onCallback(int i2, Bundle bundle) {
            if (i2 == 1) {
                PCStateBox.this.mCallback.onPCState(IQueryPcStateConstants.PcStatus.valueOf(bundle.getString(IQueryPcStateConstants.KEY_PC_STATE)));
            }
        }
    };

    public static abstract class AbsPCStateCallback {
        public void onPCState(IQueryPcStateConstants.PcStatus pcStatus) {
        }
    }

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

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

    public PCStateBox(AbsPCStateCallback absPCStateCallback) {
        this.mCallback = absPCStateCallback;
    }

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

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

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

    public void postQueryPCState() {
        IQueryPcStateService iQueryPcStateService = this.mService;
        if (iQueryPcStateService != null) {
            try {
                iQueryPcStateService.sendMessage(McuMailboxes.getID(), 2, new Bundle());
                return;
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
                return;
            }
        }
        if (this.mQueryPCStateRunnable == null) {
            QueryPCStateRunnable queryPCStateRunnable = new QueryPCStateRunnable();
            this.mQueryPCStateRunnable = queryPCStateRunnable;
            this.mConnection.post(queryPCStateRunnable);
        }
    }

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

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

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