package com.mstar.android.tvapi.factory;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import com.mstar.android.tvapi.common.exception.TvCommonException;
import com.mstar.android.tvapi.common.listener.OnEventListener;
import com.mstar.android.tvapi.common.vo.EnumColorTemperature;
import com.mstar.android.tvapi.common.vo.EnumScalerWindow;
import com.mstar.android.tvapi.common.vo.TvOsType;
import com.mstar.android.tvapi.factory.vo.DisplayResolutionType;
import com.mstar.android.tvapi.factory.vo.EnumAcOnPowerOnMode;
import com.mstar.android.tvapi.factory.vo.EnumAdcSetIndexType;
import com.mstar.android.tvapi.factory.vo.EnumFwType;
import com.mstar.android.tvapi.factory.vo.EnumPqUpdateFile;
import com.mstar.android.tvapi.factory.vo.EnumScreenMute;
import com.mstar.android.tvapi.factory.vo.FactoryNsVdSet;
import com.mstar.android.tvapi.factory.vo.PanelVersionInfo;
import com.mstar.android.tvapi.factory.vo.PictureModeValue;
import com.mstar.android.tvapi.factory.vo.PqlCalibrationData;
import com.mstar.android.tvapi.factory.vo.UrsaVersionInfo;
import com.mstar.android.tvapi.factory.vo.WbGainOffset;
import com.mstar.android.tvapi.factory.vo.WbGainOffsetEx;
import java.lang.ref.WeakReference;

/* JADX INFO: loaded from: classes.dex */
public class FactoryManager {
    public static final short PEQ_BAND_NUM = 5;
    public static final int TVFACTORY_FACTORYPROGRAM_EVENT_END = 999;
    public static final int TVFACTORY_FACTORYPROGRAM_EVENT_START = 0;
    public static final int TVFACTORY_FACTORYPROGRAM_FINISHED = 1;
    private static FactoryManager _factoryManager;
    private EventHandler mEventHandler;
    private int mFactoryManagerContext;
    private long mNativeContext;
    private OnEventListener mOnEventListener = null;

    private class EventHandler extends Handler {
        private FactoryManager mMSrv;

        public EventHandler(FactoryManager factoryManager, Looper looper) {
            super(looper);
            this.mMSrv = factoryManager;
        }

        @Override // android.os.Handler
        public void handleMessage(Message message) {
            if (this.mMSrv.mNativeContext == 0 || FactoryManager.this.mOnEventListener == null) {
                return;
            }
            FactoryManager.this.mOnEventListener.onEvent(message);
        }
    }

    static {
        try {
            System.loadLibrary("factorymanager_jni");
            native_init();
        } catch (UnsatisfiedLinkError e2) {
            System.err.println("Cannot load factorymanager_jni library:\n" + e2.toString());
        }
    }

    protected FactoryManager() {
        this.mEventHandler = null;
        Looper looperMyLooper = Looper.myLooper();
        if (looperMyLooper != null) {
            this.mEventHandler = new EventHandler(this, looperMyLooper);
        } else {
            Looper mainLooper = Looper.getMainLooper();
            if (mainLooper != null) {
                this.mEventHandler = new EventHandler(this, mainLooper);
            } else {
                this.mEventHandler = null;
            }
        }
        native_setup(new WeakReference(this));
    }

    private static void PostEvent_SnServiceDeadth(Object obj, int i2, int i3) {
    }

    public static FactoryManager getInstance() {
        if (_factoryManager == null) {
            synchronized (FactoryManager.class) {
                try {
                    if (_factoryManager == null) {
                        _factoryManager = new FactoryManager();
                    }
                } finally {
                }
            }
        }
        return _factoryManager;
    }

    private final native String getUpdatePqFilePath(int i2) throws TvCommonException;

    private final native WbGainOffset naitve_getWbGainOffset(int i2) throws TvCommonException;

    private final native void native_finalize();

    private final native PqlCalibrationData native_getAdcGainOffset(int i2, int i3) throws TvCommonException;

    private final native int native_getDisplayResolution() throws TvCommonException;

    private native int native_getEnvironmentPowerMode() throws TvCommonException;

    private native int native_getFwVersion(int i2);

    private native short native_getResolutionMappingIndex(int i2) throws TvCommonException;

    private final native WbGainOffsetEx native_getWbGainOffsetEx(int i2, int i3) throws TvCommonException;

    private static final native void native_init();

    private final native void native_setAdcGainOffset(int i2, int i3, PqlCalibrationData pqlCalibrationData) throws TvCommonException;

    private native boolean native_setEnvironmentPowerMode(int i2) throws TvCommonException;

    private final native void native_setVideoTestPattern(int i2) throws TvCommonException;

    private final native void native_setWbGainOffset(int i2, short s2, short s3, short s4, short s5, short s6, short s7) throws TvCommonException;

    private final native void native_setWbGainOffsetEx(int i2, int i3, int i4, int i5, int i6, int i7, int i8, int i9) throws TvCommonException;

    private final native void native_setup(Object obj);

