package com.benq.platform.monitor;

import G0.e;
import G0.f;
import G0.n;
import H0.q;
import T0.a;
import Y0.c;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import com.seewo.sdk.event.OSEvent;
import com.seewo.sdk.eventbus.OnEventOfOS;
import com.seewo.sdk.model.SDKSourceModel;
import java.util.ArrayList;
import java.util.List;
import kotlin.jvm.internal.g;
import kotlin.jvm.internal.l;
import o1.AbstractC0676l;
import okhttp3.HttpUrl;

/* JADX INFO: loaded from: classes.dex */
public final class SystemEventMonitor {
    private static final String ACTION_BACKLIGHT_CHANGE = "com.benq.action.BACKLIGHT_CHANGED";
    private static final String ACTION_MUTE_CHANGE = "com.benq.action.audio_mute";
    private static final String ACTION_SOURCE_CHANGE = "com.benq.source.change";
    private static final String ACTION_SOURCE_CHANGE_8195 = "com.benq.action.SWITCH_SOURCE";
    private static final String ACTION_SOURCE_PLUG = "com.benq.broadcast.source.plugdet";
    private static final String ACTION_SOURCE_PLUG_8195 = "com.benq.action.PLUG_SOURCE";
    private static final String ACTION_VOLUME_CHANGE = "com.benq.action.volume_change";
    public static final Companion Companion = new Companion(null);
    private static final String EXTRA_CURRENT_SOURCE = "currentSource";
    private static final String EXTRA_PLUG_OFF = "plugOff";
    private static final String EXTRA_PLUG_ON = "plugOn";
    private static final String EXTRA_SIGNAL = "signal";
    private static final String EXTRA_SIGNAL_SWITCH_FROM = "signalSwitchFrom";
    private static final String EXTRA_SIGNAL_SWITCH_TO = "signalSwitchTo";
    private static final String EXTRA_SWITCH_OFF = "switchOff";
    private static final String EXTRA_SWITCH_ON = "switchOn";
    public static final int INTENT_FLAGS = 16777216;
    private final Context context;

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

