package com.ifpdos.debugmenu.action;

import android.content.Context;
import android.util.Log;
import com.cvte.vman.ExtendDisplayCtrl;
import com.cvte.vman.VmanMiddleWare;
import com.cvte.vman.types.EnumOutputDisplayPort;
import com.ifpdos.debugmenu.R;
import com.ifpdos.debugmenu.action.BoxHDMIOutFormat3588Action;
import com.ifpdos.debugmenu.action.base.ItemSelectAction;
import com.ifpdos.debugmenu.entity.HdmiOutFormatBody;
import com.ifpdos.debugmenu.event.ViewEvent;
import d.f.a.r2.r2;
import d.f.a.u1.a;
import d.h.a.e;
import g.h0.c.g;
import g.h0.c.l;
import g.i;
import g.k;
import g.m0.f;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.function.Consumer;
import k.c.a.c;
import k.c.a.j;
import org.greenrobot.eventbus.ThreadMode;

/* JADX INFO: compiled from: BoxHDMIOutFormat3588Action.kt */
/* JADX INFO: loaded from: classes.dex */
@i
public final class BoxHDMIOutFormat3588Action extends ItemSelectAction {
    public static final Companion Companion = new Companion(null);
    private static final String FORMAT_PREFIX = "FMT_";
    private static final a<HdmiOutFormatBody.HdmiOutFormatEnum, String> HDMI_OUT_MAP;
    private static final String PROP_NEED_REBOOT = "persist.sys.hdmi_resolution_tip";
    private static final String TAG = "HDMIOutFormatAction";
    private List<String> mNotSupportDvi;
    private final VmanMiddleWare vman;

    /* JADX INFO: compiled from: BoxHDMIOutFormat3588Action.kt */
    @i
    public static final class Companion {
        private Companion() {
        }

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

    static {
        k[] kVarArr = {new k(HdmiOutFormatBody.HdmiOutFormatEnum.FMT_AUTO, "Auto"), new k(HdmiOutFormatBody.HdmiOutFormatEnum.FMT_1080P_50HZ, "1920x1080p50"), new k(HdmiOutFormatBody.HdmiOutFormatEnum.FMT_1080P_60HZ, "1920x1080p60"), new k(HdmiOutFormatBody.HdmiOutFormatEnum.FMT_3840X2160_30HZ, "3840x2160p30"), new k(HdmiOutFormatBody.HdmiOutFormatEnum.FMT_3840X2160_50HZ, "3840x2160p50"), new k(HdmiOutFormatBody.HdmiOutFormatEnum.FMT_3840X2160_60HZ, "3840x2160p60"), new k(HdmiOutFormatBody.HdmiOutFormatEnum.FMT_480P_60HZ, "720x480p60"), new k(HdmiOutFormatBody.HdmiOutFormatEnum.FMT_720P_60HZ, "1280x720p60"), new k(HdmiOutFormatBody.HdmiOutFormatEnum.FMT_640X480_60HZ, "640x480p60"), new k(HdmiOutFormatBody.HdmiOutFormatEnum.FMT_3440X1440_60HZ, "3440x1440p60"), new k(HdmiOutFormatBody.HdmiOutFormatEnum.FMT_7680X4320_60HZ, "7680x4320p60"), new k(HdmiOutFormatBody.HdmiOutFormatEnum.FMT_7680X4320_30HZ, "7680x4320p30"), new k(HdmiOutFormatBody.HdmiOutFormatEnum.FMT_5120X2880_60HZ, "5120x2880p60")};
        l.f(kVarArr, "pairs");
        HDMI_OUT_MAP = new a<>((k[]) Arrays.copyOf(kVarArr, 13));
    }

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public BoxHDMIOutFormat3588Action(Context context) {
        super(context);
        l.f(context, "context");
        this.mNotSupportDvi = getFormatList();
        this.vman = VmanMiddleWare.getInstance();
        d.f.a.i2.a.a().f2585b.add(this);
        c.c().k(this);
    }

