// Thirty Party Driver Layer
// Interface of Thirty Party Driver

package com.tcl.factory.thirdparty;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.util.List;

import tvos.tv.picture.TPictureManager;
import tvos.tv.thal.THalManager;

import android.annotation.SuppressLint;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.AudioManager;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.os.ServiceManager;
import android.os.StatFs;
import android.os.SystemClock;
import android.os.SystemProperties;
import android.util.Log;
import android.widget.Toast;

import com.tcl.customerapi.defs;
import com.tcl.device.authentication.SqlCommon;
import com.tcl.deviceinfo.TDeviceInfo;
import com.tcl.devicemanager.TimerManager;
import com.tcl.factory.bsp.TCL;
import com.tcl.factory.bsp.TV;
import com.tcl.factory.bsp.TVDefine;
import com.tcl.factory.def.DEFS;
import com.tcl.factory.impl.FactoryMenuAdapter;
import com.tcl.factory.utils.ConfigItem;
import com.tcl.factory.utils.ConfigMethod;
import com.tcl.factory.utils.Debug;
import com.tcl.factory.utils.RootSeekerHelper;
import com.tcl.factory.utils.TestDeviceID;
import com.tcl.factory.utils.Utils;
import com.tcl.factory.view.DialogHint;
import com.tcl.factory.view.MainMenu;
import com.tcl.os.storage.TStorageManager;
import com.tcl.tosapi.camera.TvCameraApi;
import com.tcl.tvmanager.TAppManager;
import com.tcl.tvmanager.TDtvTypeManager;
import com.tcl.tvmanager.TTv3DManager;
import com.tcl.tvmanager.TTvCecManager;
import com.tcl.tvmanager.TTvChannelManager;
import com.tcl.tvmanager.TTvCiManager;
import com.tcl.tvmanager.TTvCommonManager;
import com.tcl.tvmanager.TTvFunctionManager;
import com.tcl.tvmanager.TTvPictureManager;
import com.tcl.tvmanager.TTvPipPopManager;
import com.tcl.tvmanager.TTvSoundManager;
import com.tcl.tvmanager.TvManager;
import com.tcl.tvmanager.vo.EnTCLAspectRatio;
import com.tcl.tvmanager.vo.EnTCLAudioInputLevelType;
import com.tcl.tvmanager.vo.EnTCLAudioStandard;
import com.tcl.tvmanager.vo.EnTCLChanelListType;
import com.tcl.tvmanager.vo.EnTCLColorTemperature;
import com.tcl.tvmanager.vo.EnTCLDtvType;
import com.tcl.tvmanager.vo.EnTCLEnergySaving;
import com.tcl.tvmanager.vo.EnTCLInputSource;
import com.tcl.tvmanager.vo.EnTCLMemberServiceType;
import com.tcl.tvmanager.vo.EnTCLMsgToDBC;
import com.tcl.tvmanager.vo.EnTCLPictureMode;
import com.tcl.tvmanager.vo.EnTCLSoundMode;
import com.tcl.tvmanager.vo.EnTCLSoundScene;
import com.tcl.tvmanager.vo.ProgramInfo;
import com.tcl.utility.property.PropertyImpl;

public class ThirdParty {
    private final static String TAG = "ThirdParty";

    public static int byteCount = 0;
    public static Context mContext;
    public static boolean serialStatus = false;
    public static boolean warmupStatus = false;
    public static WakeLock mWakeLock = null;
    private static TestDeviceID mTestDevice = null;

    public static TDeviceInfo mTDeviceInfo = null;
    public static FactoryMenuAdapter mFactoryAdapter;
    //	public static FactoryMenuManager mFactoryAdapter;
    public static TTvCommonManager mTvCommonManager = null;
    public static TTvChannelManager mTvChannelManager;
    public static TTvPictureManager mTvPictureManager;
    public static TTvPipPopManager mTvPipPopManager;
    public static TTvSoundManager mTvSoundManager;
    public static TTv3DManager mTv3dManager;
    public static TTvCiManager mTvCiManager;
    public static TStorageManager mStorageManager;
    public static TDtvTypeManager mDtvTypeManager;
    public static TimerManager mTimerManager;
    public static TTvFunctionManager mTvFunctionManager;
    public static PowerManager mPowerManager;
    public static TPictureManager mTpiPictureManager;
    public static DialogHint mDialogHint = null;
    private static AudioManager audiomanager = null;//Jane add

    private static String dongleVersion = null;
    private final static String NO_DONGLE = "no dongle";

    private final static Object mActionDoneSync = new Object();
    private static boolean mActionDone;
    private static final int MAX_BROADCAST_TIME = 3 * 1000;
    private static String usbLogoPath = "";
    private static String usbBootAnimationPath = "";
    private static String usbBootVideoPath = "";
    private static int flg_hotelBootLogoCheckStatus = DEFS.HOTEL_BOOT_LOGO_CHECK_STATUS_NULL;
    private static String bootLogoMd5 = "";
    private static String bootAnimMd5 = "";
    private static String bootVideoMd5 = "";
    private static String bootVideoIniMd5 = "";
    private static String HotelLogoName = "";
    private static boolean mIsConfigV2 = false;
    public static THalManager mTHalManager = null;
    private static TvCameraApi mTvCameraApi = null;
    public static TTvCecManager mTvCecManager;
    public static PropertyImpl mProImpl = null;
    static TvManager mTvManager;
    private final static String ACCESS_KEY = "CUHddI7z0MEjoYM+pzBDE1/isVCXbHqE763VcUkjFeJbMvxxBjHcyN14vNM3ziK5UqlLv/AgQ2yWovKV3yD8uG2XDfgdPXVrjSaBMLTuyVzMv6sO44LHIP685Q8tG+nhCDFYRZUTzTdlj7r//HsrJtVI0GygqV0C0IRaPacOOZQzbTmYD+U0GnrC4UWnFmZKRx5q6h5baMcfFPZaGGEIM+mCZ71drqNoio0CBa4M6RJt9xaUZXl/Ibu2Lei2CIAJZhTdV1FYEbOTgHQCfnXTLm/uADHMtAkZUdzBEIo1RD+uvTd37EfRtcpY8H/EU3XUkXqOg8cHSlKIPdOSqR4Ynw==";
    private static RootSeekerHelper rootSeekerHelper;

    @SuppressLint("InvalidWakeLockTag")
    public ThirdParty(Context mContext_) {
        ThirdParty.mContext = mContext_;
        mIsConfigV2 = ConfigItem.isConfigV2(mContext);
//		mFactoryAdapter = FactoryMenu.getFactoryMenuManager();
//		mFactoryAdapter = FactoryMenu.getFactoryMenuManager();
        mTvManager = TvManager.getInstance(mContext);

        rootSeekerHelper = new RootSeekerHelper(mContext_, ACCESS_KEY);
        Log.v(TAG, "1");
        if (null == mFactoryAdapter) {
            mFactoryAdapter = FactoryMenuAdapter.getInstance(mContext_);
        }
        Log.v(TAG, "2");
        if (null == mTvCommonManager) {
            mTvCommonManager = TTvCommonManager.getInstance(mContext_);
        }
        Log.v(TAG, "3");
        if (null == mTvChannelManager) {
            mTvChannelManager = TTvChannelManager.getInstance(mContext_);
        }
        Log.v(TAG, "4");
        if (null == mTvPictureManager) {
            mTvPictureManager = TTvPictureManager.getInstance(mContext_);
        }
        Log.v(TAG, "5");
        if (null == mTvSoundManager) {
            mTvSoundManager = TTvSoundManager.getInstance(mContext_);
        }
        Log.v(TAG, "6");
        if (null == mDtvTypeManager) {
            mDtvTypeManager = TDtvTypeManager.getInstance(mContext_);
        }
        Log.v(TAG, "7");
        if (null == mTvFunctionManager) {
            mTvFunctionManager = TTvFunctionManager.getInstance(mContext_);
        }
        Log.v(TAG, "8");
        if (null == mPowerManager) {
            mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
            mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "Factory");
        }
        Log.v(TAG, "9");
        if (null == mTpiPictureManager) {
            mTpiPictureManager = TPictureManager.getInstance(mContext_);
        }
        Log.v(TAG, "10");

        if (null == mTvCecManager) {
            mTvCecManager = TTvCecManager.getInstance(mContext_);
        }
        Log.v(TAG, "11");
        if (null == mProImpl) {
            mProImpl = PropertyImpl.getInstance(mContext_);
        }
        Log.v(TAG, "12");
        if (null == mTHalManager) {
            mTHalManager = THalManager.getInstance(mContext_);
        }
        Log.v(TAG, "13");
        if (null == mTvCameraApi) {
            mTvCameraApi = TvCameraApi.getInstance();
        }
        Log.v(TAG, "14");
        //setHotelLogoName();
        if (mTDeviceInfo == null) mTDeviceInfo = TDeviceInfo.getInstance();
        Log.v(TAG, "15");
        if (audiomanager == null)
            audiomanager = (AudioManager) mContext_.getSystemService(Context.AUDIO_SERVICE);//Jane add
        Log.v(TAG, "16");
/*
		Handler handler = new Handler()
		{
		   public void handleMessage(Message msg)
		   {
				if (msg.what == EnTCLCallBackSetSourceMsg.EN_TCL_SET_SOURCE_END_SUCCEED.ordinal()) {
					Debug.v(TAG, "[EN_TCL_SET_SOURCE_END_SUCCEED]");
					if(DEFS.asyncCommand == DEFS.CMD_setATVChannel){
						int AtvChNum = DEFS.asyncCommandArg1;
						TV.setATVChannel(AtvChNum);
						TCL.handlerAsyncCmdReset();
					}
				}
				super.handleMessage(msg);
		   }
		};
		TTvManager.getInstance(null).setHandler(handler,TTvUtils.TV_HANDLER_INDEX_TV_SET_SOURCE);
*/
    }


