package com.benq.platform;

import O1.m;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.os.UserHandle;
import android.util.Log;
import com.benq.platform.IBenqRecorderService;
import com.benq.platform.IBenqService;
import com.benq.platform.IBenqServicePool;
import com.benq.platform.ITestService;
import com.benq.platform.events.UdiConnectionStateEvent;
import com.benq.platform.test.TestService;
import com.benq.platform.utils.CTSStatusChangeListener;
import com.benq.platform.utils.TouchPanelUtils;
import com.benq.platform.utils.UDIHelper;
import com.droidlogic.app.ScreenControlManager;
import kotlin.jvm.internal.g;
import kotlin.jvm.internal.l;
import org.greenrobot.eventbus.ThreadMode;

/* JADX INFO: loaded from: classes.dex */
public final class MainService extends Service {
    private static final String AUDIO_RECORD_SERVER = "BenQIFPAudioRecord";
    private static final String BENQ_SERVER = "BenQIFPSys";
    public static final Companion Companion = new Companion(null);
    private static final String RECORD_SERVER = "BenQIFPRecorder";
    private static final String TAG = "@MainService";
    private boolean hasHandledUdiConnection;
    private boolean hasRegisteredCtsStatusListener;
    private IFPBenQAudioRecordService mAudioRecordService;
    private IFPBenQService mBenqService;
    private IFPRecordService mRecordService;
    private Boolean mRemindSideBarStatus;

    private final class BenqServicePoolImpl extends IBenqServicePool.Stub {
        public BenqServicePoolImpl() {
        }

        public IBinder getService(String str) throws RemoteException {
            IBenqRecorderService.Stub stub;
            Log.d("BenQIFPSys", "get service: " + str);
            if (str == null) {
                return null;
            }
            int iHashCode = str.hashCode();
            if (iHashCode != -1652968533) {
                if (iHashCode != 1511707584) {
                    if (iHashCode != 1586015674 || !str.equals("BenQIFPAudioRecord")) {
                        return null;
                    }
                    stub = MainService.this.mAudioRecordService;
                    if (stub == null) {
                        l.s("mAudioRecordService");
                        return null;
                    }
                } else {
                    if (!str.equals("BenQIFPSys")) {
                        return null;
                    }
                    stub = MainService.this.mBenqService;
                    if (stub == null) {
                        l.s("mBenqService");
                        return null;
                    }
                }
            } else {
                if (!str.equals("BenQIFPRecorder")) {
                    return null;
                }
                stub = MainService.this.mRecordService;
                if (stub == null) {
                    l.s("mRecordService");
                    return null;
                }
            }
            return stub;
        }
    }

    public static final class Companion {
        public /* synthetic */ Companion(g gVar) {
            this();
        }

        private Companion() {
        }
    }

    private final void handleUdiConnected() {
        if (this.hasHandledUdiConnection) {
            return;
        }
        this.hasHandledUdiConnection = true;
        Log.d(TAG, "UDI connected, starting dependent business");
        checkCtsStatus();
        if (this.hasRegisteredCtsStatusListener) {
            return;
        }
        this.hasRegisteredCtsStatusListener = true;
        UDIHelper.INSTANCE.registerCTSStatus(new CTSStatusChangeListener() { // from class: com.benq.platform.MainService.handleUdiConnected.1
            @Override // com.benq.platform.utils.CTSStatusChangeListener
            public void onStatusChange(boolean z2) {
                Log.d(MainService.TAG, "CTS status change to " + z2);
                MainService.this.checkCtsStatus();
                IFPBenQService iFPBenQService = MainService.this.mBenqService;
                if (iFPBenQService == null) {
                    l.s("mBenqService");
                    iFPBenQService = null;
                }
                iFPBenQService.notifyCtsStateChange();
            }
        });
    }

    private final void initTouchPanelService() {
        Log.d(TAG, "Initializing TouchPanel service connection");
        TouchPanelUtils.Companion companion = TouchPanelUtils.Companion;
        companion.getInstance(this).setReconnectConfig(3000L, 5, true);
        companion.getInstance(this).addConnectionListener(new TouchPanelUtils.OnServiceConnectionListener() { // from class: com.benq.platform.MainService.initTouchPanelService.1
            @Override // com.benq.platform.utils.TouchPanelUtils.OnServiceConnectionListener
            public void onServiceConnected() {
                Log.d(MainService.TAG, "TouchPanel service connected successfully");
            }

            @Override // com.benq.platform.utils.TouchPanelUtils.OnServiceConnectionListener
            public void onServiceDisconnected() {
                Log.d(MainService.TAG, "TouchPanel service disconnected");
            }
        });
        companion.getInstance(this).connectService();
    }

    private final void observeUdiConnection() {
        if (O1.c.c().j(this)) {
            return;
        }
        O1.c.c().q(this);
    }

    public final void checkCtsStatus() {
        if (!UDIHelper.INSTANCE.getCTSStatus()) {
            Boolean bool = this.mRemindSideBarStatus;
            if (bool != null) {
                com.seewo.vcommons.data.d.q(IFPBenQService.BENQ_PROP_SIDE_BAR, String.valueOf(bool));
            }
            IFPBenQService iFPBenQService = this.mBenqService;
            if (iFPBenQService == null) {
                l.s("mBenqService");
                iFPBenQService = null;
            }
            iFPBenQService.onAfterBinder();
            return;
        }
        this.mRemindSideBarStatus = Boolean.valueOf(com.seewo.vcommons.data.d.f(IFPBenQService.BENQ_PROP_SIDE_BAR, true));
        com.seewo.vcommons.data.d.q(IFPBenQService.BENQ_PROP_SIDE_BAR, "false");
        Intent intent = new Intent(IFPBenQService.ACTION_SLIDEBAR_OFF);
        intent.addFlags(16777216);
        UserHandle userHandle = com.seewo.hiddenapi.g.f3343c;
        com.seewo.hiddenapi.c.c(this, intent, userHandle);
        Intent intent2 = new Intent(IFPBenQService.ACTION_SLIDEBAR_OFF_NEW);
        intent2.addFlags(16777216);
        com.seewo.hiddenapi.c.c(this, intent2, userHandle);
    }