    private final List<String> formatsToEntryList(List<String> list) {
        final ArrayList arrayList = new ArrayList();
        list.forEach(new Consumer() { // from class: d.f.a.p1.m
            @Override // java.util.function.Consumer
            public final void accept(Object obj) {
                BoxHDMIOutFormat3588Action.formatsToEntryList$lambda$5(arrayList, (String) obj);
            }
        });
        Log.d(TAG, "formatsToEntryList: formatResultList = " + arrayList);
        return arrayList;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final void formatsToEntryList$lambda$5(List list, String str) {
        l.f(list, "$entryList");
        l.f(str, "s");
        list.add(f.A(str, FORMAT_PREFIX, "", false, 4));
    }

    private final List<String> getFormatList() {
        try {
            EnumOutputDisplayPort enumOutputDisplayPort = EnumOutputDisplayPort.CVTE_SOURCE_HDMI_OUT1;
            List<String> physicalDisplayUserResolutionList = VmanMiddleWare.getInstance().getPhysicalDisplayCtrl().getPhysicalDisplayUserResolutionList(enumOutputDisplayPort);
            if (physicalDisplayUserResolutionList.isEmpty()) {
                Log.d(TAG, "HDMI Out getExtendDisplayUserResolutionList");
                physicalDisplayUserResolutionList = VmanMiddleWare.getInstance().getExtendDisplayCtrl().getExtendDisplayUserResolutionList();
            } else {
                Log.d(TAG, "TYPE_C Out getPhysicalDisplayUserResolutionList: [" + enumOutputDisplayPort + ']');
            }
            ArrayList arrayList = null;
            if (physicalDisplayUserResolutionList != null) {
                ArrayList arrayList2 = new ArrayList();
                for (Object obj : physicalDisplayUserResolutionList) {
                    String str = (String) obj;
                    Log.d(TAG, "getResolutionList:" + str);
                    boolean z = HDMI_OUT_MAP.f3422b.get(str) != null;
                    if (!z) {
                        e.a(TAG).c(5, null, "not support resolution [" + str + ']', new Object[0]);
                    }
                    if (z) {
                        arrayList2.add(obj);
                    }
                }
                arrayList = new ArrayList(f.a.y.a.C(arrayList2, 10));
                Iterator it = arrayList2.iterator();
                while (it.hasNext()) {
                    HdmiOutFormatBody.HdmiOutFormatEnum hdmiOutFormatEnum = HDMI_OUT_MAP.f3422b.get((String) it.next());
                    l.c(hdmiOutFormatEnum);
                    arrayList.add(hdmiOutFormatEnum.name());
                }
            }
            Log.d(TAG, "getFormatList: dataList = " + arrayList);
            return arrayList != null ? g.c0.g.K(arrayList) : new ArrayList();
        } catch (Throwable th) {
            Object objL = f.a.y.a.L(th);
            Throwable thA = g.l.a(objL);
            if (thA != null) {
                Log.e(TAG, "getFormatList: error", thA);
            }
            if (g.l.a(objL) != null) {
                objL = new ArrayList();
            }
            return (List) objL;
        }
    }

    private final HdmiOutFormatBody getHdmiOutFormat() {
        String extendDisplayResolution = this.vman.getExtendDisplayCtrl().getExtendDisplayResolution();
        d.b.a.a.a.O("getHdmiOutFormat resolution ", extendDisplayResolution, TAG);
        HdmiOutFormatBody.HdmiOutFormatEnum hdmiOutFormatEnum = HDMI_OUT_MAP.f3422b.get(extendDisplayResolution);
        d.b.a.a.a.U(d.b.a.a.a.B("getEnumFromString format "), hdmiOutFormatEnum != null ? hdmiOutFormatEnum.name() : null, TAG);
        if (hdmiOutFormatEnum == null) {
            return null;
        }
        HdmiOutFormatBody hdmiOutFormatBody = new HdmiOutFormatBody();
        hdmiOutFormatBody.setFormat(hdmiOutFormatEnum);
        return hdmiOutFormatBody;
    }

    private final void postResolutionDisplayEvent(String str) {
    }

    private final void setHdmiOutFormat(String str) {
        HdmiOutFormatBody.HdmiOutFormatEnum hdmiOutFormatEnumValueOf = HdmiOutFormatBody.HdmiOutFormatEnum.valueOf(str);
        ExtendDisplayCtrl extendDisplayCtrl = this.vman.getExtendDisplayCtrl();
        a<HdmiOutFormatBody.HdmiOutFormatEnum, String> aVar = HDMI_OUT_MAP;
        boolean extendDisplayResolution = extendDisplayCtrl.setExtendDisplayResolution(aVar.a.get(hdmiOutFormatEnumValueOf));
        StringBuilder sbB = d.b.a.a.a.B("setHdmiOutFormat format ");
        sbB.append(aVar.a.get(hdmiOutFormatEnumValueOf));
        sbB.append(" --> ");
        sbB.append(extendDisplayResolution);
        Log.i(TAG, sbB.toString());
    }

    /* JADX WARN: Multi-variable type inference failed */
    @j(threadMode = ThreadMode.MAIN)
    public final void event(ViewEvent.UpdateViewEntries updateViewEntries) {
        l.f(updateViewEntries, "event");
        if (updateViewEntries.viewId != r2.HDMI_DVI.ordinal()) {
            Log.d(TAG, "event: event.viewId != Constant.ViewID.HDMI_DVI.ordinal(), ignore event and operation...");
            return;
        }
        List<String> formatList = getFormatList();
        this.mNotSupportDvi = formatList;
        ((d.f.a.j2.e.i) this.mViewModel).e(formatsToEntryList(formatList));
        Context context = this.mContext;
        l.e(context, "mContext");
        int selectIndex = getSelectIndex(context);
        Log.d(TAG, "on event, change select index " + selectIndex);
        ((d.f.a.j2.e.i) this.mViewModel).f(selectIndex);
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemSelectAction
    public List<String> getEntryList(Context context) {
        l.f(context, "context");
        return formatsToEntryList(this.mNotSupportDvi);
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemSelectAction
    public int getSelectIndex(Context context) {
        l.f(context, "context");
        if (this.mNotSupportDvi.isEmpty()) {
            Log.d(TAG, "getSelectIndex: [1/3] HdmiFormatDataList is null or Empty, indexResult = 0");
            return 0;
        }
        StringBuilder sbB = d.b.a.a.a.B("getSelectIndex: [1/3] HdmiFormatDataList = ");
        sbB.append(this.mNotSupportDvi);
        sbB.append(", HdmiFormatDataList.size() = ");
        List<String> list = this.mNotSupportDvi;
        l.c(list);
        sbB.append(list.size());
        Log.d(TAG, sbB.toString());
        HdmiOutFormatBody hdmiOutFormat = getHdmiOutFormat();
        if (hdmiOutFormat == null) {
            Log.d(TAG, "getSelectIndex: [2/3] currentHdmiFormatData is null, indexResult = 0");
            return 0;
        }
        String str = hdmiOutFormat.getFormat() + "";
        postResolutionDisplayEvent(str);
        int iIndexOf = this.mNotSupportDvi.indexOf(str);
        Log.d(TAG, "getSelectIndex: [3/3] currentHdmiFormatDataStr = " + str + ", currentHdmiFormatIndex = " + iIndexOf);
        return iIndexOf;
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemSelectAction
    public boolean isEnable() {
        boolean extendDisplayEnabled = this.vman.getExtendDisplayCtrl().getExtendDisplayEnabled();
        d.b.a.a.a.P("isEnable: ", extendDisplayEnabled, TAG);
        return extendDisplayEnabled;
    }

    /* JADX WARN: Multi-variable type inference failed */
    @j(threadMode = ThreadMode.MAIN)
    public final void onEvent(ViewEvent.UpdateViewEnable updateViewEnable) {
        l.f(updateViewEnable, "event");
        int i2 = updateViewEnable.viewId;
        if (i2 == r2.HDMI_DVI.ordinal() || i2 == r2.TYPE_C_OUT_FORMAT1.ordinal()) {
            d.b.a.a.a.V(d.b.a.a.a.B("onEvent: UpdateViewEnable "), updateViewEnable.isEnabled, TAG);
            if (!updateViewEnable.isEnabled) {
                setEnable((d.f.a.j2.e.i) this.mViewModel, false);
                return;
            }
            setEnable((d.f.a.j2.e.i) this.mViewModel, true);
            Integer numD = ((d.f.a.j2.e.i) this.mViewModel).f2627l.d();
            if (numD != null) {
                postResolutionDisplayEvent(this.mNotSupportDvi.get(numD.intValue()));
            }
        }
    }

    @Override // com.ifpdos.debugmenu.action.base.ItemSelectAction
    public void onSelect(Context context, int i2) {
        l.f(context, "context");
        String str = this.mNotSupportDvi.get(i2);
        setHdmiOutFormat(str);
        postResolutionDisplayEvent(str);
        Log.d(TAG, "onSelect: called, setHdmiFormatData into Udi, index = " + i2 + ", currentHdmiFormatDataSet = " + str);
        if (d.i.f.c.c.g(PROP_NEED_REBOOT, false)) {
            c.n.a.d0(R.string.str_hdmi_hdmiout_format_tip);
        }
    }
}
