package com.mstar.android.tvapi.dtv.dvb.isdb;

import android.os.Parcel;
import android.util.Log;
import com.mstar.android.tvapi.common.exception.TvCommonException;
import com.mstar.android.tvapi.dtv.dvb.isdb.vo.GingaInfo;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;

/* JADX INFO: loaded from: classes.dex */
public class GingaManager {
    private static final String LIBRARY = "gingamanager_jni";
    private static final String TAG = "GingaManager";
    private static GingaManager mInstance;
    private long mNativeContext;

    static {
        try {
            System.loadLibrary(LIBRARY);
            native_init();
        } catch (UnsatisfiedLinkError e2) {
            Log.e(TAG, String.format("Cannot load %s library:%s\n", LIBRARY, e2.toString()));
        }
    }

    protected GingaManager() {
        try {
            native_setup(new WeakReference(this));
        } catch (Exception e2) {
            e2.printStackTrace();
        }
    }

    private final native boolean _getGingaApps(Parcel parcel, Parcel parcel2) throws TvCommonException;

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

    private final native void native_finalize();

    private static final native void native_init();

    private final native void native_setup(Object obj);

    public final native boolean autoStartApplication() throws TvCommonException;

    public final native boolean disableGigna() throws TvCommonException;

    public final native boolean enableGinga() throws TvCommonException;

    public void finalize() throws Throwable {
        super.finalize();
        try {
            native_finalize();
        } catch (Exception e2) {
            e2.printStackTrace();
        }
        mInstance = null;
    }

    public final List<GingaInfo> getApps(String str) throws TvCommonException {
        Parcel parcelObtain = Parcel.obtain();
        Parcel parcelObtain2 = Parcel.obtain();
        parcelObtain2.writeInterfaceToken("mstar.IPlayerImpl");
        parcelObtain2.writeString(str);
        Log.i(TAG, str);
        _getGingaApps(parcelObtain2, parcelObtain);
        ArrayList arrayList = new ArrayList();
        int i2 = parcelObtain.readInt();
        for (int i3 = 0; i3 < i2; i3++) {
            GingaInfo gingaInfo = new GingaInfo();
            gingaInfo.aid = parcelObtain.readInt();
            gingaInfo.oid = parcelObtain.readInt();
            gingaInfo.name = parcelObtain.readString();
            gingaInfo.type = parcelObtain.readInt();
            gingaInfo.flag = parcelObtain.readInt();
            arrayList.add(gingaInfo);
        }
        parcelObtain2.recycle();
        parcelObtain.recycle();
        return arrayList;
    }

    public final native boolean isGingaEnabled() throws TvCommonException;

    public final native boolean isGingaRunning() throws TvCommonException;

    public final native boolean processKey(int i2, boolean z2) throws TvCommonException;

    public final native boolean startApplication(long j2, long j3) throws TvCommonException;

    public final native boolean stopApplication() throws TvCommonException;
}