    @Override // android.app.Service
    public IBinder onBind(Intent intent) {
        Log.d("BenQIFPSys", "onBind");
        return new BenqServicePoolImpl();
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r4v1 */
    /* JADX WARN: Type inference failed for: r4v2 */
    /* JADX WARN: Type inference failed for: r4v3, types: [android.os.IBinder] */
    @Override // android.app.Service
    public void onCreate() {
        super.onCreate();
        initTouchPanelService();
        this.mRecordService = new IFPRecordService(this);
        Context baseContext = getBaseContext();
        l.d(baseContext, "getBaseContext(...)");
        this.mAudioRecordService = new IFPBenQAudioRecordService(baseContext);
        IFPBenQAudioRecordService iFPBenQAudioRecordService = this.mAudioRecordService;
        ?? r4 = 0;
        if (iFPBenQAudioRecordService == null) {
            l.s("mAudioRecordService");
            iFPBenQAudioRecordService = null;
        }
        IFPBenQService iFPBenQService = new IFPBenQService(this, iFPBenQAudioRecordService);
        this.mBenqService = iFPBenQService;
        iFPBenQService.onCreate();
        IFPRecordService iFPRecordService = this.mRecordService;
        if (iFPRecordService == null) {
            l.s("mRecordService");
            iFPRecordService = null;
        }
        iFPRecordService.onCreate();
        observeUdiConnection();
        try {
            IBenqService.Stub stub = this.mBenqService;
            if (stub == null) {
                l.s("mBenqService");
                stub = null;
            }
            ServiceManager.addService("BenQIFPSys", stub);
            IFPRecordService iFPRecordService2 = this.mRecordService;
            if (iFPRecordService2 == null) {
                l.s("mRecordService");
            } else {
                r4 = iFPRecordService2;
            }
            ServiceManager.addService("BenQIFPRecorder", (IBinder) r4);
            ServiceManager.addService("benqTest", new ITestService.Stub() { // from class: com.benq.platform.MainService.onCreate.1
                public Bitmap screenshot() {
                    Y0.c.h("BenQIFPSys", "screenshot start");
                    Bitmap bitmapCaptureAmlogic = ScreenControlManager.captureAmlogic(MainService.this, 3840, 2160, 1);
                    Y0.c.h("BenQIFPSys", "screenshot:" + bitmapCaptureAmlogic);
                    return bitmapCaptureAmlogic;
                }

                public Bitmap screenshot1(Rect rect) {
                    Y0.c.h("BenQIFPSys", "screenshot start");
                    Bitmap bitmapCaptureAmlogic = ScreenControlManager.captureAmlogic(MainService.this, 3840, 2160, 1);
                    Y0.c.h("BenQIFPSys", "screenshot:" + bitmapCaptureAmlogic);
                    return bitmapCaptureAmlogic;
                }
            });
            com.seewo.vcommons.data.d.q("persist.sys.vssdk.system", "true");
        } catch (Exception e2) {
            com.seewo.vcommons.data.d.q("persist.sys.vssdk.system", "false");
            Log.v("BenQIFPSys", "add service error.", e2);
        }
        Log.d(TAG, "Server onCreate");
        if (com.seewo.vcommons.data.d.j()) {
            Log.d(TAG, "start TestService");
            com.seewo.hiddenapi.c.e(this, new Intent(this, (Class<?>) TestService.class), com.seewo.hiddenapi.g.f3343c);
        }
    }

    @Override // android.app.Service
    public void onDestroy() {
        super.onDestroy();
        IFPBenQService iFPBenQService = this.mBenqService;
        IFPRecordService iFPRecordService = null;
        if (iFPBenQService == null) {
            l.s("mBenqService");
            iFPBenQService = null;
        }
        iFPBenQService.onDestroy();
        IFPRecordService iFPRecordService2 = this.mRecordService;
        if (iFPRecordService2 == null) {
            l.s("mRecordService");
        } else {
            iFPRecordService = iFPRecordService2;
        }
        iFPRecordService.onDestroy();
        TouchPanelUtils.Companion.getInstance(this).disconnectService();
        if (O1.c.c().j(this)) {
            O1.c.c().t(this);
        }
        Log.d(TAG, "Server onDestroy");
    }

    @Override // android.app.Service
    public int onStartCommand(Intent intent, int i2, int i3) {
        return 1;
    }

    @m(sticky = true, threadMode = ThreadMode.MAIN)
    public final void onUdiConnectionStateChanged(UdiConnectionStateEvent event) {
        l.e(event, "event");
        if (event.isConnected()) {
            handleUdiConnected();
            return;
        }
        if (this.hasHandledUdiConnection) {
            return;
        }
        Log.d(TAG, "UDI unavailable, continue with non-UDI initialization");
        IFPBenQService iFPBenQService = this.mBenqService;
        if (iFPBenQService == null) {
            l.s("mBenqService");
            iFPBenQService = null;
        }
        iFPBenQService.onAfterBinder();
    }
}
