package com.mstar.android.tvapi.common;

import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import com.mstar.android.tvapi.common.exception.TvCommonException;
import com.mstar.android.tvapi.common.listener.OnEventListener;
import com.mstar.android.tvapi.common.vo.CaptureThumbnailResult;
import com.mstar.android.tvapi.common.vo.EnumPvrStatus;
import com.mstar.android.tvapi.common.vo.PvrFileInfo;
import com.mstar.android.tvapi.common.vo.PvrPlaybackSpeed;
import com.mstar.android.tvapi.common.vo.PvrUsbDeviceLabel;
import com.mstar.android.tvapi.common.vo.VideoWindowType;
import java.lang.ref.WeakReference;

/* JADX INFO: loaded from: classes.dex */
public final class PvrManager {
    public static final int E_FILE_SYSTEM_TYPE_EXFAT = 7;
    public static final int E_FILE_SYSTEM_TYPE_EXT2 = 3;
    public static final int E_FILE_SYSTEM_TYPE_EXT3 = 4;
    public static final int E_FILE_SYSTEM_TYPE_EXT4 = 8;
    public static final int E_FILE_SYSTEM_TYPE_INVALID = 9;
    public static final int E_FILE_SYSTEM_TYPE_JFFS2 = 1;
    public static final int E_FILE_SYSTEM_TYPE_MSDOS = 5;
    public static final int E_FILE_SYSTEM_TYPE_NTFS = 6;
    public static final int E_FILE_SYSTEM_TYPE_UNKNOWN = 0;
    public static final int E_FILE_SYSTEM_TYPE_VFAT = 2;
    public static final int PVR_FILE_INFO_SORT_CHANNEL = 3;
    public static final int PVR_FILE_INFO_SORT_FILENAME = 0;
    public static final int PVR_FILE_INFO_SORT_LCN = 2;
    public static final int PVR_FILE_INFO_SORT_MAX_KEY = 5;
    public static final int PVR_FILE_INFO_SORT_PROGRAM = 4;
    public static final int PVR_FILE_INFO_SORT_TIME = 1;
    private static final String TAG = "PvrManager";
    public static final int TVPVR_FORMAT_EVENT_END = 1999;
    public static final int TVPVR_FORMAT_EVENT_START = 1000;
    public static final int TVPVR_NOTIFY_FORMAT_FINISHED = 1001;
    public static final int TVPVR_NOTIFY_PLAYBACK_BEGIN = 2002;
    public static final int TVPVR_NOTIFY_PLAYBACK_STOP = 2001;
    public static final int TVPVR_NOTIFY_USB_INSERTED = 1;
    public static final int TVPVR_NOTIFY_USB_REMOVED = 2;
    public static final int TVPVR_PLAYBACK_EVENT_END = 2999;
    public static final int TVPVR_PLAYBACK_EVENT_START = 2000;
    public static final int TVPVR_USB_EVENT_END = 999;
    public static final int TVPVR_USB_EVENT_START = 0;
    private static PvrManager _pvrManager;
    private EventHandler mEventHandler;
    private long mNativeContext;
    private OnEventListener mOnEventListener;
    private OnPvrEventListener mOnPvrEventListener;
    private int mPvrManagerContext;

    private class EventHandler extends Handler {
        private PvrManager mMSrv;

        public EventHandler(PvrManager pvrManager, Looper looper) {
            super(looper);
            this.mMSrv = pvrManager;
        }

