package com.mstar.android.tvapi.common;

import com.mstar.android.tvapi.common.exception.TvCommonException;
import com.mstar.android.tvapi.common.vo.EnumFavoriteId;
import com.mstar.android.tvapi.common.vo.EnumFirstServiceInputType;
import com.mstar.android.tvapi.common.vo.EnumFirstServiceType;
import com.mstar.android.tvapi.common.vo.EnumProgramAttribute;
import com.mstar.android.tvapi.common.vo.EnumProgramCountType;
import com.mstar.android.tvapi.common.vo.EnumProgramInfoType;
import com.mstar.android.tvapi.common.vo.EnumProgramLoopType;
import com.mstar.android.tvapi.common.vo.GetServiceInfo;
import com.mstar.android.tvapi.common.vo.ProgramInfo;
import com.mstar.android.tvapi.common.vo.ProgramInfoQueryCriteria;
import com.mstar.android.tvapi.dtv.atsc.vo.AtscMainListChannelInformation;
import java.lang.ref.WeakReference;

/* JADX INFO: loaded from: classes.dex */
public final class ChannelManager {
    private static final String ICHANNEL_MANAGER = "mstar.IChannelManager";
    private static ChannelManager _channelManager;
    private final String TAG = "ChannelManager";
    private int mChannelManagerContext;
    private long mNativeContext;

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

    private ChannelManager() {
        native_setup(new WeakReference(this));
    }

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

    protected static ChannelManager getInstance() {
        if (_channelManager == null) {
            synchronized (ChannelManager.class) {
                try {
                    if (_channelManager == null) {
                        _channelManager = new ChannelManager();
                    }
                } finally {
                }
            }
        }
        return _channelManager;
    }

    private final native ProgramInfo native_ATSC_getProgramInfo(int i2) throws TvCommonException;

    private final native void native_addProgramToFavorite(int i2, int i3, short s2, int i4) throws TvCommonException;

    private final native boolean native_changeToFirstService(int i2, int i3) throws TvCommonException;

    private final native void native_deleteProgramFromFavorite(int i2, int i3, short s2, int i4) throws TvCommonException;

    private final native void native_finalize();

    private final native boolean native_genMixProgList(boolean z2) throws TvCommonException;

    private final native boolean native_getProgramAttribute(int i2, int i3, short s2, int i4) throws TvCommonException;

    private final native int native_getProgramCount(int i2) throws TvCommonException;

    private final native ProgramInfo native_getProgramInfo(ProgramInfoQueryCriteria programInfoQueryCriteria, int i2) throws TvCommonException;

    private final native ProgramInfo native_getProgramInfoById(int i2) throws TvCommonException;

    private final native String native_getProgramName(int i2, short s2, short s3) throws TvCommonException;

    private static final native void native_init();

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

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

    private final native void native_setProgramAttribute(int i2, int i3, short s2, int i4, boolean z2) throws TvCommonException;

    private final native void native_setup(Object obj);

    private static void postEventFromNative(Object obj, int i2, int i3, int i4, Object obj2) {
    }

    public void addProgramToFavorite(EnumFavoriteId enumFavoriteId, int i2, short s2, int i3) throws TvCommonException {
        native_addProgramToFavorite(enumFavoriteId.getValue(), i2, s2, i3);
    }

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

    public final native boolean changeProgramList() throws TvCommonException;

    public boolean changeToFirstService(EnumFirstServiceInputType enumFirstServiceInputType, EnumFirstServiceType enumFirstServiceType) throws TvCommonException {
        return native_changeToFirstService(enumFirstServiceInputType.ordinal(), enumFirstServiceType.ordinal());
    }

    public final native boolean deleteAllMainList() throws TvCommonException;

    public final native boolean deleteAtvMainList() throws TvCommonException;

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

    public final native boolean deleteDtvMainList() throws TvCommonException;

    public void deleteProgramFromFavorite(EnumFavoriteId enumFavoriteId, int i2, short s2, int i3) throws TvCommonException {
        native_deleteProgramFromFavorite(enumFavoriteId.getValue(), i2, s2, i3);
    }

    protected void finalize() throws Throwable {
        super.finalize();
        native_finalize();
        _channelManager = null;
    }

    public boolean genMixProgList(boolean z2) throws TvCommonException {
        return native_genMixProgList(z2);
    }

    public final native int getCurrChannelNumber() throws TvCommonException;

    public final native AtscMainListChannelInformation getCurrentChannelInformation() throws TvCommonException;

    public final native ProgramInfo getCurrentProgramInfo() throws TvCommonException;

    public final native int getNvodReferenceServicesCount() throws TvCommonException;

    public final native GetServiceInfo[] getNvodReferenceServicesInfo(int i2) throws TvCommonException;

    public boolean getProgramAttribute(EnumProgramAttribute enumProgramAttribute, int i2, short s2, int i3) throws TvCommonException {
        return native_getProgramAttribute(enumProgramAttribute.ordinal(), i2, s2, i3);
    }

    public int getProgramCount(EnumProgramCountType enumProgramCountType) throws TvCommonException {
        return native_getProgramCount(enumProgramCountType.ordinal());
    }

    public ProgramInfo getProgramInfo(ProgramInfoQueryCriteria programInfoQueryCriteria, EnumProgramInfoType enumProgramInfoType) throws TvCommonException {
        ProgramInfo programInfoNative_getProgramInfo = native_getProgramInfo(programInfoQueryCriteria, enumProgramInfoType.ordinal());
        String str = programInfoNative_getProgramInfo.serviceName;
        if (str != null && !str.isEmpty() && 2 <= str.length() && 19 == str.charAt(0)) {
            programInfoNative_getProgramInfo.serviceName = new String(str.substring(1));
        }
        return programInfoNative_getProgramInfo;
    }

    public final ProgramInfo getProgramInfoById(int i2) throws TvCommonException {
        return native_getProgramInfoById(i2);
    }

    public String getProgramName(int i2, short s2, short s3) throws TvCommonException {
        String strNative_getProgramName = native_getProgramName(i2, s2, s3);
        return (strNative_getProgramName == null || strNative_getProgramName.isEmpty() || 2 > strNative_getProgramName.length() || 19 != strNative_getProgramName.charAt(0)) ? strNative_getProgramName : new String(strNative_getProgramName.substring(1));
    }

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

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

    public final void programDown(EnumProgramLoopType enumProgramLoopType) throws TvCommonException {
        native_programDown(enumProgramLoopType.ordinal());
    }

    public final void programUp(EnumProgramLoopType enumProgramLoopType) throws TvCommonException {
        native_programUp(enumProgramLoopType.ordinal());
    }

    protected void release() throws Throwable {
        _channelManager = null;
    }

    public final native void returnToPreviousProgram() throws TvCommonException;

    public final native void selectProgram(int i2, short s2, int i3) throws TvCommonException;

    public final native boolean selectProgram(int i2, int i3) throws TvCommonException;

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

    public void setProgramAttribute(EnumProgramAttribute enumProgramAttribute, int i2, short s2, int i3, boolean z2) throws TvCommonException {
        native_setProgramAttribute(enumProgramAttribute.ordinal(), i2, s2, i3, z2);
    }

    public final native void setProgramName(int i2, int i3, String str) throws TvCommonException;

    public final native void setProgramName(int i2, short s2, int i3, String str) throws TvCommonException;

    public final native boolean setTvDirectTuning(int i2, int i3) throws TvCommonException;

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

    public ProgramInfo getProgramInfo(int i2) throws TvCommonException {
        return native_ATSC_getProgramInfo(i2);
    }
}
