package com.doverfuelingsolutions.issp.driver.tools.shell;

import android.text.TextUtils;
import android.util.Log;

/**
 * @author Lear
 * @description
 * @date 2019/12/18 13:41
 */
public class BoardHelper {

    private static final String BOARD1_CMD = "cat /proc/mcu | grep board_id";
    private static final String BOARD1_TOKEN = "board_id = 4";
    private static final String BOARD2_CMD = "getprop ro.hardinfo";
    private static final String BOARD2_TOKEN = "QJ-iCON39-180528-WHNE73-031609";
    private static final String BOARD3_CMD = "getprop ro.product.model";
    private static final String BOARD3_TOKEN = "QJ-ICON28NL";

    public static boolean isAuthorizedDevice() {
        // test command line
        CommandResult cmd1 = Shell.SH.run(BOARD1_CMD);
        if (cmd1.isSuccessful()) {
            String res = cmd1.getStdout();
            if (TextUtils.equals(res, BOARD1_TOKEN)) {
                return true;
            }
        }

        CommandResult cmd2 = Shell.SH.run(BOARD2_CMD);
        if (cmd2.isSuccessful()) {
            String res = cmd2.getStdout();
            if (TextUtils.equals(res, BOARD2_TOKEN)){
                return true;
            }

            // 检测新主板
            CommandResult cmd3 = Shell.SH.run(BOARD3_CMD);
            if (cmd3.isSuccessful()) {
                String res3 = cmd3.getStdout();
                return TextUtils.equals(res3, BOARD3_TOKEN);
            }
        }

        return false;
    }

    public static boolean isICON28NL(){
        CommandResult cmd3 = Shell.SH.run(BOARD3_CMD);
        if (cmd3.isSuccessful()) {
            String res3 = cmd3.getStdout();
            return TextUtils.equals(res3, BOARD3_TOKEN);
        }

        return  false;
    }
}
