package com.seewo.libmcuservice;

import a.b.c.a.a;
import android.content.Context;
import android.content.Intent;
import android.os.Binder;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
import com.seewo.libmcuservice.aidl.IMcuService;
import com.seewo.libmcuservice.aidl.IOsdService;
import com.seewo.libmcuservice.aidl.IServiceCallback;
import com.seewo.libmcuservice.constant.ICommonConstants;
import com.seewo.libmcuservice.constant.IOsdConstants;
import com.seewo.libmcuservice.model.NoTouchArea;

/* JADX INFO: loaded from: classes.dex */
public class OsdBox extends AbstractMailbox {
    private static final String NULL_POINT = "IOsdService is null";
    private static final String TAG = "OsdBox";
    private AddOrUpdateAreaMsgRunnable mAddOrUpdateAreaMsgRunnable;
    private Context mContext;
    private AbsOsdCallBack mOsdCallBack;
    private IOsdService mService;
    private IServiceCallback mServiceCallback = new IServiceCallback.Stub() { // from class: com.seewo.libmcuservice.OsdBox.1
        @Override // com.seewo.libmcuservice.aidl.IServiceCallback
        public void onCallback(int i2, Bundle bundle) {
            Log.d(OsdBox.TAG, "mServiceCallback--->action: " + i2);
            if (OsdBox.this.mOsdCallBack == null) {
                Log.d(OsdBox.TAG, "mOsdCallBack: == null");
            }
            switch (i2) {
                case 36:
                    OsdBox.this.mOsdCallBack.onGetAddOrUpdateAreaResult(bundle);
                    break;
                case 37:
                    OsdBox.this.mOsdCallBack.onGetDeleteAreaResult(bundle);
                    break;
                case 38:
                    OsdBox.this.mOsdCallBack.onGetQuerySpecificAreaResult(bundle);
                    break;
                case 39:
                    OsdBox.this.mOsdCallBack.onGetQueryAllAreaResult(bundle);
                    break;
            }
        }
    };

    public static abstract class AbsOsdCallBack {
        public void onGetAddOrUpdateAreaResult(Bundle bundle) {
        }

        public void onGetDeleteAreaResult(Bundle bundle) {
        }

        public void onGetQueryAllAreaResult(Bundle bundle) {
        }

        public void onGetQuerySpecificAreaResult(Bundle bundle) {
        }
    }

    public class AddOrUpdateAreaMsgRunnable implements Runnable {
        public NoTouchArea area;

        public AddOrUpdateAreaMsgRunnable(NoTouchArea noTouchArea) {
            this.area = noTouchArea;
        }

        @Override // java.lang.Runnable
        public void run() {
            OsdBox.this.sendAreaMsg(this.area);
        }
    }

    public OsdBox(Context context) {
        this.mContext = context;
    }

    public OsdBox(Context context, AbsOsdCallBack absOsdCallBack) {
        this.mContext = context;
        this.mOsdCallBack = absOsdCallBack;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public void sendAreaMsg(NoTouchArea noTouchArea) {
        Bundle bundle = new Bundle();
        bundle.putSerializable(IOsdConstants.KEY_NON_OPREATION_AREA, noTouchArea);
        try {
            this.mService.sendMessage(McuMailboxes.getID(), 36, bundle);
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

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

    @Override // com.seewo.libmcuservice.AbstractMailbox
    public void initService(IMcuService iMcuService) {
        try {
            this.mService = iMcuService.getOsdService();
            StringBuilder sb = new StringBuilder();
            sb.append("mConnection service: ");
            boolean z = true;
            sb.append(this.mService != null);
            Log.d(TAG, sb.toString());
            StringBuilder sb2 = new StringBuilder();
            sb2.append("mConnection callback: ");
            if (this.mOsdCallBack == null) {
                z = false;
            }
            sb2.append(z);
            Log.d(TAG, sb2.toString());
            this.mService.registerCallback(new Binder(), this.mContext.getPackageName(), this.mServiceCallback);
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

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

    public void postAddOrUpdateAreaMsg(NoTouchArea noTouchArea) {
        StringBuilder sbC = a.C(" pArea:");
        sbC.append(noTouchArea.toString());
        Log.d(TAG, sbC.toString());
        if (this.mService != null) {
            sendAreaMsg(noTouchArea);
            return;
        }
        if (this.mAddOrUpdateAreaMsgRunnable == null) {
            AddOrUpdateAreaMsgRunnable addOrUpdateAreaMsgRunnable = new AddOrUpdateAreaMsgRunnable(noTouchArea);
            this.mAddOrUpdateAreaMsgRunnable = addOrUpdateAreaMsgRunnable;
            this.mConnection.post(addOrUpdateAreaMsgRunnable);
        }
        Log.e(TAG, NULL_POINT);
    }

    public void postDeleteAreaMsg(byte b2) {
        Log.d(TAG, "delete area id : " + ((int) b2));
        if (this.mService == null) {
            Log.e(TAG, NULL_POINT);
            return;
        }
        Bundle bundle = new Bundle();
        bundle.putByte(IOsdConstants.KEY_AREA_ID, b2);
        try {
            this.mService.sendMessage(McuMailboxes.getID(), 37, bundle);
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

    public void postOsdOff() {
        Intent intent = new Intent(IOsdConstants.ACTION_IN_OSD_OFF);
        intent.putExtra(ICommonConstants.KEY_PACKAGE_NAME, this.mContext.getPackageName());
        this.mContext.sendBroadcast(intent);
    }

    public void postOsdOn() {
        Intent intent = new Intent(IOsdConstants.ACTION_IN_OSD_ON);
        intent.putExtra(ICommonConstants.KEY_PACKAGE_NAME, this.mContext.getPackageName());
        this.mContext.sendBroadcast(intent);
    }

    public void postQueryAllNoTouchArea() {
        Log.d(TAG, "query all no touch area");
        IOsdService iOsdService = this.mService;
        if (iOsdService == null) {
            Log.e(TAG, NULL_POINT);
            return;
        }
        try {
            iOsdService.sendMessage(McuMailboxes.getID(), 39, new Bundle());
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

    public void postQueryNoTouchAreaByIdMsg(byte b2) {
        Log.d(TAG, "query area id: " + ((int) b2));
        if (this.mService == null) {
            Log.e(TAG, NULL_POINT);
            return;
        }
        Bundle bundle = new Bundle();
        bundle.putByte(IOsdConstants.KEY_AREA_ID, b2);
        try {
            this.mService.sendMessage(McuMailboxes.getID(), 38, bundle);
        } catch (RemoteException e2) {
            Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
        }
    }

    @Override // com.seewo.libmcuservice.AbstractMailbox
    public void release() {
        Log.d(TAG, "release callback");
        IOsdService iOsdService = this.mService;
        if (iOsdService != null) {
            try {
                iOsdService.unregisterCallback(this.mContext.getPackageName(), this.mServiceCallback);
            } catch (RemoteException e2) {
                Log.e(TAG, LibMcuApplication.REMOTE_EXCEPTION, e2);
            }
        }
    }
}