//	public static void setStorageValue(int address, int value) {
//		mFactoryAdapter.writeValue2TVStorage(0, address, value);
//		Debug.v(TAG, "setStorageValue : " + address + "," + value);
//	}
//
//	public static int getStorageValue(int address) {
//		int valueT = mFactoryAdapter.readValueFromTVStorage(0, address);
//		Debug.v(TAG, "getStorageValue ["+address+"]: " + valueT);
//		return valueT;
//	}


    public static String getModelName() {
        return mTDeviceInfo.getModelName(getProjectIDValue());
    }

    public static String getClientType() {
        return mTDeviceInfo.getClientType(getProjectIDValue());
    }

    public static String getPanelName() {
        if (ThirdParty.isSupportPanelID()) {
            return mFactoryAdapter.getPanelName();
        } else {
            return mTDeviceInfo.getPanelName(getProjectIDValue());
        }

    }

    @SuppressWarnings("finally")
    public static String getLocal() {
        String local = null;
        try {
            String clientType = mTDeviceInfo.getClientType(getProjectIDValue());
            local = clientType.split("-")[1];
        } catch (ArrayIndexOutOfBoundsException e) {
            Log.d(TAG, "getLocal error:" + e.getMessage());
            local = null;
        } finally {
            return local;
        }


    }

    // /////RC660//add by duanliang/////////////////
    public static String read_RC71S_DongleVesion() {
        Log.i(TAG, "read_RC71S_DongleVesion = " + dongleVersion);
        if (dongleVersion == null || NO_DONGLE.equalsIgnoreCase(dongleVersion)) {
            String fileName = "/data/dongle_version_flag.ini";
            //RootSeeker.exec("su");
            setRootSeek("rm /data/dongle_version_flag.ini");
            //RootSeeker.exec("mount -o remount rw system");
            setRootSeek("system/xbin/dongle_version");
//			RootSeeker.exec("system/xbin/dongle_assist_nfc -s");
            try {
                Thread.sleep(600);// 10second
            } catch (InterruptedException e) {
            }
            setRootSeek("sync");
            setRootSeek("busybox chmod 777 -R /data/dongle_version_flag.ini");
            try {
                Thread.sleep(200);// 10second
            } catch (InterruptedException e) {
            }
            dongleVersion = readFileByLines(fileName);
        }
        Log.i(TAG, "read_RC71S_DongleVesion end = " + dongleVersion);
        if (dongleVersion != null) {
            return dongleVersion;
        } else {
            return NO_DONGLE;
        }
    }

    public static String readFileByLines(String fileName) {
        File file = new File(fileName);
        BufferedReader reader = null;
        String tempString = null;
        try {
            reader = new BufferedReader(new FileReader(file));
            int line = 1;
            while ((tempString = reader.readLine()) != null) {
                // ��ʾ�к�
                System.out.println("line " + line + ": " + tempString);
                line++;
                break;
            }
            reader.close();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException e1) {
                }
            }
        }

        Log.i(TAG, "tempString=" + tempString + "=" + (tempString == null || tempString.startsWith("1")));
        return (tempString == null || tempString.startsWith("1")) ? NO_DONGLE : tempString;
    }

    public static String getHardwareVersion() {
        return mTDeviceInfo.getHardwareVersion();
    }

    public static String getSoftwareVersion() {
        String configPackVersion = mFactoryAdapter.getConfigPackVersion();
        if (configPackVersion != null && configPackVersion.length() > 0) {
            return mTDeviceInfo.getSoftwareVersion() + "." + configPackVersion.replaceAll("\r|\n", "");
        } else {
            Log.i("api", "get configPackVersion is null " + configPackVersion);
            return mTDeviceInfo.getSoftwareVersion();
        }
    }


    public static short[] getSNShort() // ԭ����byte[]
    {
        // ������f1�Խ�
        return null;
//		byte[] dataT = new byte[ConfigType.SN_SIZE];
//		int actual_size = 0;
//		actual_size = mFactoryAdapter.readTVStorage(0, ConfigType.ADDR_SN, dataT, ConfigType.SN_SIZE);
//		Debug.v(TAG, "getSNShort LEN:" + dataT.length);
//		return Utils.byte2Short(dataT);
    }

    public static void setSNShort(short[] data) {
        // ������f1�Խ�
//		int actual_size = 0;
//		if(data.length>ConfigType.SN_SIZE) actual_size=ConfigType.SN_SIZE;
//		else actual_size=data.length;
//		Debug.v(TAG, "setSNShort LEN:" + data.length);
//		actual_size = mFactoryAdapter.writeTVStorage(0, ConfigType.ADDR_SN, Utils.short2Byte(data), actual_size);
    }

    public static String getSNString() // ԭ����byte[]
    {
        String data = mFactoryAdapter.getSNString();
        Debug.v(TAG, "getSNString : " + data);
        return data;
    }

    public static void setSNString(String data) {
        setSNShort(Utils.BinString2Short(data));
        Debug.v(TAG, "setSNString : " + data);
    }

    public static boolean hasCI() {
        return mFactoryAdapter.hasCI();
    }

    public static boolean hasWideVine() {
        return mFactoryAdapter.hasWideVine();
    }

    public static boolean hasHDCP() {
        return mFactoryAdapter.hasHDCP();
    }

    public static boolean hasDRM() {
        return mFactoryAdapter.hasDRM();
    }

    public static boolean hasWIDI() {
        return mFactoryAdapter.hasWIDI();
    }

    public static void setProjectIDValue(int dataValue) {
        mFactoryAdapter.setProjectID(dataValue);
        Debug.v(TAG, "setProjectIDValue : " + dataValue);
    }

    public static int getProjectIDValue() {
        int value = 0;
        value = mFactoryAdapter.getProjectID();
        Debug.v(TAG, "getProjectIDValue : " + value);
        return value;
    }

    public static List getProjectIDList() {
        return mTDeviceInfo.getProjectList();
    }

    public static void setPanelIDValue(int dataValue) {
        mFactoryAdapter.setPanelID(dataValue);
        Debug.v(TAG, "setPanelIDValue : " + dataValue);
    }

    public static int getPanelIDValue() {
        int value = 0;
        value = mFactoryAdapter.getPanelID();
        Debug.v(TAG, "getPanelIDValue : " + value);
        return value;
    }

    public static boolean isSupportPanelID() {
        return mFactoryAdapter.isSupportPanelID();
    }

    public static int getPanelMaxIDValue() {
        int value = 0;
        value = mFactoryAdapter.getPanelMaxID();
        Debug.v(TAG, "getPanelMaxIDValue : " + value);
        return value;
    }

    /*
     *MAC��ַ����48λ�Ķ���������ɣ���6���ֽڡ���ͨ������??6���Ʊ�ʾ�ġ�ǰ24λ����������IEEE��׼��֯����ĳ��Ҵ��룬�ǹ̶��ģ�������ĵڰ�λһ����0����Ϊ��������ַ��һ���ǵ�����ַ����IPv4�Ļ����У���ֵ������鲥��ַ����У��ڰ�λ�Ķ��������֣�0��?����ַ??����鲥��ַ����ô������16�����е�һ�ֽڵڶ�������һ���Ǹ�ż��ʮ���Ƹ����֪��ǡ��ǡ������Ҳ����˵�ڶ�������һ����0????????��A��C��E���е�һ������ô��ֵ��������鲥��ַ�ͼ򵥶���??
     */
    public static void setMACAddressShort(short[] macAddress) { // 6Bit to 12Bit,��˫??
        // ������f1�Խ�
//		short[] mac = new short[12];
//		int len = macAddress.length;
//		if(len>6) len=6;
//		if(len<6) return;
//
//		if((macAddress[0] & 0x1) != 0) return; //invalid mac addr
//
//		for(int i=0;i<6;i++) {
//			mac[i]=macAddress[i];
//			mac[i+6]=macAddress[i];
//		}
//		mFactoryAdapter.writeTVStorage(0, ConfigType.ADDR_MAC, Utils.short2Byte(mac), ConfigType.MAC_SIZE);
//		Debug.v(TAG, "setMACAddressShort LEN:"+macAddress.length);
//
//		setMacCRC((int)ConfigType.CRCCalculate(macAddress,ConfigType.MAC_SIZE/2));  // crc
//		ThirdParty.setMacFlag(DEFS.MAC_DEVICE_HDCP_OK);
    }

    public static short[] getMACAddressShort()  // 12Bit to 6Bit
    {
        // ������f1�Խ�
        return null;
//		byte[] data = new byte[ConfigType.MAC_SIZE];
//		mFactoryAdapter.readTVStorage(0, ConfigType.ADDR_MAC, data, ConfigType.MAC_SIZE);
//		Debug.v(TAG, "getMACAddressShort LEN:"+data.length);
//
//		byte[] mac = new byte[ConfigType.MAC_SIZE/2];
//		for(int i=0;i<ConfigType.MAC_SIZE/2;i++){
//			mac[i]=data[i];
//		}
//
//		return Utils.byte2Short(mac);
    }

    public static void setMACAddressString(String macAddress) {
        setMACAddressShort(Utils.byte2Short(Utils.hex2byte(macAddress)));
        Debug.v(TAG, "setMACAddressString : " + macAddress);
    }

    public static String getMACAddressString() // ֻҪ��һ??
    {
        String data = mFactoryAdapter.getMacAddress();
        Debug.v(TAG, "getMACAddressString : " + data);
        return data;
    }

    public static void setRegiterCodeShort(short[] data) {
        // ������f1�Խ�
//		mFactoryAdapter.writeTVStorage(0, ConfigType.ADDR_REGISTER_CODE, Utils.short2Byte(data),ConfigType.REGISTER_CODE_SIZE);
    }

    public static short[] getRegiterCodeShort()  // 12Bit to 6Bit
    {
        // ������f1�Խ�
        return null;
//		byte[] dataT = new byte[ConfigType.REGISTER_CODE_SIZE];
//		int actual_size = 0;
//		actual_size = mFactoryAdapter.readTVStorage(0, ConfigType.ADDR_REGISTER_CODE, dataT, ConfigType.REGISTER_CODE_SIZE);
//		Debug.v(TAG, "getRegiterCodeData LEN:" + dataT.length);
//		return Utils.byte2Short(dataT);
    }

    public static String getRegiterCodeString() {
        String data = mFactoryAdapter.getRegisterCode();
        Debug.v(TAG, "getRegiterCodeString : " + data);
        return data;
    }

    public static String getUserID() {
        try {
            ContentResolver resolver = mContext.getContentResolver();

            String deviceid = null;

            deviceid = SqlCommon.getDum(resolver);
            if (deviceid == null || "000".equals(deviceid)) {
                return "";
            }
            return deviceid;
        } catch (Exception e) {
            Log.i("Exception", e.toString());
            return "";
        }
    }

    public static boolean getDeviceIDShortStatus() {
        // ������f1�Խ�
        return false;
//		boolean status = false;
//		mTestDevice = new TestDeviceID(mContext);
//		status = Utils.int2Boolean(ThirdParty.getStorageValue(ConfigType.ADDR_DEVICE_ID_FLAG));
//		Debug.v(TAG, "getDeviceIDShortStatus : " + status);
//		return status;
    }

    public static short[] getDeviceIDShort() {
        // ������f1�Խ�
        return null;
//		byte[] data = new byte[ConfigType.DEVICE_ID_SIZE];
//		int actual_size = 0;
//		actual_size = mFactoryAdapter.readTVStorage(0, ConfigType.ADDR_DEVICE_ID, data,
//				ConfigType.DEVICE_ID_SIZE);
//
//		Debug.v(TAG, "getDeviceIDShort len:"+data.length);
//		return Utils.byte2Short(data);
    }

    public static void setDeviceIDShort(short[] data) {
        // ������f1�Խ�
//		Debug.v(TAG, "setDeviceIDShort len:"+data.length);
//		mFactoryAdapter.writeTVStorage(0, ConfigType.ADDR_DEVICE_ID, Utils.short2Byte(data),
//				ConfigType.DEVICE_ID_SIZE);
//
//		setDeviceIDCRC((int)ConfigType.CRCCalculate(data,ConfigType.DEVICE_ID_SIZE));  // crc
//		ThirdParty.setDeviceIDFlag(DEFS.MAC_DEVICE_HDCP_OK);
    }

    public static String getDeviceIDString() {
        String data = mFactoryAdapter.getDeviceID();
        Debug.v(TAG, "getDeviceIDString : " + data);
        return data;
    }

    public static void setDeviceIDString(String data) {
        Debug.v(TAG, "setDeviceIDString : " + data);
        setDeviceIDShort(Utils.BinString2Short(data));
    }

    public static void setHdcpKeyShort(short[] data) {
        // ������f1�Խ�
//		Debug.v(TAG, "setHdcpKeyShort len:"+data.length);
//		mFactoryAdapter.writeTVStorage(0, ConfigType.ADDR_HDCP_KEY, Utils.short2Byte(data),
//				data.length);
//
//		setHdcpKeyCRC((int)ConfigType.CRCCalculate(data,data.length));
//		ThirdParty.setHdcpFlag(DEFS.MAC_DEVICE_HDCP_OK);
    }

    public static short[] getHdcpKeyShort() {
        // ������f1�Խ�
        return null;
//		byte[] data = new byte[ConfigType.HDCP_KEY_SIZE];
//		int actual_size = mFactoryAdapter.readTVStorage(0, ConfigType.ADDR_HDCP_KEY, data, ConfigType.HDCP_KEY_SIZE);
//
//		Debug.v(TAG, "getHdcpKeyShort len:"+actual_size);
//		return Utils.byte2Short(data);
    }

    public static void setHdcpKey20Short(short[] data) {
        // ������f1�Խ�
//		Debug.v(TAG, "setHdcpKey20Short len:"+data.length);
//		mFactoryAdapter.writeTVStorage(0, ConfigType.ADDR_HDCP_KEY_2_0, Utils.short2Byte(data),
//				data.length);
//
//		setHdcpKey20CRC((int)ConfigType.CRCCalculate(data,data.length));
//		ThirdParty.setHdcp20Flag(DEFS.MAC_DEVICE_HDCP_OK);
    }

    public static short[] getHdcpKey20Short() {
        // ������f1�Խ�
        return null;
//		byte[] data = new byte[ConfigType.HDCP_KEY_2_0_SIZE];
//		int actual_size = mFactoryAdapter.readTVStorage(0, ConfigType.ADDR_HDCP_KEY_2_0, data, ConfigType.HDCP_KEY_2_0_SIZE);
//
//		Debug.v(TAG, "getHdcpKey20Short len:"+actual_size);
//		return Utils.byte2Short(data);
    }

    public static void setHdcpFlag(int val) {
        // ������f1�Խ�
//		mFactoryAdapter.writeValue2TVStorage(0, ConfigType.ADDR_HDCP_KEY_FLAG, val);
    }

    public static void setHdcp20Flag(int val) {
        // ������f1�Խ�
//		mFactoryAdapter.writeValue2TVStorage(0, ConfigType.ADDR_HDCP_KEY_2_0_FLAG, val);
    }

    public static void setMacFlag(int val) {
        // ������f1�Խ�
//		mFactoryAdapter.writeValue2TVStorage(0, ConfigType.ADDR_MAC_FLAG, val);
    }

    public static void setDeviceIDFlag(int val) {
        // ������f1�Խ�
//		mFactoryAdapter.writeValue2TVStorage(0, ConfigType.ADDR_DEVICE_ID_FLAG, val);
    }

    public static void setNonStandardFlag(int val) {
        // ������f1�Խ�
//		mFactoryAdapter.writeValue2TVStorage(0, ConfigType.ADDR_NON_STANDARD_FLAG, val);
    }

    public static void resetAllFlag() {
        ThirdParty.setHdcpFlag(0);
        ThirdParty.setHdcp20Flag(0);
        ThirdParty.setMacFlag(0);
        ThirdParty.setMacCRC(0);
        ThirdParty.setSNCRC(0);
    }

    public static short[] pollingHdcpStatus() {
        // ������f1�Խ�
        short[] returnStatus = {0};
//		int hdcpStatus = ThirdParty.getStorageValue(ConfigType.ADDR_HDCP_KEY_FLAG);
//		if ((hdcpStatus == DEFS.MAC_DEVICE_HDCP_OK)&&Setup.pollingHdcpCRC())
//			returnStatus[0] = DEFS.STATUS_OK;
//		else
//			returnStatus[0] = DEFS.STATUS_ERROR;
//
//		Debug.v(TAG, "pollingHdcpStatus");
        return returnStatus;
    }

    public static short[] pollingHdcp20Status() {
        // ������f1�Խ�
        short[] returnStatus = {0};
//		int hdcp20status = ThirdParty.getStorageValue(ConfigType.ADDR_HDCP_KEY_2_0_FLAG);
//		if ((hdcp20status == DEFS.MAC_DEVICE_HDCP_OK)&&Setup.pollingHdcp20CRC())
//			returnStatus[0] = DEFS.STATUS_OK;
//		else
//			returnStatus[0] = DEFS.STATUS_ERROR;
//
//		Debug.v(TAG, "pollingHdcp20Status");
        return returnStatus;
    }


    /*
	0x00: All data hadn��t been installed
	0x01:MAC address successful
	0x02: Device ID successful
	0x03:Mac and device ID had been installed
	0x04: User ID successful
	0x05:Mac and user ID had been installed
	0x06:User ID and device ID had been installed
	0x07:All data had been installed
	 */
    public static short[] pollingDeviceIDAndMacStatus() {
        // ������f1�Խ�
        short[] returnStatus = {0};
//		short macStatus = (short) getStorageValue(ConfigType.ADDR_MAC_FLAG);
//		short devicedIdStatus = (short) getStorageValue(ConfigType.ADDR_DEVICE_ID_FLAG);
//
//		if ((macStatus == DEFS.MAC_DEVICE_HDCP_OK)&&(Setup.pollingMacCRC())) {
//			if ((devicedIdStatus == DEFS.MAC_DEVICE_HDCP_OK) &&(Setup.pollingDeviceIDCRC()))
//				returnStatus[0] = 3;
//			else
//				returnStatus[0] = 1;
//		} else {
//			if ((devicedIdStatus == DEFS.MAC_DEVICE_HDCP_OK)&&(Setup.pollingDeviceIDCRC()))
//				returnStatus[0] = 2;
//			else
//				returnStatus[0] = 0;
//		}
//		Debug.v(TAG, "[pollingDeviceIDAndMacStatus]"+returnStatus);
        return returnStatus;
    }

    public static void setDeviceIDCRC(int crc) {
        // ������f1�Խ�
//		Debug.v(TAG, "[setDeviceIDCRC]"+crc);
//		mFactoryAdapter.writeValue2TVStorage(0, ConfigType.ADDR_DEVICE_ID_CRC, crc & 0xff);
//		mFactoryAdapter.writeValue2TVStorage(0, ConfigType.ADDR_DEVICE_ID_CRC + 1, (crc >> 8) & 0xff);
    }

    public static void setHdcpKeyCRC(int crc) {
        // ������f1�Խ�
//		Debug.v(TAG, "[setHdcpKeyCRC]"+crc);
//		mFactoryAdapter.writeValue2TVStorage(0, ConfigType.ADDR_HDCP_KEY_CRC, crc & 0xff);
//		mFactoryAdapter.writeValue2TVStorage(0, ConfigType.ADDR_HDCP_KEY_CRC + 1, (crc >> 8) & 0xff);
    }

    public static void setHdcpKey20CRC(int crc) {
        // ������f1�Խ�
//		Debug.v(TAG, "[setHdcpKey20CRC]"+crc);
//		mFactoryAdapter.writeValue2TVStorage(0, ConfigType.ADDR_HDCP_KEY_2_0_CRC, crc & 0xff);
//		mFactoryAdapter.writeValue2TVStorage(0, ConfigType.ADDR_HDCP_KEY_2_0_CRC + 1, (crc >> 8) & 0xff);
    }

    public static void setMacCRC(int crc) {
        // ������f1�Խ�
//		Debug.v(TAG, "[setMacCRC]"+crc);
//		mFactoryAdapter.writeValue2TVStorage(0, ConfigType.ADDR_MAC_CRC, crc & 0xff);
//		mFactoryAdapter.writeValue2TVStorage(0, ConfigType.ADDR_MAC_CRC + 1, (crc >> 8) & 0xff);
    }

    public static void setSNCRC(int crc) {
        // ������f1�Խ�
//		Debug.v(TAG, "[setSNCRC]"+crc);
//
//		mFactoryAdapter.writeValue2TVStorage(0, ConfigType.ADDR_SN_CRC, crc & 0xff);
//		mFactoryAdapter.writeValue2TVStorage(0, ConfigType.ADDR_SN_CRC + 1, (crc >> 8) & 0xff);
    }

    public static void resetAllCrc() {
        ThirdParty.setDeviceIDCRC(0);
        ThirdParty.setHdcpKeyCRC(0);
        ThirdParty.setHdcpKey20CRC(0);
        ThirdParty.setMacCRC(0);
        ThirdParty.setSNCRC(0);
    }

    public static int getDeviceIDCRC() {
        // ������f1�Խ�
        return 0;
//		int CRC = 0;
//		int lowValue = mFactoryAdapter.readValueFromTVStorage(0, ConfigType.ADDR_DEVICE_ID_CRC);
//		int highValue = mFactoryAdapter.readValueFromTVStorage(0, ConfigType.ADDR_DEVICE_ID_CRC + 1);
//		CRC = ((highValue << 8) & 0xff00) + (lowValue & 0xff);
//
//		Debug.v(TAG, "[getDeviceIDCRC]"+CRC);
//		return CRC;
    }

    public static int getHdcpKeyCRC() {
        int CRC = 0;
        // ������f1�Խ�
//		int lowValue = mFactoryAdapter.readValueFromTVStorage(0, ConfigType.ADDR_HDCP_KEY_CRC);
//		int highValue = mFactoryAdapter.readValueFromTVStorage(0, ConfigType.ADDR_HDCP_KEY_CRC + 1);
//		CRC = ((highValue << 8) & 0xff00) + (lowValue & 0xff);
//
//		Debug.v(TAG, "[getHdcpKeyCRC]"+CRC);
        return CRC;
    }

    public static int getHdcpKey20CRC() {
        int CRC = 0;
        // ������f1�Խ�
//		int lowValue = mFactoryAdapter.readValueFromTVStorage(0, ConfigType.ADDR_HDCP_KEY_2_0_CRC);
//		int highValue = mFactoryAdapter.readValueFromTVStorage(0, ConfigType.ADDR_HDCP_KEY_2_0_CRC + 1);
//		CRC = ((highValue << 8) & 0xff00) + (lowValue & 0xff);
//
//		Debug.v(TAG, "[getHdcpKey20CRC]"+CRC);
        return CRC;
    }

    public static int getMacCRC() {
        int CRC = 0;
        // ������f1�Խ�
//		int lowValue = mFactoryAdapter.readValueFromTVStorage(0, ConfigType.ADDR_MAC_CRC);
//		int highValue = mFactoryAdapter.readValueFromTVStorage(0, ConfigType.ADDR_MAC_CRC + 1);
//		CRC = ((highValue << 8) & 0xff00) + (lowValue & 0xff);
//
//		Debug.v(TAG, "[getMacCRC]"+CRC);
        return CRC;
    }

    public static int getSNCRC() {
        int CRC = 0;
        // ������f1�Խ�
//		int lowValue = mFactoryAdapter.readValueFromTVStorage(0, ConfigType.ADDR_SN_CRC);
//		int highValue = mFactoryAdapter.readValueFromTVStorage(0, ConfigType.ADDR_SN_CRC + 1);
//		CRC = ((highValue << 8) & 0xff00) + (lowValue & 0xff);
//
//		Debug.v(TAG, "[getSNCRC]"+CRC);
        return CRC;
    }

    public static boolean getDModeStatus() {
//		boolean status = false;
//
//		status = Utils.int2Boolean(ThirdParty.getStorageValue(ConfigType.ADDR_DMODE_FLAG));
//		Debug.v(TAG, "getDModeStatus :" + status);
//		return status;
        boolean status = mFactoryAdapter.getDModeStatus();
        Debug.v(TAG, "getDModeStatus :" + status);
        return status;
    }

    public static void setDModeStatus(boolean status) {
//		int value = 0;
//		value = Utils.boolean2Int(status);
//
//		ThirdParty.setStorageValue(ConfigType.ADDR_DMODE_FLAG, value);
        Debug.v(TAG, "setDModeStatus :" + status);
        mFactoryAdapter.setDModeStatus(status);
    }

    public static boolean getPModeStatus() {
//		boolean status = Utils.int2Boolean(ThirdParty
//				.getStorageValue(ConfigType.ADDR_PMODE_FLAG));
//		Debug.v(TAG, "getPModeStatus :" + status);
//		return status;
        boolean status = mFactoryAdapter.getPModeStatus();
        Debug.v(TAG, "getPModeStatus :" + status);
        Log.i("api", "getPModeStatus :" + status);
        return status;
    }

    public static boolean getSitaPModeStatus() {
        boolean status = mFactoryAdapter.getSitaPModeStatus();
        Debug.v(TAG, "getSitaPModeStatus :" + status);
        return status;
    }

    public static void setPModeStatus(boolean status) {
//		int value = 0;
//		value = Utils.boolean2Int(status);
//		ThirdParty.setStorageValue(ConfigType.ADDR_PMODE_FLAG, value);
        Debug.v(TAG, "setPModeStatus :" + status);
        if (status) {
            ThirdParty.setSTRstatus(false);
            ThirdParty.setWakeLockStatus(true);
            SystemProperties.set("persist.P_MODE", "1");
            SystemProperties.set("persist.sys.logd.level", "V");
        } else {
            ThirdParty.setWakeLockStatus(false);
            SystemProperties.set("persist.P_MODE", "0");
            setRootSeek("rm -Rf /data/property/persist.P_MODE");
        }
        mFactoryAdapter.setPModeStatus(status);
        ThirdParty.broadCastPmodeStatus();
    }

    public static void setSitaPModeStatus(boolean status) {
        Debug.v(TAG, "setSitaPModeStatus :" + status);
        mFactoryAdapter.setSitaPModeStatus(status);
    }

    public static boolean getSKDModeStatus() {
        boolean status = mFactoryAdapter.getSKDModeStatus();
        Debug.v(TAG, "setSKDModeStatus :" + status);
        return status;
    }

    public static void setSKDModeStatus(boolean status) {
        Debug.v(TAG, "setSKDModeStatus :" + status);
        mFactoryAdapter.setSKDModeStatus(status);
    }

    public static boolean getWModeStatus() {
//		int value = 0;
//		boolean status = false;
//		value = ThirdParty.getStorageValue(ConfigType.ADDR_WMODE_FLAG);
//		status = Utils.int2Boolean(value);
//		Debug.v(TAG, "getWModeStatus :" + status);
//		return status;
        if (mFactoryAdapter == null) {
            Log.i("eeeff", "server is null? " + ServiceManager
                    .getService("com.tcl.factory.service"));
        }
        boolean status = mFactoryAdapter.getWarmUpModeStatus();
        Debug.v(TAG, "getWModeStatus :" + status);
        return status;
    }

    public static void setWModeStatus(boolean status) {
//		int value = 0;
//		DEFS.warmupStatus = status;
//		value = Utils.boolean2Int(status);
//		ThirdParty.setStorageValue(ConfigType.ADDR_WMODE_FLAG, value);
        Debug.v(TAG, "setWModeStatus :" + status);
        mFactoryAdapter.setWarmUpModeStatus(status);
    }

    public static boolean getDPModeStatus() {
        boolean DModeStatus = false;
        boolean PModeStatus = false;
        DModeStatus = ThirdParty.getDModeStatus();
        PModeStatus = ThirdParty.getPModeStatus();
        if (DModeStatus | PModeStatus) {
            Debug.v(TAG, "getDPModeStatus : " + DEFS.Enable);
            return DEFS.Enable;
        } else {
            Debug.v(TAG, "getDPModeStatus : " + DEFS.Disable);
            return DEFS.Disable;
        }
    }

    public static boolean getSerialDebugStatus() {
        boolean serialDebugStatus = mFactoryAdapter.getSerialDebugStatus();
        Debug.v(TAG, "getSerialDebugStatus : " + serialDebugStatus);
        return serialDebugStatus;
    }

    public static int getHotelFlag() {
        int status = mFactoryAdapter.getHotelFlag();
        Debug.v(TAG, "getHotelFlag : " + status);
        return status;
    }

    public static void setHotelFlag(int value) {
        Debug.v(TAG, "setHotelFlag : " + value);
        mFactoryAdapter.setHotelFlag(value);
    }

    /**
     * ���þƵ�˵�ѡ��
     *
     * @param defineId �Ƶ�˵�ѡ��ID �磺����log
     * @param value    0��OFF  1��ON
     * @author liuyuanfeng
     * @create 2015-1-9 ����11:17:33
     */
    public static void setHotelAttribute(int defineId, boolean value) {
        Log.d("lyf", "1.setHotelAttribute defineId = " + defineId + ", value =" + value);
        mFactoryAdapter.setHotelAttribute(defineId, (value == true ? 1 : 0));
    }

    /**
     * ���þƵ�˵�ѡ��
     *
     * @param defineId �Ƶ�˵�ѡ��ID �磺Ƶ��
     * @param value
     * @author liuyuanfeng
     * @create 2015-1-9 ����11:17:33
     */
    public static void setHotelAttribute(int defineId, int value) {
        Log.d("lyf", "1.setHotelAttribute defineId = " + defineId + ", value =" + value);
        mFactoryAdapter.setHotelAttribute(defineId, value);
    }

    /**
     * ���defineId��ȡĬ��ֵ
     *
     * @param defineId �Ƶ�˵�ѡ��ID �磺����log
     * @return true or false
     * @author liuyuanfeng
     * @create 2015-1-9 ����11:21:51
     */
    public static boolean getHotelAttribute(int defineId) {
        int value = mFactoryAdapter.getHotelAttribute(defineId);
        Log.d("lyf", "2.GetHotelAttribute defineId = " + defineId + ", value =" + value);
        return value == 1 ? true : false;
    }

    /**
     * ���defineId��ȡĬ��ֵ
     *
     * @param defineId �Ƶ�˵�ѡ��ID �磺Ƶ��
     * @return
     * @author liuyuanfeng
     * @create 2015-1-9 ����11:21:51
     */
    public static int getHotelAttribute(int defineId, int defineId2) {
        int value = mFactoryAdapter.getHotelAttribute(defineId);
        Log.d("lyf", "2.GetHotelAttribute defineId = " + defineId + ", value =" + value);
        return value;
    }

    public static boolean getNonStandardStatus() {
        // ������f1�Խ�
//		int resulte = getStorageValue(ConfigType.ADDR_NON_STANDARD_FLAG);
//		if (resulte == DEFS.NON_STANDARD_OFF) {
//			Debug.v(TAG, "getNonStandardStatus : " + DEFS.Disable);
//			return DEFS.Disable;
//		} else {
//			Debug.v(TAG, "getNonStandardStatus : " + DEFS.Enable);
//			return DEFS.Enable;
//		}
        return DEFS.Disable;
    }

    public static void setNonStandardStatus(boolean status) {
        // ������f1�Խ�
//		int value = 0;
//		if (status)
//			value=DEFS.NON_STANDARD_ON;
//		else {
//			value=DEFS.NON_STANDARD_OFF;
//		}
//
//		ThirdParty.setStorageValue(ConfigType.ADDR_NON_STANDARD_FLAG, value);
//		Debug.v(TAG, "setNonStandardStatus : " + status);

    }

    public static int getCityIDValue() {
        // ������f1�Խ�
        return 0;
//		int value = ThirdParty.getStorageValue(ConfigType.ADDR_CITY_AREA);
//		Debug.v(TAG, "getCityIDValue : " + value);
//		return value;
    }

    public static void setCityIDValue(int value) {
        // ������f1�Խ�
//		ThirdParty.setStorageValue(ConfigType.ADDR_CITY_AREA, value);
//		Debug.v(TAG, "setCityIDValue : " + value);
    }


    public static int getAreaFrequenceValue() {
        // ������f1�Խ�
        return 0;
//		int highValue = ((ThirdParty.getStorageValue(ConfigType.ADDR_MAIN_FREQUENCY) << 8) & 0xff00);
//		int lowValue = (ThirdParty.getStorageValue(ConfigType.ADDR_MAIN_FREQUENCY + 1) & 0xff);
//		int value = (highValue + lowValue);
//		Debug.v(TAG, "getAreaFrequenceValue : " + value);
//		return value;
    }

    public static void setFactoryTestData(short[] data) {
        // ������f1�Խ�
//		setStorageValue(ConfigType.ADDR_FACTORY_TEST, data[0]);
//		setStorageValue(ConfigType.ADDR_FACTORY_TEST + 1, data[1]);
//		setStorageValue(ConfigType.ADDR_FACTORY_TEST + 2, data[2]);
//		setStorageValue(ConfigType.ADDR_FACTORY_TEST + 3, data[3]);
    }

    public static short[] getFactoryTestData() {
        short[] data = new short[4];
        // ������f1�Խ�
//		data[0] = (short) getStorageValue(ConfigType.ADDR_FACTORY_TEST);
//		data[1] = (short) getStorageValue(ConfigType.ADDR_FACTORY_TEST + 1);
//		data[2] = (short) getStorageValue(ConfigType.ADDR_FACTORY_TEST + 2);
//		data[3] = (short) getStorageValue(ConfigType.ADDR_FACTORY_TEST + 3);

        return data;
    }


    public static void NVMReset() {
        //Toast.makeText(mContext, "NVM and ShutDown", Toast.LENGTH_SHORT).show();
        mFactoryAdapter.shellExecute("nvmInit");
        Debug.v(TAG, "NVMReset");
        Toast.makeText(mContext, "NVM reset finish!", Toast.LENGTH_LONG).show();
    }

    public static void ResetAll() {
        //Toast.makeText(mContext, "ResetALL", Toast.LENGTH_SHORT).show();
        mFactoryAdapter.shellExecute("nvmResetAll");
        Debug.v(TAG, "nvmResetAll");
        Toast.makeText(mContext, "NVM reset all finish!", Toast.LENGTH_LONG).show();
    }

    static void actionDone() {
        synchronized (mActionDoneSync) {
            mActionDone = true;
            mActionDoneSync.notifyAll();
        }
    }

    public static void NVMResetSelect(final boolean bResetAll) {
        final Handler handler = new Handler() {
            public void handleMessage(Message msg) {
                if (msg.what == 0) {
                    if (MainMenu._Instance != null) {
                        MainMenu._Instance.updateListView(10);
                    }
                    Toast.makeText(mContext, "NVM reset all finish!", Toast.LENGTH_LONG).show();
                } else if (msg.what == 1) {
                    if (MainMenu._Instance != null) {
                        MainMenu._Instance.updateListView(10);
                    }
                    Toast.makeText(mContext, "NVM reset finish!", Toast.LENGTH_LONG).show();
                } else {
                    Toast.makeText(mContext, "NVM reset start...", Toast.LENGTH_LONG).show();
                }
                super.handleMessage(msg);
            }
        };
        new Thread(new Runnable() {
            @Override
            public void run() {
                BroadcastReceiver br = new BroadcastReceiver() {
                    @Override
                    public void onReceive(Context context, Intent intent) {
                        // We don't allow apps to cancel this, so ignore the result.
                        Log.d(TAG, "gaoyunpei,enter receiver.");
                        actionDone();
                        Log.d(TAG, "gaoyunpei,out receiver.");
                    }
                };
                handler.sendEmptyMessage(2);

                mActionDone = false;
                Intent intent = new Intent();
                intent.setAction("tcl.intent.ACTION_FACTORY_SHOP");
                intent.addFlags(Intent.FLAG_RECEIVER_FOREGROUND);
                intent.setPackage("com.tcl.tvinput");
                mContext.sendOrderedBroadcast(intent, null, br, null, 0, null, null);
                Log.d(TAG, "gaoyunpei,receiver work begin.");
                final long endTime = SystemClock.elapsedRealtime() + MAX_BROADCAST_TIME;
                synchronized (mActionDoneSync) {
                    while (!mActionDone) {
                        long delay = endTime - SystemClock.elapsedRealtime();
                        if (delay <= 0) {
                            Log.d(TAG, "gaoyunpei,Shop broadcast timed out");
                            break;
                        }
                        try {
                            mActionDoneSync.wait(delay);
                        } catch (InterruptedException e) {
                        }
                    }
                }
                if (bResetAll == true) {
                    mFactoryAdapter.shellExecute("nvmResetAll");
                    handler.sendEmptyMessage(0);
                } else {
                    mFactoryAdapter.shellExecute("nvmInit");
                    handler.sendEmptyMessage(1);
                }
            }
        }).start();
    }

    public static void shopInit() {
        String str = "";

        Toast.makeText(mContext, "ShopInit ......", Toast.LENGTH_SHORT).show();
        Intent mIntent = new Intent();
        mIntent.setClass(mContext, com.tcl.factory.view.ShopActivity.class);
        mIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        mContext.startActivity(mIntent);

        Debug.v(TAG, "shopInit");
    }

    public static void loadDefaultGamma() {
        Toast.makeText(mContext, "loadDefaultGamma", Toast.LENGTH_SHORT).show();
        mFactoryAdapter.shellExecute("loadDefaultGamma");
        Debug.v(TAG, "loadDefaultGamma");
    }

    public static void USB2NVM(int value) {
        String path = TCL.getUSBMountPath(mContext);
        if (null == path || ("".equals(path))) {
            Toast.makeText(mContext, "NO_USB_MOUNT", Toast.LENGTH_SHORT).show();
            return;
        }
        if (mFactoryAdapter.CloneUSB2TV(value)) {
            if (value == 4)    //hotel data
            {
                Hotel_UsbToNvm();
                Toast.makeText(mContext, "USB_TO_NVM is doing, please wait... ", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(mContext, "USB_TO_NVM_OK", Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(mContext, "USB_TO_NVM_NG", Toast.LENGTH_SHORT).show();
        }
		/*
		DEFS.clone_result = DEFS.USB_TO_NVM_OK;
		if(path.length()>9) {
			Toast.makeText(mContext, "USB_TO_NVM_OK", Toast.LENGTH_SHORT).show();
		}
		*/
        Debug.v(TAG, "USB2NVM : " + value);
    }


    public static void USB2NVM_ChannelDate(int value) {
        if (mFactoryAdapter.CloneUSB2TV(value)) {

            Intent intent = new Intent(defs.MSG_USB_TO_NVM_OK);
//			Toast.makeText(mContext, "USB_TO_NVM_OK", Toast.LENGTH_SHORT).show();
            ThirdParty.mContext.sendBroadcast(intent);
        } else {

            Intent intent = new Intent(defs.MSG_USB_TO_NVM_NG);
            ThirdParty.mContext.sendBroadcast(intent);
//			Toast.makeText(mContext, "USB_TO_NVM_NG", Toast.LENGTH_SHORT).show();
        }
    }


    /*
     * 1 all data 2 channel 3 eeprom 4 user setting
     */
    public static void NVM2USB(int value) {
        String path = TCL.getUSBMountPath(mContext);


        if (null == path || ("".equals(path))) {
            Toast.makeText(mContext, "NO_USB_MOUNT", Toast.LENGTH_SHORT).show();
            return;
        }
        if (mFactoryAdapter.CloneTV2USB(value)) {
            if (value == 4)    //hotel data
            {
                Hotel_nvmToUsb();
                Toast.makeText(mContext, "NVM_TO_USB is doing, please wait... ", Toast.LENGTH_SHORT).show();
            } else {
                Toast.makeText(mContext, "NVM_TO_USB_OK", Toast.LENGTH_SHORT).show();
            }
        } else {
            Toast.makeText(mContext, "NVM_TO_USB_NG", Toast.LENGTH_SHORT).show();
        }
		/*
		DEFS.clone_result = DEFS.NVM_TO_USB_OK;
		if(path.length()>9) {
			Toast.makeText(mContext, "NVM_TO_USB_OK", Toast.LENGTH_SHORT).show();
		}
		*/
        Debug.v(TAG, "NVM2USB : " + value);
    }

    public static void NVM2USB_ChannelDate(int value) {
        if (mFactoryAdapter.CloneTV2USB(value)) {

            ThirdParty.mContext.sendBroadcast(new Intent(defs.MSG_NVM_TO_USB_OK));

        } else {
            ThirdParty.mContext.sendBroadcast(new Intent(defs.MSG_NVM_TO_USB_NG));
        }

    }

    // =====================================================================================

    public static int getAudioModeValue() {
        @SuppressWarnings("unchecked")
        int audioMode = DEFS.SM_STANDARD;

        switch (mTvSoundManager.getSoundMode()) {
            case EN_TCL_STANDARD:
                audioMode = DEFS.SM_STANDARD;
                break;
            case EN_TCL_MOVIE:
                audioMode = DEFS.SM_MOVIE;
                break;
            case EN_TCL_NEWS:
                audioMode = DEFS.SM_NEWS;
                break;
            case EN_TCL_MUSIC:
                audioMode = DEFS.SM_MUSIC;
                break;
            default:
                audioMode = DEFS.SM_PERSONAL; // ?
                break;
        }
        Debug.v(TAG, "getAudioModeValue : " + audioMode);
        return audioMode;
    }

    public static void setAudioModeValue(int value) {
        @SuppressWarnings("unchecked")
        EnTCLSoundMode audioMode = EnTCLSoundMode.EN_TCL_STANDARD;

        switch (value) {
            case DEFS.SM_STANDARD:
                audioMode = EnTCLSoundMode.EN_TCL_STANDARD;
                break;
            case DEFS.SM_MOVIE:
                audioMode = EnTCLSoundMode.EN_TCL_MOVIE;
                break;
            case DEFS.SM_NEWS:
                audioMode = EnTCLSoundMode.EN_TCL_NEWS;
                break;
            case DEFS.SM_MUSIC:
                audioMode = EnTCLSoundMode.EN_TCL_MUSIC;
                break;
            default:
                audioMode = EnTCLSoundMode.EN_TCL_STANDARD;
                break;
        }
        mTvSoundManager.setSoundMode(audioMode);
        Debug.v(TAG, "setAudioModeValue : " + audioMode);
    }

    public static int getAudioSceneValue() {
        int value = 0;

        switch (mTvSoundManager.getSoundScene()) {
            case EN_TCL_DESKTOP:
                value = DEFS.VOL_DESKTOP;
                break;
            case EN_TCL_HANGUP:
                value = DEFS.VOL_WALL;
                break;
            default:
                value = DEFS.VOL_DESKTOP;
                break;
        }
        Debug.v(TAG, "getAudioSceneValue : " + value);
        return value;
    }

    public static void setAudioSceneValue(int voiceScene) {
        @SuppressWarnings("unchecked")
        EnTCLSoundScene soundScene = EnTCLSoundScene.EN_TCL_DESKTOP;
        switch (voiceScene) {
            case DEFS.VOL_WALL:
                soundScene = EnTCLSoundScene.EN_TCL_HANGUP;
                break;

            case DEFS.VOL_DESKTOP:
                soundScene = EnTCLSoundScene.EN_TCL_DESKTOP;
                break;
            default:
                soundScene = EnTCLSoundScene.EN_TCL_DESKTOP;
        }

        mTvSoundManager.setSoundScene(soundScene);

        Debug.v(TAG, "setAudioSceneValue : " + voiceScene);
    }

    public static int getAudioTypeValue() {
        int value = DEFS.PATT_DK;
        switch (mTvChannelManager.getAudioStandard()) {
            case EN_TCL_DK:
                value = DEFS.PATT_DK;
                break;
            case EN_TCL_BG:
                value = DEFS.PATT_BG;
                break;
            case EN_TCL_I:
                value = DEFS.PATT_I;
                break;
            case EN_TCL_M:
                value = DEFS.PATT_M;
                break;
            case EN_TCL_L:
                value = DEFS.PATT_L;
                break;
        }
        Debug.v(TAG, "getAudioTypeValue : " + value);
        return value;
    }

    public static void setAudioTypeValue(int value) {
        EnTCLAudioStandard audioStandard = EnTCLAudioStandard.EN_TCL_BG;
        switch (value) {
            case DEFS.PATT_DK:
                audioStandard = EnTCLAudioStandard.EN_TCL_DK;
                break;
            case DEFS.PATT_BG:
                audioStandard = EnTCLAudioStandard.EN_TCL_BG;
                break;
            case DEFS.PATT_I:
                audioStandard = EnTCLAudioStandard.EN_TCL_I;
                break;
            case DEFS.PATT_M:
                audioStandard = EnTCLAudioStandard.EN_TCL_M;
                break;
            case DEFS.PATT_L:
                audioStandard = EnTCLAudioStandard.EN_TCL_L;
                break;
            default:
                audioStandard = EnTCLAudioStandard.EN_TCL_DK;
                break;
        }
        mTvChannelManager.setAudioStandard(audioStandard);

        Debug.v(TAG, "setAudioTypeValue : " + value);
    }

    public static void selectSrcUSB() {
        Intent tmpItent = new Intent("android.intent.action.mediacenter");
        tmpItent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        mContext.startActivity(tmpItent);
        return;
    }

    public static boolean getAudioMuteStatus() {
        boolean value = mTvSoundManager.getAudioMuteEnabled();
        Debug.v(TAG, "getAudioMuteStatus : " + false);
        return value;
    }

    public static void setAudioMuteStatus(boolean status) {
        mTvSoundManager.setAudioMuteEnabled(status);
        Debug.v(TAG, "setAudioMuteStatus : " + status);
    }

    public static void setAudioMuteStatusVisible(boolean status) {
//			audiomanager.setMasterMute(status,1);//hubin
        Debug.v(TAG, "setAudioMuteStatusVisible : " + status);
    }

    public static int getAudioVolumeValue() {
        int value = 0;
//		value = mTvSoundManager.getVolume();
        value = audiomanager.getStreamVolume(AudioManager.STREAM_MUSIC);
        Debug.v(TAG, "getAudioVolumeValue : " + value);
        return value;
    }

    public static void setAudioVolumeValue(int value) {
//		mTvSoundManager.setVolume(value);//Jane 0814
        audiomanager.setStreamVolume(AudioManager.STREAM_MUSIC, value, 0);
        Debug.v(TAG, "setAudioVolumeValue : " + value);
    }

    public static int getAudioBalanceValue() {
        int value = 0;
        value = mTvSoundManager.getBalance();
        Debug.v(TAG, "getAudioBalanceValue : " + value);
        return value;
    }

    public static void setAudioBalanceValue(int value) {
        mTvSoundManager.setBalance(value);
        Debug.v(TAG, "setAudioBalanceValue : " + value);
    }

    public static void setAudioVolumeDown() {
        int volume = ThirdParty.getAudioVolumeValue();
        if (volume > 0)
            volume--;
        ThirdParty.setAudioVolumeValue(volume);
        Debug.v(TAG, "setAudioVolumeDOWN");
    }

    public static void setAudioVolumeUp() {
        int volume = ThirdParty.getAudioVolumeValue();
        if (volume < 100)
            volume++;
        ThirdParty.setAudioVolumeValue(volume);
        Debug.v(TAG, "setAudioVolumeUP");
    }

    public static int getAudioFormatValue() {
        int voiceFormats = DEFS.PATT_DK;

        EnTCLAudioStandard audioStandard = mTvChannelManager.getAudioStandard();

        switch (audioStandard) {
            case EN_TCL_DK:
                voiceFormats = DEFS.PATT_DK;
                break;
            case EN_TCL_I:
                voiceFormats = DEFS.PATT_I;
                break;
            case EN_TCL_M:
                voiceFormats = DEFS.PATT_M;
                break;
            case EN_TCL_BG:
                voiceFormats = DEFS.PATT_BG;
                break;
            case EN_TCL_L:
                voiceFormats = DEFS.PATT_L;
                break;

            default:
                voiceFormats = 0;
                break;
        }
        Debug.v(TAG, "getAudioFormatValue : " + voiceFormats);
        return voiceFormats;
    }

    public static boolean setAudioFormatValue(int voiceFormats) {
        boolean ret = true;
        EnTCLAudioStandard audioStandard = EnTCLAudioStandard.EN_TCL_BG;

        EnTCLInputSource inputSource = mTvCommonManager.getCurrentInputSource();
        if (inputSource != EnTCLInputSource.EN_TCL_ATV)
            mTvCommonManager.setInputSource(EnTCLInputSource.EN_TCL_ATV);

        switch (voiceFormats) {
            case DEFS.PATT_DK:
                audioStandard = EnTCLAudioStandard.EN_TCL_DK;
                break;
            case DEFS.PATT_BG:
                audioStandard = EnTCLAudioStandard.EN_TCL_BG;
                break;
            case DEFS.PATT_I:
                audioStandard = EnTCLAudioStandard.EN_TCL_I;
                break;
            case DEFS.PATT_M:
                audioStandard = EnTCLAudioStandard.EN_TCL_M;
                break;
            case DEFS.PATT_L:
                audioStandard = EnTCLAudioStandard.EN_TCL_L;
                break;
        }

        mTvChannelManager.setAudioStandard(audioStandard);

        Debug.v(TAG, "setAudioFormatValue : " + voiceFormats);
        return ret;
    }

    public static void setAudioSmartVolumeStatus(boolean status) {
        mTvSoundManager.setAvcEnabled(status);
        Debug.v(TAG, "setAudioSmartVolumeStatus : " + status);
    }

    public static boolean getAudioSmartVolumeStatus() {
        boolean status = mTvSoundManager.getAvcEnabled();
        Debug.v(TAG, "getAudioSmartVolumeStatus : " + status);
        return status;
    }


    public static int getPictureModeValue() {
        int pic_mode = 0;

        switch (mTvPictureManager.getPictureMode()) {
            case EN_TCL_STANDARD:
                pic_mode = DEFS.PM_STANDARD;
                break;
            case EN_TCL_VIVID:
                pic_mode = DEFS.PM_VIVID;
                break;
            case EN_TCL_MILD:
                pic_mode = DEFS.PM_MILD;
                break;
            case EN_TCL_USER:
                pic_mode = DEFS.PM_USER;
                break;
            case EN_TCL_STUDIO:
                pic_mode = DEFS.PM_DYNAMIC;
                break;
            default:
                pic_mode = DEFS.PM_STANDARD;
        }
        Debug.v(TAG, "getPictureModeValue :" + pic_mode);
        return pic_mode;
    }

    public static void setPictureModeValue(int value) {
        @SuppressWarnings("unchecked")
        EnTCLPictureMode pictureMode = EnTCLPictureMode.EN_TCL_STANDARD;

        switch (value) {
            case DEFS.PM_STANDARD:
                pictureMode = EnTCLPictureMode.EN_TCL_STANDARD;
                break;
            case DEFS.PM_MILD:
                pictureMode = EnTCLPictureMode.EN_TCL_MILD;
                break;
            case DEFS.PM_USER:
                pictureMode = EnTCLPictureMode.EN_TCL_USER;
                break;
            case DEFS.PM_VIVID:
                pictureMode = EnTCLPictureMode.EN_TCL_VIVID;
                break;
            case DEFS.PM_DYNAMIC:
                pictureMode = EnTCLPictureMode.EN_TCL_STUDIO;
                break;
        }
        mTvPictureManager.setPictureMode(pictureMode);
        Debug.v(TAG, "setPictureModeValue :" + value);
    }

    public static int getPictureFormatValue() {
        int value = 0;
        EnTCLAspectRatio aspectRatio = mTvPictureManager.getAspectRatio();
        switch (aspectRatio) {
            case EN_TCL_AUTO:
                value = 0;
                break;
            case EN_TCL_16X9:
                value = 1;
                break;
            case EN_TCL_4X3:
                value = 2;
                break;
            default:
                value = 0;
        }
        Debug.v(TAG, "getPictureFormatValue : " + value);
        return value;
    }

    public static void setPictureFormatValue(int mode) {
        EnTCLAspectRatio aspectRatio = EnTCLAspectRatio.EN_TCL_AUTO;
        switch (mode) {
            case 0:
                aspectRatio = EnTCLAspectRatio.EN_TCL_AUTO;
                break;
            case 1:
                aspectRatio = EnTCLAspectRatio.EN_TCL_16X9;
                break;
            case 2:
                aspectRatio = EnTCLAspectRatio.EN_TCL_4X3;
                break;
            default:
                aspectRatio = EnTCLAspectRatio.EN_TCL_AUTO;

        }
        mTvPictureManager.setAspectRatio(aspectRatio);
        Debug.v(TAG, "setPictureFormatValue : " + mode);
    }

    public static int getSharpnessValue() {
        int value = mTvPictureManager.getSharpness();
        Debug.v(TAG, "getSharpnessValue : " + value);
        return value;
    }

    public static void setSharpnessValue(int value) {
        mTvPictureManager.setSharpness(value);
        Debug.v(TAG, "setSharpnessValue : " + value);
    }


    public static int getHueValue() {
        int value = mTvPictureManager.getHue();
        Debug.v(TAG, "getHueValue : " + value);
        return value;
    }

    public static void setHueValue(int value) {
        mTvPictureManager.setHue(value);
        Debug.v(TAG, "setHueValue : " + value);
    }


    public static int getContrastValue() {
        int value = mTvPictureManager.getContrast();
        Debug.v(TAG, "getContrastValue : " + value);
        return value;
    }

    public static void setContrastValue(int value) {
        mTvPictureManager.setContrast(value);
        Debug.v(TAG, "setContrastValue : " + value);
    }

    public static int getBrightnessValue() {
        int value = mTvPictureManager.getBrightness();
        Debug.v(TAG, "getBrightnessValue : " + value);
        return value;
    }

    public static void setBrightnessValue(int value) {
        mTvPictureManager.setBrightness(value);
        Debug.v(TAG, "setBrightnessValue : " + value);
    }

    public static int getSaturationValue() {
        int value = mTvPictureManager.getSaturation();
        Debug.v(TAG, "getSaturationValue : " + value);
        return value;
    }

    public static void setSaturationValue(int value) {
        mTvPictureManager.setSaturation(value);
        Debug.v(TAG, "setSaturationValue : " + value);
    }

    public static int getBackLightValue() {
        int value = mTvPictureManager.getBacklight();
        Debug.v(TAG, "getBackLightValue : " + value);
        return value;
    }

    public static void setBackLightValue(int value) {
        mTvPictureManager.setBacklight(value);
        Debug.v(TAG, "setBackLightValue : " + value);
    }

    public static int getGraphicBacklightValue() {
        int value = mTvPictureManager.getGraphicBacklight();
        Debug.v(TAG, "getGraphicBackLightValue : " + value);
        return value;
    }

    public static void setGraphicBackLightValue(int value) {
        mTvPictureManager.setGraphicBacklight(value);
        Debug.v(TAG, "setGraphicBackLightValue : " + value);
    }


    // =====================================================================================


    public static boolean getCICardStatus() {
        boolean status = DEFS.Disable;
        boolean state = false;
        state = mTvCiManager.isCAMInserted();
        if (state != false)
            status = DEFS.Enable;
        Debug.v(TAG, "getCICardStatus : " + state);
        return status;
    }

    public static void cleanChannelList() {
        mFactoryAdapter.cleanChannelList();//Jane add 0805
        mTvChannelManager.clearDtvChannelList();
        Debug.v(TAG, "cleanChannelList");
    }

    public static int channelPreSet(int value) {
        Log.d(TAG, "channelPreSet value = " + value);
        int result = 0;
        cleanChannelList();

//		PresetChannel channelPreSet = new PresetChannel();

//		int channelList[][] = channelPreSet.getChannelList(value);

//		int row = channelList.length;

        setSourceType(DEFS.SOURCE_ATV, 0);
        result = mFactoryAdapter.PalPreSetChannel(value, "CH " + value,
                0, 0, 0);//Jane 0805
//		mTvChannelManager.addDtvCurProgramInfoItem(1);
//		mTvChannelManager.addDtvDVBMuxInfoItem( 1, 46, 16384, 4000, 642000, 6875,3,"���ڹ��");
//		mTvChannelManager.addDtvProgramerInfoItem(1, 0, 5233, 5233, 1, 65535, 5232, channelPreSet.ChannelAttr[0], 0, channelPreSet.AudioInfo[0],  channelPreSet.DtvParPamName[0]);
//		mTvChannelManager.addDtvProgramerInfoItem(1, 1, 8190, 5249, 2, 65535, 5248, channelPreSet.ChannelAttr[1], 0, channelPreSet.AudioInfo[1],  channelPreSet.DtvParPamName[1]);
//
//		// =================add for DTMB DTV start=======================
//		mTvChannelManager.addDTMBCurProgramInfoItem(0);
//		mTvChannelManager.addDTMBDVBMuxInfoItem( 1, 1, 32766, 32766, 506000, 0, 0,"SFN_TVB");
//		mTvChannelManager.addDTMBDVBMuxInfoItem( 2 , 46, 16384, 4000, 674000, 0, 0,"���ڹ��");
//		mTvChannelManager.addDTMBDVBMuxInfoItem( 3, 8707, 8648, 12322, 690000, 0, 0,"T-Systems");
////		mTvChannelManager.addDTMBProgramerInfoItem(1, 0, 821, 821, 1, 65535, 82, channelPreSet.DTMBChannelAttr[0], 0, channelPreSet.DTMBAudioInfo[0],  channelPreSet.DTMBDtvParPamName[0]);
////		mTvChannelManager.addDTMBProgramerInfoItem(1, 1, 831, 831, 2, 65535, 83, channelPreSet.DTMBChannelAttr[1], 0, channelPreSet.DTMBAudioInfo[1],  channelPreSet.DTMBDtvParPamName[1]);
////		mTvChannelManager.addDTMBProgramerInfoItem(1, 2, 851, 851, 3, 65535, 85, channelPreSet.DTMBChannelAttr[2], 0, channelPreSet.DTMBAudioInfo[2],  channelPreSet.DTMBDtvParPamName[2]);
//
////		mTvChannelManager.addDTMBProgramerInfoItem(2, 0, 5233, 5233, 1, 65535, 5232, channelPreSet.DTMBChannelAttr[3], 0, channelPreSet.DTMBAudioInfo[3],  channelPreSet.DTMBDtvParPamName[3]);
////		mTvChannelManager.addDTMBProgramerInfoItem(2, 1, 8190, 5249, 2, 65535, 5248, channelPreSet.DTMBChannelAttr[4], 0, channelPreSet.DTMBAudioInfo[4],  channelPreSet.DTMBDtvParPamName[4]);
//		mTvChannelManager.addDTMBProgramerInfoItem(3, 0, 577, 577, 1, 65535, 16420, channelPreSet.DTMBChannelAttr[5], 0, channelPreSet.DTMBAudioInfo[5],  channelPreSet.DTMBDtvParPamName[5]);
//		mTvChannelManager.addDTMBProgramerInfoItem(3, 1, 609, 609, 2, 65535, 16422, channelPreSet.DTMBChannelAttr[6], 0, channelPreSet.DTMBAudioInfo[6],  channelPreSet.DTMBDtvParPamName[6]);
//		mTvChannelManager.addDTMBProgramerInfoItem(3, 2, 273, 273, 3, 65535, 16401, channelPreSet.DTMBChannelAttr[7], 0, channelPreSet.DTMBAudioInfo[7],  channelPreSet.DTMBDtvParPamName[7]);
//		mTvChannelManager.addDTMBProgramerInfoItem(3, 3, 2689, 2689, 4, 65535, 19072, channelPreSet.DTMBChannelAttr[8], 0, channelPreSet.DTMBAudioInfo[8],  channelPreSet.DTMBDtvParPamName[8]);
//		// =====================add for DTMB DTV end==========================
//
        TCL.AsyncPresetChannel();
        Debug.v(TAG, "channelPreSet, result = ." + result);
        return result;
    }


    public static void selectProgram(int value) {
        mTvChannelManager.selectProgram(value, EnTCLMemberServiceType.EN_TCL_ATV);
        Debug.v(TAG, "channelSetValue ATV");
    }

    public static void selectProgramDTV(int value) {
        mTvChannelManager.selectProgram(value, EnTCLMemberServiceType.EN_TCL_DTV);
        Debug.v(TAG, "channelSetValue DTV");
    }

    public static void ChannelSet(int value) {
        if (value == 0) {
//			mFactoryAdapter.cleanChannelList();
//			mFactoryAdapter.PalPreSetChannel(0, "CH " + 0,
//					0, 0, 0);
            TV.writeV(TVDefine.AudioVolume, 65);
            int index = 5;

            List<ProgramInfo> chlList = mTvChannelManager.getChannelList(EnTCLChanelListType.EN_CHANNEL_ANALOGUE);
            if (chlList != null) {
                for (ProgramInfo pinfo : chlList) {
                    Log.i("factory", "pinfo.number=" + pinfo.number);
                    if (pinfo.number == 9005 || pinfo.number == 62) {
                        index = pinfo.number;//Toast.makeText(mContext, "index...." + index, Toast.LENGTH_SHORT).show();
                        break;
                    }
                }
            }

            Log.i("factory", "index=" + index);
            selectProgram(index);
            Toast.makeText(mContext, "RATTLE ON....", Toast.LENGTH_SHORT).show();
            DEFS.RATTLE_ON_OFF = 1;
        } else {
            Toast.makeText(mContext, "RATTLE OFF....", Toast.LENGTH_SHORT).show();
            TV.writeV(TVDefine.AudioVolume, 30);
            DEFS.RATTLE_ON_OFF = 0;
        }
        Debug.v(TAG, " ChannelSet ATV");
    }

    /**
     * �Ƿ�Ϊ������Ŀ,Ĭ���ǹ���
     */
    public static boolean isCnPrj() {
        boolean propertyValue = ConfigItem.isShowItem(mContext, ConfigItem.CONFIG_CN_PROJECT);
        Log.i(TAG, "isCnPrj=" + propertyValue);
        return propertyValue;
    }

    /**
     * �ϻ�ģʽ�Ƿ��ѡ,Ĭ�Ͽ�ѡ
     */
    public static boolean isWarmUpAble() {
        boolean propertyValue = ConfigItem.isShowItem(mContext, ConfigItem.CONFIG_WARMUP_ABLE);
        Log.i(TAG, "isWarmUpAble=" + propertyValue);
        return propertyValue;
    }

    /**
     * ��ƽ��ѡ���Ƿ��ѡ��,Ĭ�Ͽ�ѡ
     */
    public static boolean isWhiteBalanceChangeAble() {
        boolean propertyValue = ConfigItem.isShowItem(mContext, ConfigItem.CONFIG_WHITEBALANCE);
        Log.i(TAG, "isWhiteBalanceChangeAble=" + propertyValue);
        return propertyValue;
    }

    /**
     * ��ƽ�����Ƿ���ʾGAMAѡ�Ĭ�ϲ���ʾ
     */
    public static boolean isWhiteBalanceShowGamma() {
        boolean propertyValue = ConfigItem.showDefaultFalse(mContext, ConfigItem.CONFIG_GAMMA);
        Log.i(TAG, "isWhiteBalanceShowGamma=" + propertyValue);
        return propertyValue;
    }

    /**
     * ����Ϊfalse֮��Powermode������ѡ,Ĭ�Ͽ�ѡ
     */
    public static boolean isPowerModeSelectAble() {
        boolean propertyValue = ConfigItem.isShowItem(mContext, ConfigItem.CONFIG_POWERMODE);
        Log.i(TAG, "isPowerModeSelectAble=" + propertyValue);
        return propertyValue;
    }

    /**
     * �Ƿ�����Խ���A���l��
     *
     * @return ���]�����ã�Ĭ�Ϸ���false
     * @author wangst
     * @Date 20150522
     */
    public static boolean hasYNPresetChannel() {
        boolean propertyValue = ConfigItem.showDefaultFalse(mContext, ConfigItem.CONFIG_YN_CHANNEL);
        Log.i(TAG, "hasYNPresetChannel=" + propertyValue);
        return propertyValue;
    }

    /**
     * �Ƿ�����̩���A���l��
     *
     * @return ���]�����ã�Ĭ�Ϸ���false
     * @author wangst
     * @Date 20150522
     */
    public static boolean hasTHPresetChannel() {
        boolean propertyValue = ConfigItem.showDefaultFalse(mContext, ConfigItem.CONFIG_TH_CHANNEL);
        Log.i(TAG, "hasTHPresetChannel=" + propertyValue);
        return propertyValue;
    }

    /**
     * �Ƿ����ӷ��ɱ��A���l��
     *
     * @return ���]�����ã�Ĭ�Ϸ���false
     * @author wangst
     * @Date 20150522
     */
    public static boolean hasPHPresetChannel() {
        boolean propertyValue = ConfigItem.showDefaultFalse(mContext, ConfigItem.CONFIG_PH_CHANNEL);
        Log.i(TAG, "hasPHPresetChannel=" + propertyValue);
        return propertyValue;
    }

    /**
     * �Ƿ�����ӡ���������A���l��
     */
    public static boolean hasINPresetChannel() {
        boolean propertyValue = ConfigItem.showDefaultFalse(mContext, ConfigItem.CONFIG_IN_CHANNEL);
        Log.i(TAG, "hasINPresetChannel=" + propertyValue);
        return propertyValue;
    }

    /**
     * �Ƿ����Ӷ���˹�A���l��
     */
    public static boolean hasRUPresetChannel() {
        boolean propertyValue = ConfigItem.showDefaultFalse(mContext, ConfigItem.CONFIG_RU_CHANNEL);
        Log.i(TAG, "hasRUPresetChannel=" + propertyValue);
        return propertyValue;
    }

    /**
     * �Ƿ�����CVT�A���l��
     */
    public static boolean hasCVTPresetChannel() {
        boolean propertyValue = ConfigItem.showDefaultFalse(mContext, ConfigItem.CONFIG_CVT_CHANNEL);
        Log.i(TAG, "hasCVTresetChannel=" + propertyValue);
        return propertyValue;
    }

    /**
     * �Ƿ�����TNS�A���l��
     */
    public static boolean hasTNSPresetChannel() {
        boolean propertyValue = ConfigItem.showDefaultFalse(mContext, ConfigItem.CONFIG_TNS_CHANNEL);
        Log.i(TAG, "hasTNSresetChannel=" + propertyValue);
        return propertyValue;
    }

    /**
     * �Ƿ����Ӱ����A���l��
     */
    public static boolean hasEGPresetChannel() {
        boolean propertyValue = ConfigItem.showDefaultFalse(mContext, ConfigItem.CONFIG_EG_CHANNEL);
        Log.i(TAG, "hasEGresetChannel=" + propertyValue);
        return propertyValue;
    }

    /**
     * �Ƿ�����ӡ���A���l��
     */
    public static boolean hasINDPresetChannel() {
        boolean propertyValue = ConfigItem.showDefaultFalse(mContext, ConfigItem.CONFIG_IND_CHANNEL);
        Log.i(TAG, "hasINDPresetChannel=" + propertyValue);
        return propertyValue;
    }

    /**
     * �Ƿ����Ӹ��ױ����A���l��
     */
    public static boolean hasCOLPresetChannel() {
        boolean propertyValue = ConfigItem.showDefaultFalse(mContext, ConfigItem.CONFIG_COL_CHANNEL);
        Log.i(TAG, "hasCOLPresetChannel=" + propertyValue);
        return propertyValue;
    }

    /**
     * �Ƿ��ϻ����˳������˵�
     *
     * @return ���û�����ô����Ĭ�Ϸ���false
     * @author wangst
     * @Date 20150526
     */
    public static boolean isWarmupQuitApp() {
        boolean propertyValue = ConfigItem.showDefaultFalse(mContext, ConfigItem.CONFIG_WARMUP_QUIT);
        Log.i(TAG, "isWarmupQuitApp=" + propertyValue);
        return propertyValue;
    }

    public static String GetDeviceTestServerArea() {
        String propertyValue = ConfigItem.GetConfigItem(mContext, ConfigItem.CONFIG_DID_TEST_AREA);
        Log.i(TAG, "ConfigValue=" + propertyValue);
        return propertyValue;
    }

    public static String GetInputSourceList() {
        String propertyValue = ConfigItem.GetConfigItem(mContext, ConfigItem.CONFIG_SOURCE_LIST);
        Log.i(TAG, "ConfigValue=" + propertyValue);
        return propertyValue;
    }

    public static String GetPictureModePreset() {
        String propertyValue = ConfigItem.GetConfigItem(mContext, ConfigItem.CONFIG_PICTURE_PRESET_LIST);
        Log.i(TAG, "ConfigValue=" + propertyValue);
        return propertyValue;
    }

    public static String GetSoundModePreset() {
        String propertyValue = ConfigItem.GetConfigItem(mContext, ConfigItem.CONFIG_SOUND_MODE_LIST);
        Log.i(TAG, "ConfigValue=" + propertyValue);
        return propertyValue;
    }

    public static void setChannelDown() {
        mTvChannelManager.programDown();
        Debug.v(TAG, "setChannelDown");
    }

    public static void setChannelUp() {
        mTvChannelManager.programUp();
        Debug.v(TAG, "setChannelUp");
    }

    static int sourceTypeIndex = 0;

    public static int getSourceTypeIndex() {
        // TODO Auto-generated method stub
        String sourceType = getSourceType();
        Log.d(TAG, " sourceType=" + sourceType + " sourceTypeIndex = " + sourceTypeIndex);
        return sourceTypeIndex;
    }

    public static String getSourceType() {
        String str = "";
        EnTCLInputSource inputSource = mTvCommonManager.getCurrentInputSource();
        Log.i(TAG, "getCurrentInputSource" + inputSource);
        switch (inputSource) {
            case EN_TCL_NONE:
                str = "ATV";
                sourceTypeIndex = 0;
                break;
            case EN_TCL_ATV:
                str = "ATV";
                sourceTypeIndex = 0;
                break;
            case EN_TCL_DTV:
                str = "DTV";
                sourceTypeIndex = 1;
                break;
            case EN_TCL_AV1:
                str = "AV";
                sourceTypeIndex = 2;
                break;
            case EN_TCL_AV2:
                str = "AV2";
                sourceTypeIndex = 3;
                break;
            case EN_TCL_YPBPR:
                str = "YPBPR";
                sourceTypeIndex = 5;
                break;
            case EN_TCL_YPBPR2:
                str = "YPBPR2";
                break;
            case EN_TCL_YPBPR3:
                str = "YPBPR3";
                break;
            case EN_TCL_HDMI1:
                str = "HDMI";
                sourceTypeIndex = 6;
                break;
            case EN_TCL_HDMI2:
                str = "HDMI2";
                sourceTypeIndex = 7;
                break;
            case EN_TCL_HDMI3:
                str = "HDMI3";
                break;
            case EN_TCL_HDMI4:
                str = "HDMI4";
                break;
            case EN_TCL_VGA:
                str = "VGA";
                sourceTypeIndex = 4;
                break;
            case EN_TCL_DV:
                str = "DV";
                break;
            case EN_TCL_DV2:
                str = "DV2";
                break;
            case EN_TCL_DV3:
                str = "DV3";
                break;
            case EN_TCL_DV4:
                str = "DV4";
                break;
            case EN_TCL_STORAGE:
                str = "STORAGE";
                break;
            case EN_TCL_STORAGE2:
                str = "STORAGE2";
                break;
            case EN_TCL_KTV:
                str = "KTV";
                break;
        }
        Debug.v(TAG, "getSourceType : " + str);
        return str;
    }

    public static void setLastSourceType() {
        EnTCLInputSource inputSource = mTvCommonManager.getLastestSavedSource();
        mTvCommonManager.setInputSource(inputSource);
    }

    public static void setSourceType(int type, int index, boolean asLastestSavedSource) {
        EnTCLInputSource inputSource = EnTCLInputSource.EN_TCL_ATV;
        Debug.v(TAG, "setSourceType : " + type + "," + index);
        switch (type) {
            case DEFS.SOURCE_NONE:
                inputSource = EnTCLInputSource.EN_TCL_NONE;
                break;
            case DEFS.SOURCE_ATV:
                inputSource = EnTCLInputSource.EN_TCL_ATV;
                break;
            case DEFS.SOURCE_DTV:
                inputSource = EnTCLInputSource.EN_TCL_DTV;
                break;
            case DEFS.SOURCE_AV:
                if (index == 1)
                    inputSource = EnTCLInputSource.EN_TCL_AV1;
                else if (index == 2)
                    inputSource = EnTCLInputSource.EN_TCL_AV2;
                else
                    inputSource = EnTCLInputSource.EN_TCL_AV1;
                break;
            case DEFS.SOURCE_YPBPR:
                if (index == 1)
                    inputSource = EnTCLInputSource.EN_TCL_YPBPR;
//			else if (index == 2)
//				inputSource = InputSource.YPBPR2;
//			else if (index == 3)
//				inputSource = InputSource.YPBPR3;
                else
                    inputSource = EnTCLInputSource.EN_TCL_YPBPR;
                break;
            case DEFS.SOURCE_HDMI:
                if (index == 1)
                    inputSource = EnTCLInputSource.EN_TCL_HDMI1;
                else if (index == 2)
                    inputSource = EnTCLInputSource.EN_TCL_HDMI2;
                else if (index == 3)
                    inputSource = EnTCLInputSource.EN_TCL_HDMI3;
                else if (index == 4)
                    inputSource = EnTCLInputSource.EN_TCL_HDMI4;
                else
                    inputSource = EnTCLInputSource.EN_TCL_HDMI1;
                break;
            case DEFS.SOURCE_VGA:
                inputSource = EnTCLInputSource.EN_TCL_VGA;
                break;
            case DEFS.SOURCE_DV:
                if (index == 1)
                    inputSource = EnTCLInputSource.EN_TCL_DV;
                else if (index == 2)
                    inputSource = EnTCLInputSource.EN_TCL_DV2;
                else if (index == 3)
                    inputSource = EnTCLInputSource.EN_TCL_DV3;
                else if (index == 4)
                    inputSource = EnTCLInputSource.EN_TCL_DV4;
                else
                    inputSource = EnTCLInputSource.EN_TCL_DV;
                break;
            case DEFS.SOURCE_STORAGE:
                if (index == 1)
                    inputSource = EnTCLInputSource.EN_TCL_STORAGE;
                else if (index == 2)
                    inputSource = EnTCLInputSource.EN_TCL_STORAGE2;
                break;
            case DEFS.SOURCE_KTV:
                inputSource = EnTCLInputSource.EN_TCL_KTV;
                break;
        }

        mTvCommonManager.setInputSource(inputSource, asLastestSavedSource);
        Debug.v(TAG, "setSourceType : " + type + "," + index);
        Utils.showSourceType(Utils.getSourceName(type, index));
        Debug.v(TAG, "setSourceType : " + type + "," + index);
    }

    public static void setSourceType(int type, int index) {
        boolean asLastestSavedSource = true;
        setSourceType(type, index, asLastestSavedSource);
//		EnTCLInputSource inputSource = EnTCLInputSource.EN_TCL_ATV;
//		switch (type) {
//		case DEFS.SOURCE_NONE:
//			inputSource = EnTCLInputSource.EN_TCL_NONE;
//			break;
//		case DEFS.SOURCE_ATV:
//			inputSource = EnTCLInputSource.EN_TCL_ATV;
//			break;
//		case DEFS.SOURCE_DTV:
//			inputSource = EnTCLInputSource.EN_TCL_DTV;
//			break;
//		case DEFS.SOURCE_AV:
//			if (index == 1)
//				inputSource = EnTCLInputSource.EN_TCL_AV1;
//			else if (index == 2)
//				inputSource = EnTCLInputSource.EN_TCL_AV2;
//			else
//				inputSource = EnTCLInputSource.EN_TCL_AV1;
//			break;
//		case DEFS.SOURCE_YPBPR:
//			if (index == 1)
//				inputSource = EnTCLInputSource.EN_TCL_YPBPR;
////			else if (index == 2)
////				inputSource = InputSource.YPBPR2;
////			else if (index == 3)
////				inputSource = InputSource.YPBPR3;
//			else
//				inputSource = EnTCLInputSource.EN_TCL_YPBPR;
//			break;
//		case DEFS.SOURCE_HDMI:
//			if (index == 1)
//				inputSource = EnTCLInputSource.EN_TCL_HDMI1;
//			else if (index == 2)
//				inputSource = EnTCLInputSource.EN_TCL_HDMI2;
//			else if (index == 3)
//				inputSource = EnTCLInputSource.EN_TCL_HDMI3;
//			else if (index == 4)
//				inputSource = EnTCLInputSource.EN_TCL_HDMI4;
//			else
//				inputSource = EnTCLInputSource.EN_TCL_HDMI1;
//			break;
//		case DEFS.SOURCE_VGA:
//			inputSource = EnTCLInputSource.EN_TCL_VGA;
//			break;
//		case DEFS.SOURCE_DV:
//			if (index == 1)
//				inputSource = EnTCLInputSource.EN_TCL_DV;
//			else if (index == 2)
//				inputSource = EnTCLInputSource.EN_TCL_DV2;
//			else if (index == 3)
//				inputSource = EnTCLInputSource.EN_TCL_DV3;
//			else if (index == 4)
//				inputSource = EnTCLInputSource.EN_TCL_DV4;
//			else
//				inputSource = EnTCLInputSource.EN_TCL_DV;
//			break;
//		case DEFS.SOURCE_STORAGE:
//			if (index == 1)
//				inputSource = EnTCLInputSource.EN_TCL_STORAGE;
//			else if (index == 2)
//				inputSource = EnTCLInputSource.EN_TCL_STORAGE2;
//			break;
//		case DEFS.SOURCE_KTV:
//			inputSource = EnTCLInputSource.EN_TCL_KTV;
//			break;
//		}
//
//		mTvCommonManager.setInputSource(inputSource, asLastestSavedSource);
//		Utils.showSourceType(Utils.getSourceName(type, index));
//		Debug.v(TAG, "setSourceType : " + type + "," + index);
    }


    public static void setDtvType(int arg) {
        EnTCLDtvType type = EnTCLDtvType.EN_TCL_DVBC;
        if (arg == DEFS.TYPE_DVBC) type = EnTCLDtvType.EN_TCL_DVBC;
        else type = EnTCLDtvType.EN_TCL_DTMB;
        mDtvTypeManager.setDtvType(type);
    }

    public static void SetDtvTypeAndSelectProgram(int arg1, int arg2) {
        EnTCLDtvType type = EnTCLDtvType.EN_TCL_DVBC;
        if (arg1 == DEFS.TYPE_DVBC) type = EnTCLDtvType.EN_TCL_DVBC;
        else type = EnTCLDtvType.EN_TCL_DTMB;
        mDtvTypeManager.facSetDtvTypeAndSelectProgram(type, arg2);
    }

    public static int getDtvType() {
        EnTCLDtvType type = EnTCLDtvType.EN_TCL_DVBC;
        type = mDtvTypeManager.getDtvType();
        if (type == EnTCLDtvType.EN_TCL_DVBC) return DEFS.TYPE_DVBC;
        else return DEFS.TYPE_DTMB;
    }

    public static void setSerialStatus(boolean status) {
        if (status == DEFS.Enable) {
//			SerialUtils.getInstance().OpenUartSerial();
            DEFS.uartOpenStatus = DEFS.Enable;
            //��Pģʽ�ر���Ȼ�⿪??
            //ThirdParty.setNatureLightPrintEnable(false);
            ThirdParty.setNatureLightEnabled(false);
            ThirdParty.setPictureModeValue(DEFS.PM_STANDARD);
        } else if (status == DEFS.Disable) {
//			SerialUtils.getInstance().CloseUARTSerial();
            DEFS.uartOpenStatus = DEFS.Disable;
            //�ر�Pģʽ����Ȼ�⿪??
            //ThirdParty.setNatureLightPrintEnable(true);
            ThirdParty.setNatureLightEnabled(true);
        }
        Debug.v(TAG, "setSerialStatus : " + status);
    }

    public static void setSerialOutputData(short[] data) {

//		SerialUtils.getInstance().outPutUartData(data);
        Debug.v(TAG, "setSerialOutputData len: " + data.length);
    }

    public static void setPowerKeyPassToApp(boolean status) {
        int value = 0;
        value = Utils.boolean2Int(status);
//		Intent intent = new Intent("com.android.internal.policy.impl.DisableKeyReceiver");
//		intent.setAction("com.tcl.KeyEventBroadcastReceiver_disable");
//		mContext.sendBroadcast(intent);

        Debug.v(TAG, "setPowerKeyPassToApp : " + status);
    }

    @SuppressWarnings("unchecked")
    public static void setPanelRotateStatus(boolean status) {
        mFactoryAdapter.setPanelRotateStatus(status);
        Debug.v(TAG, "setPanelRotateStatus : " + status);
    }

    @SuppressWarnings("unchecked")
    public static boolean getPanelRotateStatus() {
        boolean status = mFactoryAdapter.getPanelRotateStatus();
        Debug.v(TAG, "getPanelRotateStatus : " + status);
        return status;
    }

    public static void setPowerModeValue(int enable) {
        mFactoryAdapter.setPowerMode(enable);

        Debug.v(TAG, "setPowerModeValue : " + enable);
    }

    public static int getPowerModeValue() {
        int value = mFactoryAdapter.getPowerMode();
        Debug.v(TAG, "getPowerModeValue : " + value);
        return value;
    }

    public static int setTargetInfoForTV(int src, int tuner, int chnum, int fromSita) {

        int source = mFactoryAdapter.getTargetSource();
        int tunermode = mFactoryAdapter.getTargetTunerMode();
        int channelnum = mFactoryAdapter.getTargetChannelNumber();
        if (fromSita == 0) {
            source = src;
            tunermode = tuner;
            channelnum = chnum;
        }
        Intent aIntent = new Intent();
        aIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        aIntent.setAction(Intent.ACTION_VIEW);
        aIntent.setPackage("com.tcl.tv");

        switch (source) {
            case DEFS.HOTEL_SOURCE_ATV:
                aIntent.putExtra("targetSource", "atv");
                aIntent.putExtra("serviceType", "EN_TCL_ATV");
                break;
            case DEFS.HOTEL_SOURCE_DTV:
                aIntent.putExtra("targetSource", "dtv");
                aIntent.putExtra("serviceType", "EN_TCL_DTV");
                break;
            case DEFS.HOTEL_SOURCE_AV1:
                aIntent.putExtra("targetSource", "av1");
                aIntent.putExtra("serviceType", "null");
                break;
            case DEFS.HOTEL_SOURCE_AV2:
                aIntent.putExtra("targetSource", "av2");
                aIntent.putExtra("serviceType", "null");
                break;
            case DEFS.HOTEL_SOURCE_YPBPR:
                aIntent.putExtra("targetSource", "ypbpr");
                aIntent.putExtra("serviceType", "null");
                break;
            case DEFS.HOTEL_SOURCE_VGA:
                aIntent.putExtra("targetSource", "vga");
                aIntent.putExtra("serviceType", "null");
                break;
            case DEFS.HOTEL_SOURCE_HDMI1:
                aIntent.putExtra("targetSource", "hdmi1");
                aIntent.putExtra("serviceType", "null");
                break;
            case DEFS.HOTEL_SOURCE_HDMI2:
                aIntent.putExtra("targetSource", "hdmi2");
                aIntent.putExtra("serviceType", "null");
                break;
            case DEFS.HOTEL_SOURCE_HDMI3:
                aIntent.putExtra("targetSource", "hdmi3");
                aIntent.putExtra("serviceType", "null");
                break;
            case DEFS.HOTEL_SOURCE_HDMI4:
                aIntent.putExtra("targetSource", "hdmi4");
                aIntent.putExtra("serviceType", "null");
                break;
            default:
                aIntent.putExtra("targetSource", "null");
                aIntent.putExtra("serviceType", "null");
                break;
        }
        switch (tunermode) {
            case 0:
                aIntent.putExtra("tuner_mode", "dvbc");
                break;
            case 1:
                aIntent.putExtra("tuner_mode", "dvbt");
                break;
            case 2:
                aIntent.putExtra("tuner_mode", "dtmb");
                break;
            case 3:
                aIntent.putExtra("tuner_mode", "dvbs");
                break;
            case 4:
                aIntent.putExtra("tuner_mode", "isdb");
                break;
            case 5:
                aIntent.putExtra("tuner_mode", "atsc");
                break;
            case 6:
                aIntent.putExtra("tuner_mode", "cqam");
                break;
            default:
                aIntent.putExtra("tuner_mode", "null");
                break;
        }
        aIntent.putExtra("channelnum", channelnum);

        try {
            mContext.startActivity(aIntent);
        } catch (ActivityNotFoundException exception) {
            Debug.v(TAG, "Activity not found !");
        }
        return 1;
    }

    //Menu:0  139
    //AV1: 8  1
    public static int getIRKeyCodeValue() {
        int key = mFactoryAdapter.getRemoteControlButtonValue();
        Debug.v(TAG, "getSidePanelKeyCodeValue :" + key);
        return key;
    }

    public static int getSidePanelButtonValue() {
        int key = mFactoryAdapter.getSidePanelButtonValue();
        Debug.v(TAG, "getSidePanelButtonValue :" + key);
        return key;
    }


    // -------------------------------------------------------------------------------------------------------------------------------------------------


    public static void setKeyLockStatus(boolean status) {
        mFactoryAdapter.setPanelKeyLockStatus(status);
        Debug.v(TAG, "setKeyLockStatus : " + status);
    }

    public static void setThreeDMode(boolean status) {
        if (status == DEFS.Enable) {
            Toast.makeText(mContext, "3D Mode Enable!", Toast.LENGTH_SHORT).show();
            ConfigMethod.set3DMode(2);
        } else {
            Toast.makeText(mContext, "3D Mode Disable!", Toast.LENGTH_SHORT).show();
            ConfigMethod.set3DMode(ConfigMethod.SUB_MODE_3D_IND);//0
        }
        Debug.v(TAG, "setThreeDMode " + ":" + status);
    }

    public static void setMicphoneStatus(int status) {
        try {
            TAppManager appManager = TAppManager.getInstance(mContext);
            if (status == 1) {
                appManager.setMicrophoneMute(false);
            } else {
                appManager.setMicrophoneMute(true);
            }
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            Debug.v(TAG, "Error when setting MIC");
        }
    }

    public static void setKaraOKMicphoneVolume(int value) {
        try {
            TAppManager appManager = TAppManager.getInstance(mContext);
            appManager.setInputLevel(EnTCLAudioInputLevelType.EN_TCL_AUD_PREMIXER_KTV_MIC_IN, value);
        } catch (Exception e) {
            Debug.v(TAG, "Error when set kara ok Micphone volume " + value + ", " + e.getMessage());
        }
    }

    public static void setKaraOKBackgroundVolume(int value) {
        try {
            TAppManager appManager = TAppManager.getInstance(mContext);
            appManager.setInputLevel(EnTCLAudioInputLevelType.EN_TCL_AUD_PREMIXER_KTV_MP3_IN,
                    value);
        } catch (Exception e) {
            Debug.v(TAG, "Error when set kara ok background volume " + value + ", " + e.getMessage());
        }
    }


    public static void setIrKeyEnabled(boolean status) {
        if (status) {
            Intent intent = new Intent("com.tcl.enableIrKey");//zhifeng.huang
            mContext.sendBroadcast(intent);
        } else {
            Intent intent = new Intent("com.tcl.disableIrKey");//zhifeng.huang
            mContext.sendBroadcast(intent);
        }
    }

    public static void setKeyEventBroadcastReceiverEnabled(boolean status) {
        if (status) {
            Intent intent = new Intent("com.tcl.KeyEventBroadcastReceiver_enable");//zhifeng.huang
            mContext.sendBroadcast(intent);
        } else {
            Intent intent = new Intent("com.tcl.KeyEventBroadcastReceiver_disable");//zhifeng.huang
            mContext.sendBroadcast(intent);
        }
    }

    public static String getBootcodeVersion() {
        return mFactoryAdapter.getBootcodeVersion();
    }

    public static String getTconVersion() {
        return mFactoryAdapter.getTconVersion();
    }

    //Curve
    // =====================================================================================
    public static void updateBackLight() {
        int value = 0;
        value = mTvPictureManager.getBacklight();
        mTvPictureManager.setBacklight(value);
    }

    public static void updateBrightness() {
        int value = 0;
        value = mTvPictureManager.getBrightness();
        mTvPictureManager.setBrightness(value);
    }

    public static void updateContrast() {
        int value = 0;
        value = mTvPictureManager.getContrast();
        mTvPictureManager.setContrast(value);
    }

    public static void updateSaturation() {
        int value = 0;
        value = mTvPictureManager.getSaturation();
        mTvPictureManager.setSaturation(value);
    }

    public static void updateHue() {
        int value = 0;
        value = mTvPictureManager.getHue();
        mTvPictureManager.setHue(value);
    }

    public static void updateSharpness() {
        int value = 0;
        value = mTvPictureManager.getSharpness();
        mTvPictureManager.setSharpness(value);
    }

    public static void updateVolume() {
        int value = 0;
        value = mTvSoundManager.getVolume();
        mTvSoundManager.setVolume(value);
    }

    public static void setCurve(int type, int index, int value) {
        mFactoryAdapter.setCurve(type, index, value);
        Debug.v(TAG, "set" + type + "Curve " + index + ":" + value);
    }

    public static int getCurve(int type, int index) {
        int value = 0;
        value = mFactoryAdapter.getCurve(type, index);
        Debug.v(TAG, "get" + type + "Curve " + index + ":" + value);
        return value;
    }
    //Curve End
    // =====================================================================================


    //WhiteBalance
    // =====================================================================================

    public static int getRGainValue() {
        int rGainValue = 0;
        rGainValue = mFactoryAdapter.getRedGainValue();
        Debug.v(TAG, "getRGainValue : " + rGainValue);
        return rGainValue;
    }

    public static void setRGainValue(int value) {
        mFactoryAdapter.setRedGainValue(value);
        Debug.v(TAG, "setRGainValue : " + value);
    }

    @SuppressWarnings("unchecked")
    public static int getGGainValue() {
        int gGainValue = mFactoryAdapter.getGreenGainValue();
        Debug.v(TAG, "getGGainValue : " + gGainValue);
        return gGainValue;
    }

    @SuppressWarnings("unchecked")
    // 20/127=0.1575
    public static void setGGainValue(int value) {
        mFactoryAdapter.setGreenGainValue(value);
        Debug.v(TAG, "setGGainValue : " + value);
    }

    //  0-255 switch to  +-128
    @SuppressWarnings("unchecked")
    public static int getBGainValue() {
        int bGainValue = mFactoryAdapter.getBlueGainValue();
        Debug.v(TAG, "getBGainValue : " + bGainValue);
        return bGainValue;
    }

    @SuppressWarnings("unchecked")
    public static void setBGainValue(int value) {
        mFactoryAdapter.setBlueGainValue(value);
        Debug.v(TAG, "setBGainValue : " + value);
    }

    @SuppressWarnings("unchecked")
    public static int getRGainOffsetValue() {
        int rOffsetValue = mFactoryAdapter.getRedOffsetValue();
        Debug.v(TAG, "getRGainOffsetValue : " + rOffsetValue);
        return rOffsetValue;
    }

    @SuppressWarnings("unchecked")
    public static void setRGainOffsetValue(int value) {
        mFactoryAdapter.setRedOffsetValue(value);
        Debug.v(TAG, "setRGainOffsetValue : " + value);
    }

    public static int getGGainOffsetValue() {
        int gOffsetValue = mFactoryAdapter.getGreenOffsetValue();
        Debug.v(TAG, "getGGainOffsetValue : " + gOffsetValue);
        return gOffsetValue;
    }

    public static void setGGainOffsetValue(int value) {
        mFactoryAdapter.setGreenOffsetValue(value);
        Debug.v(TAG, "setGGainOffsetValue : " + value);
    }

    public static int getBGainOffsetValue() {
        int value = mFactoryAdapter.getBlueOffsetValue();
        Debug.v(TAG, "getBGainOffsetValue : " + value);
        return value;
    }

    public static void setBGainOffsetValue(int value) {
        mFactoryAdapter.setBlueOffsetValue(value);
        Debug.v(TAG, "setBGainOffsetValue : " + value);
    }

    public static void whiteBalanceInit() {
//		ThirdParty.setPictureModeValue(DEFS.PM_VIVID);
//		ThirdParty.setColorTemperatureValue(DEFS.TMP_STANDARD);
//		ThirdParty.setNatureLightEnabled(false);
//		ThirdParty.setDccEnabled(false);
//		ThirdParty.setBackLightValue(100);
        mFactoryAdapter.shellExecute("whiteBalanceInit");

        Toast.makeText(mContext, "whiteBalanceInit", Toast.LENGTH_SHORT).show();
        Debug.v(TAG, "whiteBalanceInit");
    }

    public static void setColorTemperatureValue(int value) {
        EnTCLColorTemperature colorTemperature = EnTCLColorTemperature.EN_TCL_STANDARD;
        switch (value) {
            case DEFS.TMP_STANDARD:
                colorTemperature = EnTCLColorTemperature.EN_TCL_STANDARD;
                break;
            case DEFS.TMP_COOL:
                colorTemperature = EnTCLColorTemperature.EN_TCL_COOL;
                break;
            case DEFS.TMP_WARM:
                colorTemperature = EnTCLColorTemperature.EN_TCL_WARM;
                break;
            case DEFS.TMP_WARM2:
                colorTemperature = EnTCLColorTemperature.EN_TCL_WARM_EX;
                break;
            default:
                colorTemperature = EnTCLColorTemperature.EN_TCL_STANDARD;
                break;
        }
        mTvPictureManager.setColorTemperature(colorTemperature);
        Toast.makeText(mContext, "colorTemperature: " + colorTemperature, Toast.LENGTH_SHORT).show();
        Debug.v(TAG, "setColorTemperatureValue : " + value);
    }

    public static int getColorTemperatureValue() {
        int value = DEFS.TMP_STANDARD;
        EnTCLColorTemperature colorTemperature = mTvPictureManager
                .getColorTemperature();

        if (colorTemperature == null) {
            colorTemperature = EnTCLColorTemperature.EN_TCL_STANDARD;
        }
        switch (colorTemperature) {
            case EN_TCL_STANDARD:
                value = DEFS.TMP_STANDARD;
                break;
            case EN_TCL_COOL:
                value = DEFS.TMP_COOL;
                break;
            case EN_TCL_WARM:
                value = DEFS.TMP_WARM;
                break;
            case EN_TCL_WARM_EX:
                value = DEFS.TMP_WARM2;
                break;
            default:
                value = DEFS.TMP_STANDARD;
        }
        Debug.v(TAG, "getColorTemperatureValue : " + value);
        return value;
    }
    //WhiteBalance end
    // =====================================================================================

    //NatureLight
    // =====================================================================================

    public static int getNatureLightBPValue() {
        return mFactoryAdapter.getNatureLightBPValue();
    }

    public static void setNatureLightBPValue(int value) {
        mFactoryAdapter.setNatureLightBPValue(value);
        Debug.v(TAG, "setNatureLightBPValue : " + value);
    }

    public static int getNatureLightAPL2Value() {
        return mFactoryAdapter.getNatureLightAPL2Value();
    }

    public static void setNatureLightAPL2Value(int value) {
        mFactoryAdapter.setNatureLightAPL2Value(value);
        Debug.v(TAG, "setNatureLightAPL2Value : " + value);
    }

    public static void setNatureLightModeValue(int value) {
        mFactoryAdapter.setNaturalLightModeValue(value);
    }

    public static int getNatureLightModeValue() {
        return mFactoryAdapter.getNaturalLightModeValue();
    }

    public static void setNatureLightEnable(boolean value) {
        mFactoryAdapter.setNaturalLightEnable(value);
    }

    public static boolean getNatureLightEnable() {
        return mFactoryAdapter.getNaturalLightEnable();
    }

    public static void setNatureLightPrintEnable(boolean value) {
        mFactoryAdapter.setNaturalLightPrintEnable(value);
    }

    public static boolean getNatureLightPrintEnable() {
        return mFactoryAdapter.getNaturalLightPrintEnable();
    }

    public static void setNatureLightVerboseLevel(int value) {
        mFactoryAdapter.setNatureLightVerboseLevel(value);
        Debug.v(TAG, "setNatureLightVerboseLevel : " + value);
    }

    public static int getNatureLightVerboseLevel() {
        return mFactoryAdapter.getNatureLightVerboseLevel();
    }

    public static int getNatureLightSBLValue() {
        return mFactoryAdapter.getNatureLightSBLValue();
    }

    public static void setNatureLightSBLValue(int value) {
        mFactoryAdapter.setNatureLightSBLValue(value);
        Debug.v(TAG, "setNatureLightSBLValue : " + value);
    }

    public static int getNatureLightBKEValue() {
        return mFactoryAdapter.getNatureLightBKEValue();
    }

    public static void setNatureLightBKEValue(int value) {
        mFactoryAdapter.setNatureLightBKEValue(value);
        Debug.v(TAG, "setNatureLightAPL2Value : " + value);
    }

    public static int getNatureLightDimAPValue() {
        return mFactoryAdapter.getNatureLightDimAPValue();
    }

    public static void setNatureLightDimAPValue(int value) {
        mFactoryAdapter.setNatureLightDimAPValue(value);
        Debug.v(TAG, "setNatureLightDimAPValue : " + value);
    }

    public static short[] getNaturaLightParameter() {
        short[] parameter = new short[3];
        parameter[0] = (short) ThirdParty.getNatureLightBPValue();
        parameter[1] = (short) ThirdParty.getNatureLightAPL2Value();
        parameter[2] = (short) ThirdParty.getNatureLightBKEValue();
//		parameter[2] = (short) ThirdParty.getNatureLightBDValue();
        Debug.v(TAG, "getNaturaLightParameter");
        return parameter;
    }

    public static boolean getNatureLightEnabled() {
        boolean ret = false;
        ret = mTvPictureManager.getNatureLightEnabled();
        Debug.v(TAG, "getNatureLightEnabled " + ":" + ret);
        return ret;
    }

    public static void setNatureLightEnabled(boolean status) {
        if (status == true) {
            mTvPictureManager.setEnergySaving(EnTCLEnergySaving.EN_TCL_ENERGY_SAVING_HIGH);
        } else {
            mTvPictureManager.setEnergySaving(EnTCLEnergySaving.EN_TCL_ENERGY_SAVING_OFF);
        }

        Debug.v(TAG, "setNatureLightEnabled " + ":" + status);
    }

    public static boolean getDccEnabled() {
        boolean ret = false;
        ret = mTvPictureManager.getDccEnabled();
        Debug.v(TAG, "getDccEnabled " + ":" + ret);
        return ret;
    }

    public static void setDccEnabled(boolean status) {
        mTvPictureManager.setDccEnabled(status);
        Debug.v(TAG, "setDccEnabled " + ":" + status);
    }

    //NatureLight end
    // =====================================================================================

    //descramblerbox
    // =====================================================================================
    public static void setChinaDescramblerBox1(boolean status) {
        mFactoryAdapter.setChinaDescramblerBox1(status);
    }

    public static boolean getChinaDescramblerBox1() {
        return mFactoryAdapter.getChinaDescramblerBox1();
    }

    public static void setChinaDescramblerBox2(boolean status) {
        mFactoryAdapter.setChinaDescramblerBox2(status);
    }

    public static boolean getChinaDescramblerBox2() {
        return mFactoryAdapter.getChinaDescramblerBox2();
    }

    public static void setChinaDescramblerBox2Delay(int value) {
        mFactoryAdapter.setChinaDescramblerBox2Delay(value);
    }

    public static int getChinaDescramblerBox2Delay() {
        return mFactoryAdapter.getChinaDescramblerBox2Delay();
    }

    //ssc
    // =====================================================================================
    public static void setLVDSSpan(int value) {
        mFactoryAdapter.setLVDSSpan(value);
        Debug.v(TAG, "setLVDSSpan " + ":" + value);
    }

    public static void setLVDSSSC(boolean value) {
        mFactoryAdapter.setLVDSSSC(value);
        Debug.v(TAG, "setLVDSSSC " + ":" + value);
    }

    public static int setLVDSSteps(int value) {
        mFactoryAdapter.setLVDSSteps(value);
        Debug.v(TAG, "getLVDSSpan " + ":" + value);
        return value;
    }

    public static int getLVDSSpan() {
        int value = 0;
        value = mFactoryAdapter.getLVDSSpan();

        Debug.v(TAG, "getLVDSSpan " + ":" + value);
        return value;
    }

    public static boolean getLVDSSSC() {
        boolean value = mFactoryAdapter.getLVDSSSC();
        Debug.v(TAG, "getLVDSSSC " + ":" + value);
        return value;
    }

    public static int getLVDSSteps() {
        int value = 0;
        value = mFactoryAdapter.getLVDSSteps();
        Debug.v(TAG, "getLVDSSpan " + ":" + value);
        return value;
    }

    public static void setMemorySpan(int value) {
        mFactoryAdapter.setMemorySpan(value);
        Debug.v(TAG, "setMemorySpan " + ":" + value);
    }

    public static void setMemorySSC(boolean value) {
        mFactoryAdapter.setMemorySSC(value);
        Debug.v(TAG, "setMemorySSC " + ":" + value);
    }

    public static int setMemorySteps(int value) {
        mFactoryAdapter.setMemorySteps(value);
        Debug.v(TAG, "setMemorySteps " + ":" + value);
        return value;
    }

    public static int getMemorySpan() {
        int value = 0;
        value = mFactoryAdapter.getMemorySpan();

        Debug.v(TAG, "getMemorySpan " + ":" + value);
        return value;
    }

    public static boolean getMemorySSC() {
        boolean value = mFactoryAdapter.getMemorySSC();
        Debug.v(TAG, "getMemorySSC " + ":" + value);
        return value;
    }

    public static int getMemorySteps() {
        int value = 0;
        value = mFactoryAdapter.getMemorySteps();
        Debug.v(TAG, "getMemorySteps " + ":" + value);
        return value;
    }

    //overscan
    // =====================================================================================
    public static int getHorizonPosition() {
        int value = 0;
        value = mFactoryAdapter.getHorizonPosition();
        Debug.v(TAG, "getHorizonPosition " + ":" + value);
        return value;
    }

    public static int getHorizonZoomSize() {
        int value = 0;
        value = mFactoryAdapter.getHorizonZoomSize();
        Debug.v(TAG, "getHorizonZoomSize " + ":" + value);
        return value;
    }

    public static int getVerticalPosition() {
        int value = 0;
        value = mFactoryAdapter.getVerticalPosition();
        Debug.v(TAG, "getVerticalPosition " + ":" + value);
        return value;
    }

    public static int getVerticalZoomSize() {
        int value = 0;
        value = mFactoryAdapter.getVerticalZoomSize();
        Debug.v(TAG, "getVerticalZoomSize " + ":" + value);
        return value;
    }

    public static void setHorizonPosition(int value) {
        mFactoryAdapter.setHorizonPosition(value);
        Debug.v(TAG, "setHorizonPosition " + ":" + value);
    }

    public static void setHorizonZoomSize(int value) {
        mFactoryAdapter.setHorizonZoomSize(value);
        Debug.v(TAG, "setHorizonZoomSize " + ":" + value);
    }

    public static void setVerticalPosition(int value) {
        mFactoryAdapter.setVerticalPosition(value);
        Debug.v(TAG, "setVerticalPosition " + ":" + value);
    }

    public static void setVerticalZoomSize(int value) {
        mFactoryAdapter.setVerticalZoomSize(value);
        Debug.v(TAG, "setVerticalZoomSize " + ":" + value);
    }

    // =====================================================================================
    public static boolean setAutoADCColor() {
        Debug.d(TAG, "setAutoADCColor");
        return mFactoryAdapter.setAutoADCColor();
    }

    /**
     * 0 fail; 1 ok; other ng
     */
    public static int getAutoADCStatus() {
        int value = 2;
        value = mFactoryAdapter.getAutoADCStatus();
        Debug.d(TAG, "getAutoADCStatus: " + value);
        if (value != 0 && value != 1) {
            value = 2;
        }
        return value;
    }

    public static int getAutoADCColorRGain() {
        int value = 0;
        value = mFactoryAdapter.getAutoADCColorRGain();
        Debug.d(TAG, "getAutoADCColorRGain: " + value);
        return value;
    }


    public static int getAutoADCColorGGain() {
        int value = 0;
        value = mFactoryAdapter.getAutoADCColorGGain();
        Debug.d(TAG, "getAutoADCColorGGain: " + value);
        return value;
    }


    public static int getAutoADCColorBGain() {
        int value = 0;
        value = mFactoryAdapter.getAutoADCColorBGain();
        Debug.d(TAG, "getAutoADCColorBGain: " + value);
        return value;
    }


    public static int getAutoADCColorROffset() {
        int value = 0;
        value = mFactoryAdapter.getAutoADCColorROffset();
        Debug.d(TAG, "getAutoADCColorROffset: " + value);
        return value;
    }


    public static int getAutoADCColorGOffset() {
        int value = 0;
        value = mFactoryAdapter.getAutoADCColorGOffset();
        Debug.d(TAG, "getAutoADCColorGOffset: " + value);
        return value;
    }


    public static int getAutoADCColorBOffset() {
        int value = 0;
        value = mFactoryAdapter.getAutoADCColorBOffset();
        Debug.d(TAG, "getAutoADCColorBOffset: " + value);
        return value;
    }

    public static void setAutoADCColorBGain(int iValue) {
        Debug.d(TAG, "setAutoADCColorBGain: " + iValue);
        mFactoryAdapter.setAutoADCColorBGain(iValue);
    }

    public static void setAutoADCColorBOffset(int iValue) {
        Debug.d(TAG, "setAutoADCColorBOffset: " + iValue);
        mFactoryAdapter.setAutoADCColorBOffset(iValue);
    }

    public static void setAutoADCColorGGain(int iValue) {
        Debug.d(TAG, "setAutoADCColorGGain: " + iValue);
        mFactoryAdapter.setAutoADCColorGGain(iValue);
    }

    public static void setAutoADCColorGOffset(int iValue) {
        Debug.d(TAG, "setAutoADCColorGOffset: " + iValue);
        mFactoryAdapter.setAutoADCColorGOffset(iValue);
    }

    public static void setAutoADCColorRGain(int iValue) {
        Debug.d(TAG, "setAutoADCColorRGain: " + iValue);
        mFactoryAdapter.setAutoADCColorRGain(iValue);
    }

    public static void setAutoADCColorROffset(int iValue) {
        Debug.d(TAG, "setAutoADCColorROffset: " + iValue);
        mFactoryAdapter.setAutoADCColorROffset(iValue);
    }


    // =====================================================================================


    public static short[] getPanelPixelShort(short xpoint, short ypoint, short num) {
        int len = num;
        int[] ret = {0};
        short[] pixData = new short[num * 3];
        Debug.v(TAG, "[getPanelPixelShort] xpoint/ypoint/num" + ":" + xpoint + "/" + ypoint + "/" + num);
        ret = mFactoryAdapter.getPanelPixel((int) xpoint, (int) ypoint, (int) num);
        Debug.v(TAG, "[getPanelPixelShort] ret.length=" + ret.length);
        if (len > ret.length) len = ret.length;
        for (int i = 0; i < len; i++) {
            pixData[i * 3] = (short) ((ret[i] >> 16) & 0xff);
            pixData[i * 3 + 1] = (short) ((ret[i] >> 8) & 0xff);
            pixData[i * 3 + 2] = (short) (ret[i] & 0xff);
        }
        return pixData;
    }

    //panel swing
    // =====================================================================================
    public static void setVby1DrivingCurrent(int value) {
        mFactoryAdapter.setVby1DrivingCurrent(value);
    }

    public static int getVby1DrivingCurrent() {
        return mFactoryAdapter.getVby1DrivingCurrent();
    }
    // =====================================================================================


    public static String getVolumeDevpath(String mount_point) {
        return mStorageManager.getVolumeDevpath(mount_point);
    }

    public static void sendMsgToDBC(int enumNum) {
        EnTCLMsgToDBC msg = EnTCLMsgToDBC.EN_TCL_DBC_GRAPHIC;
        switch (enumNum) {
            case 0:
                msg = EnTCLMsgToDBC.EN_TCL_DBC_GRAPHIC;
                break;
            case 1:
                msg = EnTCLMsgToDBC.EN_TCL_DBC_TV;
                break;
            case 2:
                msg = EnTCLMsgToDBC.EN_TCL_DBC_NO_SIGNAL;
                break;
            case 3:
                msg = EnTCLMsgToDBC.EN_TCL_DBC_HAS_SIGNAL;
                break;
        }
        mTvPictureManager.sendMsgToDBC(msg);
    }

    public static void setGraphicBacklight(int arg0) {
        mTvPictureManager.setGraphicBacklight(arg0);
    }

    public static int getMemcLevel() {
        // ��ʱ���� 2014-3-4

//		int value = mFactoryAdapter.getMemcLevel();
//		Debug.v(TAG, "getMemcLevel : " + value);
//		return value;
        return 0;
    }

    public static void setMemcLevel(int level) {
        // 暂时屏蔽 2014-3-4

//		mFactoryAdapter.setMemcLevel(level);
//		Debug.v(TAG, "setMemcLevel : " + level);
    }

    public static String getNonstandardDTV() {
        return mFactoryAdapter.getNonstandardDTV();
    }

    public static void preNonstandardDTV() {
        mFactoryAdapter.preNonstandardDTV();
    }

    public static void nextNonstandardDTV() {
        mFactoryAdapter.nextNonstandardDTV();
    }

    public static boolean getWatchDog() {
        boolean value = mFactoryAdapter.getWathDog();
        Debug.v(TAG, "getWatchDog " + ":" + value);
        return value;
    }

    public static boolean setWatchDog(boolean status) {
        boolean value = mFactoryAdapter.setWathDog(status);
        Debug.v(TAG, "setWatchDog status : result" + ":::: " + status + "::" + value);
        return value;
    }

    public static boolean FPCImageUpgrade() {
        return mFactoryAdapter.FPCImageUpgrade();
    }

    public static int getFPCImageUpgradeProgress() {
        return mFactoryAdapter.getFPCImageUpgradeProgress();
    }

    public static boolean CIKeyUpgrade() {
        return mFactoryAdapter.CIKeyUpgrade();
    }

    public static boolean WideVineKeyUpgrade() {
        return mFactoryAdapter.WideVineKeyUpgrade();
    }

    public static boolean HdmiKeyUpgrade() {
        return mFactoryAdapter.HdmiKeyUpgrade();
    }

    public static boolean WidiKeyUpgrade() {
        return mFactoryAdapter.WidiKeyUpgrade();
    }

    public static boolean VB1_LVDS_Upgrade() {
        return mFactoryAdapter.VB1_LVDS_Upgrade();
    }

    public static boolean MACUpgrade() {
        return mFactoryAdapter.MACUpgrade();
    }

    public static void setBluetooth3dWorkStatus(int status) {
        if (null == mFactoryAdapter) {
            Log.d(TAG, "setBluetooth3dWorkStatus mFactoryAdapter is null");
            return;
        }
        mFactoryAdapter.setBluetooth3dWorkStatus(status);
    }

    public static void setBluetooth3dSyncStatus(int status) {
        if (null == mFactoryAdapter) {
            Log.d(TAG, "setBluetooth3dSyncStatus mFactoryAdapter is null");
            return;
        }
        mFactoryAdapter.setBluetooth3dSyncStatus(status);
    }

    public static void setSscFrcEnable(boolean status) {
        mFactoryAdapter.setSscFrcEnable(status);
    }

    public static boolean getSscFrcEnable() {
        return mFactoryAdapter.getSscFrcEnable();
    }

    public static void setSscFrcSpan(int value) {
        mFactoryAdapter.setSscFrcSpan(value);
    }

    public static int getSscFrcSpan() {
        return mFactoryAdapter.getSscFrcSpan();
    }

    public static void setSscFrcStep(int value) {
        mFactoryAdapter.setSscFrcStep(value);
    }

    public static int getSscFrcStep() {
        return mFactoryAdapter.getSscFrcStep();
    }

    public static void setSscOsdEnable(boolean status) {
        mFactoryAdapter.setSscOsdEnable(status);
    }

    public static boolean getSscOsdEnable() {
        return mFactoryAdapter.getSscOsdEnable();
    }

    public static void setSscOsdSpan(int value) {
        mFactoryAdapter.setSscOsdSpan(value);
    }

    public static int getSscOsdSpan() {
        return mFactoryAdapter.getSscOsdSpan();
    }

    public static void setSscOsdStep(int value) {
        mFactoryAdapter.setSscOsdStep(value);
    }

    public static int getSscOsdStep() {
        return mFactoryAdapter.getSscOsdStep();
    }

    public static String getProjectName() {
        return mFactoryAdapter.getProjectName();
    }

    public static String getStbcCodeVersion() {
        return mFactoryAdapter.getStbcCodeVersion();
    }

    public static boolean getSTRstatus() {
        return mTvFunctionManager.strSuspendGetStatus();
    }

    public static void setSTRstatus(boolean status) {
        boolean rs = mTvFunctionManager.strSuspendSetStatus(status);
        Debug.v(TAG, "strSuspendSetStatus " + ":" + status + "  rs = " + rs);
    }

    public static void setShopModeStatus(boolean status) {
        boolean rs = mTpiPictureManager.setPictureBoostMode(status);
        Debug.v(TAG, "setShopModeStatus " + ":" + status + "  rs = " + rs);
    }

    public static boolean getShopModeStatus() {
        boolean rs = mTpiPictureManager.getPictureBoostMode();
        Debug.v(TAG, "getShopModeStatus " + ":" + "  rs = " + rs);
        return rs;
    }

    public static String getFrcCodeVersion() {
        return mFactoryAdapter.getFrcCodeVersion();

    }

    public static void setEnergySaving(EnTCLEnergySaving es) {
        boolean rs = mTvPictureManager.setEnergySaving(es);
        Debug.v(TAG, "setEnergySaving " + ":" + es + "  rs = " + rs);
    }

    public static EnTCLEnergySaving getEnergySaving() {
        return mTvPictureManager.getEnergySaving();
    }


    public static void setPicMode(int source) {
        EnTCLPictureMode en_pic = EnTCLPictureMode.EN_TCL_STANDARD;
        if (source == PM_NORMAL) {
            en_pic = EnTCLPictureMode.EN_TCL_STANDARD;
        }
        if (source == PM_VIVID) {
            en_pic = EnTCLPictureMode.EN_TCL_VIVID;
        }
        if (source == PM_MILD) {
            en_pic = EnTCLPictureMode.EN_TCL_MILD;
        }
        if (source == PM_USER) {
            en_pic = EnTCLPictureMode.EN_TCL_USER;
        }
        mTvPictureManager.setPictureMode(en_pic);

        try {
            Runtime.getRuntime().exec("sync"); //$NON-NLS-1$
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /* pic mode */
    public final static int PM_NORMAL = 0;
    public final static int PM_VIVID = 1;
    public final static int PM_MILD = 2;
    public final static int PM_USER = 3;


    public static boolean getAdbdStatus() {
        boolean enableAdb = true;
        String sysconfig;
        Log.v(TAG, "sysconfig is setting");

        sysconfig = SystemProperties.get("persist.sys.usb.config", "");
        if (sysconfig.equals("")) {        // api version < 4.0
            sysconfig = SystemProperties.get("persist.sys.service.adbd.enable", "");
            Log.v(TAG, "sysconfig get data:" + sysconfig);
            if (sysconfig.equals("")) {
                Log.v(TAG, "sysconfig is null");
                enableAdb = false;
            } else if (sysconfig.equals("0")) {
                Log.v(TAG, "sysconfig is 0");
                enableAdb = false;
            } else if (sysconfig.equals("1")) {
                Log.v(TAG, "sysconfig is 1");
                enableAdb = true;
            }
        } else {
            if (sysconfig.equals("none")) {
                enableAdb = false;
            } else {
                enableAdb = true;
            }
        }
        Log.v(TAG, "GetAdbdStatus enableAdb:" + enableAdb);
        return enableAdb;
    }

    public static void setAdbdStatus(boolean enable) {
        if (enable) {
            SystemProperties.set("persist.sys.service.adbd.enable", "1");
            SystemProperties.set("persist.sys.usb.config", "adb");
        } else {
            SystemProperties.set("persist.sys.service.adbd.enable", "0");
            SystemProperties.set("persist.sys.usb.config", "none");
        }
        Log.v(TAG, "SetAdbdStatus enable:" + enable);
    }

    public static boolean LocalDimmingUpgrade() {
        return mFactoryAdapter.LocalDimmingUpgrade();
    }

    public static String getLocalDimmingVersion() {
        return mFactoryAdapter.getLocalDimmingVersion();
    }

    public static void broadCastPmodeStatus() {
        Intent intent = new Intent();
        if (getPModeStatus()) {
            intent.setAction("com.tcl.factory.pmode.on");
            mContext.sendBroadcast(intent);
        } else {
            intent.setAction("com.tcl.factory.pmode.off");
            mContext.sendBroadcast(intent);
        }

    }

    @SuppressLint("InvalidWakeLockTag")
    public static void setWakeLockStatus(boolean status) {
        if (status) {
            if (mPowerManager == null) {
                mPowerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE);
            }
            if (mWakeLock == null) {
                mWakeLock = mPowerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "Factory");
            }
            if (!mWakeLock.isHeld()) {
                Debug.v(TAG, "setWakeLockStatus : " + status);
                mWakeLock.acquire();
            }
        } else {
            if (mWakeLock != null) {
                if (mWakeLock.isHeld()) {
                    Debug.v(TAG, "setWakeLockStatus : " + status);
                    mWakeLock.release();
                    mWakeLock = null;
                }
            }
        }
    }

    public static String getDrmString() {
        String data = mFactoryAdapter.getDrmString();
        Debug.v(TAG, "getDrmString : " + data);
        return data;
    }

    public static boolean getGetUserIDStatus() {
        boolean value = mFactoryAdapter.getGetUserIDStatus();
        Debug.v(TAG, "getGetUserIDStatus " + ":" + value);
        return value;
    }

    public static boolean setGetUserIDStatus(boolean status) {
        boolean value = mFactoryAdapter.setGetUserIDStatus(status);
        Debug.v(TAG, "setGetUserIDStatus status : result" + ":::: " + status + "::" + value);
        return value;
    }

    public static boolean getBGM() {
        boolean value = mFactoryAdapter.getBGM();
        Debug.v(TAG, "getBGM " + ":" + value);
        return value;
    }

    public static boolean setBGM(boolean status) {
        boolean value = mFactoryAdapter.setBGM(status);
        Debug.v(TAG, "setBGM status : result" + ":::: " + status + "::" + value);
        return value;
    }

    public static boolean getNMR() {
        boolean value = mFactoryAdapter.getNMR();
        Debug.v(TAG, "getNMR " + ":" + value);
        return value;
    }

    public static boolean setNMR(boolean status) {
        boolean value = mFactoryAdapter.setNMR(status);
        Debug.v(TAG, "setNMR status : result" + ":::: " + status + "::" + value);
        return value;
    }

    public static int getDVBT2ModeValue() {
        int value = mFactoryAdapter.getDVBT2ModeValue();
        Debug.v(TAG, "getDVBT2ModeValue : " + value);
        return value;
    }

    public static boolean setDVBT2ModeValue(int mode) {
        boolean value = mFactoryAdapter.setDVBT2ModeValue(mode);
        Debug.v(TAG, "setDVBT2ModeValue : " + mode);
        return value;
    }

    public static boolean getHbbTVMode() {
        boolean value = mFactoryAdapter.getHbbTVMode();
        Debug.v(TAG, "getHbbTVMode " + ":" + value);
        return value;
    }

    public static boolean setHbbTVMode(boolean status) {
        boolean value = mFactoryAdapter.setHbbTVMode(status);
        Debug.v(TAG, "setHbbTVMode status : result" + ":::: " + status + "::" + value);
        return value;
    }

    public static String getRunningTimeString() {
        String data = mFactoryAdapter.getRunningTimeString();
        Debug.v(TAG, "getDeviceIDString : " + data);
        return data;
    }

    public static int getAdcMaxValue() {
        int value = mFactoryAdapter.getAdcMaxValue();
        Debug.v(TAG, "getAdcMaxValue : " + value);
        return value;
    }

    public static int getAdcMinValue() {
        int value = mFactoryAdapter.getAdcMinValue();
        Debug.v(TAG, "getAdcMinValue : " + value);
        return value;
    }

    public static int getRatioMinValue() {
        int value = mFactoryAdapter.getRatioMinValue();
        Debug.v(TAG, "getRatioMinValue : " + value);
        return value;
    }

    public static boolean OpenHbbtvPortal(String str_URL) {
        boolean value = mFactoryAdapter.OpenHbbtvPortal(str_URL);
        Debug.v(TAG, "OpenHbbtvPortal status : result" + ":::: " + str_URL + "::" + value);
        return value;
    }

    public static boolean startRecordTS(String str_URL) {
        boolean value = mFactoryAdapter.startRecordTS(str_URL);
        Debug.v(TAG, "startRecordTS status : result" + ":::: " + str_URL + "::" + value);
        return value;
    }

    public static boolean stopRecordTS() {
        boolean value = false;
        try {
            value = mFactoryAdapter.stopRecordTS();
            Debug.v(TAG, "stopRecordTS status : " + value);
        } catch (Exception e) {
            Debug.v(TAG, "stopRecordTS" + value + "," + e.getMessage());
        }
        return value;
    }

    public static boolean checkPackage(String packageName) {
        if (packageName == null || "".equals(packageName)) {
            return false;
        }
        try {
            mContext.getPackageManager()
                    .getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
            return true;
        } catch (NameNotFoundException e) {
            Debug.v(TAG, "Package " + packageName + " not exist!");
            return false;
        }
    }

    public static boolean IsEUArea() {

        String clientType = getClientType();
        Log.d(TAG, "getArea() clientType = " + clientType);

        if (clientType == null) {
            Log.e(TAG, "clientType = " + clientType);
            return false;
        }

        String info[] = clientType.split("-");
        if (info != null && info.length >= 2) {
            String area = info[1];
            if (area.endsWith("EU")) {
                return true;
            }
        }
        return false;
    }


    public static void setAdcMaxValue(int value) {
        mFactoryAdapter.setAdcMaxValue(value);
        Debug.v(TAG, "setAdcMaxValue : " + value);
    }


    public static void setAdcMinValue(int value) {
        mFactoryAdapter.setAdcMinValue(value);
        Debug.v(TAG, "setAdcMinValue : " + value);
    }


    public static void setRatioMinValue(int value) {
        mFactoryAdapter.setRatioMinValue(value);
        Debug.v(TAG, "setRatioMinValue : " + value);
    }

    public static void setHotelBootLogo(int value) {
        if (mFactoryAdapter.setHotelBootLogo(value)) {
            mContext.sendBroadcast(new Intent(defs.MSG_SET_UP_SUCCESS));
        } else {
            mContext.sendBroadcast(new Intent(defs.MSG_SET_UP_FAIL));
        }
    }

    public static void SetNoPowerLogo() {
        String tmpPath = DEFS.BlackLogoPath + HotelLogoName;
        try {
            File f = new File(tmpPath);
            if (!f.exists()) {
                Toast.makeText(mContext, "Error!! Set up fail !!", Toast.LENGTH_SHORT).show();
                return;
            }
            setHotelBootLogo(DEFS.HOTEL_NO_LOGO);
        } catch (Exception e) {
            Toast.makeText(mContext, "Error!! Set up fail !!", Toast.LENGTH_SHORT).show();
            e.printStackTrace();
            return;
        }
    }

    public static boolean checkPictureSize() {
        try {
            File f = new File(usbLogoPath);
            Log.i("api", "usbLogoPath " + usbLogoPath);
            Log.i("api", "logo file " + f.exists());
            if (!f.exists()) {
//				String err_str = "Error!! Not found "+HotelLogoName+" in U disk !!";
//				Toast.makeText(mContext, err_str, Toast.LENGTH_SHORT).show();
                ThirdParty.mContext.sendBroadcast(new Intent(defs.MSG_NO_USB_MOUNT));
                return false;
            }
            Log.i("api", "HotelLogoName " + HotelLogoName);
            if (HotelLogoName.equals(DEFS.BMP_LogoName) || HotelLogoName.equals(DEFS.BMP_Logo_LogoName)) {
                Bitmap bitmap = BitmapFactory.decodeFile(usbLogoPath);
                int height = bitmap.getHeight();
                int width = bitmap.getWidth();
                Debug.v(TAG, "readPictureSize width =" + width + "  height = " + height);
                if (!(((width == 1920) && (height == 1080)) || ((width == 1280) && (height == 720)))) {
//					Toast.makeText(mContext, "Error!! The resolution of the logo isn't 1920x1080 or 1280x720!!", Toast.LENGTH_SHORT).show();
                    ThirdParty.mContext.sendBroadcast(new Intent(defs.MSG_LOGO_RESOLUTION_ERR));
                    return false;
                }
                return true;
            }

            //check picture file size
            long fileLen = f.length();
            Log.i("api", "fileLen=" + fileLen);
//			if(fileLen>DEFS.MAX_HOTEL_BOOT_LOGO_FILE_SIZE)// file is more then 1M
//			{
////				Toast.makeText(mContext, "Error!! The size of the logo file is larger then 1M !", Toast.LENGTH_SHORT).show();
//				ThirdParty.mContext.sendBroadcast(new Intent(defs.MSG_LOGO_SIZE_ERR));
//				return false;
//			}

            //check picture size
            ExifInterface exifInterface = new ExifInterface(usbLogoPath);
            int pic_width = exifInterface.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0);
            int pic_length = exifInterface.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0);
            Log.i("api", "readPictureSize pic_width =" + pic_width + "  pic_length = " + pic_length);
            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inJustDecodeBounds = true;
            Bitmap bitmap = BitmapFactory.decodeFile(usbLogoPath, options);
            Log.i("api", "wight," + options.outWidth);
            Log.i("api", "Height," + options.outHeight);
            pic_width = options.outWidth;
            pic_length = options.outHeight;
            if (!(((pic_width == 1920) && (pic_length == 1080)) || ((pic_width == 1280) && (pic_length == 720)))) {
//				Toast.makeText(mContext, "Error!! The resolution of the logo isn't 1920x1080 or 1280x720!!", Toast.LENGTH_SHORT).show();
                ThirdParty.mContext.sendBroadcast(new Intent(defs.MSG_LOGO_RESOLUTION_ERR));
                return false;
            }

            //check picture style
            byte[] tempbytes = new byte[2048];
            int byteread = 0;
            int i;
            boolean next_check = false;
            boolean check_result = true;
            ;
            FileInputStream in = new FileInputStream(usbLogoPath);
            Debug.v(TAG, "check picture style start");
            Log.i("api", "check picture style start");
            while ((byteread = in.read(tempbytes)) != -1) {
//				Log.i("api","byteread = "+byteread+"   tempbytes = "+tempbytes[0] );
                if (next_check)    //previous array find 0xFF
                {
                    if (tempbytes[0] == DEFS.FLG_BMP_PROGRESSIVE_TYPE)//(tempbytes[0]==0xC2)
                    {
                        //Toast.makeText(mContext, "boot0.jpg style error!!", Toast.LENGTH_SHORT).show();
                        check_result = false;
                        Log.i("api", "logo.bmp style error!!");
                        Log.i("api", "tempbytes[0] " + tempbytes[0]);
                    }
                    Log.i("api", "false tempbytes[0] " + tempbytes[0]);
                    next_check = false;
                } else {
                    for (i = 0; i < byteread - 1; i++) {
                        if ((tempbytes[i] == -1) && (tempbytes[i + 1] == DEFS.FLG_BMP_PROGRESSIVE_TYPE))//(tempbytes[i]==0xFF&&(tempbytes[i+1]==0xC2))
                        {
                            check_result = false;
                            break;
                        }
                    }
                }
                if (!check_result) {
                    break;
                }
                if (tempbytes[byteread - 1] == -1)//(tempbytes[byteread-1]==0xFF)
                {
                    next_check = true;
                }
            }
            if (in != null) {
                in.close();
            }
            Log.i("api", "check picture style end");
            Log.i("api", "check_result " + check_result);
            if (!check_result) {
//				Toast.makeText(mContext, "Error!!The picture type of the logo isn't baseline!!", Toast.LENGTH_SHORT).show();
                ThirdParty.mContext.sendBroadcast(new Intent(defs.MSG_LOGO_COPY_ERR));
                return false;
            }

            return true;
        } catch (IOException e) {
            Debug.v(TAG, "jacky checkPictureSize 111");
            e.printStackTrace();
        }
        return false;
    }

    public static boolean showUserLogoPicture() {
        try {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            File picFile = new File(usbLogoPath);
            intent.setDataAndType(Uri.fromFile(picFile), "image/*");
            mContext.startActivity(intent);
            return true;
        } catch (Exception e) {
            Debug.v(TAG, "showUserLogoPicture fail!!");
            Toast.makeText(mContext, "Error!! Play logo fail !!", Toast.LENGTH_SHORT).show();
        }
        return false;
    }

    public static boolean showUserBootVideo() {
/*
		try  {
			Intent intent = new Intent(Intent.ACTION_VIEW);
			intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
			File videoFile=new File(usbBootVideoPath);
			intent.setDataAndType(Uri.fromFile(videoFile), "video/*");
			mContext.startActivity(intent);
			return true;
		}
		catch (Exception e)
		{
			Debug.v(TAG, "showUserVideo fail!!");
			Toast.makeText(mContext, "show logo picture NG!!", Toast.LENGTH_SHORT).show();
		}
		return false;
*/
        return mFactoryAdapter.startHotelCheckBootVideo();
    }

    public static boolean CheckUserLogoPicture() {
        String tmpPath = TCL.getUSBMountPath(mContext);

        if (null == tmpPath || ("".equals(tmpPath))) {
            Toast.makeText(mContext, "NO_USB_MOUNT", Toast.LENGTH_SHORT).show();
        } else {
            String filePath = tmpPath + DEFS.Define_usbLogoPath + HotelLogoName;
            Debug.v(TAG, "jacky filePath=" + filePath);
            usbLogoPath = filePath;
            boolean flg = true;
            flg = checkPictureSize();
            if (flg) {
                boolean result = showUserLogoPicture();
                if (result) {
                    setHotelBootLogoCheckStatus(DEFS.HOTEL_BOOT_LOGO_CHECK_STATUS_LOGO);
                    return true;
                }
            }
        }
        return false;
    }

    private static void cleanUserBootAnimation() {
        setRootSeek("rm -f " + DEFS.UserLogoPath + DEFS.PowerAnimaionName);
        setRootSeek("sync");
    }

    private static void cleanUserBootVideo() {
        setRootSeek("rm -f " + DEFS.UserLogoPath + DEFS.PowerVideoName);
        setRootSeek("rm -f " + DEFS.UserLogoPath + DEFS.PowerVideoIniName);
        setRootSeek("sync");
    }

    public static boolean CheckUserBootAnimation() {
        final String tmpPath = TCL.getUSBMountPath(mContext);
        if (null == tmpPath || ("".equals(tmpPath))) {
            Toast.makeText(mContext, "NO_USB_MOUNT", Toast.LENGTH_SHORT).show();
        } else {
            final String filePath = tmpPath + DEFS.Define_usbLogoPath + DEFS.PowerAnimaionName;
            Debug.v(TAG, "jacky filePath=" + filePath);
            try {
                File f = new File(filePath);
                if (!f.exists()) {
                    Toast.makeText(mContext, "Error!! Not found bootanimation.zip in U disk !!", Toast.LENGTH_SHORT).show();
                    return false;
                }
                //check file size
                long fileLen = f.length();
                Debug.v(TAG, "fileLen=" + fileLen);
                if (fileLen > DEFS.MAX_HOTEL_BOOT_ANMI_FILE_SIZE)// file is more then 30M
                {
                    Toast.makeText(mContext, "Error!! The size of the file is larger then 30M !", Toast.LENGTH_SHORT).show();
                    return false;
                }

                if (fileLen > getDataRemainingSpace()) {
                    Toast.makeText(mContext, "Error!!No space to save file!!", Toast.LENGTH_SHORT).show();
                    return false;
                }
                usbBootAnimationPath = filePath;
                String cmd = "cp -rf " + usbBootAnimationPath + " " + "/tmp/bootanimation.zip";
                setRootSeek(cmd);
                cmd = "chmod -R 755  /tmp/bootanimation.zip";
                setRootSeek(cmd);
                cmd = "sync";
                setRootSeek(cmd);
                SystemProperties.set(DEFS.HOTEL_PROPERTY_TEST_ANIM_STATUS, "0");
                SystemProperties.set("ctl.start", "offanim:2");
                setHotelBootLogoCheckStatus(DEFS.HOTEL_BOOT_LOGO_CHECK_STATUS_ANIMATION);
                return true;
            } catch (Exception e) {
                Toast.makeText(mContext, "Error!! Not found bootanimation.zip in U disk !!", Toast.LENGTH_SHORT).show();
                e.printStackTrace();
                return false;
            }
        }
        return false;
    }

    public static boolean CheckUserBootVideo() {
        String tmpPath = TCL.getUSBMountPath(mContext);

        if (null == tmpPath || ("".equals(tmpPath))) {
            Toast.makeText(mContext, "NO_USB_MOUNT", Toast.LENGTH_SHORT).show();
        } else {
            String filePath = tmpPath + DEFS.Define_usbLogoPath + DEFS.PowerVideoName;
            Debug.v(TAG, "jacky filePath=" + filePath);
            Log.i("api", "jacky filePath=" + filePath);
            usbBootVideoPath = filePath;
            File f = new File(filePath);
            if (!f.exists()) {
                Toast.makeText(mContext, "Error!! Not found bootvideo.ts in U disk !!", Toast.LENGTH_SHORT).show();
                return false;
            }
            long fileLen = f.length();
            Debug.v(TAG, "fileLen=" + fileLen);
            if (fileLen > DEFS.MAX_HOTEL_BOOT_VIDEO_FILE_SIZE)// file is more then 30M
            {
                Toast.makeText(mContext, "Error!! The size of the file is larger then 50M !", Toast.LENGTH_SHORT).show();
                return false;
            }

            if (fileLen > getDataRemainingSpace()) {
                Toast.makeText(mContext, "Error!!No space to save file!!", Toast.LENGTH_SHORT).show();
                return false;
            }

            String cmd = "cp -rf " + usbBootVideoPath + " /tmp/";
            setRootSeek(cmd);
            cmd = "cp -rf " + tmpPath + DEFS.Define_usbLogoPath + "ts.ini  /tmp/";
            setRootSeek(cmd);
            cmd = "chmod -R 755  /tmp/bootvideo.ts";
            setRootSeek(cmd);
            cmd = "chmod -R 755  /tmp/ts.ini";
            setRootSeek(cmd);
            cmd = "sync";
            setRootSeek(cmd);
            //clean no signal icon
            if (!getPModeStatus()) {
                Intent intent = new Intent();
                intent.setAction("com.tcl.factory.pmode.on");
                mContext.sendBroadcast(intent);
            }

            boolean result = showUserBootVideo();
            Log.i("api", "showUserBootVideo result" + result);
            if (result) {
                setHotelBootLogoCheckStatus(DEFS.HOTEL_BOOT_LOGO_CHECK_STATUS_VIDEO);
                return true;
            }
            if (!getPModeStatus()) {
                Intent intent = new Intent();
                intent.setAction("com.tcl.factory.pmode.off");
                mContext.sendBroadcast(intent);
            }
        }
        return false;
    }

    public static void setUserBootAnimation(String path) {
        final File file = new File(path);
        if (!file.exists()) {
            Log.e(TAG, "setUserBootAnimation: " + path + " not exists");
            return;
        }
        if (!file.isFile()) {
            Log.e(TAG, "setUserBootAnimation: " + path + " is not valid file");
            return;
        }

        Log.d(TAG, "setUserBootAnimation: " + path);
        setRootSeek("mkdir -p " + DEFS.UserLogoPath);
        setRootSeek("cp -f '" + path + "' " + DEFS.UserLogoPath + DEFS.PowerAnimaionName);
        setRootSeek("chmod 777 " + DEFS.UserLogoPath + DEFS.PowerAnimaionName);
        setRootSeek("sync");
        setHotelBootAnimation(DEFS.HOTEL_USER_LOGO);
    }

    public static void setUserBootVideo() {
        String tmpPath = TCL.getUSBMountPath(mContext);
        String cmd = "";
        if (null == tmpPath || ("".equals(tmpPath))) {
            Toast.makeText(mContext, "NO_USB_MOUNT", Toast.LENGTH_SHORT).show();
        } else {
            String filePath = tmpPath + DEFS.Define_usbLogoPath + DEFS.PowerVideoName;
            String filePath2 = tmpPath + DEFS.Define_usbLogoPath + DEFS.PowerVideoIniName;
            Debug.v(TAG, "jacky filePath=" + filePath);
            try {
                File f = new File(filePath);
                File f2 = new File(filePath2);
                if (!(f.exists() && f2.exists())) {
                    Toast.makeText(mContext, "Error!! Not found bootvideo.ts or ts.ini in U disk !!", Toast.LENGTH_SHORT).show();
                    return;
                } else {
                    cmd = "mkdir -p " + DEFS.UserLogoPath;
                    setRootSeek(cmd);
                    cmd = "cp -rf " + filePath + " " + DEFS.UserLogoPath;
                    setRootSeek(cmd);
                    cmd = "cp -rf " + filePath2 + " " + DEFS.UserLogoPath;
                    setRootSeek(cmd);
                    cmd = "chmod -R 777  " + DEFS.UserLogoPath;
                    setRootSeek(cmd);
                    cmd = "sync";
                    setRootSeek(cmd);

                    String video_file_path = DEFS.UserLogoPath + DEFS.PowerVideoName;
                    String ini_file_path = DEFS.UserLogoPath + DEFS.PowerVideoIniName;
                    File video_f = new File(video_file_path);
                    File ini_f = new File(ini_file_path);
                    if (!(video_f.exists() && ini_f.exists())) {
                        Toast.makeText(mContext, "Error!! Copy bootvideo.ts or ts.ini file fail!!", Toast.LENGTH_SHORT).show();
                        return;
                    }
                    if (setHotelBootVideo(DEFS.HOTEL_USER_BOOT_VIDEO)) {
                        showToastForBootAnimation("Set up success!!");
                    } else {
                        showToastForBootAnimation("Error!!Set up fail!!");
                    }
                }
            } catch (Exception e) {
                Toast.makeText(mContext, "Error!!Set up fail!!", Toast.LENGTH_SHORT).show();
                e.printStackTrace();
                return;
            }
        }
    }

    public static int getHotelBootLogoCheckStatus() {
        return flg_hotelBootLogoCheckStatus;
    }

    public static void setHotelBootLogoCheckStatus(int flg) {
        flg_hotelBootLogoCheckStatus = flg;
    }

    public static void setPowerLogo(int value) {
        //setHotelLogoName();
        switch (value) {
            case DEFS.HOTEL_DEFAULT_LOGO:
                setHotelBootLogo(DEFS.HOTEL_DEFAULT_LOGO);
                break;
            case DEFS.HOTEL_NO_LOGO:
                //SetNoPowerLogo();
                setHotelBootLogo(DEFS.HOTEL_NO_LOGO);
                break;
            case DEFS.HOTEL_USER_LOGO:
                CheckUserLogoPicture();
                break;
            default:
                break;
        }
    }

    public static void setPower(int value) {
        switch (value) {
            case DEFS.HOTEL_DEFAULT_LOGO:
                if (setHotelBootAnimation(DEFS.HOTEL_DEFAULT_LOGO)) {
                    Toast.makeText(mContext, "Set up success!!", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(mContext, "Error!!Set up fail!!", Toast.LENGTH_SHORT).show();
                }
                break;
            case DEFS.HOTEL_NO_LOGO:
                //SetNoPowerAnimation();
                if (setHotelBootAnimation(DEFS.HOTEL_NO_LOGO)) {
                    Toast.makeText(mContext, "Set up success!!", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(mContext, "Error!!Set up fail!!", Toast.LENGTH_SHORT).show();
                }
                break;
            case DEFS.HOTEL_USER_LOGO:
                CheckUserBootAnimation();
                break;
            default:
                break;
        }
    }

    public static void setPowerVideo(int value) {
        switch (value) {
            case DEFS.HOTEL_NO_BOOT_VIDEO:
                if (setHotelBootVideo(DEFS.HOTEL_NO_BOOT_VIDEO)) {
                    showToastForBootAnimation("Set up success!!");
                } else {
                    showToastForBootAnimation("Error!!Set up fail!!");
                }
                break;
            case DEFS.HOTEL_USER_BOOT_VIDEO:
                CheckUserBootVideo();
                break;
            default:
                break;
        }
    }

    public static void SetNoPowerAnimation() {
        String tmpPath = DEFS.BlackLogoPath + DEFS.PowerAnimaionName;
        try {
            File f = new File(tmpPath);
            Debug.v(TAG, "jacky SetNoPowerAnimation path =   " + tmpPath + "flg=" + f.exists());
            if (!f.exists()) {
                Toast.makeText(mContext, "Error!!Set up fail!!", Toast.LENGTH_SHORT).show();
                return;
            }
            if (setHotelBootAnimation(DEFS.HOTEL_NO_LOGO)) {
                showToastForBootAnimation("Set up success!!");
            } else {
                showToastForBootAnimation("Error!!Set up fail!!");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return;
        }
    }

    public static boolean setHotelBootAnimation(int value) {
        Log.d(TAG, "setHotelBootAnimation: " + value);
        switch (value) {
            case DEFS.HOTEL_DEFAULT_LOGO:
                SystemProperties.set(DEFS.HOTEL_PROPERTY_BOOT_ANIM, "0");
                break;
            case DEFS.HOTEL_NO_LOGO:
                SystemProperties.set(DEFS.HOTEL_PROPERTY_BOOT_ANIM, "1");
                break;
            case DEFS.HOTEL_USER_LOGO:
                SystemProperties.set(DEFS.HOTEL_PROPERTY_BOOT_ANIM, "2");
                break;
        }
        if (mFactoryAdapter.setHotelBootAnimation(value)) {
            if (value != DEFS.HOTEL_DEFAULT_LOGO) {
                setHotelBootVideo(DEFS.HOTEL_NO_BOOT_VIDEO);
            }
            if (value != DEFS.HOTEL_USER_LOGO) {
                cleanUserBootAnimation();
            }
            return true;
        } else {
            return false;
        }
    }

    public static boolean setHotelBootVideo(int value) {
        Log.d(TAG, "setHotelBootVideo: " + value);
        switch (value) {
            case DEFS.HOTEL_NO_BOOT_VIDEO:
                SystemProperties.set(DEFS.HOTEL_PROPERTY_BOOT_VIDEO, "0");
                break;
            case DEFS.HOTEL_USER_BOOT_VIDEO:
                SystemProperties.set(DEFS.HOTEL_PROPERTY_BOOT_VIDEO, "1");
                break;
        }
        if (mFactoryAdapter.setHotelBootVideo(value)) {
            if (value == DEFS.HOTEL_USER_BOOT_VIDEO) {
                setHotelBootAnimation(DEFS.HOTEL_DEFAULT_LOGO);
            } else {
                cleanUserBootVideo();
            }
            return true;
        } else {
            return false;
        }
    }

    public static void setHotelSilentInstal(boolean mode) {
        Debug.v(TAG, "setHotelSilentInstal =" + mode);
        if (mode) {
            SystemProperties.set(DEFS.HOTEL_PROPERTY_SLIENT_INSTALL, "1");
        } else {
            SystemProperties.set(DEFS.HOTEL_PROPERTY_SLIENT_INSTALL, "0");
        }
        mFactoryAdapter.setHotelSilentInstal(mode);
    }

    public static boolean setHotelScreenPosition(boolean value) {
        Debug.v(TAG, "setHotelScreenPosition =" + value);
        if (value) {
            SystemProperties.set(DEFS.HOTEL_PROPERTY_SCREEN_HV, "v");
        } else {
            SystemProperties.set(DEFS.HOTEL_PROPERTY_SCREEN_HV, "h");
        }
        return mFactoryAdapter.setHotelScreenPosition(value);
    }

    public static void hotel_startUserApk() {
        String HotelLauncherAppName = mFactoryAdapter.getHotelLauncherAppName();
        if (!HotelLauncherAppName.equals("null")) {
            String HotelLauncherActivityName = mFactoryAdapter.getHotelLauncherActivityName();
            Debug.v(TAG, "UserData =" + HotelLauncherAppName + ",className = " + HotelLauncherActivityName);
            try {
                Intent myIntent = new Intent();
                myIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                ComponentName cn = new ComponentName(HotelLauncherAppName, HotelLauncherActivityName);

                myIntent.setComponent(cn);
                myIntent.setAction("android.intent.action.VIEW");
                mContext.startActivity(myIntent);
            } catch (Exception e) {
            }
        }
    }

    public static boolean setStandbyLEDIndicatorMode(int value) {
        Debug.d(TAG, "SetHotelLedIndicator =" + value);
        TvManager tvManager = TvManager.getInstance(mContext);
        switch (value) {
            case 0:    //on mode
                tvManager.getProperty().set(DEFS.SITA_PROPERTY_KEY_BOOTUP_LED_STANDBY, DEFS.SITA_PROPERTY_VALUE_BOOTUP_LED_ON);
                break;
            case 1:    //off mode
                tvManager.getProperty().set(DEFS.SITA_PROPERTY_KEY_BOOTUP_LED_STANDBY, DEFS.SITA_PROPERTY_VALUE_BOOTUP_LED_OFF);
                break;
            case 2: //Hotel mode
                tvManager.getProperty().set(DEFS.SITA_PROPERTY_KEY_BOOTUP_LED_STANDBY, DEFS.SITA_PROPERTY_VALUE_BOOTUP_LED_BREATHING);
                break;
            default:
                return false;
        }
        Debug.d(TAG, "setStandbyLEDIndicatorMode = " + value);
        return mFactoryAdapter.setStandbyLEDIndicatorMode(value);
    }

    private static void Hotel_nvmToUsb() {
        new Thread(new Runnable() {

            @Override
            public void run() {
                Looper.prepare();
                String cmd = "";
                String tmpPath = TCL.getUSBMountPath(mContext);
                Debug.v(TAG, "Hotel_nvmToUsb ============== init start================ ");
                if (null == tmpPath || ("".equals(tmpPath))) {
                    Toast.makeText(mContext, "NO_USB_MOUNT", Toast.LENGTH_SHORT).show();
                } else {
                    createHotelMd5File();
                    cmd = "mkdir -p " + tmpPath + "/database/user_logo/";
                    Debug.v(TAG, cmd);
                    setRootSeek(cmd);
                    cmd = "cp -rf " + DEFS.UserLogoPath + "* " + tmpPath + "/database/user_logo/";
                    Debug.v(TAG, cmd);
                    setRootSeek(cmd);
                    cmd = "sync";
                    setRootSeek(cmd);
                    Toast.makeText(mContext, "NVM_TO_USB_OK", Toast.LENGTH_SHORT).show();
                    Debug.v(TAG, "Hotel_nvmToUsb ============== init end================ ");
                }
                Looper.loop();
            }
        }).start();
    }

    private static void Hotel_UsbToNvm() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                Looper.prepare();
                String cmd = "";
                String tmpPath = TCL.getUSBMountPath(mContext);
                Debug.v(TAG, "Hotel_UsbToNvm ============= init start================ ");

                if (null == tmpPath || ("".equals(tmpPath))) {
                    Toast.makeText(mContext, "NO_USB_MOUNT", Toast.LENGTH_SHORT).show();
                } else {
                    cmd = "mkdir -p " + DEFS.UserLogoPath;
                    setRootSeek(cmd);
                    cmd = "cp -rf " + tmpPath + "/database/user_logo/* " + DEFS.UserLogoPath;
                    setRootSeek(cmd);
                    cmd = "chmod -R 777  " + DEFS.UserLogoPath;
                    setRootSeek(cmd);
                    cmd = "sync";
                    setRootSeek(cmd);

                    if (!CheckHotelFileMD5()) {
                        Toast.makeText(mContext, "Error!!MD5 check fail!!", Toast.LENGTH_SHORT).show();
                    } else {
                        hotel_clone_sync_db();
                        Toast.makeText(mContext, "USB_TO_NVM_OK", Toast.LENGTH_SHORT).show();
                    }

                }
                Debug.v(TAG, "Hotel_UsbToNvm =============== init end================ ");
                Looper.loop();
            }
        }).start();
    }

    public static void HotelModeInit() {
        Debug.v(TAG, "HotelModeInit ============== init start================ ");
        SystemProperties.set(DEFS.HOTEL_PROPERTY_HOTEL_HOTKEY, "1");
        int boot_logo_mode = mFactoryAdapter.getHotelBootLogo();
        if (boot_logo_mode != DEFS.HOTEL_DEFAULT_LOGO) {
            mFactoryAdapter.setHotelBootLogo(boot_logo_mode);
        }

        int power_on_mode = getPowerModeValue();
        if (power_on_mode != mFactoryAdapter.getHotelPowerOnMode()) {
            mFactoryAdapter.setHotelPowerOnMode(power_on_mode);
        }

        int standby_led_mode = 0;
        String led_str = SystemProperties.get(DEFS.SITA_PROPERTY_KEY_BOOTUP_LED_STANDBY, "");
        if (led_str.equals(DEFS.SITA_PROPERTY_VALUE_BOOTUP_LED_OFF))
            standby_led_mode = 1;
        else if (led_str.equals(DEFS.SITA_PROPERTY_VALUE_BOOTUP_LED_BREATHING))
            standby_led_mode = 2;
        if (standby_led_mode != mFactoryAdapter.getStandbyLEDIndicatorMode()) {
            mFactoryAdapter.setStandbyLEDIndicatorMode(standby_led_mode);
        }
        Debug.v(TAG, "HotelModeInit ============== init end================ ");
    }

    public static void HotelModeExit() {
        Debug.v(TAG, "HotelModeInit ============== exit start================ ");
        SystemProperties.set(DEFS.HOTEL_PROPERTY_HOTEL_HOTKEY, "0");
        String cmd = "rm -f /data/property/" + DEFS.HOTEL_PROPERTY_HOTEL_HOTKEY;
        setRootSeek(cmd);

        int boot_logo_mode = mFactoryAdapter.getHotelBootLogo();
        if (boot_logo_mode != DEFS.HOTEL_DEFAULT_LOGO) {
            mFactoryAdapter.setHotelBootLogo(DEFS.HOTEL_DEFAULT_LOGO);
        }
        Debug.v(TAG, "HotelModeInit ============== exit end================ ");
    }

    public static void hotel_reset_to_default() {
        if (getHotelFlag() != DEFS.COMMON_OFF) {
            setHotelFlag(DEFS.COMMON_OFF);
            SystemProperties.set(DEFS.HOTEL_PROPERTY_HOTEL_HOTKEY, "0");
            String cmd = "rm -f /data/property/" + DEFS.HOTEL_PROPERTY_HOTEL_HOTKEY;
            setRootSeek(cmd);
        }
        if (mFactoryAdapter.getHotelBootLogo() != DEFS.HOTEL_DEFAULT_LOGO) {
            mFactoryAdapter.setHotelBootLogo(DEFS.HOTEL_DEFAULT_LOGO);
        }
        if (mFactoryAdapter.getHotelBootAnimation() != DEFS.HOTEL_DEFAULT_LOGO) {
            setHotelBootAnimation(DEFS.HOTEL_DEFAULT_LOGO);
        }
        if (mFactoryAdapter.getHotelBootVideo() != DEFS.HOTEL_DEFAULT_LOGO) {
            setHotelBootVideo(DEFS.HOTEL_NO_BOOT_VIDEO);
        }
        if (mFactoryAdapter.getHotelScreenPosition()) {
            setHotelScreenPosition(false);
        }
        if (mFactoryAdapter.getHotelSilentInstal()) {
            setHotelSilentInstal(false);
        }
        if (mFactoryAdapter.getStandbyLEDIndicatorMode() != 0) {
            setStandbyLEDIndicatorMode(0);
        }
        String appName = mFactoryAdapter.getHotelLauncherAppName();
        if (!(appName == null || appName.equals("") || appName.equals("null"))) {
            setHotelLauncherAppName("Null");
            setHotelLauncherActivityName("Null");
        }
    }

    public static long getDataRemainingSpace() {
        Debug.v(TAG, "getDataRemainingSpace");
        StatFs sf = new StatFs("/data");
        long blockSize = sf.getBlockSize();
        long blockCount = sf.getBlockCount();
        long availCount = sf.getAvailableBlocks();

        long remainingSize = availCount * blockSize - DEFS.DATA_PARTION_REMAIN_SIZE;
        Debug.v(TAG, "blockSize = " + blockSize + ",blockCount = " + blockCount + ",availCount = " + availCount + ",remainingSize = " + remainingSize);
        return remainingSize;
    }

    public static void hotel_clone_sync_db() {
        mFactoryAdapter.setHotelBootLogo(mFactoryAdapter.getHotelBootLogo());
        setHotelBootAnimation(mFactoryAdapter.getHotelBootAnimation());
        setHotelBootVideo(mFactoryAdapter.getHotelBootVideo());
        setHotelScreenPosition(mFactoryAdapter.getHotelScreenPosition());
        setHotelSilentInstal(mFactoryAdapter.getHotelSilentInstal());
        setPowerModeValue(mFactoryAdapter.getHotelPowerOnMode());
        setStandbyLEDIndicatorMode(mFactoryAdapter.getStandbyLEDIndicatorMode());
        setHotelLauncherAppName(mFactoryAdapter.getHotelLauncherAppName());
        setHotelLauncherActivityName(mFactoryAdapter.getHotelLauncherActivityName());
    }

    public static void HotelwirteMd5ToFile(String fileName) {
        String md5FileName = DEFS.UserLogoPath + DEFS.HotelMD5FileName;
        String f = DEFS.UserLogoPath + fileName;
        String md5_str = Utils.getFileMD5String(f);
        if (md5_str != null) {
            Debug.d(TAG, fileName + " md5 = " + md5_str);
            String str = fileName + ":" + md5_str;
            Utils.writeTxtFile(md5FileName, str);
            return;
        }
        Debug.d(TAG, "HotelwirteMd5ToFile can't find file:" + fileName);
    }

    public static void createHotelMd5File() {
        Debug.d(TAG, "start createHotelMd5File");
        String cmd = "rm -f " + DEFS.UserLogoPath + DEFS.HotelMD5FileName;
        setRootSeek(cmd);

        HotelwirteMd5ToFile(HotelLogoName);
        HotelwirteMd5ToFile(DEFS.PowerAnimaionName);
        HotelwirteMd5ToFile(DEFS.PowerVideoName);
        HotelwirteMd5ToFile(DEFS.PowerVideoIniName);
        Debug.d(TAG, "end createHotelMd5File");
    }

    public static boolean CheckHotelFileMD5() {
        Debug.d(TAG, "CheckHotelFileMD5 start");
        boolean ret = false;
        File f1 = new File(DEFS.UserLogoPath + HotelLogoName);
        if (f1.exists()) {
            if (!CheckFileMD5(HotelLogoName)) {
                Debug.e(TAG, HotelLogoName + " MD5 check ERROR!!");
                return false;
            }
        }
        File f2 = new File(DEFS.UserLogoPath + DEFS.PowerAnimaionName);
        if (f2.exists()) {
            if (!CheckFileMD5(DEFS.PowerAnimaionName)) {
                Debug.e(TAG, DEFS.PowerAnimaionName + " MD5 check ERROR!!");
                return false;
            }
        }
        File f3 = new File(DEFS.UserLogoPath + DEFS.PowerVideoName);
        if (f3.exists()) {
            if (!CheckFileMD5(DEFS.PowerVideoName)) {
                Debug.e(TAG, DEFS.PowerVideoName + " MD5 check ERROR!!");
                return false;
            }
        }
        File f4 = new File(DEFS.UserLogoPath + DEFS.PowerVideoIniName);
        if (f4.exists()) {
            if (!CheckFileMD5(DEFS.PowerVideoIniName)) {
                Debug.e(TAG, DEFS.PowerVideoIniName + " MD5 check ERROR!!");
                return false;
            }
        }
        Debug.d(TAG, "CheckHotelFileMD5 end");
        return true;
    }

    public static boolean CheckFileMD5(String fileName) {

        String md5File = DEFS.UserLogoPath + DEFS.HotelMD5FileName;
        boolean ret = false;

        File file = new File(md5File);
        if (!file.exists()) {
            Debug.d(TAG, md5File + " doesn't not exist.");
            return ret;
        } else {
            try {
                BufferedReader buffreader = new BufferedReader(new FileReader(file));
                String line;
                while ((line = buffreader.readLine()) != null) {
                    Debug.d(TAG, line);
                    if (line.contains(fileName)) {
                        int index = line.indexOf(":");
                        if (index > 0 && index < line.length()) {
                            String md5 = line.substring(index + 1);
                            Debug.d(TAG, fileName + " md5 = " + md5);
                            if (Utils.md5check_key(DEFS.UserLogoPath + fileName, md5)) {
                                ret = true;
                                break;
                            }
                        }
                    }
                }
                buffreader.close();
            } catch (IOException e) {
                Debug.d(TAG, e.getMessage());
            }
        }
        return ret;
    }

    public static boolean setHotelLauncherAppName(String name) {
        Debug.v(TAG, "setHotelLauncherAppName =" + name);
        SystemProperties.set(DEFS.HOTEL_PROPERTY_HOTEL_USER_APP, name);
        mFactoryAdapter.setHotelLauncherAppName(name);
        return true;
    }

    public static boolean setHotelLauncherActivityName(String name) {
        Debug.v(TAG, "setHotelLauncherActivityName =" + name);
        SystemProperties.set(DEFS.HOTEL_PROPERTY_HOTEL_USER_ACTIVITY, name);
        mFactoryAdapter.setHotelLauncherActivityName(name);
        return true;
    }

    public static void setLogoApi(String path) {
        Log.d(TAG, "setLogoApi: " + path);
        if (path.endsWith(".raw") || path.endsWith(".jpg")) {
            path = new File(path).getParent();
        }
        if (!new File(path, "logo.raw").exists() && !new File(path, "logo.jpg").exists()) {
            Log.e(TAG, "setLogoApi: logo file not found");
            return;
        }
        Log.i(TAG, "set memory.factory.hotel.path: " + path);
        TvManager.getInstance(mContext).getProperty().set("memory.factory.hotel.path", path);
        setHotelBootLogo(DEFS.HOTEL_USER_LOGO);
    }

    public static void setPowerAnimation(int value) {
        switch (value) {
            case DEFS.HOTEL_DEFAULT_LOGO:
                if (setHotelBootAnimation(DEFS.HOTEL_DEFAULT_LOGO)) {
                    Toast.makeText(mContext, "Set up success!!", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(mContext, "Error!!Set up fail!!", Toast.LENGTH_SHORT).show();
                }
                break;
            case DEFS.HOTEL_NO_LOGO:
                //SetNoPowerAnimation();
                if (setHotelBootAnimation(DEFS.HOTEL_NO_LOGO)) {
                    Toast.makeText(mContext, "Set up success!!", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(mContext, "Error!!Set up fail!!", Toast.LENGTH_SHORT).show();
                }
                break;
            case DEFS.HOTEL_USER_LOGO:
                CheckUserBootAnimation();
                break;
            default:
                break;
        }
    }

    public static void setVideoApi(String path) {
        final File dir = new File(path);
        if (!dir.exists() || !dir.isDirectory()) {
            Log.e(TAG, "setVideoApi: " + path + " is not a valid directory");
            return;
        }
        final File videoFile = new File(path, DEFS.PowerVideoName);
        final File iniFile = new File(path, DEFS.PowerVideoIniName);
        if (!videoFile.exists()) {
            Log.e(TAG, "setVideoApi: " + videoFile.getAbsolutePath() + " not exists");
            return;
        }
        if (!iniFile.exists()) {
            Log.e(TAG, "setVideoApi: " + iniFile.getAbsolutePath() + " not exists");
            return;
        }

        setRootSeek("mkdir -p " + DEFS.UserLogoPath);
        setRootSeek("cp -f '" + videoFile.getAbsolutePath() + "' " + (DEFS.UserLogoPath + DEFS.PowerVideoName));
        setRootSeek("chmod 777 " + (DEFS.UserLogoPath + DEFS.PowerVideoName));
        setRootSeek("cp -f '" + iniFile.getAbsolutePath() + "' " + (DEFS.UserLogoPath + DEFS.PowerVideoIniName));
        setRootSeek("chmod 777 " + (DEFS.UserLogoPath + DEFS.PowerVideoIniName));
        setRootSeek("sync");

        setHotelBootVideo(DEFS.HOTEL_USER_BOOT_VIDEO);
    }

    public static void setSourceTypeApi(int type) {//hubin add 20180417
        EnTCLInputSource inputSource = EnTCLInputSource.EN_TCL_ATV;

        switch (type) {
            case DEFS.HOTEL_SOURCE_ATV:
                inputSource = EnTCLInputSource.EN_TCL_ATV;
                break;
            case DEFS.HOTEL_SOURCE_DTV:
                inputSource = EnTCLInputSource.EN_TCL_DTV;
                break;
            case DEFS.HOTEL_SOURCE_AV2:
                inputSource = EnTCLInputSource.EN_TCL_AV1;
                break;
            case DEFS.HOTEL_SOURCE_YPBPR:
                inputSource = EnTCLInputSource.EN_TCL_YPBPR;
                break;
            case DEFS.HOTEL_SOURCE_HDMI1:
                inputSource = EnTCLInputSource.EN_TCL_HDMI1;
                break;
            case DEFS.HOTEL_SOURCE_HDMI2:
                inputSource = EnTCLInputSource.EN_TCL_HDMI2;
                break;
            case DEFS.HOTEL_SOURCE_HDMI3:
                inputSource = EnTCLInputSource.EN_TCL_HDMI3;
                break;
            case DEFS.HOTEL_SOURCE_VGA:
                inputSource = EnTCLInputSource.EN_TCL_VGA;
                break;
            case DEFS.HOTEL_SOURCE_STORAGE:
                inputSource = EnTCLInputSource.EN_TCL_STORAGE;
                break;
            default:
                break;
        }

        mTvCommonManager.setInputSource(inputSource, true);
        Debug.v(TAG, "setSourceType : " + type);
//		Utils.showSourceType(Utils.getSourceName(type, index));
//		Debug.v(TAG, "setSourceType : " + type + "," + index);
    }


    public static String getSourceTypeApi() {//hubin add 20180417
        String str = "";
        EnTCLInputSource inputSource = mTvCommonManager.getCurrentInputSource();
        Log.v(TAG, "getCurrentInputSource" + inputSource);
        switch (inputSource) {
            case EN_TCL_ATV:
                str = "ATV";
                break;
            case EN_TCL_DTV:
                str = "DTV";
                break;
            case EN_TCL_AV1:
                str = "AV";
                break;
            case EN_TCL_HDMI1:
                str = "HDMI";
                break;
            case EN_TCL_HDMI2:
                str = "HDMI2";
                break;
            case EN_TCL_HDMI3:
                str = "HDMI3";
                break;
            case EN_TCL_STORAGE:
                str = "STORAGE";
                break;
            default:
                str = "STORAGE";
        }
        Debug.v(TAG, "getSourceType : " + str);
        return str;
    }

    public static int getCurrentChannelNumber() {

        return mTvChannelManager.getCurrentChannelNumber();
    }

    public static boolean isSignalSource(String sourceName) {
        boolean isHasSignal_HDMI1 = TTvCommonManager.getInstance(null).isInserted(EnTCLInputSource.EN_TCL_HDMI1);
        boolean isHasSignal_HDMI2 = TTvCommonManager.getInstance(null).isInserted(EnTCLInputSource.EN_TCL_HDMI2);
        boolean isHasSignal_HDMI3 = TTvCommonManager.getInstance(null).isInserted(EnTCLInputSource.EN_TCL_HDMI3);
        if (sourceName == null || sourceName.trim().length() <= 0) {
            return false;
        }
        switch (sourceName) {
            case defs.EN_TCL_HDMI1:
                return isHasSignal_HDMI1;
            case defs.EN_TCL_HDMI2:
                return isHasSignal_HDMI2;
            case defs.EN_TCL_HDMI3:
                return isHasSignal_HDMI3;
            default:
                return false;
        }
    }


    public static void showToastForBootAnimation(String tips) {
        String isShowLogoTotast = SystemProperties.get(defs.SHOW_VIDEO_TOAST, "true");
        if (isShowLogoTotast.equals("true")) {
            Toast.makeText(mContext, tips, Toast.LENGTH_SHORT).show();
        } else {
            SystemProperties.set(defs.SHOW_VIDEO_TOAST, "true");
        }
    }

    /**
     * @param retainColon whether or not to carry with colon
     * @return wired mac address
     */
    public static String getEthMacAddress(boolean retainColon) {
        final String macPath = "/sys/class/net/eth0/address";
        File address = new File(macPath);
        String buff = null;
        if (address.exists()) {
            BufferedReader br;
            try {
                br = new BufferedReader(new FileReader(macPath));
                buff = br.readLine();
                if (!retainColon) {
                    buff = buff.replace(":", "");
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (buff != null) {
            buff = buff.toUpperCase();
        }
        return buff;
    }

    public static boolean setRootSeek(String cmd) {
        return mFactoryAdapter.setRootSeek(cmd);
    }
}


