package com.mstar.android.tv;

import android.os.RemoteException;
import android.text.format.Time;
import android.util.Log;
import com.mstar.android.tvapi.common.vo.PresentFollowingEventInfo;
import com.mstar.android.tvapi.dtv.atsc.vo.AtscEpgEventInfo;
import com.mstar.android.tvapi.dtv.atsc.vo.AtscProgramInfo;
import com.mstar.android.tvapi.dtv.vo.DtvEitInfo;
import com.mstar.android.tvapi.dtv.vo.DtvType;
import com.mstar.android.tvapi.dtv.vo.EpgEventInfo;
import com.mstar.android.tvapi.dtv.vo.EpgFirstMatchHdCast;
import com.mstar.android.tvapi.dtv.vo.EpgHdSimulcast;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class TvEpgManager {
    public static final int EPG_DETAIL_DESCRIPTION = 1;
    public static final int EPG_EXTEND_DESCRIPTION = 3;
    public static final int EPG_GUIDANCE_DESCRIPTION = 2;
    public static final int EPG_NONE_DESCRIPTION = 4;
    public static final int EPG_SHORT_DESCRIPTION = 0;
    private static final String TAG = "TvEpgManager";
    static TvEpgManager mInstance;
    private static ITvEpg mService;

    private TvEpgManager() {
    }

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

    private int getLocalTime(Time time) {
        int millis = (int) (time.toMillis(false) / 1000);
        int clockOffset = TvTimerManager.getInstance().getClockOffset();
        if (true == TvTimerManager.getInstance().getDaylightSavingState()) {
            clockOffset -= 3600;
        }
        int i2 = millis + clockOffset;
        Log.d(TAG, "getLocalTime(), seconds = " + i2);
        return i2;
    }

    private static ITvEpg getService() {
        ITvEpg iTvEpg = mService;
        if (iTvEpg != null) {
            return iTvEpg;
        }
        if (true == TvServiceBinder.isNeedBindService()) {
            ITvService tvService = TvServiceBinder.getTvService();
            if (tvService == null) {
                Log.e(TAG, "TvService doesn't exist!!");
                throw new NullPointerException("TvService doesn't exist.");
            }
            try {
                mService = tvService.getTvEpg();
            } catch (RemoteException e2) {
                e2.printStackTrace();
            }
        } else {
            mService = TvManager.getInstance().getTvEpg();
        }
        return mService;
    }

    public void addingEpgPriority(AtscProgramInfo atscProgramInfo, int i2) {
        Log.d(TAG, "addingEpgPriority, paras programInfo = " + atscProgramInfo + ", addingPriority = " + i2);
        try {
            getService().addingEpgPriority(atscProgramInfo, i2);
        } catch (RemoteException e2) {
            e2.printStackTrace();
        }
    }

    public boolean beginToGetEventInformation(int i2, int i3, int i4, int i5) {
        try {
            return getService().beginToGetEventInformation(i2, i3, i4, i5);
        } catch (RemoteException e2) {
            e2.printStackTrace();
            return false;
        }
    }

    public boolean disableEpgBarkerChannel() {
        try {
            return getService().disableEpgBarkerChannel();
        } catch (RemoteException e2) {
            e2.printStackTrace();
            return false;
        }
    }

    public boolean enableEpgBarkerChannel() {
        try {
            return getService().enableEpgBarkerChannel();
        } catch (RemoteException e2) {
            e2.printStackTrace();
            return false;
        }
    }

    public void endToGetEventInformation() {
        try {
            getService().endToGetEventInformation();
        } catch (RemoteException e2) {
            e2.printStackTrace();
        }
    }

    public int getAtscEventCount(int i2, int i3, int i4, int i5, Time time) {
        Log.d(TAG, "getEventCount, paras majorNumber = " + i2 + ", minorNumber = " + i3 + ", serviceNumber = " + i4 + ", programId = " + i5 + ", baseTime = " + time);
        return getAtscEventCount(i2, i3, i4, i5, getLocalTime(time));
    }

    public AtscEpgEventInfo getAtscEventInfoByTime(int i2, int i3, int i4, int i5, Time time) {
        Log.d(TAG, "getAtscEventInfoByTime, paras majorNumber = " + i2 + ", minorNumber = " + i3 + ", serviceNumber = " + i4 + ", programId = " + i5 + ", baseTime = " + time);
        return getAtscEventInfoByTime(i2, i3, i4, i5, getLocalTime(time));
    }

    public int getDvbEventCount(int i2, int i3, long j2) {
        int dvbEventCount;
        Log.d(TAG, "getEventCount, paras serviceType = " + i2 + ", programId = " + i3 + ", baseTime = " + j2);
        try {
            dvbEventCount = getService().getDvbEventCount(i2, i3, j2);
            try {
                Log.d(TAG, "return int " + dvbEventCount);
            } catch (RemoteException e2) {
                e = e2;
                e.printStackTrace();
            }
        } catch (RemoteException e3) {
            e = e3;
            dvbEventCount = -1;
        }
        return dvbEventCount;
    }

    public EpgEventInfo getDvbEventInfoByTime(int i2, int i3, Time time) {
        Log.d(TAG, "getDvbEventInfoByTime, paras serviceNumber = " + i2 + ", programId = " + i3 + ", baseTime = " + time);
        try {
            return getService().getDvbEventInfoByTime(i2, i3, time.toMillis(true));
        } catch (RemoteException e2) {
            e2.printStackTrace();
            return null;
        }
    }

    public DtvEitInfo getEitInfo(boolean z2) {
        try {
            return getService().getEitInfo(z2);
        } catch (RemoteException e2) {
            e2.printStackTrace();
            return null;
        }
    }

    public int getEpgEventOffsetTime(Time time, boolean z2) {
        try {
            return getService().getEpgEventOffsetTime(time.toMillis(true), z2);
        } catch (RemoteException e2) {
            e2.printStackTrace();
            return -1;
        }
    }

    public PresentFollowingEventInfo getEpgPresentFollowingEventInfo(short s2, int i2, boolean z2, int i3) {
        try {
            return getService().getPresentFollowingEventInfo(s2, i2, z2, i3);
        } catch (RemoteException e2) {
            e2.printStackTrace();
            return null;
        }
    }

    public final EpgFirstMatchHdCast getEvent1stMatchHdBroadcast(int i2, int i3, Time time) {
        Log.d(TAG, "getEvent1stMatchHdBroadcast, serviceNo = " + i3 + ", baseTime = " + time);
        try {
            return getService().getEvent1stMatchHdBroadcast(i2, i3, time.toMillis(true));
        } catch (RemoteException e2) {
            e2.printStackTrace();
            return null;
        }
    }

    @Deprecated
    public int getEventCount(int i2, int i3, int i4, int i5, Time time) {
        return getAtscEventCount(i2, i3, i4, i5, time);
    }

    @Deprecated
    public String getEventDescriptor(short s2, int i2, Time time, DtvType.EnumEpgDescriptionType enumEpgDescriptionType) {
        return getEventDescriptor(s2, i2, time, enumEpgDescriptionType.ordinal());
    }

    public AtscEpgEventInfo getEventExtendInfoByTime(int i2, int i3, int i4, int i5, Time time) {
        Log.d(TAG, "getEventExtendInfoByTime, paras majorNumber = " + i2 + ", minorNumber = " + i3 + ", serviceNumber = " + i4 + ", programId = " + i5 + ", baseTime = " + time);
        return getEventExtendInfoByTime(i2, i3, i4, i5, getLocalTime(time));
    }

    public List<EpgHdSimulcast> getEventHdSimulcast(short s2, int i2, Time time, short s3) {
        try {
            return getService().getEventHdSimulcast(s2, i2, time.toMillis(true), s3);
        } catch (RemoteException e2) {
            e2.printStackTrace();
            return null;
        }
    }

    public List<EpgEventInfo> getEventInfo(short s2, int i2, Time time, int i3) {
        try {
            return getService().getEventInfo(s2, i2, time.toMillis(false), i3);
        } catch (RemoteException e2) {
            e2.printStackTrace();
            return null;
        }
    }

    @Deprecated
    public AtscEpgEventInfo getEventInfoByTime(int i2, int i3, int i4, int i5, Time time) {
        return getAtscEventInfoByTime(i2, i3, i4, i5, time);
    }

    public AtscEpgEventInfo getFirstEventInformation(Time time) {
        Log.d(TAG, "getFirstEventInformation, baseTime = " + time);
        return getFirstEventInformation(getLocalTime(time));
    }

    @Deprecated
    public int getIsdbEventCount(int i2, int i3, Time time) {
        return getDvbEventCount(i2, i3, time.toMillis(true));
    }

    public AtscEpgEventInfo getNextEventInformation() {
        try {
            return getService().getNextEventInformation();
        } catch (RemoteException e2) {
            e2.printStackTrace();
            return null;
        }
    }

    @Deprecated
    public PresentFollowingEventInfo getPresentFollowingEventInfo(short s2, int i2, boolean z2, DtvType.EnumEpgDescriptionType enumEpgDescriptionType) {
        return getEpgPresentFollowingEventInfo(s2, i2, z2, enumEpgDescriptionType.ordinal());
    }

    public boolean resetEPGProgPriority() {
        try {
            return getService().resetEPGProgPriority();
        } catch (RemoteException e2) {
            e2.printStackTrace();
            return false;
        }
    }

    public String getEventDescriptor(short s2, int i2, Time time, int i3) {
        try {
            return getService().getEventDescriptor(s2, i2, time.toMillis(true), i3);
        } catch (RemoteException e2) {
            e2.printStackTrace();
            return null;
        }
    }

    @Deprecated
    public EpgEventInfo getEventInfoByTime(int i2, int i3, Time time) {
        return getDvbEventInfoByTime(i2, i3, time);
    }

    public AtscEpgEventInfo getFirstEventInformation(int i2) {
        ITvEpg service = getService();
        try {
            Log.d(TAG, "getFirstEventInformation, baseTime = " + i2);
            return service.getFirstEventInformation(i2);
        } catch (RemoteException e2) {
            e2.printStackTrace();
            return null;
        }
    }

    public int getAtscEventCount(int i2, int i3, int i4, int i5, int i6) {
        int atscEventCount;
        Log.d(TAG, "getEventCount, paras majorNumber = " + i2 + ", minorNumber = " + i3 + ", serviceNumber = " + i4 + ", programId = " + i5 + ", baseTime = " + i6);
        try {
            atscEventCount = getService().getAtscEventCount(i2, i3, i4, i5, i6);
            try {
                Log.d(TAG, "return int " + atscEventCount);
            } catch (RemoteException e2) {
                e = e2;
                e.printStackTrace();
            }
        } catch (RemoteException e3) {
            e = e3;
            atscEventCount = -1;
        }
        return atscEventCount;
    }

    public AtscEpgEventInfo getAtscEventInfoByTime(int i2, int i3, int i4, int i5, int i6) {
        Log.d(TAG, "getAtscEventInfoByTime, paras majorNumber = " + i2 + ", minorNumber = " + i3 + ", serviceNumber = " + i4 + ", programId = " + i5 + ", baseTime = " + i6);
        try {
            return getService().getAtscEventInfoByTime(i2, i3, i4, i5, i6);
        } catch (RemoteException e2) {
            e2.printStackTrace();
            return null;
        }
    }

    public AtscEpgEventInfo getEventExtendInfoByTime(int i2, int i3, int i4, int i5, int i6) {
        Log.d(TAG, "getEventExtendInfoByTime, paras majorNumber = " + i2 + ", minorNumber = " + i3 + ", serviceNumber = " + i4 + ", programId = " + i5 + ", baseTime = " + i6);
        try {
            return getService().getEventExtendInfoByTime(i2, i3, i4, i5, i6);
        } catch (RemoteException e2) {
            e2.printStackTrace();
            return null;
        }
    }
}
