package sto.android.app;

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import sto.android.os.SystemProperties;
import android.provider.Settings;
import android.util.Log;
import android.view.KeyEvent;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;

import kaicom.android.app.impl.Device;
import kaicom.android.app.impl.Device.ScanCallback;
import kaicom.android.app.impl.MeigDevice;
import sto.android.app.manager.ModifyAudioManager;
import sto.android.app.manager.SetRegisterManager;

/**
 * 凯立实现类
 *
 * @author Don
 */
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public class KaicomJNI implements StoJNI {

    private static final String KAICOM_DISABLE_USB_DEBUG = "com.kaicom.disable_usb_debug";
    private static final String KAICOM_DISABLE_SCREEN_LOCK = "com.kaicom.disable.screen_lock";
    private static final String KAICOM_DISABLE_INSTALL_PACKAGE = "com.kaicom.disable.install.package";
    private static final String KAICOM_DISABLE_STATUSBAR_EXPAND = "com.kaicom.disable_statusbar_expand";
    private static final String KAICOM_SYSTEM_REBOOT = "com.kaicom.system_reboot";
    private static final String KAICOM_SYSTEM_SHUTDOWN = "com.kaicom.system_shutdown";
    private static final String KAICOM_SET_SYSTEM_TIME = "com.kaicom.set_system_time";
    private static final String KAICOM_SET_MACHINE_CODE = "com.kaicom.set.machine.code";
    private static final String KAICOM_SET_GPIO_STATUS = "com.kaicom.set.gpio.status";
    public static final String KAICOM_DISABLE_KEYPAD = "com.kaicom.disable_keypad";
    public static final String KAICOM_DISABLE_KEYPAD_STRING = "kaicom_disable_keypad_string";
    private static final String KAICOM_DISABLE_KEYDOWN_TONE = "com.kaicom.disable.keydowntone";
    private static final String KAICOM_DISABLE_SCAN_MESSAGE = "com.kaicom.disable.scan.message";
    private static final String KAICOM_DISABLE_TOUCH_SCREEN = "com.kaicom.disable.touch_screen";
    private static final String KAICOM_DISABLE_SCAN_MESSAGE_ENTER = "com.kaicom.disable.scan.message.enter";
    private static final String KAICOM_ANYKEY_WAKEUP = "com.kaicom.anykey.wakeup";
    private static final String KAICOM_INSTALL_PACKAGE_WITH_SILENCE = "com.kaicom.install.packege.with.silence";
    private static final String KAICOM_INSTALL_PACKAGE_EXTRA_APK_PATH = "com.kaicom.install.packege.extra.apk.path";
    private static final String KAICOM_INSTALL_PACKAGE_EXTRA_TIPS_FORMAT = "com.kaicom.install.packege.extra.tips.format";
    private static final String KAICOM_DISABLE_BROWSER = "com.kaicom.disable.browser";
    private static final String KAICOM_CONFIG_GPS_STATUS = "com.kaicom.config.gps.status";
    private static final String KAICOM_ENABLE_SCANNER_MESSAGE_TONE = "com.kaicom.enable.scannerMessage.tone";

    private static KaicomJNI kaicomJNI;
    private static String TAG = "kaicomJNI";
    private Context mContext;
    private int mScanModel = 0;
    private int mPlatform = 0;
    KaiScanner2D mScanner = null;
    private static ScanCallBack mScanCB;
    String mScanCode;
    private static int mScannerCounter = 0;
    private static Boolean newScanInterface = false;
    private static Boolean newScanInterfaceScanning = false;
    private Device meig;
    public static final int PLATFORM_WDT420 = 1;// 用于平台区分
    public static final int PLATFORM_WDT585 = 2;
    public static final int PLATFORM_WDT520 = 3;
    public static final int PLATFORM_WDT521 = 3;
    public static final int PLATFORM_WDT520S = 3;
    public static final int PLATFORM_WDT585P = 3;
    public static final int PLATFORM_WDT510 = 4;
    public static final int PLATFORM_WDT550 = 5;
    public static final int PLATFORM_WDTK7 = 3;
    public static final int PLATFORM_WDTK2 = 3;
    public static final int PLATFORM_WDT560 = 7;
    public static final int PLATFORM_W170 = 6;// added by xlf@kaicom.cn for W170
    public static final int PLATFORM_WDTK9 = 8;

    static {

        if (new Build().MODEL.equals("520") || new Build().MODEL.equals("521")
                || new Build().MODEL.endsWith("520S")
                || new Build().MODEL.endsWith("585P")) {
            System.loadLibrary("kaicom520");
        } else if (new Build().MODEL.equals("510")) {
            System.loadLibrary("kaicom510");
        } else if (new Build().MODEL.equals("585")) {
            System.loadLibrary("kaicom585");
        } else if (new Build().MODEL.equals("420")) {
            System.loadLibrary("kaicom420");
        } else if (new Build().MODEL.equals("550")) {
            System.loadLibrary("kaicom550");
        } else if (new Build().MODEL.equals("K7")) {
            if (Build.VERSION.SDK_INT > 22) {
                System.loadLibrary("kaicomk7u");
            } else {
                // modified by xlf@kaicom.cn for k7 2.0 begin
                if (new Build().DISPLAY.substring(2, 4).equals("72")) {
                    Log.i("KaicomJNI", "k7 2.0");
                    System.loadLibrary("kaicomk7s");
                } else {
                    Log.i("KaicomJNI", "k7");
                    System.loadLibrary("kaicomk7");
                }
            }
            // modified by xlf@kaicom.cn for k7 2.0 end
        } else if (new Build().MODEL.equals("K2")) {
            System.loadLibrary("kaicomk2");
        } else if (new Build().MODEL.equals("570")) {
            if(Build.VERSION.SDK_INT > 22){
                System.loadLibrary("kaicom570n");
            }else{
                System.loadLibrary("kaicom570");
            }

        } else if (new Build().MODEL.equals("560")) {
            // added by xlf@kaicom.cn for W170 begin
        } else if (new Build().MODEL.equals("W170")) {
            // added by xlf@kaicom.cn for W170 end
        } else if (new Build().MODEL.equals("K9")) {

        } else if (Build.MODEL.equals("K211")) {
            System.loadLibrary("kaicomk211");
        } else if(Build.MODEL.equals("W571")){
            System.loadLibrary("kaicomk571");
        }else {
            System.loadLibrary("kaicom420");
        }
    }

    private KaicomJNI(Context context) {
        mContext = context;
        if (new Build().MODEL.equals("560")) {
            mScanModel = MODEL_EM1350;
            meig = new MeigDevice(mContext);
            meig.registerListener(new ScanCallback() {

                @Override
                public void onDeviceScanResultWithType(String str, int type) {
                    mScanCB.onScanResults(str, type);
                }

                @Override
                public void onDeviceScanResult(String str) {
                    mScanCB.onScanResults(str);
                }
            });
            // added by xlf@kaicom.cn for W170 begin-003
        } else if (new Build().MODEL.equals("W170")) {
            mScanModel = MODEL_W170;
            // added by xlf@kaicom.cn for W170 end-003
        } else if (new Build().MODEL.equals("K9")) {
            mScanModel = MODEL_K9;
        } else {
            mScanModel = getmScanModel();
        }
        if (new Build().MODEL.equals("560")) {
            mPlatform = PLATFORM_WDT560;
        } else if (new Build().MODEL.equals("W170")) {
            mPlatform = PLATFORM_W170;
        } else if (new Build().MODEL.equals("K9")) {
            mPlatform = PLATFORM_WDTK9;
        } else {
            mPlatform = getPlatform();
        }
        if (mScanModel == MODEL_SE4500 || mScanModel == MODEL_SE4710
                || mScanModel == MODEL_SE4710_TC || mScanModel == MODEL_HN5600) {
            if (SystemProperties.get("ro.boogoob.broadcast.interface").equals(
                    "1")) {
                newScanInterface = true;
            }
        } else if (new Build().MODEL.equals("W170") || new Build().MODEL.equals("K9")) {
            newScanInterface = true;
        }
    }

    public static KaicomJNI getInstance(Context context) {
        if (kaicomJNI == null) {
            kaicomJNI = new KaicomJNI(context);
            IntentFilter inFilter = new IntentFilter(
                    "com.kaicom.cenon.receivescanaction");
            BroadcastReceiver br = new BroadcastReceiver() {
                @Override
                public void onReceive(Context arg0, Intent arg1) {
                    if ("com.kaicom.cenon.receivescanaction".equals(arg1
                            .getAction().toString())) {
                        Log.i(TAG, "result" + arg1.getStringExtra("data"));
                        if (mScanCB != null) {
                            mScanCB.onScanResults(arg1.getStringExtra("data"));
                            mScanCB.onScanResults(arg1.getStringExtra("data"),
                                    arg1.getIntExtra("type", -1));
                        }
                        newScanInterfaceScanning = false;
                    }
                }
            };
            context.getApplicationContext().registerReceiver(br, inFilter);
        }
        return kaicomJNI;
    }

    /**
     * 获取平台号。
     *
     * @return 1=PLATFORM_WDT420，2=PLATFORM_WDT585 3 = PLATFORM_WDT520,4 =
     * PLATFORM_WDT510, 5 = PLATFORM_WDT550;
     */
    public native int GetPlatform();

    public native void SetGPIOStatus(int gpio, int status);

    @Override
    public void SetGPIOStatusJNI(int gpio, int status) {
        SetGPIOStatus(gpio, status);
    }

    private native void setScannerOn();

    @Override
    public void SetScannerOn() {
        if (new Build().MODEL.equals("560")) {
            Log.i(TAG, "SCAN_ENABLE");
            if (meig != null) {
                meig.barcodeOn();
                meig.setScanMode(false);
            }
        } else {
            if (newScanInterface) {
                Intent intent = new Intent(KAICOM_ENABLE_SCANNER_MESSAGE_TONE);
                intent.putExtra(KAICOM_ENABLE_SCANNER_MESSAGE_TONE, false);
                if (mContext != null)
                    mContext.sendBroadcast(intent);
                Intent scanner = new Intent("com.kaicom.scanner");
                scanner.putExtra("setscanner", "on");
                mContext.sendBroadcast(scanner);
                newScanInterfaceScanning = false;
            } else {
                try {
                    RandomAccessFile file = new RandomAccessFile(
                            "/sdcard/scanner", "rw");
                    try {
                        file.seek(0);
                        System.out.println("######## file read");
                        mScannerCounter = file.readInt();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }

                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                }

                if (mScanModel == MODEL_SE4500 || mScanModel == MODEL_SE4710
                        || mScanModel == MODEL_SE4710_TC) {
                    if (mScanner == null) {
                        mScanner = new KaiScanner2D(mScanCB);
                    }
                    mScanner.doOpen(mContext);
                    toUser_ics();
                } else {
                    setScannerOn();
                }
            }
        }
    }

    private native void setScannerStart();

    @Override
    public void SetScannerStart() {
        if (new Build().MODEL.equals("560")) {
            Log.i("xlf", "barcodeStartDecode");
            if (meig != null)
                meig.barcodeStartDecodeAPP();
        } else {
            if (newScanInterface) {
                Intent scanner = new Intent("com.kaicom.scanner");
                scanner.putExtra("setscanner", "start");
                mContext.sendBroadcast(scanner);
                newScanInterfaceScanning = true;
            } else {

                if (mScanModel == MODEL_SE4500 || mScanModel == MODEL_SE4710
                        || mScanModel == MODEL_SE4710_TC) {
                    if (mScanner == null) {
                        mScanner = new KaiScanner2D(mScanCB);
                    }
                    mScanner.doStart();
                } else
                    setScannerStart();
            }
        }
    }

    /**
     * 停止扫描
     */
    private native void setScannerStop();

    @Override
    public void SetScannerStop() {
        if (new Build().MODEL.equals("560")) {
            if (meig != null)
                meig.barcodeStopDecode();
        } else {
            if (newScanInterface) {
                Intent scanner = new Intent("com.kaicom.scanner");
                scanner.putExtra("setscanner", "stop");
                mContext.sendBroadcast(scanner);
                newScanInterfaceScanning = false;
            } else {
                if (mScanModel == MODEL_SE4500 || mScanModel == MODEL_SE4710
                        || mScanModel == MODEL_SE4710_TC) {
                    if (mScanner == null) {
                        mScanner = new KaiScanner2D(mScanCB);
                    }
                    mScanner.doStop();
                } else {
                    setScannerStop();
                }
            }
        }
    }

    private native void setScannerOff();

    @Override
    public void SetScannerOff() {
        if (new Build().MODEL.equals("560")) {
            if (meig != null)
                meig.barcodeOff();
        } else {
            if (newScanInterface) {
                Intent scanner = new Intent("com.kaicom.scanner");
                scanner.putExtra("setscanner", "off");
                mContext.sendBroadcast(scanner);
                newScanInterfaceScanning = false;
            } else {
                if (mScanModel == MODEL_SE4500 || mScanModel == MODEL_SE4710
                        || mScanModel == MODEL_SE4710_TC) {
                    if (mScanner == null) {
                        mScanner = new KaiScanner2D(mScanCB);
                    }
                    // mScanner.doClose();
                    Log.e("xujiademo", "isAllowScreenShotChordEnabled1111111");
                    toUser_ics();// added by xujia
                    mScanner.doSetValue(306, 0);
                    mScanner.doSetValue(298, 0);
                    mScanner.doStart();
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException ex) {
                        // Log.e("0305", "interrupted!!!!!");
                    }

                    toUserr_ics();// added by xujia
                    mScanner.doStop();
                    mScanner.doClose();
                    toRoot_ics();
                    Log.d("xujiademo", "isAllowScreenShotChordEnabled2222222");
                } else {
                    setScannerOff();
                }
            }
        }
    }

    private void toUserr_ics() {
        try {
            execCommand(new String[]{
                    "/system/bin/sh",
                    "-c",
                    "echo 2"
                            + " > /sys/module/tpd_setting/parameters/sdl_camera"});
        } catch (Exception e) {

            android.util.Log.d("xujiademo", "isAllowScreenShotChordEnabled e=="
                    + e);
        }
    }

    private void toUser_ics() {
        try {
            execCommand(new String[]{
                    "/system/bin/sh",
                    "-c",
                    "echo 0"
                            + " > /sys/module/tpd_setting/parameters/sdl_camera"});
        } catch (Exception e) {

            android.util.Log.d("xujiademo", "isAllowScreenShotChordEnabled e=="
                    + e);
        }
    }

    private void toRoot_ics() {
        try {
            execCommand(new String[]{
                    "/system/bin/sh",
                    "-c",
                    "echo 1"
                            + " > /sys/module/tpd_setting/parameters/sdl_camera"});
        } catch (Exception e) {
            android.util.Log.d("xujiademo", "isAllowScreenShotChordEnabled e=="
                    + e);
        }

    }

    public static final String ERROR = "ERROR";
    private static StringBuilder sResult = new StringBuilder("");

    public static int execCommand(String[] command) throws IOException {
        Runtime runtime = Runtime.getRuntime();
        Process proc = runtime.exec(command);
        InputStream inputstream = proc.getInputStream();
        InputStreamReader inputstreamreader = new InputStreamReader(inputstream);
        BufferedReader bufferedreader = new BufferedReader(inputstreamreader);

        sResult.delete(0, sResult.length());
        try {
            if (proc.waitFor() == 0) {
                String line;
                while ((line = bufferedreader.readLine()) != null) {
                    sResult.append(line);
                }
                return 0;

            } else {
                return -1;
            }
        } catch (InterruptedException e) {
            return -1;
        } finally {
            if (null != bufferedreader) {
                try {
                    bufferedreader.close();
                } catch (IOException e) {
                }
            }
        }
    }

    private native int setScannerPara(int para, int value);

    private native int getScannerPara(int para);

    private native String setScannerStringPara(String para, String value);

    private native String getScannerStringPara(String para);

    @Override
    public int SetScannerPara(int para, int value) {
        if (new Build().MODEL.equals("560")) {
            int ret = -1;
            if (meig != null) {
                ret = meig.getScannerParaInt(para);
            }
            return ret;
        } else if (new Build().MODEL.equals("W170")) {
            return 1;
        } else if (mScanModel != MODEL_HN5600) {
            return setScannerPara(para, value);
        } else {
            return 1;
        }
    }

    @Override
    public int GetScannerPara(int para) {
        int ret = -1;
        if (mScanModel != MODEL_HN5600 && !new Build().MODEL.equals("560")
                && !new Build().MODEL.equals("W170")) {
            ret = getScannerPara(para);
        }
        return ret;
    }

    @Override
    public String SetScannerPara(String para, String value) {
        return setScannerStringPara(para, value);
    }

    @Override
    public String GetScannerPara(String para) {
        return getScannerStringPara(para);
    }

    private native void setScannerRetriger();

    @Override
    public void SetScannerRetriger() {
        if (newScanInterface) {

        } else {
            if (mScanModel == MODEL_SE4500 || mScanModel == MODEL_SE4710
                    || mScanModel == MODEL_SE4710_TC) {
                if (mScanner == null) {
                    mScanner = new KaiScanner2D(mScanCB);
                }
                mScanner.resetTrigger();
            } else
                setScannerRetriger();
        }
    }

    private native void setScannerTimerOut(int sec);

    @Override
    public void SetScannerTimerOut(int sec) {
        if (newScanInterface) {

        } else {
            if (mScanModel == MODEL_SE4500 || mScanModel == MODEL_SE4710
                    || mScanModel == MODEL_SE4710_TC) {
                if (mScanner == null) {
                    mScanner = new KaiScanner2D(mScanCB);
                }
                mScanner.setTimeout(sec);
            } else
                setScannerTimerOut(sec);
        }
    }

    private native boolean getScannerIsScanning();

    @Override
    public boolean GetScannerIsScanning() {
        if (newScanInterface) {
            return newScanInterfaceScanning;
        } else {
            if (new Build().MODEL.equals("560")) {
                if (meig != null) {
                    return meig.isScanning();
                } else {
                    return true;
                }
            } else {
                if (mScanModel == MODEL_SE4500 || mScanModel == MODEL_SE4710
                        || mScanModel == MODEL_SE4710_TC) {
                    if (mScanner == null) {
                        mScanner = new KaiScanner2D(mScanCB);
                    }
                    return mScanner.isScanning();
                } else
                    return getScannerIsScanning();
            }
        }
    }

    public native int GetScannerModel();

    @Override
    public int getmScanModel() {
        if (new Build().MODEL.equals("560")) {
            return MODEL_EM1350;
        } else if (new Build().MODEL.equals("W170")) {
            return MODEL_W170;
        } else if (new Build().MODEL.equals("K9")) {
            return MODEL_K9;
        }
        return GetScannerModel();
    }

    private native void setSystemReboot();

    @Override
    public void SetSystemReboot() {
        if (mPlatform == PLATFORM_WDT420 || mPlatform == PLATFORM_WDT510) {
            setSystemReboot();
        } else if (mPlatform == PLATFORM_WDT550) {
            Intent intent = new Intent(KAICOM_SYSTEM_REBOOT);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        } else if (mPlatform == PLATFORM_WDT560) {
            if (meig != null)
                meig.reboot();
        } else if (mPlatform == PLATFORM_W170 || mPlatform == PLATFORM_WDTK9) {
            Intent intent = new Intent("com.kaili.reboot");
            if (mContext != null)
                mContext.sendBroadcast(intent);
        } else {
            rongQi_SetSystemReboot();
        }
    }

    private native void setSystemShutdown();

    @Override
    public void SetSystemShutdown() {
        if (mPlatform == PLATFORM_WDT420 || mPlatform == PLATFORM_WDT510) {
            setSystemShutdown();
        } else if (mPlatform == PLATFORM_WDT585 || mPlatform == PLATFORM_WDT520) {
            rongQi_SetSystemShutdown();
        } else if (mPlatform == PLATFORM_WDT550) {
            Intent intent = new Intent(KAICOM_SYSTEM_SHUTDOWN);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        } else if (mPlatform == PLATFORM_WDT560) {
            if (meig != null)
                meig.powerOff();
        } else if (mPlatform == PLATFORM_W170 || mPlatform == PLATFORM_WDTK9) {
            Intent intent = new Intent("com.kaili.shutdown");
            if (mContext != null)
                mContext.sendBroadcast(intent);
        }
    }

    private native void setSystemTime(String mm);

    @Override
    public void SetSystemTime(String mm) {
        System.out.println("#############Kaicom settime:");
        if (mPlatform == PLATFORM_WDT420 || mPlatform == PLATFORM_WDT510) {
            setSystemTime(mm);
        } else if (mPlatform == PLATFORM_WDT550) {
            Intent intent = new Intent(KAICOM_SET_SYSTEM_TIME);
            intent.putExtra("time", mm);
            if (mContext != null) {
                mContext.sendBroadcast(intent);
            }
            System.out.println("#############Kaicom2 settime:");
        } else if (mPlatform == PLATFORM_WDT560) {
            if (meig != null)
                meig.setTime(Long.parseLong(mm));
        } else if (mPlatform == PLATFORM_W170) {
            Intent intent = new Intent("com.kaili.setsystemtime");
            intent.putExtra("mm", mm);
            if (mContext != null) {
                mContext.sendBroadcast(intent);
            }
        } else if (mPlatform == PLATFORM_WDTK9) {
            long l = Long.parseLong(mm);
            Intent intent = new Intent("com.kaili.setsystemtime");
            intent.putExtra("mm", l);
            if (mContext != null) {
                mContext.sendBroadcast(intent);
            }
        } else {
            System.out.println("#############Kaicom3 settime:");
            rongQi_SetSystemTime(mm);
        }
    }

    private native void setMachineCode(String code);

    @Override
    public void SetMachineCode(String code) {
        if (mPlatform == PLATFORM_WDT420 || mPlatform == PLATFORM_WDT510) {
            setMachineCode(code);
        } else if (mPlatform == PLATFORM_WDT585 || mPlatform == PLATFORM_WDT520) {
            rongQi_SetMachineCode(code);
        } else if (mPlatform == PLATFORM_WDT550) {
            Intent intent = new Intent(KAICOM_SET_MACHINE_CODE);
            intent.putExtra(KAICOM_SET_MACHINE_CODE, code);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        } else if (mPlatform == PLATFORM_WDT560) {
            if (meig != null)
                meig.setCustomCode(code);
        } else if (new Build().MODEL.equals("W170")) {
            Intent intent = new Intent("com.sxsn.setting");
            intent.putExtra("sxsn", code);
            if (mContext != null) {
                mContext.sendBroadcast(intent);
            }
        } else if (new Build().MODEL.equals("K9")) {
            Intent intent = new Intent("com.cysn");
            intent.putExtra("cysn", code);
            if (mContext != null) {
                mContext.sendBroadcast(intent);
            }
        }
    }

    private native String getMachineCode();

    @SuppressLint("NewApi")
    @Override
    public String GetMachineCode() {
        if (mPlatform == PLATFORM_WDT420 || mPlatform == PLATFORM_WDT510) {
            return getMachineCode();
        } else if (mPlatform == PLATFORM_WDT585 || mPlatform == PLATFORM_WDT520) {
            return rongQi_GetMachineCode();
        } else if (mPlatform == PLATFORM_WDT550) {
            return Settings.Global.getString(mContext.getContentResolver(),
                    "kaicom_machine_code");
        } else if (mPlatform == PLATFORM_WDT560) {
            if (meig != null) {
                return meig.getCustomCode();
            } else {
                return null;
            }
        } else if (new Build().MODEL.equals("W170")) {
            return Settings.Global.getString(mContext.getContentResolver(),
                    "sxsn").substring(0, 15);
        } else if (new Build().MODEL.equals("K9")) {
            return Settings.Global.getString(mContext.getContentResolver(),
                    "sxsn");
        } else {
            return null;
        }
    }

    @Override
    public void disableKeypad() {
        if (new Build().MODEL.equals("560")) {
            if (meig != null)
                meig.setKeyStatus(false);
        } else {
            Intent intent = new Intent(KAICOM_DISABLE_KEYPAD);
            intent.putExtra(KAICOM_DISABLE_KEYPAD, true);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        }
    }

    @Override
    public void disableKeypadEnableCustom(String customstr) {
        Intent intent = new Intent(KAICOM_DISABLE_KEYPAD);
        intent.putExtra(KAICOM_DISABLE_KEYPAD, true);
        intent.putExtra(KAICOM_DISABLE_KEYPAD_STRING, customstr);
        if (mContext != null)
            mContext.sendBroadcast(intent);
    }

    @Override
    public void enableKeypad() {
        if (new Build().MODEL.equals("560")) {
            if (meig != null)
                meig.setKeyStatus(true);
        } else {
            Intent intent = new Intent(KAICOM_DISABLE_KEYPAD);
            intent.putExtra(KAICOM_DISABLE_KEYPAD, false);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        }
    }

    @Override
    public void enableKeydownTone() {
        if (mPlatform == PLATFORM_WDT585 || mPlatform == PLATFORM_WDT520
                || mPlatform == PLATFORM_WDT550) {
            if (mContext != null) {
                Intent intent = new Intent(KAICOM_DISABLE_KEYDOWN_TONE);
                intent.putExtra(KAICOM_DISABLE_KEYDOWN_TONE, false);
                intent.setPackage("com.android.kailibtest");
                mContext.startService(intent);
            }
        } else if (mPlatform == PLATFORM_WDT560) {
            if (meig != null)
                meig.setButtonSoundStatus(true);
        }
    }

    @SuppressLint("NewApi")
    @Override
    public int GetStatusKeydownTone() {
        if (mPlatform == PLATFORM_WDT585 || mPlatform == PLATFORM_WDT550) {
            if (mContext != null) {
                return Settings.Global.getInt(mContext.getContentResolver(),
                        "keydown_tone_enabled", 1);
            }
        }
        return 1;
    }

    @Override
    public void disableKeydownTone() {
        if (mPlatform == PLATFORM_WDT585 || mPlatform == PLATFORM_WDT520
                || mPlatform == PLATFORM_WDT550) {
            if (mContext != null) {
                Intent intent = new Intent(KAICOM_DISABLE_KEYDOWN_TONE);
                intent.putExtra(KAICOM_DISABLE_KEYDOWN_TONE, true);
                intent.setPackage("com.android.kailibtest");
                mContext.startService(intent);
            }
        } else if (mPlatform == PLATFORM_WDT560) {
            if (meig != null)
                meig.setButtonSoundStatus(false);
        }
    }

    @Override
    public void TurnOffStatusBarExpand() {
        Log.i("xlf", "TurnOffStatusBarExpand");
        if (new Build().MODEL.equals("560")) {
            if (meig != null)
                meig.setStatusBarEpxand(false);
        } else {
            Intent intent = new Intent(KAICOM_DISABLE_STATUSBAR_EXPAND);
            intent.putExtra(KAICOM_DISABLE_STATUSBAR_EXPAND, true);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        }
    }

    private native int getStatusBarExpand();

    @SuppressLint("NewApi")
    @Override
    public int GetStatusBarExpand() {
        if (new Build().MODEL.equals("W170")) {
            int value = android.provider.Settings.Global
                    .getInt(mContext.getContentResolver(),
                            "statusbar_enable_expand", 0);
            if (value == 0) {
                return 1;
            } else {
                return 0;
            }
        } else if (mPlatform == PLATFORM_WDT585) {
            if (mContext != null) {
                return Settings.Secure.getInt(mContext.getContentResolver(),
                        "statusbar_enable_expand", 1);
            } else {
                return 1;
            }
        } else if (mPlatform == PLATFORM_WDT520 || mPlatform == PLATFORM_WDT550) {
            if (mContext != null) {
                System.out.println("###########################get1："
                        + Settings.Global.getInt(mContext.getContentResolver(),
                        "statusbar_enable_expand", 1));
                return Settings.Global.getInt(mContext.getContentResolver(),
                        "statusbar_enable_expand", 1);
            } else {
                return 1;
            }
        } else if (new Build().MODEL.equals("K9")) {
            return android.provider.Settings.Global.getInt(
                    mContext.getContentResolver(), "statusbar_enabled", 0);
        } else if (mPlatform == PLATFORM_WDT560) {
            if (meig.getStatusBarEpxand()) {
                return 1;
            } else {
                return 0;
            }
        } else {
            return getStatusBarExpand();
        }
    }

    @Override
    public void TurnOnStatusBarExpand() {
        if (new Build().MODEL.equals("560")) {
            if (meig != null)
                meig.setStatusBarEpxand(true);
        } else {
            Intent intent = new Intent(KAICOM_DISABLE_STATUSBAR_EXPAND);
            intent.putExtra(KAICOM_DISABLE_STATUSBAR_EXPAND, false);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        }
    }

    @Override
    public void TurnOffUSBDebug() {
        if (new Build().MODEL.equals("560")) {
            if (meig != null)
                meig.setAdbEnable(false);
        } else {
            Intent intent = new Intent(KAICOM_DISABLE_USB_DEBUG);
            intent.putExtra(KAICOM_DISABLE_USB_DEBUG, true);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        }
    }

    private native int getStatusUSBDebug();

    @SuppressLint("NewApi")
    @Override
    public int GetStatusUSBDebug() {
        if (new Build().MODEL.equals("560")) {
            return 1;
        } else if (new Build().MODEL.equals("W170")) {
            return 1;
        } else if (new Build().MODEL.equals("K9")) {
            return Settings.Global.getInt(mContext.getContentResolver(),
                    "adb_enabled", 0);
        } else {
            if (mPlatform == PLATFORM_WDT585) {
                if (mContext != null) {
                    return Settings.Secure.getInt(
                            mContext.getContentResolver(), "adb_enabled", 0);
                } else {
                    return 0;
                }
            } else if (mPlatform == PLATFORM_WDT520
                    || mPlatform == PLATFORM_WDT550) {
                if (mContext != null) {
                    return Settings.Global.getInt(
                            mContext.getContentResolver(), "adb_enabled", 0);
                } else {
                    return 0;
                }
            } else {
                return getStatusUSBDebug();
            }
        }
    }

    @Override
    public void TurnOnUSBDebug() {
        if (new Build().MODEL.equals("560")) {
            if (meig != null)
                meig.setAdbEnable(true);
        } else {
            Intent intent = new Intent(KAICOM_DISABLE_USB_DEBUG);
            intent.putExtra(KAICOM_DISABLE_USB_DEBUG, false);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        }
    }

    @Override
    public void TurnOffInstallManager() {
        if (new Build().MODEL.equals("560")) {
            if (meig != null)
                meig.setNoInstallApkStatus(true);
        } else if (new Build().MODEL.equals("K9")) {
            Intent intent = new Intent(KAICOM_DISABLE_INSTALL_PACKAGE);
            intent.putExtra(KAICOM_DISABLE_INSTALL_PACKAGE, true);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        } else {
            Intent intent = new Intent(KAICOM_DISABLE_INSTALL_PACKAGE);
            intent.putExtra(KAICOM_DISABLE_INSTALL_PACKAGE, 0);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        }
    }

    private native int getStatusInstallManager();

    @SuppressLint("NewApi")
    @Override
    public int GetStatusInstallManager() {
        if (new Build().MODEL.equals("W170")) {
            return android.provider.Settings.Global.getInt(
                    mContext.getContentResolver(), "install_enabled", 0);
        } else if (new Build().MODEL.equals("560")) {
            if (meig.getNoInstallApkStatus()) {
                return 0;
            } else {
                return 1;
            }
        } else if (new Build().MODEL.equals("K9")) {
            return android.provider.Settings.Global.getInt(
                    mContext.getContentResolver(), "install_enabled", 0);
        } else {
            if (mPlatform == PLATFORM_WDT585) {
                if (mContext != null) {
                    return Settings.Secure
                            .getInt(mContext.getContentResolver(),
                                    "install_enabled", 1);
                } else {
                    return 1;
                }
            } else if (mPlatform == PLATFORM_WDT520
                    || mPlatform == PLATFORM_WDT550) {
                if (mContext != null) {

                    return Settings.Global
                            .getInt(mContext.getContentResolver(),
                                    "install_enabled", 1);
                } else {
                    return 1;
                }
            } else if (mPlatform == PLATFORM_WDT420
                    || mPlatform == PLATFORM_WDT510) {
                return getStatusInstallManager();
            } else {
                return -1;
            }
        }
    }

    @Override
    public void TurnOnInstallManager() {
        if (new Build().MODEL.equals("560")) {
            if (meig != null)
                meig.setNoInstallApkStatus(false);
        } else if (new Build().MODEL.equals("K9")) {
            Intent intent = new Intent(KAICOM_DISABLE_INSTALL_PACKAGE);
            intent.putExtra(KAICOM_DISABLE_INSTALL_PACKAGE, false);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        } else {
            Intent intent = new Intent(KAICOM_DISABLE_INSTALL_PACKAGE);
            intent.putExtra(KAICOM_DISABLE_INSTALL_PACKAGE, 1);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        }
    }

    @Override
    public void TurnOnScreenLock() {
        if (new Build().MODEL.equals("560")) {
            if (meig != null)
                meig.setKeyguardEnable(true);
        } else {
            Intent intent = new Intent(KAICOM_DISABLE_SCREEN_LOCK);
            intent.putExtra(KAICOM_DISABLE_SCREEN_LOCK, false);
            if (mPlatform == PLATFORM_WDT420 || mPlatform == PLATFORM_WDT550) {
                if (mContext != null)
                    mContext.sendBroadcast(intent);
            } else if (mPlatform == PLATFORM_WDT585
                    || mPlatform == PLATFORM_WDT510
                    || mPlatform == PLATFORM_WDT520) {
                intent.setPackage("com.android.kailibtest");
                if (mContext != null)
                    mContext.startService(intent);
            }
        }
    }

    private native int getStatusScreenLock();

    @SuppressLint("NewApi")
    @Override
    public int GetStatusScreenLock() {
        if (mPlatform == PLATFORM_WDT585) {
            if (mContext != null) {

                return Settings.System.getInt(mContext.getContentResolver(),
                        "screen_lock_on", 1);
            } else {
                return 1;
            }
        } else if (mPlatform == PLATFORM_WDT520 || mPlatform == PLATFORM_WDT550) {
            if (mContext != null) {
                System.out.println("###########################get3："
                        + Settings.System.getInt(mContext.getContentResolver(),
                        "screen_lock_on", 1));
                return Settings.Global.getInt(mContext.getContentResolver(),
                        "screen_lock_on", 1);
            } else {
                return 1;
            }
        } else if (mPlatform == PLATFORM_WDT420) {
            if (mContext != null)
                return Settings.Secure.getInt(mContext.getContentResolver(),
                        KAICOM_DISABLE_SCREEN_LOCK, 1);
            else {
                return 1;
            }
        } else if (mPlatform == PLATFORM_WDT510) {
            return getStatusScreenLock();
        } else if (mPlatform == PLATFORM_WDT560) {
            if (meig.getKeyguardEnable()) {
                return 1;
            } else {
                return 0;
            }
        } else {
            return -1;
        }
    }

    @Override
    public void TurnOffScreenLock() {
        if (new Build().MODEL.equals("560")) {
            if (meig != null)
                meig.setKeyguardEnable(false);
        } else {
            Intent intent = new Intent(KAICOM_DISABLE_SCREEN_LOCK);
            intent.putExtra(KAICOM_DISABLE_SCREEN_LOCK, true);
            if (mPlatform == PLATFORM_WDT420 || mPlatform == PLATFORM_WDT550) {
                if (mContext != null)
                    mContext.sendBroadcast(intent);
            } else if (mPlatform == PLATFORM_WDT585
                    || mPlatform == PLATFORM_WDT510
                    || mPlatform == PLATFORM_WDT520) {
                intent.setPackage("com.android.kailibtest");
                if (mContext != null)
                    mContext.startService(intent);
            }
        }
    }

    private native int getStatusWakeUp();

    @Override
    public int GetStatusWakeUp() {
        if ((Build.MODEL.equals("K2") || Build.MODEL.equals("K211")||Build.MODEL.equals("W571")) && Build.VERSION.SDK_INT > 23) {
            return android.provider.Settings.Global.getInt(
                    mContext.getContentResolver(), "boogoob.anyKey.wakeup",
                    1);
        }
        if (new Build().MODEL.equals("W170")) {
            return 1;
        } else if (new Build().MODEL.equals("W560")) {
            if (meig.getWakeupEnable()) {
                return 0;
            } else {
                return 1;
            }
        } else if (new Build().MODEL.equals("K9")) {
            return android.provider.Settings.Global.getInt(
                    mContext.getContentResolver(), "powerkey_enabled", 0);
        } else {
            return getStatusWakeUp();
        }
    }

    private native void cfgPowerKeyWakeUp();

    @Override
    public void CfgPowerKeyWakeUp() {

        if (Build.MODEL.equals("K2") || Build.MODEL.equals("K211")||Build.MODEL.equals("W571")) {
            Intent intent = new Intent("com.kaicom.enable.anykeyWakeUp");
            intent.putExtra("com.kaicom.enable.anykeyWakeUp", false);
            if (mContext != null) {
                mContext.sendBroadcast(intent);
            }

            return;
        }
        if (new Build().MODEL.equals("W170")) {
            Intent intent = new Intent("com.kaicom.isScreenOn");
            intent.putExtra("com.kaicom.isScreenOn", true);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        } else if (new Build().MODEL.equals("560")) {
            if (meig != null)
                meig.setWakeupEnable(false);
        } else {
            if (mPlatform == PLATFORM_WDT585 || mPlatform == PLATFORM_WDT520
                    || mPlatform == PLATFORM_WDT510) {
                cfgPowerKeyWakeUp();
            } else if (mPlatform == PLATFORM_WDT550) {
                Intent intent = new Intent(KAICOM_ANYKEY_WAKEUP);
                intent.putExtra(KAICOM_ANYKEY_WAKEUP, false);
                if (mContext != null)
                    mContext.sendBroadcast(intent);
            }
        }
    }

    private native void cfgAnyKeyWakeUp();

    @Override
    public void CfgAnyKeyWakeUp() {
        if (Build.MODEL.equals("K2") || Build.MODEL.equals("K211")||Build.MODEL.equals("W571")) {
            Intent intent = new Intent("com.kaicom.enable.anykeyWakeUp");
            intent.putExtra("com.kaicom.enable.anykeyWakeUp", true);
            if (mContext != null) {
                mContext.sendBroadcast(intent);
            }

            return;
        }
        if (new Build().MODEL.equals("W170")) {
            Intent intent = new Intent("com.kaicom.isScreenOn");
            intent.putExtra("com.kaicom.isScreenOn", false);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        } else if (new Build().MODEL.equals("560")) {
            if (meig != null)
                meig.setWakeupEnable(true);
        } else {
            if (mPlatform == PLATFORM_WDT585 || mPlatform == PLATFORM_WDT520
                    || mPlatform == PLATFORM_WDT510) {
                cfgAnyKeyWakeUp();
            } else if (mPlatform == PLATFORM_WDT550) {
                Intent intent = new Intent(KAICOM_ANYKEY_WAKEUP);
                intent.putExtra(KAICOM_ANYKEY_WAKEUP, true);
                if (mContext != null)
                    mContext.sendBroadcast(intent);
            }
        }
    }

    // 585返回触摸屏使能状态
    private native int getStatusTouchscreen();

    // 420触摸屏开关
    private native void enableTouchpanel(int flag);

    private int getStatusTouchscreen420() {
        int ret = 0;
        if (mContext != null)
            ret = Settings.Secure.getInt(mContext.getContentResolver(),
                    KAICOM_DISABLE_TOUCH_SCREEN, 0);
        return ret;
    }

    @Override
    public void Disable_touch_screen() {
        if (new Build().MODEL.equals("560")) {
            if (meig != null)
                meig.setScreenStatus(false);
        } else {
            if (mPlatform == PLATFORM_WDT420 || mPlatform == PLATFORM_WDT550) {
                Intent intent = new Intent(KAICOM_DISABLE_TOUCH_SCREEN);
                intent.putExtra(KAICOM_DISABLE_TOUCH_SCREEN, true);
                if (mContext != null)
                    mContext.sendBroadcast(intent);
            } else if (mPlatform == PLATFORM_WDT585
                    || mPlatform == PLATFORM_WDT520
                    || mPlatform == PLATFORM_WDT510) {
                enableTouchpanel(0);
            }
        }
    }

    @Override
    public void Enable_touch_screen() {
        if (new Build().MODEL.equals("560")) {
            if (meig != null)
                meig.setScreenStatus(true);
        } else {
            if (mPlatform == PLATFORM_WDT420 || mPlatform == PLATFORM_WDT550) {
                Intent intent = new Intent(KAICOM_DISABLE_TOUCH_SCREEN);
                intent.putExtra(KAICOM_DISABLE_TOUCH_SCREEN, false);
                if (mContext != null)
                    mContext.sendBroadcast(intent);
            } else if (mPlatform == PLATFORM_WDT585
                    || mPlatform == PLATFORM_WDT520
                    || mPlatform == PLATFORM_WDT510) {
                enableTouchpanel(1);
            }
        }
    }

    @Override
    public int GetStatusTouch_screen() {
        if (new Build().MODEL.equals("560")) {
            if (meig.getScreenStatus()) {
                return 1;
            } else {
                return 0;
            }
        } else {
            if (PLATFORM_WDT420 == GetPlatform()) {
                return getStatusTouchscreen420();
            } else if (mPlatform == PLATFORM_WDT585
                    || mPlatform == PLATFORM_WDT520
                    || mPlatform == PLATFORM_WDT510
                    || mPlatform == PLATFORM_WDT550) {
                return getStatusTouchscreen();
            } else {
                return -1;
            }
        }
    }

    @Override
    public void StoJNI_InstallApkWithSilence(String apkPath,
                                             boolean runAfterFinished) {
        if (mPlatform == PLATFORM_WDT420 || mPlatform == PLATFORM_WDT510
                || mPlatform == PLATFORM_WDT520 || mPlatform == PLATFORM_WDT585
                || mPlatform == PLATFORM_WDT550) {
            Log.v("jdh", "#######################/mnt/sdcard/abc.apk install");
            Intent intent = new Intent(KAICOM_INSTALL_PACKAGE_WITH_SILENCE);
            intent.putExtra(KAICOM_INSTALL_PACKAGE_EXTRA_APK_PATH, apkPath);
            if (runAfterFinished)
                intent.putExtra(KAICOM_INSTALL_PACKAGE_EXTRA_TIPS_FORMAT, 1);
            mContext.sendBroadcast(intent);
        } else if (mPlatform == PLATFORM_WDT560) {
            if (meig != null)
                meig.installApp(apkPath);
        } else if (mPlatform == PLATFORM_W170) {
            Intent intent = new Intent("com.start.silentInStall");
            intent.putExtra("silentInStall", apkPath);
            if (mContext != null) {
                mContext.sendBroadcast(intent);
            }
        }
    }

    @Override
    public void TurnOnOffGPS(boolean set) {
        if (mPlatform == PLATFORM_WDT420 || mPlatform == PLATFORM_WDT510) {
            Intent intent = new Intent(KAICOM_CONFIG_GPS_STATUS);
            intent.putExtra(KAICOM_CONFIG_GPS_STATUS, set);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        }
    }

    @Override
    public void TurnOnOffBrowser(boolean set) {
        if (new Build().MODEL.equals("W170") || new Build().MODEL.equals("K9")) {
            Intent intent = new Intent(KAICOM_DISABLE_BROWSER);
            intent.putExtra(KAICOM_DISABLE_BROWSER, !set);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        } else if (new Build().MODEL.equals("560")) {
            if (meig != null)
                meig.setBrowserStatus(set);
        } else {
            Intent intent = new Intent(KAICOM_DISABLE_BROWSER);
            intent.putExtra(KAICOM_DISABLE_BROWSER, set);
            if (mContext != null)
                mContext.sendBroadcast(intent);
        }
    }

    private native void enableTouchHomepanel(int flag);

    private native void enableTouchMenupanel(int flag);

    private native void enableTouchBackpanel(int flag);

    private native int getStatusTouchHomescreen();

    private native int getStatusTouchMenuscreen();

    private native int getStatusTouchBackscreen();

    @Override
    public void Disable_home_touch_screen() {
        if (new Build().MODEL.equals("H8") || new Build().MODEL.equals("K2") || Build.MODEL.equals("K211")
                || new Build().MODEL.equals("K7")||Build.MODEL.equals("W571")) {
            enableTouchHomepanel(0);
        } else if (new Build().MODEL.equals("W170")) {
            Intent intent = new Intent("com.kaicom.disable_keypad.home");
            intent.putExtra("com.kaicom.disable_keypad.home", true);
            mContext.sendBroadcast(intent);
        }
    }

    @Override
    public void Enable_home_touch_screen() {
        if (new Build().MODEL.equals("H8") || new Build().MODEL.equals("K2") || Build.MODEL.equals("K211")
                || new Build().MODEL.equals("K7")||Build.MODEL.equals("W571")) {
            enableTouchHomepanel(1);
        } else if (new Build().MODEL.equals("W170")) {
            Intent intent = new Intent("com.kaicom.disable_keypad.home");
            intent.putExtra("com.kaicom.disable_keypad.home", false);
            mContext.sendBroadcast(intent);
        }
    }

    public int GetStatusTouch_Home_screen() {
        if (mPlatform == PLATFORM_WDT520) {
            return getStatusTouchHomescreen();
        } else if (new Build().MODEL.equals("W170")) {
            int value = android.provider.Settings.Global.getInt(
                    mContext.getContentResolver(), "disable_keypad_home", 0);
            if (value == 0) {
                return 1;
            } else {
                return 0;
            }
        }
        return 1;
    }

    @Override
    public void Disable_menu_touch_screen() {
        if (new Build().MODEL.equals("H8") || new Build().MODEL.equals("K2") || Build.MODEL.equals("K211")
                || new Build().MODEL.equals("K7")||Build.MODEL.equals("W571")) {
            enableTouchMenupanel(0);
        }
    }

    @Override
    public void Enable_menu_touch_screen() {
        if (new Build().MODEL.equals("H8") || new Build().MODEL.equals("K2") || Build.MODEL.equals("K211")
                || new Build().MODEL.equals("K7")||Build.MODEL.equals("W571")) {
            enableTouchMenupanel(1);
        }
    }

    @Override
    public int GetStatusTouch_Menu_screen() {
        if (mPlatform == PLATFORM_WDT520) {
            return getStatusTouchMenuscreen();
        }
        return 1;
    }

    @Override
    public void Disable_back_touch_screen() {
        if (new Build().MODEL.equals("H8") || new Build().MODEL.equals("K2") || Build.MODEL.equals("K211")
                || new Build().MODEL.equals("K7")||Build.MODEL.equals("W571")) {
            enableTouchBackpanel(0);
        }
    }

    @Override
    public void Enable_back_touch_screen() {
        if (new Build().MODEL.equals("H8") || new Build().MODEL.equals("K2") || Build.MODEL.equals("K211")
                || new Build().MODEL.equals("K7")||Build.MODEL.equals("W571")) {
            enableTouchBackpanel(1);
        }
    }

    @Override
    public int GetStatusTouch_Back_screen() {
        if (mPlatform == PLATFORM_WDT520) {
            return getStatusTouchBackscreen();
        }
        return 1;
    }

    @Override
    public void setmScanCB(ScanCallBack mScanCB) {
        System.out.println("############setmScanCB:");
        if (mScanModel == MODEL_SE4500 || mScanModel == MODEL_SE4710
                || mScanModel == MODEL_SE4710_TC) {
            if (!newScanInterface) {
                if (mScanner == null) {
                    mScanner = new KaiScanner2D(mScanCB);
                }
                mScanner = new KaiScanner2D(mScanCB);
            }
        }
        this.mScanCB = mScanCB;
    }

    public void ScanResults(String str, int type) {
        // mScanCode = str;
        System.out.println("#############扫描结果" + str);
        if (mScanCB != null) {
            mScanCB.onScanResults(str, type);
            mScanCB.onScanResults(str);
        }
    }

    @Override
    public String getPdaBrand() {
        return "kaicom";
    }

    private void rongQi_SetSystemReboot() {
        if (mPlatform == PLATFORM_WDT585 || mPlatform == PLATFORM_WDT520) {
            if (mContext != null) {
                Intent intent = new Intent("com.kaili.reboot");
                intent.setPackage("com.android.kailibtest");
                mContext.startService(intent);
            }
        }
    }

    private void rongQi_SetSystemShutdown() {
        if (mPlatform == PLATFORM_WDT585 || mPlatform == PLATFORM_WDT520) {
            if (mContext != null) {
                Intent intent = new Intent("com.kaili.shutdown");
                intent.setPackage("com.android.kailibtest");
                mContext.startService(intent);
            }
        }
    }

    private void rongQi_SetSystemTime(String mm) {
        if (mPlatform == PLATFORM_WDT585 || mPlatform == PLATFORM_WDT520) {
            if (mContext != null) {
                Intent intent = new Intent("com.kaili.setsystemtime");
                intent.putExtra("time", mm);
                intent.setPackage("com.android.kailibtest");
                mContext.startService(intent);
                System.out.println("#############K7 settime:");
            }
        }
        System.out.println("#############Kaicom4 settime:");
    }

    private void rongQi_SetMachineCode(String code) {
        if (mPlatform == PLATFORM_WDT585 || mPlatform == PLATFORM_WDT520) {
            if (mContext != null) {
                Intent intent = new Intent("com.kaili.SetMachineCode");
                intent.putExtra("com.kaili.SetMachineCode", code);
                intent.setPackage("com.android.kailibtest");
                mContext.startService(intent);
                System.out.println("########weiyima#####" + code);
            }
        }
    }

    private String rongQi_GetMachineCode() {
        if (mPlatform == PLATFORM_WDT585 || mPlatform == PLATFORM_WDT520) {
            BufferedReader buffer;
            String s;
            File file;
            try {
                InputStream in = new FileInputStream(
                        "/data/app/machine_code.txt");
                if (in != null) {
                    buffer = new BufferedReader(new InputStreamReader(in));
                    s = buffer.readLine();
                    if (s == null) {
                        return null;// "please set machine code first";
                    } else {
                        return s;
                    }
                }
                in.close();
            } catch (IOException e) {
                Log.v("Machine", e.getMessage());
            }
            return null;// "can not read";
        }
        return null;// "platform not fit";
    }

    /*******
     * //Menu public static final int Key_LeftFuntion =
     * KeyEvent.KEYCODE_MENU;//82-199 //上 public static final int Key_Up =
     * KeyEvent.KEYCODE_DPAD_UP;//19 //删除 public static final int
     * Key_RightFuntion = KeyEvent.KEYCODE_DEL;//67 //左 public static final int
     * Key_Left = KeyEvent.KEYCODE_DPAD_LEFT;//21 //OK public static final int
     * Key_OK = KeyEvent.KEYCODE_DPAD_CENTER;//23 //右 public static final int
     * Key_Right = KeyEvent.KEYCODE_DPAD_RIGHT;//22 //scan public static final
     * int Key_Dial = KeyEvent.KEYCODE_BUTTON_MODE;//110 //下 public static final
     * int Key_Down = KeyEvent.KEYCODE_DPAD_DOWN;//20 //返回 public static final
     * int Key_HangUp = KeyEvent.KEYCODE_BACK;//4
     *
     * public static final int Key_1 = KeyEvent.KEYCODE_1;//8 public static
     * final int Key_2 = KeyEvent.KEYCODE_2;//9 public static final int Key_3 =
     * KeyEvent.KEYCODE_3;//10 public static final int Key_4 =
     * KeyEvent.KEYCODE_4;//11 public static final int Key_5 =
     * KeyEvent.KEYCODE_5;//12 public static final int Key_6 =
     * KeyEvent.KEYCODE_6;//13 public static final int Key_7 =
     * KeyEvent.KEYCODE_7;//14 public static final int Key_8 =
     * KeyEvent.KEYCODE_8;//15 public static final int Key_9 =
     * KeyEvent.KEYCODE_9;//16 //* public static final int Key_Star =
     * KeyEvent.KEYCODE_STAR;//17 //0 public static final int Key_0 =
     * KeyEvent.KEYCODE_0;//7 //# public static final int Key_Pound =
     * KeyEvent.KEYCODE_POUND;//18 // F1 public static final int Key_F1 =
     * KeyEvent.KEYCODE_BUTTON_A;//96 // F2 public static final int Key_F2 =
     * KeyEvent.KEYCODE_BUTTON_B;//97 //F3 public static final int Key_F3 =
     * KeyEvent.KEYCODE_EXPLORER;//64 //F4 public static final int Key_F4 =
     * KeyEvent.KEYCODE_SOFT_RIGHT;//2 //F5 public static final int Key_F5 =
     * KeyEvent.KEYCODE_BUTTON_THUMBL;//106 //F6 public static final int Key_F6
     * = KeyEvent.KEYCODE_BUTTON_THUMBR;//107 //F7 public static final int
     * Key_F7 = KeyEvent.KEYCODE_BUTTON_L2;//104 //F8 public static final int
     * Key_F8 = KeyEvent.KEYCODE_BUTTON_R2;//105 //右圆 音量+ public static final
     * int Key_VolumeUp = KeyEvent.KEYCODE_VOLUME_UP;//24 //左圆 音量- public static
     * final int Key_VolumeDown = KeyEvent.KEYCODE_VOLUME_DOWN;//25 //左侧键盘
     * public static final int Key_ScanLeft = KeyEvent.KEYCODE_BUTTON_L1;//102
     * //右侧键盘 public static final int Key_ScanRight =
     * KeyEvent.KEYCODE_BUTTON_R1;//103
     *
     * //-------------下面是K7的键值对应关系-----------------------------------------
     *
     * //Menu（Touch Key） public static final int KeyK7_Menu =
     * KeyEvent.KEYCODE_MENU;//82 //Home（Touch Key） public static final int
     * KeyK7_Home = KeyEvent.KEYCODE_HOME;//3 //Back（Touch Key） public static
     * final int KeyK7_Back = KeyEvent.KEYCODE_BACK;//4 //LeftSoftKey public
     * static final int KeyK7_LeftSoftKey = KeyEvent.KEYCODE_DPAD_CENTER;//23
     * //MiddleScan public static final int KeyK7_Scan =
     * KeyEvent.KEYCODE_BUTTON_MODE;//110 //RightSoftKey==Back public static
     * final int KeyK7_RightSoftKey = KeyEvent.KEYCODE_BACK;//4 //LeftScan
     * public static final int KeyK7_LeftScan = KeyEvent.KEYCODE_BUTTON_L1;//102
     * //RightScan public static final int KeyK7_RightScan =
     * KeyEvent.KEYCODE_BUTTON_R1;//103 //Volume + public static final int
     * KeyK7_VolumeUp = KeyEvent.KEYCODE_VOLUME_UP;//24 //Volume - public static
     * final int KeyK7_VolumeDown = KeyEvent.KEYCODE_VOLUME_DOWN;//25 //Fn
     * public static final int KeyK7_Fn = KeyEvent.KEYCODE_F1;//131 //Lock
     * public static final int KeyK7_Lock = KeyEvent.KEYCODE_SOFT_RIGHT;//2
     * //delete public static final int KeyK7_Delete = KeyEvent.KEYCODE_DEL;//67
     * //Aa public static final int KeyK7_Aa = KeyEvent.KEYCODE_F3;//133 //Enter
     * public static final int KeyK7_Enter = KeyEvent.KEYCODE_ENTER;//66 //*
     * public static final int KeyK7_Star = KeyEvent.KEYCODE_STAR;//17 //0
     * public static final int KeyK7_0 = KeyEvent.KEYCODE_0;//7 //# public
     * static final int KeyK7_Pound = KeyEvent.KEYCODE_POUND;//18 //num 1-9
     * public static final int KeyK7_1 = KeyEvent.KEYCODE_1;//8 public static
     * final int KeyK7_2 = KeyEvent.KEYCODE_2;//9 public static final int
     * KeyK7_3 = KeyEvent.KEYCODE_3;//10 public static final int KeyK7_4 =
     * KeyEvent.KEYCODE_4;//11 public static final int KeyK7_5 =
     * KeyEvent.KEYCODE_5;//12 public static final int KeyK7_6 =
     * KeyEvent.KEYCODE_6;//13 public static final int KeyK7_7 =
     * KeyEvent.KEYCODE_7;//14 public static final int KeyK7_8 =
     * KeyEvent.KEYCODE_8;//15 public static final int KeyK7_9 =
     * KeyEvent.KEYCODE_9;//16
     */
    @Override
    public int getEventFuction(int keycode) {

        Log.d(TAG, "######" + TAG + "getEventFunction");
        if (new Build().MODEL.equals("K7")) {
            switch (keycode) {
                // scan
                // Menu（Touch Key）
                case KeyEvent.KEYCODE_MENU:// 82
                    return StoPdaKeyEvent.KEYCODE_MENU;
                // Home（Touch Key）
                case KeyEvent.KEYCODE_HOME:// 3
                    return StoPdaKeyEvent.KEYCODE_HOME;
                // Back（Touch Key）
                case KeyEvent.KEYCODE_BACK:// 4
                    return StoPdaKeyEvent.KEYCODE_BACK;
                // LeftSoftKey
                case KeyEvent.KEYCODE_DPAD_CENTER:// 23
                    return StoPdaKeyEvent.KEYCODE_DPAD_CENTER;
                // MiddleScan
                case KeyEvent.KEYCODE_BUTTON_MODE:// 110
                    // LeftScan
                case KeyEvent.KEYCODE_BUTTON_L1:// 102
                    // RightScan
                case KeyEvent.KEYCODE_BUTTON_R1:// 103
                    return StoPdaKeyEvent.KEYCODE_SCAN;
                // RightSoftKey==Back
                // case KeyEvent.KEYCODE_BACK://4
                // Volume +
                case KeyEvent.KEYCODE_VOLUME_UP:// 24
                    return StoPdaKeyEvent.KEYCODE_VOLUME_UP;
                // Volume -
                case KeyEvent.KEYCODE_VOLUME_DOWN:// 25
                    return StoPdaKeyEvent.KEYCODE_VOLUME_DOWN;
                // Fn
                case KeyEvent.KEYCODE_F1:// 131
                    return StoPdaKeyEvent.KEYCODE_FUNCTION;
                // Lock
                case KeyEvent.KEYCODE_SOFT_RIGHT:// 2
                    return StoPdaKeyEvent.KEYCODE_LOCK;
                // delete
                case KeyEvent.KEYCODE_DEL:// 67
                    return StoPdaKeyEvent.KEYCODE_DEL;
                // Aa
                case KeyEvent.KEYCODE_F3:// 133
                    return StoPdaKeyEvent.KEYCODE_F3;
                // Enter
                case KeyEvent.KEYCODE_ENTER:// 66
                    return StoPdaKeyEvent.KEYCODE_ENTER;
                // *
                case KeyEvent.KEYCODE_STAR:// 17
                    return StoPdaKeyEvent.KEYCODE_STAR;
                // 0
                case KeyEvent.KEYCODE_0:// 7
                    return StoPdaKeyEvent.KEYCODE_0;
                // #
                case KeyEvent.KEYCODE_POUND:// 18
                    return StoPdaKeyEvent.KEYCODE_POUND;
                // num 1-9
                case KeyEvent.KEYCODE_1:// 8
                    return StoPdaKeyEvent.KEYCODE_1;
                case KeyEvent.KEYCODE_2:// 9
                    return StoPdaKeyEvent.KEYCODE_2;
                case KeyEvent.KEYCODE_3:// 10
                    return StoPdaKeyEvent.KEYCODE_3;
                case KeyEvent.KEYCODE_4:// 11
                    return StoPdaKeyEvent.KEYCODE_4;
                case KeyEvent.KEYCODE_5:// 12
                    return StoPdaKeyEvent.KEYCODE_5;
                case KeyEvent.KEYCODE_6:// 13
                    return StoPdaKeyEvent.KEYCODE_6;
                case KeyEvent.KEYCODE_7:// 14
                    return StoPdaKeyEvent.KEYCODE_7;
                case KeyEvent.KEYCODE_8:// 15
                    return StoPdaKeyEvent.KEYCODE_8;
                case KeyEvent.KEYCODE_9:// 16
                    return StoPdaKeyEvent.KEYCODE_9;
                default:
                    return 0;
            }
        } else if (new Build().MODEL.equals("560")) {
            switch (keycode) {
                case KeyEvent.KEYCODE_DEL:
                    return StoPdaKeyEvent.KEYCODE_DEL;
                case KeyEvent.KEYCODE_MENU:
                    return StoPdaKeyEvent.KEYCODE_MENU;
                case KeyEvent.KEYCODE_DPAD_LEFT:
                    return StoPdaKeyEvent.KEYCODE_DPAD_LEFT;
                case KeyEvent.KEYCODE_DPAD_DOWN:
                    return StoPdaKeyEvent.KEYCODE_DPAD_DOWN;
                case KeyEvent.KEYCODE_DPAD_RIGHT:
                    return StoPdaKeyEvent.KEYCODE_DPAD_RIGHT;
                case KeyEvent.KEYCODE_DPAD_UP:
                    return StoPdaKeyEvent.KEYCODE_DPAD_UP;
                case KeyEvent.KEYCODE_BACK:
                    return StoPdaKeyEvent.KEYCODE_BACK;
                case KeyEvent.KEYCODE_0:
                    return StoPdaKeyEvent.KEYCODE_0;
                case KeyEvent.KEYCODE_1:
                    return StoPdaKeyEvent.KEYCODE_1;
                case KeyEvent.KEYCODE_2:
                    return StoPdaKeyEvent.KEYCODE_2;
                case KeyEvent.KEYCODE_3:
                    return StoPdaKeyEvent.KEYCODE_3;
                case KeyEvent.KEYCODE_4:
                    return StoPdaKeyEvent.KEYCODE_4;
                case KeyEvent.KEYCODE_5:
                    return StoPdaKeyEvent.KEYCODE_5;
                case KeyEvent.KEYCODE_6:
                    return StoPdaKeyEvent.KEYCODE_6;
                case KeyEvent.KEYCODE_7:
                    return StoPdaKeyEvent.KEYCODE_7;
                case KeyEvent.KEYCODE_8:
                    return StoPdaKeyEvent.KEYCODE_8;
                case KeyEvent.KEYCODE_9:
                    return StoPdaKeyEvent.KEYCODE_9;
                case KeyEvent.KEYCODE_STAR:
                    return StoPdaKeyEvent.KEYCODE_STAR;
                case KeyEvent.KEYCODE_POUND:
                    return StoPdaKeyEvent.KEYCODE_POUND;
                case KeyEvent.KEYCODE_F1:
                    return StoPdaKeyEvent.KEYCODE_F1;
                case KeyEvent.KEYCODE_F2:
                    return StoPdaKeyEvent.KEYCODE_F2;
                case KeyEvent.KEYCODE_F3:
                    return StoPdaKeyEvent.KEYCODE_F3;
                case KeyEvent.KEYCODE_F4:
                    return StoPdaKeyEvent.KEYCODE_F4;
                case KeyEvent.KEYCODE_F5:
                    return StoPdaKeyEvent.KEYCODE_F5;
                case KeyEvent.KEYCODE_F6:
                    return StoPdaKeyEvent.KEYCODE_F6;
                case 260:
                    return StoPdaKeyEvent.KEYCODE_SCAN;
                case KeyEvent.KEYCODE_VOLUME_UP:
                    return StoPdaKeyEvent.KEYCODE_VOLUME_UP;
                case KeyEvent.KEYCODE_VOLUME_DOWN:
                    return StoPdaKeyEvent.KEYCODE_VOLUME_DOWN;
                case KeyEvent.KEYCODE_ENTER:
                    return StoPdaKeyEvent.KEYCODE_DPAD_CENTER;
                default:
                    return 0;
            }
        } else if (new Build().MODEL.equals("570")) {
            switch (keycode) {
                case KeyEvent.KEYCODE_BUTTON_L1:// 102
                    // 左侧扫描键
                case KeyEvent.KEYCODE_BUTTON_R1:// 103
                    // right scan key
                case KeyEvent.KEYCODE_BUTTON_MODE:// 110
                    // scan key
                    return StoPdaKeyEvent.KEYCODE_SCAN;
                case KeyEvent.KEYCODE_MENU:// 82
                    return StoPdaKeyEvent.KEYCODE_MENU; // 82
                // menu key
                case KeyEvent.KEYCODE_BACK:// 4
                    return StoPdaKeyEvent.KEYCODE_BACK;
                // back key
                case KeyEvent.KEYCODE_DPAD_CENTER:// 23
                    return StoPdaKeyEvent.KEYCODE_DPAD_CENTER;
                // OK key
                case KeyEvent.KEYCODE_DPAD_LEFT:// 21
                    return StoPdaKeyEvent.KEYCODE_DPAD_LEFT;
                // Left key
                case KeyEvent.KEYCODE_DPAD_RIGHT:// 22
                    return StoPdaKeyEvent.KEYCODE_DPAD_RIGHT;
                // Right key
                case KeyEvent.KEYCODE_DPAD_UP:// 19
                    return StoPdaKeyEvent.KEYCODE_DPAD_UP;
                // Up key
                case KeyEvent.KEYCODE_DPAD_DOWN:// 20
                    return StoPdaKeyEvent.KEYCODE_DPAD_DOWN;
                // Down key
                case KeyEvent.KEYCODE_1:// 8
                    return StoPdaKeyEvent.KEYCODE_1;
                case KeyEvent.KEYCODE_2:// 9
                    return StoPdaKeyEvent.KEYCODE_2;
                case KeyEvent.KEYCODE_3:// 10
                    return StoPdaKeyEvent.KEYCODE_3;
                case KeyEvent.KEYCODE_4:// 11
                    return StoPdaKeyEvent.KEYCODE_4;
                case KeyEvent.KEYCODE_5:// 12
                    return StoPdaKeyEvent.KEYCODE_5;
                case KeyEvent.KEYCODE_6:// 13
                    return StoPdaKeyEvent.KEYCODE_6;
                case KeyEvent.KEYCODE_7:// 14
                    return StoPdaKeyEvent.KEYCODE_7;
                case KeyEvent.KEYCODE_8:// 15
                    return StoPdaKeyEvent.KEYCODE_8;
                case KeyEvent.KEYCODE_9:// 16
                    return StoPdaKeyEvent.KEYCODE_9;
                case KeyEvent.KEYCODE_STAR:// 17
                    return StoPdaKeyEvent.KEYCODE_STAR;
                // * key
                case KeyEvent.KEYCODE_0:// 7
                    return StoPdaKeyEvent.KEYCODE_0;
                case KeyEvent.KEYCODE_POUND:// 18
                    return StoPdaKeyEvent.KEYCODE_POUND;
                // # key
                case KeyEvent.KEYCODE_F1:
                    return StoPdaKeyEvent.KEYCODE_F1;
                // F1
                case KeyEvent.KEYCODE_F2:
                    return StoPdaKeyEvent.KEYCODE_F2;
                // F2
                case KeyEvent.KEYCODE_F3:
                    return StoPdaKeyEvent.KEYCODE_F3;
                // F3
                case KeyEvent.KEYCODE_F4:
                    return StoPdaKeyEvent.KEYCODE_F4;
                // F4
                case KeyEvent.KEYCODE_F5:
                    return StoPdaKeyEvent.KEYCODE_F5;
                case KeyEvent.KEYCODE_F6:
                    return StoPdaKeyEvent.KEYCODE_F6;
                case KeyEvent.KEYCODE_VOLUME_UP:// 24
                    return StoPdaKeyEvent.KEYCODE_VOLUME_UP;
                // volume up
                case KeyEvent.KEYCODE_VOLUME_DOWN:// 25
                    return StoPdaKeyEvent.KEYCODE_VOLUME_DOWN;
                // volume down
                default:
                    return 0;
            }
        } else if (new Build().MODEL.equals("K2") || Build.MODEL.equals("K211")||Build.MODEL.equals("W571")) {
            switch (keycode) {
                case KeyEvent.KEYCODE_BUTTON_L1:// 102
                    // 左侧扫描键
                case KeyEvent.KEYCODE_BUTTON_R1:// 103
                    // right scan key
                case KeyEvent.KEYCODE_BUTTON_MODE:// 110
                    // scan key
                    return StoPdaKeyEvent.KEYCODE_SCAN;
                case KeyEvent.KEYCODE_MENU:// 82
                    return StoPdaKeyEvent.KEYCODE_MENU; // 82
                // menu key
                case KeyEvent.KEYCODE_BACK:// 4
                    return StoPdaKeyEvent.KEYCODE_BACK;
                // back key
                case KeyEvent.KEYCODE_DEL:// 67
                    return StoPdaKeyEvent.KEYCODE_DEL;
                // delete key
                case KeyEvent.KEYCODE_DPAD_CENTER:// 23
                    return StoPdaKeyEvent.KEYCODE_DPAD_CENTER;
                // OK key
                case KeyEvent.KEYCODE_DPAD_LEFT:// 21
                    return StoPdaKeyEvent.KEYCODE_DPAD_LEFT;
                // Left key
                case KeyEvent.KEYCODE_DPAD_RIGHT:// 22
                    return StoPdaKeyEvent.KEYCODE_DPAD_RIGHT;
                // Right key
                case KeyEvent.KEYCODE_DPAD_UP:// 19
                    return StoPdaKeyEvent.KEYCODE_DPAD_UP;
                // Up key
                case KeyEvent.KEYCODE_DPAD_DOWN:// 20
                    return StoPdaKeyEvent.KEYCODE_DPAD_DOWN;
                // Down key
                case KeyEvent.KEYCODE_1:// 8
                    return StoPdaKeyEvent.KEYCODE_1;
                case KeyEvent.KEYCODE_2:// 9
                    return StoPdaKeyEvent.KEYCODE_2;
                case KeyEvent.KEYCODE_3:// 10
                    return StoPdaKeyEvent.KEYCODE_3;
                case KeyEvent.KEYCODE_4:// 11
                    return StoPdaKeyEvent.KEYCODE_4;
                case KeyEvent.KEYCODE_5:// 12
                    return StoPdaKeyEvent.KEYCODE_5;
                case KeyEvent.KEYCODE_6:// 13
                    return StoPdaKeyEvent.KEYCODE_6;
                case KeyEvent.KEYCODE_7:// 14
                    return StoPdaKeyEvent.KEYCODE_7;
                case KeyEvent.KEYCODE_8:// 15
                    return StoPdaKeyEvent.KEYCODE_8;
                case KeyEvent.KEYCODE_9:// 16
                    return StoPdaKeyEvent.KEYCODE_9;
                case KeyEvent.KEYCODE_STAR:// 17
                    return StoPdaKeyEvent.KEYCODE_STAR;
                // * key
                case KeyEvent.KEYCODE_0:// 7
                    return StoPdaKeyEvent.KEYCODE_0;
                case KeyEvent.KEYCODE_POUND:// 18
                    return StoPdaKeyEvent.KEYCODE_POUND;
                // # key
                case KeyEvent.KEYCODE_F1:
                    return StoPdaKeyEvent.KEYCODE_F1;
                // F1
                case KeyEvent.KEYCODE_F2:
                    return StoPdaKeyEvent.KEYCODE_F2;
                // F2
                case KeyEvent.KEYCODE_F3:
                    return StoPdaKeyEvent.KEYCODE_F3;
                // F3
                case KeyEvent.KEYCODE_F4:
                    return StoPdaKeyEvent.KEYCODE_F4;
                // F4
                case KeyEvent.KEYCODE_VOLUME_UP:// 24
                    return StoPdaKeyEvent.KEYCODE_VOLUME_UP;
                // volume up
                case KeyEvent.KEYCODE_VOLUME_DOWN:// 25
                    return StoPdaKeyEvent.KEYCODE_VOLUME_DOWN;
                // volume down
                default:
                    return 0;
            }
        } else {
            switch (keycode) {
                // scan
                case KeyEvent.KEYCODE_BUTTON_MODE:// 110
                    // 左侧键盘
                case KeyEvent.KEYCODE_BUTTON_L1:// 102
                    // 右侧键盘
                case KeyEvent.KEYCODE_BUTTON_R1:// 103
                    return StoPdaKeyEvent.KEYCODE_SCAN;
                // 左功能键
                case KeyEvent.KEYCODE_MENU:
                    return StoPdaKeyEvent.KEYCODE_SOFT_LEFT;
                // 上
                case KeyEvent.KEYCODE_DPAD_UP:
                    return StoPdaKeyEvent.KEYCODE_DPAD_UP;
                // 删除
                case KeyEvent.KEYCODE_DEL:// 67
                    return StoPdaKeyEvent.KEYCODE_DEL;
                // 左
                case KeyEvent.KEYCODE_DPAD_LEFT:// 21
                    return StoPdaKeyEvent.KEYCODE_DPAD_LEFT;
                // OK
                case KeyEvent.KEYCODE_DPAD_CENTER:// 23
                    return StoPdaKeyEvent.KEYCODE_DPAD_CENTER;
                // 右
                case KeyEvent.KEYCODE_DPAD_RIGHT:// 22
                    return StoPdaKeyEvent.KEYCODE_DPAD_RIGHT;
                // 下
                case KeyEvent.KEYCODE_DPAD_DOWN:// 20
                    return StoPdaKeyEvent.KEYCODE_DPAD_DOWN;
                // 返回
                case KeyEvent.KEYCODE_BACK:// 4
                    return StoPdaKeyEvent.KEYCODE_BACK;
                case KeyEvent.KEYCODE_1:// 8
                    return StoPdaKeyEvent.KEYCODE_1;
                case KeyEvent.KEYCODE_2:// 9
                    return StoPdaKeyEvent.KEYCODE_2;
                case KeyEvent.KEYCODE_3:// 10
                    return StoPdaKeyEvent.KEYCODE_3;
                case KeyEvent.KEYCODE_4:// 11
                    return StoPdaKeyEvent.KEYCODE_4;
                case KeyEvent.KEYCODE_5:// 12
                    return StoPdaKeyEvent.KEYCODE_5;
                case KeyEvent.KEYCODE_6:// 13
                    return StoPdaKeyEvent.KEYCODE_6;
                case KeyEvent.KEYCODE_7:// 14
                    return StoPdaKeyEvent.KEYCODE_7;
                case KeyEvent.KEYCODE_8:// 15
                    return StoPdaKeyEvent.KEYCODE_8;
                case KeyEvent.KEYCODE_9:// 16
                    return StoPdaKeyEvent.KEYCODE_9;
                // *
                case KeyEvent.KEYCODE_STAR:// 17
                    return StoPdaKeyEvent.KEYCODE_STAR;
                // 0
                case KeyEvent.KEYCODE_0:// 7
                    return StoPdaKeyEvent.KEYCODE_0;
                // #
                case KeyEvent.KEYCODE_POUND:// 18
                    return StoPdaKeyEvent.KEYCODE_POUND;
                // F1
                case KeyEvent.KEYCODE_BUTTON_A:// 96
                    return StoPdaKeyEvent.KEYCODE_F1;
                // F2
                case KeyEvent.KEYCODE_BUTTON_B:// 97
                    return StoPdaKeyEvent.KEYCODE_F2;
                // F3
                case KeyEvent.KEYCODE_EXPLORER:// 64
                    return StoPdaKeyEvent.KEYCODE_F3;
                // F4
                case KeyEvent.KEYCODE_SOFT_RIGHT:// 2
                    return StoPdaKeyEvent.KEYCODE_F4;
                // F5
                case KeyEvent.KEYCODE_BUTTON_THUMBL:// 106
                    return StoPdaKeyEvent.KEYCODE_F5;
                // F6
                case KeyEvent.KEYCODE_BUTTON_THUMBR:// 107
                    return StoPdaKeyEvent.KEYCODE_F6;
                // F7
                case KeyEvent.KEYCODE_BUTTON_L2:// 104
                    return StoPdaKeyEvent.KEYCODE_F7;
                // F8
                case KeyEvent.KEYCODE_BUTTON_R2:// 105
                    return StoPdaKeyEvent.KEYCODE_F8;
                // 右圆 音量+
                case KeyEvent.KEYCODE_VOLUME_UP:// 24
                    return StoPdaKeyEvent.KEYCODE_VOLUME_UP;
                // 左圆 音量-
                case KeyEvent.KEYCODE_VOLUME_DOWN:// 25
                    return StoPdaKeyEvent.KEYCODE_VOLUME_DOWN;

                default:
                    return 0;
            }
        }

    }

    @Override
    public String getJniVer() {
        return "kai-1.0.1.0";
        // "kai-1.0.0.1"
        /**
         * 1、扫描部分的实现 2、按键部分的实现
         */
        // "kai-1.0.0.2"
        /**
         * 1、唯一码实现 2、同步时间实现 3、优化键盘 添加机型 4、更新了厂家实现 不全
         **/
        // "kai-1.0.0.3"
        /**
         * 1、增加凯立k2 k7机型
         **/
        // "kai-1.0.0.4"
        /**
         * 1、修改Scanner2D handler
         **/
        // "kai-1.0.0.5"
        /**
         * 1、修改Scanner2D 异常
         **/
        // "kai-1.0.0.6"
        /**
         * 1、增加570机型
         **/
        // "kai-1.0.0.7"
        /**
         * 1、android 5.1已经添加setService
         **/
        // "kai-1.0.0.8"
        /**
         * 1、添加新接口获取扫描结果
         **/
        // "kai-1.0.0.9"
        /**
         * 1、添加560机型
         **/
        // "kai-1.0.1.0"
        /**
         * 1、添加W170机型
         **/
    }

    @Override
    public int getPlatform() {
        return GetPlatform();
    }

    public void modifyAudio() {
        if (Build.MODEL.equals("K2") && Build.DISPLAY.compareTo("2.20.14") <= 0) {
            ModifyAudioManager.modify();
        }
    }

    public void setRegister() {
        if (Build.MODEL.equals("K2") && Build.DISPLAY.compareTo("2.20.14") <= 0) {
            SetRegisterManager.setRegister();
        }
    }

}
