package com.dss.tpservice;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import com.dss.tpservice.ITPManager;
import com.dss.tpservice.controller.ITPController;
import com.dss.tpservice.controller.MXBoardController;
import com.dss.tpservice.controller.MonitorAppController;
import com.dss.tpservice.controller.PreventScratchController;
import com.dss.tpservice.controller.TPController;
import com.dss.tpservice.controller.TPControllerV2;
import com.dss.tpservice.controller.WritingController;
import com.seewo.sdk.OpenSDK;
import com.seewo.vcommons.constants.SeewoConstants;
import com.seewo.vcommons.data.PropertiesUtils;

/* JADX INFO: loaded from: classes.dex */
public class TPManagerService extends Service {
    private static final String CHANNEL_ID = "TPManagerServiceChannel";
    private static final int NOTIFICATION_ID = 1001;
    public static final String TAG = "TPManagerService";
    private final IBinder mIBinder = new ITPManager.Stub() { // from class: com.dss.tpservice.TPManagerService.1
        @Override // com.dss.tpservice.ITPManager
        public void createLayer(WindowInfo windowInfo) throws RemoteException {
            TPManagerService.this.mTPController.createLayer(windowInfo);
            TPManagerService.this.mMonitorAppController.handleAppCreate(windowInfo);
            TPManagerService.this.mWritingController.handleAppCreate(windowInfo);
            TPManagerService.this.mPreventScratchController.handleAppCreate(windowInfo);
        }

        @Override // com.dss.tpservice.ITPManager
        public void blockTransfer(WindowInfo windowInfo) throws RemoteException {
            TPManagerService.this.mTPController.blockTransfer(windowInfo);
            TPManagerService.this.mMXBoardController.blockTransfer(windowInfo);
            TPManagerService.this.mWritingController.blockTransfer(windowInfo);
            TPManagerService.this.mPreventScratchController.blockTransfer(windowInfo);
        }

        @Override // com.dss.tpservice.ITPManager
        public void deleteLayer(WindowInfo windowInfo) throws RemoteException {
            TPManagerService.this.mTPController.deleteLayer(windowInfo);
            TPManagerService.this.mMonitorAppController.handleAppDestroy(windowInfo);
            TPManagerService.this.mWritingController.handleAppDestroy(windowInfo);
            TPManagerService.this.mPreventScratchController.handleAppDestroy(windowInfo);
        }
    };
    private MXBoardController mMXBoardController;
    private MonitorAppController mMonitorAppController;
    private PreventScratchController mPreventScratchController;
    private ITPController mTPController;
    private WritingController mWritingController;

    @Override // android.app.Service
    public void onCreate() {
        super.onCreate();
        Log.i(TAG, "TPManagerService --- onCreate");
        PropertiesUtils.setProperty("sys.tpservice.running", SeewoConstants.VALUE_LOCK_TOUCH_OFF);
        createNotificationChannel();
        startForeground(NOTIFICATION_ID, createNotification());
        Log.i(TAG, "TPManagerService started as foreground service");
        OpenSDK.getInstance().connect(this);
        if (getResources().getBoolean(R.bool.user_auto_prevent_touch_penetration)) {
            this.mTPController = new TPControllerV2(this);
        } else {
            this.mTPController = new TPController(this);
        }
        this.mMonitorAppController = new MonitorAppController();
        this.mMXBoardController = new MXBoardController(this);
        this.mWritingController = new WritingController(this);
        this.mPreventScratchController = new PreventScratchController(this);
    }

    @Override // android.app.Service
    public int onStartCommand(Intent intent, int i, int i2) {
        Log.i(TAG, "TPManagerService --- onStartCommand");
        return super.onStartCommand(intent, i, i2);
    }

    @Override // android.app.Service
    public IBinder onBind(Intent intent) {
        Log.i(TAG, "TPManagerService --- onBind");
        return this.mIBinder;
    }

    @Override // android.app.Service
    public void onDestroy() {
        super.onDestroy();
        Log.i(TAG, "TPManagerService --- onDestroy");
        OpenSDK.getInstance().disconnect();
        ITPController iTPController = this.mTPController;
        if (iTPController != null) {
            iTPController.release();
        }
        MonitorAppController monitorAppController = this.mMonitorAppController;
        if (monitorAppController != null) {
            monitorAppController.release();
        }
        MXBoardController mXBoardController = this.mMXBoardController;
        if (mXBoardController != null) {
            mXBoardController.release();
        }
        WritingController writingController = this.mWritingController;
        if (writingController != null) {
            writingController.release();
        }
        PreventScratchController preventScratchController = this.mPreventScratchController;
        if (preventScratchController != null) {
            preventScratchController.release();
        }
    }

    private void createNotificationChannel() {
        NotificationChannel notificationChannel = new NotificationChannel(CHANNEL_ID, "TP Manager Service", 2);
        notificationChannel.setDescription("Touch Panel Manager Service");
        NotificationManager notificationManager = (NotificationManager) getSystemService(NotificationManager.class);
        if (notificationManager != null) {
            notificationManager.createNotificationChannel(notificationChannel);
        }
    }

    private Notification createNotification() {
        return new Notification.Builder(this, CHANNEL_ID).setContentTitle("TP Manager Service").setContentText("Touch Panel service is running").setSmallIcon(android.R.drawable.ic_menu_info_details).build();
    }
}