        private Companion() {
        }
    }

    public /* synthetic */ class WhenMappings {
        public static final /* synthetic */ int[] $EnumSwitchMapping$0;

        static {
            int[] iArr = new int[q.values().length];
            try {
                iArr[q.HDMI4.ordinal()] = 1;
            } catch (NoSuchFieldError unused) {
            }
            try {
                iArr[q.TYPE_C1.ordinal()] = 2;
            } catch (NoSuchFieldError unused2) {
            }
            try {
                iArr[q.TYPE_C2.ordinal()] = 3;
            } catch (NoSuchFieldError unused3) {
            }
            try {
                iArr[q.VGA1.ordinal()] = 4;
            } catch (NoSuchFieldError unused4) {
            }
            try {
                iArr[q.PC.ordinal()] = 5;
            } catch (NoSuchFieldError unused5) {
            }
            $EnumSwitchMapping$0 = iArr;
        }
    }

    public SystemEventMonitor(Context context) {
        l.e(context, "context");
        this.context = context;
    }

    private final SDKSourceModel getSourceModel(q qVar) {
        List<SDKSourceModel> listD = n.f815a.d();
        l.d(listD, "getAvailableSourceModelList(...)");
        for (SDKSourceModel sDKSourceModel : listD) {
            if (qVar == sDKSourceModel.sourceItem) {
                return sDKSourceModel;
            }
        }
        return null;
    }

    private final String getSourceName(q qVar) {
        int i2 = WhenMappings.$EnumSwitchMapping$0[qVar.ordinal()];
        if (i2 == 1) {
            return "HDMI";
        }
        if (i2 == 2) {
            return "TYPE-C1";
        }
        if (i2 == 3) {
            return "TYPE-C";
        }
        if (i2 == 4) {
            return "VGA";
        }
        if (i2 == 5) {
            return "OPS";
        }
        if (!a.i(18)) {
            return qVar.name();
        }
        SDKSourceModel sourceModel = getSourceModel(qVar);
        String str = sourceModel != null ? sourceModel.name : null;
        return str == null ? HttpUrl.FRAGMENT_ENCODE_SET : str;
    }

    private final void notifyPlugSource(boolean z2, String str) {
        ArrayList arrayList = new ArrayList();
        List listI = n.f815a.i();
        l.d(listI, "getSignalSources(...)");
        int i2 = 0;
        for (Object obj : listI) {
            int i3 = i2 + 1;
            if (i2 < 0) {
                AbstractC0676l.n();
            }
            q qVar = (q) obj;
            l.b(qVar);
            arrayList.add(getSourceName(qVar));
            i2 = i3;
        }
        c.h("BenQIFPSys", "notifyPlugSource sourceList:" + (arrayList.toArray(new String[0]) instanceof String[]) + " isPlugOn:" + z2 + ", source:" + str);
        Context context = this.context;
        Intent intent = new Intent(ACTION_SOURCE_PLUG_8195);
        intent.addFlags(16777216);
        intent.putExtra(EXTRA_CURRENT_SOURCE, (String[]) arrayList.toArray(new String[0]));
        intent.putExtra(EXTRA_PLUG_ON, z2 ? str : HttpUrl.FRAGMENT_ENCODE_SET);
        if (z2) {
            str = HttpUrl.FRAGMENT_ENCODE_SET;
        }
        intent.putExtra(EXTRA_PLUG_OFF, str);
        com.seewo.hiddenapi.c.c(context, intent, com.seewo.hiddenapi.g.f3343c);
    }

    @SuppressLint({"WrongConstant"})
    private final void notifySourceChange() {
        n nVar = n.f815a;
        q qVarF = nVar.f();
        q qVarH = nVar.h();
        l.b(qVarF);
        String sourceName = getSourceName(qVarF);
        SDKSourceModel sourceModel = getSourceModel(qVarF);
        boolean z2 = sourceModel != null ? sourceModel.hasSignal : false;
        l.b(qVarH);
        String sourceName2 = getSourceName(qVarH);
        SDKSourceModel sourceModel2 = getSourceModel(qVarH);
        boolean z3 = sourceModel2 != null ? sourceModel2.hasSignal : false;
        Context context = this.context;
        Intent intent = new Intent(ACTION_SOURCE_CHANGE);
        intent.addFlags(16777216);
        intent.putExtra("source", sourceName);
        if (z2) {
            intent.putExtra(EXTRA_SIGNAL, "on");
        }
        com.seewo.hiddenapi.c.c(context, intent, com.seewo.hiddenapi.g.f3343c);
        c.h("BenQIFPSys", "notifySourceChange currentSource:" + sourceName + ", lastSource:" + sourceName2 + ", hasSignal:" + z2 + " hasSignal2:" + z3);
    }

    private final void notifySourceSwitch() {
        n nVar = n.f815a;
        q qVarF = nVar.f();
        q qVarH = nVar.h();
        l.b(qVarF);
        String sourceName = getSourceName(qVarF);
        SDKSourceModel sourceModel = getSourceModel(qVarF);
        boolean z2 = sourceModel != null ? sourceModel.hasSignal : false;
        l.b(qVarH);
        String sourceName2 = getSourceName(qVarH);
        SDKSourceModel sourceModel2 = getSourceModel(qVarH);
        boolean z3 = sourceModel2 != null ? sourceModel2.hasSignal : false;
        Context context = this.context;
        Intent intent = new Intent(ACTION_SOURCE_CHANGE_8195);
        intent.addFlags(16777216);
        intent.putExtra(EXTRA_SWITCH_ON, sourceName);
        intent.putExtra(EXTRA_SIGNAL, z2 ? "ON" : "OFF");
        intent.putExtra(EXTRA_SIGNAL_SWITCH_TO, z2 ? "ON" : "OFF");
        intent.putExtra(EXTRA_SWITCH_OFF, sourceName2);
        intent.putExtra(EXTRA_SIGNAL_SWITCH_FROM, z3 ? "ON" : "OFF");
        com.seewo.hiddenapi.c.c(context, intent, com.seewo.hiddenapi.g.f3343c);
        c.h("BenQIFPSys", "notifySourceSwitch currentSource:" + sourceName + ", lastSource:" + sourceName2 + ", hasSignal:" + z2 + " hasSignal2:" + z3);
    }

    @OnEventOfOS
    @SuppressLint({"WrongConstant"})
    public final void onBackLightChanged(OSEvent.BackLightChanged event) {
        l.e(event, "event");
        c.h("BenQIFPSys", "onBackLightChanged");
        Context context = this.context;
        Intent intent = new Intent(ACTION_BACKLIGHT_CHANGE);
        intent.addFlags(16777216);
        com.seewo.hiddenapi.c.c(context, intent, com.seewo.hiddenapi.g.f3343c);
    }

    public final void onCreate() {
        e.d().j(this);
    }

    public final void onDestroy() {
        e.d().l(this);
    }

    @OnEventOfOS
    @SuppressLint({"WrongConstant"})
    public final void onMuteChange(OSEvent.MuteChanged event) {
        l.e(event, "event");
        c.h("BenQIFPSys", "MuteChanged");
        Context context = this.context;
        Intent intent = new Intent(ACTION_MUTE_CHANGE);
        intent.putExtra("mute", f.f800a.c() ? "on" : "off");
        intent.addFlags(16777216);
        com.seewo.hiddenapi.c.c(context, intent, com.seewo.hiddenapi.g.f3343c);
    }

    @OnEventOfOS
    public final void onSourceChange(OSEvent.SourceChanged event) {
        l.e(event, "event");
        c.h("BenQIFPSys", "onSourceChange");
        notifySourceChange();
        notifySourceSwitch();
    }

    @OnEventOfOS
    @SuppressLint({"WrongConstant"})
    public final void onSourcePlugInChange(OSEvent.SourcePlugIn event) {
        l.e(event, "event");
        c.h("BenQIFPSys", "onSourcePlugInChange source:" + event.sourceItem);
        Context context = this.context;
        Intent intent = new Intent(ACTION_SOURCE_PLUG);
        intent.addFlags(16777216);
        com.seewo.hiddenapi.c.c(context, intent, com.seewo.hiddenapi.g.f3343c);
        q sourceItem = event.sourceItem;
        l.d(sourceItem, "sourceItem");
        notifyPlugSource(true, getSourceName(sourceItem));
    }

    @OnEventOfOS
    @SuppressLint({"WrongConstant"})
    public final void onSourcePlugOutChange(OSEvent.SourcePlugOut event) {
        l.e(event, "event");
        c.h("BenQIFPSys", "onSourcePlugOutChange source:" + event.sourceItem);
        Context context = this.context;
        Intent intent = new Intent(ACTION_SOURCE_PLUG);
        intent.addFlags(16777216);
        com.seewo.hiddenapi.c.c(context, intent, com.seewo.hiddenapi.g.f3343c);
        q sourceItem = event.sourceItem;
        l.d(sourceItem, "sourceItem");
        notifyPlugSource(false, getSourceName(sourceItem));
    }

    @OnEventOfOS
    public final void onSourceSignalChange(OSEvent.SourceSignalChanged event) {
        l.e(event, "event");
        n nVar = n.f815a;
        c.h("BenQIFPSys", "onSourceSignalChange, currentSource:" + nVar.f() + ", event source:" + event.sourceItem + ", hasSignal:" + event.hasSignal);
        if (nVar.f() == event.sourceItem) {
            notifySourceChange();
        }
    }

    @OnEventOfOS
    @SuppressLint({"WrongConstant"})
    public final void onVolumeChange(OSEvent.VolumeChanged event) {
        l.e(event, "event");
        c.h("BenQIFPSys", "VolumeChanged");
        Context context = this.context;
        Intent intent = new Intent(ACTION_VOLUME_CHANGE);
        intent.putExtra("volume", f.f800a.b());
        intent.addFlags(16777216);
        com.seewo.hiddenapi.c.c(context, intent, com.seewo.hiddenapi.g.f3343c);
    }
}