        @Override // android.os.Handler
        public void handleMessage(Message message) {
            if (this.mMSrv.mNativeContext == 0) {
                return;
            }
            if (PvrManager.this.mOnEventListener != null) {
                PvrManager.this.mOnEventListener.onEvent(message);
            }
            int i2 = message.what;
            if (i2 == 1) {
                if (PvrManager.this.mOnPvrEventListener != null) {
                    PvrManager.this.mOnPvrEventListener.onPvrNotifyUsbInserted(this.mMSrv, message.what, message.arg1, message.arg2);
                    return;
                }
                return;
            }
            if (i2 == 2) {
                if (PvrManager.this.mOnPvrEventListener != null) {
                    PvrManager.this.mOnPvrEventListener.onPvrNotifyUsbRemoved(this.mMSrv, message.what, message.arg1, message.arg2);
                    return;
                }
                return;
            }
            if (i2 == 1001) {
                if (PvrManager.this.mOnPvrEventListener != null) {
                    PvrManager.this.mOnPvrEventListener.onPvrNotifyFormatFinished(this.mMSrv, message.what, message.arg1, message.arg2);
                }
            } else if (i2 == 2001) {
                if (PvrManager.this.mOnPvrEventListener != null) {
                    PvrManager.this.mOnPvrEventListener.onPvrNotifyPlaybackStop(this.mMSrv, message.what, message.arg1, message.arg2);
                }
            } else if (i2 == 2002) {
                if (PvrManager.this.mOnPvrEventListener != null) {
                    PvrManager.this.mOnPvrEventListener.onPvrNotifyPlaybackBegin(this.mMSrv, message.what, message.arg1, message.arg2);
                }
            } else {
                Log.d(PvrManager.TAG, "Unknown message type " + message.what);
            }
        }
    }

    public interface OnPvrEventListener {
        boolean onPvrNotifyFormatFinished(PvrManager pvrManager, int i2, int i3, int i4);

        boolean onPvrNotifyPlaybackBegin(PvrManager pvrManager, int i2, int i3, int i4);

        boolean onPvrNotifyPlaybackStop(PvrManager pvrManager, int i2, int i3, int i4);

        boolean onPvrNotifyUsbInserted(PvrManager pvrManager, int i2, int i3, int i4);

        boolean onPvrNotifyUsbRemoved(PvrManager pvrManager, int i2, int i3, int i4);
    }

    static {
        try {
            System.loadLibrary("pvrmanager_jni");
            native_init();
        } catch (UnsatisfiedLinkError e2) {
            Log.d(TAG, "Cannot load pvrmanager_jni library:\n" + e2.toString());
        }
    }