    private static void postEventFromNative(Object obj, int i2, int i3, int i4, Object obj2) {
        EventHandler eventHandler;
        FactoryManager factoryManager = (FactoryManager) ((WeakReference) obj).get();
        if (factoryManager == null || (eventHandler = factoryManager.mEventHandler) == null) {
            return;
        }
        factoryManager.mEventHandler.sendMessage(eventHandler.obtainMessage(i2, i3, i4, obj2));
    }

    public final native boolean autoAdc() throws TvCommonException;

    public final native void copySubColorDataToAllSource() throws TvCommonException;

    public final native void copyWhiteBalanceSettingToAllSource() throws TvCommonException;

    public final native boolean disablePVRRecordAll() throws TvCommonException;

    public final native boolean disableUart() throws TvCommonException;

    public final native boolean disableWdt() throws TvCommonException;

    public final native boolean enablePVRRecordAll() throws TvCommonException;

    public final native boolean enableUart() throws TvCommonException;

    @Deprecated
    public native boolean enableUartDebug() throws TvCommonException;

    public final native boolean enableWdt() throws TvCommonException;

    public void finalize() throws Throwable {
        super.finalize();
        native_finalize();
        _factoryManager = null;
    }

    public final PqlCalibrationData getAdcGainOffset(EnumScalerWindow enumScalerWindow, EnumAdcSetIndexType enumAdcSetIndexType) throws TvCommonException {
        return native_getAdcGainOffset(enumScalerWindow.ordinal(), enumAdcSetIndexType.ordinal());
    }

    public final native byte getAutoFineGain() throws TvCommonException;

    public final native byte getAutoRFGain() throws TvCommonException;

    public final DisplayResolutionType.EnumDisplayResolutionType getDisplayResolution() throws TvCommonException {
        int ordinalThroughValue = DisplayResolutionType.EnumDisplayResolutionType.getOrdinalThroughValue(native_getDisplayResolution());
        if (ordinalThroughValue != -1) {
            return DisplayResolutionType.EnumDisplayResolutionType.values()[ordinalThroughValue];
        }
        throw new TvCommonException("funtion getDisplayResolution fail");
    }

    public native byte[] getEnableIPInfo() throws TvCommonException;

    public EnumAcOnPowerOnMode getEnvironmentPowerMode() throws TvCommonException {
        int iNative_getEnvironmentPowerMode = native_getEnvironmentPowerMode();
        if (iNative_getEnvironmentPowerMode < EnumAcOnPowerOnMode.E_ACON_POWERON_SECONDARY.ordinal() || iNative_getEnvironmentPowerMode > EnumAcOnPowerOnMode.E_ACON_POWERON_MAX.ordinal()) {
            throw new TvCommonException("get EnvironmentPowerMode failed \n");
        }
        return EnumAcOnPowerOnMode.values()[iNative_getEnvironmentPowerMode];
    }

    public native short getEnvironmentPowerOnMusicVolume() throws TvCommonException;

    public int getFwVersion(EnumFwType enumFwType) throws TvCommonException {
        return native_getFwVersion(enumFwType.ordinal());
    }

    public native String getMACAddrString() throws TvCommonException;

    @Deprecated
    public final String getPQVersion(EnumScalerWindow enumScalerWindow) throws TvCommonException {
        return native_getPQVersion(enumScalerWindow.ordinal());
    }

    public final native PictureModeValue getPictureModeValue() throws TvCommonException;

    public final native int getQmapCurrentTableIdx(short s2) throws TvCommonException;

    public final native String getQmapIpName(short s2) throws TvCommonException;

    public final native int getQmapIpNum() throws TvCommonException;

    public final native String getQmapTableName(short s2, short s3) throws TvCommonException;

    public final native int getQmapTableNum(short s2) throws TvCommonException;

    public short getResolutionMappingIndex(TvOsType.EnumInputSource enumInputSource) throws TvCommonException {
        return native_getResolutionMappingIndex(enumInputSource.ordinal());
    }

    public native String getSoftwareVersion() throws TvCommonException;

    public native boolean getUARTToHDMI() throws TvCommonException;

    public final native boolean getUartEnv() throws TvCommonException;

    public final String getUpdatePqFilePath(EnumPqUpdateFile enumPqUpdateFile) throws TvCommonException {
        return getUpdatePqFilePath(enumPqUpdateFile.ordinal());
    }

    public native boolean getWOLEnableStatus() throws TvCommonException;

    public final WbGainOffset getWbGainOffset(EnumColorTemperature enumColorTemperature) throws TvCommonException {
        return naitve_getWbGainOffset(enumColorTemperature.getValue());
    }

    public final WbGainOffsetEx getWbGainOffsetEx(EnumColorTemperature enumColorTemperature, int i2) throws TvCommonException {
        return native_getWbGainOffsetEx(enumColorTemperature.getValue(), i2);
    }

    public final native boolean isAgingModeOn() throws TvCommonException;

    public final native boolean isPVRRecordAllOn() throws TvCommonException;

    public final native boolean isUartOn() throws TvCommonException;

    public final native boolean isWdtOn() throws TvCommonException;

    public final native void loadPqTable(int i2, int i3) throws TvCommonException;

