package com.seewo.sdk.pcremotesp20;

import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import com.seewo.sdk.internal.utils.Constants;
import com.seewo.sdk.internal.utils.SDKServiceManager;
import com.seewo.sdk.pcremote.IPCRemoteSp20Callback;
import com.seewo.sdk.pcremote.IPCRemoteSp20Service;
import d.b.a.a.a;
import java.util.HashMap;
import java.util.Map;

/* JADX INFO: loaded from: classes.dex */
public class SDKPCRemoteSp20Command implements ISDKPcRemoteSp20Command {
    private static final String TAG = "SDKPCRemoteSp20Command";
    private static SDKPCRemoteSp20Command sInstance;
    private Map<String, ISDKPcRemoteSp20CommandCallback> mClientList = new HashMap();
    private IPCRemoteSp20Service mIPCRemoteSp20Service;

    private SDKPCRemoteSp20Command() {
    }

    public static SDKPCRemoteSp20Command getInstance() {
        if (sInstance == null) {
            sInstance = new SDKPCRemoteSp20Command();
        }
        return sInstance;
    }

    private boolean init() {
        IBinder service = SDKServiceManager.i().getService(Constants.SOCKET_PC_REMOTE_SP20_SERVICE);
        if (service == null) {
            return false;
        }
        this.mIPCRemoteSp20Service = IPCRemoteSp20Service.Stub.asInterface(service);
        return true;
    }

    public void reConnect() {
        Log.i(TAG, "reConnect: ");
        Map<String, ISDKPcRemoteSp20CommandCallback> map = this.mClientList;
        if (map == null || map.isEmpty()) {
            return;
        }
        for (String str : this.mClientList.keySet()) {
            registerCallBack(str, this.mClientList.get(str));
        }
    }

    @Override // com.seewo.sdk.pcremotesp20.ISDKPcRemoteSp20Command
    public boolean registerCallBack(String str, final ISDKPcRemoteSp20CommandCallback iSDKPcRemoteSp20CommandCallback) {
        a.N("registerCallBack: ", str, TAG);
        boolean zInit = init();
        IPCRemoteSp20Service iPCRemoteSp20Service = this.mIPCRemoteSp20Service;
        if (iPCRemoteSp20Service != null) {
            try {
                iPCRemoteSp20Service.registerCallBack(str, new IPCRemoteSp20Callback.Stub() { // from class: com.seewo.sdk.pcremotesp20.SDKPCRemoteSp20Command.1
                    @Override // com.seewo.sdk.pcremote.IPCRemoteSp20Callback
                    public void onHandleSp20Command(byte[] bArr) throws RemoteException {
                        iSDKPcRemoteSp20CommandCallback.onHandleSp20Command(bArr);
                    }
                });
                Map<String, ISDKPcRemoteSp20CommandCallback> map = this.mClientList;
                if (map != null) {
                    map.put(str, iSDKPcRemoteSp20CommandCallback);
                }
            } catch (RemoteException e2) {
                Log.e(TAG, "registerCallBack: ", e2);
            }
        }
        return zInit && this.mIPCRemoteSp20Service != null;
    }

    @Override // com.seewo.sdk.pcremotesp20.ISDKPcRemoteSp20Command
    public void unRegisterCallBack(String str) {
        a.N("unRegisterCallBack: ", str, TAG);
        IPCRemoteSp20Service iPCRemoteSp20Service = this.mIPCRemoteSp20Service;
        if (iPCRemoteSp20Service != null) {
            try {
                iPCRemoteSp20Service.unRegisterCallBack(str);
            } catch (RemoteException e2) {
                Log.e(TAG, "unRegisterCallBack: ", e2);
            }
        }
    }
}