    private PvrManager() {
        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));
    }

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

    private final native void native_finalize();

    private final native boolean native_getIsBootByRecord();

    private final native int native_getPlaybackSpeed() throws TvCommonException;

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

    private static final native void native_init();

    private final native boolean native_isSupportISDB();

    private final native boolean native_isSupportStandBy();

    private final native int native_pauseAlwaysTimeShiftPlayback(boolean z2) throws TvCommonException;

    private final native void native_setIsBootByRecord(boolean z2);

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

    private final native void native_setPvrRecordStandByOnOff(boolean z2);

    private final native void native_setup(Object obj);

    private final native int native_startPlayback(String str) throws TvCommonException;

    private final native int native_startPlayback(String str, int i2) throws TvCommonException;

    private final native int native_startPlayback(String str, int i2, int i3) throws TvCommonException;

    private final native int native_startRecord() throws TvCommonException;

    private final native int native_startTimeShiftPlayback() throws TvCommonException;

    private final native int native_startTimeShiftRecord() throws TvCommonException;

    private static void postEventFromNative(Object obj, int i2, int i3, int i4, Object obj2) {
        PvrManager pvrManager = (PvrManager) ((WeakReference) obj).get();
        if (pvrManager == null) {
            return;
        }
        EventHandler eventHandler = pvrManager.mEventHandler;
        if (eventHandler != null) {
            pvrManager.mEventHandler.sendMessage(eventHandler.obtainMessage(i2, i3, i4, obj2));
        }
        Log.d(TAG, "Native Pvr callback, postEventFromNative");
    }

    public final native boolean assignThumbnailFileInfoHandler(String str) throws TvCommonException;

    public final native CaptureThumbnailResult captureThumbnail() throws TvCommonException;

    public native boolean changeDevice(short s2) throws TvCommonException;

    public final native int checkUsbSpeed() throws TvCommonException;

    public final native void clearMetadata() throws TvCommonException;

    public final native boolean createMetadata(String str) throws TvCommonException;

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

    public final native void doPlaybackFastBackward() throws TvCommonException;

    public final native void doPlaybackFastForward() throws TvCommonException;

    public final native void doPlaybackJumpBackward() throws TvCommonException;

    public final native void doPlaybackJumpForward() throws TvCommonException;

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

    public final native int getCurPlaybackTimeInSecond() throws TvCommonException;

    public final native String getCurPlaybackingFileName() throws TvCommonException;

    public final native int getCurRecordTimeInSecond() throws TvCommonException;

    public final native String getCurRecordingFileName() throws TvCommonException;

    public final native long getCurTimeshiftTimeInMiliSecSinceEpoch() throws TvCommonException;

    public final native int getEstimateRecordRemainingTime() throws TvCommonException;

    public final native String getFileEventName(String str) throws TvCommonException;

    public final native int getFileLcn(int i2) throws TvCommonException;

    public final native String getFileServiceName(String str) throws TvCommonException;

    public boolean getIsBootByRecord() {
        return native_getIsBootByRecord();
    }

    public final native int getMetadataSortKey() throws TvCommonException;

    public final PvrPlaybackSpeed.EnumPvrPlaybackSpeed getPlaybackSpeed() throws TvCommonException {
        try {
            return PvrPlaybackSpeed.EnumPvrPlaybackSpeed.values()[PvrPlaybackSpeed.EnumPvrPlaybackSpeed.getOrdinalThroughValue(native_getPlaybackSpeed())];
        } catch (ArrayIndexOutOfBoundsException e2) {
            e2.printStackTrace();
            return PvrPlaybackSpeed.EnumPvrPlaybackSpeed.E_PVR_PLAYBACK_SPEED_INVALID;
        }
    }

    public final native PvrFileInfo getPvrFileInfo(int i2, int i3) throws TvCommonException;

    public final native int getPvrFileNumber() throws TvCommonException;

    public final native int getPvrFileResumePointInSec(String str, int i2) throws TvCommonException;

    public final native String getPvrMountPath() throws TvCommonException;

    public final native int getRecordedFileDurationTime(String str) throws TvCommonException;

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

    public final native int getThumbnailNumber() throws TvCommonException;

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

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

    public final native long getTimeshiftStartTimeInMiliSecSinceEpoch() throws TvCommonException;

    public final native short getUsbDeviceIndex() throws TvCommonException;

    public final PvrUsbDeviceLabel.EnumPvrUsbDeviceLabel getUsbDeviceLabel(int i2) throws TvCommonException {
        try {
            return PvrUsbDeviceLabel.EnumPvrUsbDeviceLabel.values()[PvrUsbDeviceLabel.EnumPvrUsbDeviceLabel.getOrdinalThroughValue(native_getUsbDeviceLabel(i2))];
        } catch (ArrayIndexOutOfBoundsException e2) {
            e2.printStackTrace();
            return PvrUsbDeviceLabel.EnumPvrUsbDeviceLabel.E_LABEL_UNKNOWN;
        }
    }

    public final native int getUsbDeviceNumber() throws TvCommonException;

    public final native int getUsbPartitionNumber() throws TvCommonException;

    public final native boolean isAlwaysTimeShift() throws TvCommonException;

    public final native boolean isAlwaysTimeShiftPlaybackPaused() throws TvCommonException;

    public final native boolean isAlwaysTimeShiftRecording() throws TvCommonException;

    public final native boolean isMetadataSortAscending() throws TvCommonException;

    public final native boolean isPlaybackParentalLock() throws TvCommonException;

    public final native boolean isPlaybackPaused() throws TvCommonException;

    public final native boolean isPlaybacking() throws TvCommonException;

    public final native boolean isRecordPaused() throws TvCommonException;

    public final native boolean isRecording() throws TvCommonException;

    public boolean isSupportISDB() {
        return native_isSupportISDB();
    }

    public boolean isSupportStandBy() {
        return native_isSupportStandBy();
    }

    public final native boolean isTimeShiftRecording() throws TvCommonException;

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

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

    public final native boolean jumpPlaybackTimeInMiliSecSinceEpoch(long j2) throws TvCommonException;

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

    public final EnumPvrStatus pauseAlwaysTimeShiftPlayback(boolean z2) throws TvCommonException {
        try {
            return EnumPvrStatus.values()[native_pauseAlwaysTimeShiftPlayback(z2)];
        } catch (ArrayIndexOutOfBoundsException e2) {
            e2.printStackTrace();
            return EnumPvrStatus.E_ERROR;
        }
    }

    public final native short pauseAlwaysTimeShiftRecord() throws TvCommonException;

    public final native void pausePlayback() throws TvCommonException;

    public final native void pauseRecord() throws TvCommonException;

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

    public final native void resumePlayback() throws TvCommonException;

    public final native void resumeRecord() throws TvCommonException;

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

    public native void setDebugMode(boolean z2) throws TvCommonException;

    public void setIsBootByRecord(boolean z2) {
        native_setIsBootByRecord(z2);
    }

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

    public final native void setMetadataSortKey(int i2) throws TvCommonException;

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

    public void setOnPvrEventListener(OnPvrEventListener onPvrEventListener) {
        this.mOnPvrEventListener = onPvrEventListener;
    }

    public final void setPlaybackSpeed(PvrPlaybackSpeed.EnumPvrPlaybackSpeed enumPvrPlaybackSpeed) throws TvCommonException {
        native_setPlaybackSpeed(enumPvrPlaybackSpeed.getValue());
    }

    public final native void setPlaybackSpeedInFloat(float f2) throws TvCommonException;

    public final native void setPlaybackWindow(VideoWindowType videoWindowType, int i2, int i3) throws TvCommonException;

    public final native boolean setPvrFileResumePoint(String str, int i2) throws TvCommonException;

    public final native boolean setPvrParams(String str, short s2) throws TvCommonException;

    public void setPvrRecordStandByOnOff(boolean z2) {
        native_setPvrRecordStandByOnOff(z2);
    }

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

    public final native void setTimeShiftFileSize(long j2) throws TvCommonException;

    public final native short startAlwaysTimeShiftPlayback() throws TvCommonException;

    public final native short startAlwaysTimeShiftRecord() throws TvCommonException;

    public EnumPvrStatus startPlayback(String str) throws TvCommonException {
        try {
            return EnumPvrStatus.values()[native_startPlayback(str)];
        } catch (ArrayIndexOutOfBoundsException e2) {
            e2.printStackTrace();
            return EnumPvrStatus.E_ERROR;
        }
    }

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

    public final EnumPvrStatus startRecord() throws TvCommonException {
        try {
            return EnumPvrStatus.values()[native_startRecord()];
        } catch (ArrayIndexOutOfBoundsException e2) {
            e2.printStackTrace();
            return EnumPvrStatus.E_ERROR;
        }
    }

    public final EnumPvrStatus startTimeShiftPlayback() throws TvCommonException {
        try {
            return EnumPvrStatus.values()[native_startTimeShiftPlayback()];
        } catch (ArrayIndexOutOfBoundsException e2) {
            e2.printStackTrace();
            return EnumPvrStatus.E_ERROR;
        }
    }

    public EnumPvrStatus startTimeShiftRecord() throws TvCommonException {
        try {
            return EnumPvrStatus.values()[native_startTimeShiftRecord()];
        } catch (ArrayIndexOutOfBoundsException e2) {
            e2.printStackTrace();
            return EnumPvrStatus.E_ERROR;
        }
    }

    public final native void stepInPlayback() throws TvCommonException;

    public final native void stopAlwaysTimeShiftPlayback() throws TvCommonException;

    public final native short stopAlwaysTimeShiftRecord() throws TvCommonException;

    public final native void stopPlayback() throws TvCommonException;

    public final native void stopPlaybackLoop() throws TvCommonException;

    public final native boolean stopPvr() throws TvCommonException;

    public final native void stopRecord() throws TvCommonException;

    public final native void stopTimeShift() throws TvCommonException;

    public final native void stopTimeShiftPlayback() throws TvCommonException;

    public final native void stopTimeShiftRecord() throws TvCommonException;

    public final native boolean unlockPlayback() throws TvCommonException;

    public final EnumPvrStatus startPlayback(String str, int i2) throws TvCommonException {
        try {
            return EnumPvrStatus.values()[native_startPlayback(str, i2)];
        } catch (ArrayIndexOutOfBoundsException e2) {
            e2.printStackTrace();
            return EnumPvrStatus.E_ERROR;
        }
    }

    public final EnumPvrStatus startPlayback(String str, int i2, int i3) throws TvCommonException {
        try {
            return EnumPvrStatus.values()[native_startPlayback(str, i2, i3)];
        } catch (ArrayIndexOutOfBoundsException e2) {
            e2.printStackTrace();
            return EnumPvrStatus.E_ERROR;
        }
    }
}