    public final native String native_getPQVersion(int i2) throws TvCommonException;

    public final native PanelVersionInfo panelGetVersionInfo() throws TvCommonException;

    public native short[] readBytesFromI2C(int i2, short[] sArr, short s2) throws TvCommonException;

    public void release() throws Throwable {
        _factoryManager = null;
    }

    public final native boolean resetDisplayResolution() throws TvCommonException;

    public final native boolean restoreDbFromUsb() throws TvCommonException;

    public native void restoreFactoryAtvProgramTable(short s2) throws TvCommonException;

    public native void restoreFactoryDtvProgramTable(short s2) throws TvCommonException;

    public native void restoreFactoryDtvProgramTableByRoute(short s2, short s3) throws TvCommonException;

    public final void setAdcGainOffset(EnumScalerWindow enumScalerWindow, EnumAdcSetIndexType enumAdcSetIndexType, PqlCalibrationData pqlCalibrationData) throws TvCommonException {
        native_setAdcGainOffset(enumScalerWindow.ordinal(), enumAdcSetIndexType.ordinal(), pqlCalibrationData);
    }

    public final native boolean setBrightness(short s2) throws TvCommonException;

    public native void setCIPlusKeyViaUsbKey() throws TvCommonException;

    public final native boolean setContrast(short s2) throws TvCommonException;

    public native void setDebugMode(boolean z2) throws TvCommonException;

    public boolean setEnvironmentPowerMode(EnumAcOnPowerOnMode enumAcOnPowerOnMode) throws TvCommonException {
        return native_setEnvironmentPowerMode(enumAcOnPowerOnMode.ordinal());
    }

    public native boolean setEnvironmentPowerOnMusicVolume(short s2) throws TvCommonException;

    public final native void setFactoryVdInitParameter(FactoryNsVdSet factoryNsVdSet) throws TvCommonException;

    public final native void setFactoryVdParameter(FactoryNsVdSet factoryNsVdSet) throws TvCommonException;

    public final native boolean setFixedFineGain(byte b2) throws TvCommonException;

    public native void setHDCPKeyViaUsbKey() throws TvCommonException;

    public final native boolean setHue(short s2) throws TvCommonException;

    public native void setMACAddrViaUsbKey() throws TvCommonException;

    public void setOnEventListener(OnEventListener onEventListener) {
        this.mOnEventListener = onEventListener;
    }

    public native void setPQParameterViaUsbKey() throws TvCommonException;

    public final native boolean setRFGain(byte b2) throws TvCommonException;

    public final native boolean setSaturation(short s2) throws TvCommonException;

    public final native boolean setSharpness(short s2) throws TvCommonException;

    public final native void setUARTToHDMI(boolean z2) throws TvCommonException;

    public final native void setUartEnv(boolean z2) throws TvCommonException;

    public final native boolean setVideoMuteColor(int i2) throws TvCommonException;

    public final void setVideoTestPattern(EnumScreenMute enumScreenMute) throws TvCommonException {
        native_setVideoTestPattern(enumScreenMute.ordinal());
    }

    public native void setWOLEnableStatus(boolean z2) throws TvCommonException;

    public final void setWbGainOffset(EnumColorTemperature enumColorTemperature, short s2, short s3, short s4, short s5, short s6, short s7) throws TvCommonException {
        native_setWbGainOffset(enumColorTemperature.getValue(), s2, s3, s4, s5, s6, s7);
    }

    public final void setWbGainOffsetEx(EnumColorTemperature enumColorTemperature, int i2, int i3, int i4, int i5, int i6, int i7, TvOsType.EnumInputSource enumInputSource) throws TvCommonException {
        native_setWbGainOffsetEx(enumColorTemperature.getValue(), i2, i3, i4, i5, i6, i7, enumInputSource.ordinal());
    }

    public native boolean setXvyccDataFromPanel(float f2, float f3, float f4, float f5, float f6, float f7, float f8, float f9, int i2) throws TvCommonException;

    public native boolean startUartDebug() throws TvCommonException;

    public native void stopTvService() throws TvCommonException;

    public final native boolean storeDbToUsb() throws TvCommonException;

    @Deprecated
    public native boolean switchUart() throws TvCommonException;

    public native boolean uartSwitch() throws TvCommonException;

    public final native void updatePqIniFiles() throws TvCommonException;

    public final native boolean updateSscParameter() throws TvCommonException;

    public final native UrsaVersionInfo ursaGetVersionInfo() throws TvCommonException;

    public native boolean writeBytesToI2C(int i2, short[] sArr, short[] sArr2) throws TvCommonException;

    public final String getPQVersion(int i2) throws TvCommonException {
        return native_getPQVersion(i2);
    }

    protected static FactoryManager getInstance(Object obj) {
        if (obj.getClass().getName().equals("com.mstar.android.tvapi.common.TvFactoryManagerProxy") && _factoryManager == null) {
            synchronized (FactoryManager.class) {
                try {
                    if (_factoryManager == null) {
                        _factoryManager = new FactoryManager();
                    }
                } finally {
                }
            }
        }
        return _factoryManager;
    }
}
