package com.hh.arome.ui;

import android.content.ComponentName;
import android.content.Context;
import android.content.ServiceConnection;
import android.net.ConnectivityManager;
import android.net.LinkProperties;
import android.net.Network;
import android.net.NetworkCapabilities;
import android.net.NetworkRequest;
import android.os.Build;
import android.os.Bundle;

import com.alipay.arome.aromecli.AromeInit;
import com.alipay.arome.aromecli.AromeInitOptions;
import com.alipay.arome.aromecli.AromeServiceInvoker;
import com.alipay.arome.aromecli.AromeServiceTask;
import com.alipay.arome.aromecli.requst.AromeActivateRequest;
import com.alipay.arome.aromecli.requst.AromeExitAppRequest;
import com.alipay.arome.aromecli.requst.AromeLaunchAppRequest;
import com.alipay.arome.aromecli.response.AromeExitAppResponse;
import com.alipay.arome.aromecli.response.AromeResponse;
import com.alipay.iot.bpaas.api.BPaaSApi;
import com.alipay.iot.bpaas.api.BPaaSInitCallback;
import com.alipay.iot.bpaas.api.service.BPaaSCallback;
import com.alipay.iot.bpaas.api.service.BPaaSResponse;
import com.common.lib_base.common.local.AppLocalConfigHandler;
import com.common.lib_base.utils.GlideUtils;
import com.common.lib_base.utils.NetworkUtils;
import com.common.lib_base.utils.StringUtils;
import com.common.lib_base.utils.ui.ToastUtils;
import com.common.pos.api.util.ShellUtils;


import android.app.Activity;
import android.content.Intent;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.RemoteException;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;

import com.alipay.iot.bpaas.api.InnerApi;
import com.alipay.iot.bpaas.api.ipc.IpcChannel;
import com.alipay.iot.bpaas.api.ipc.IpcListener;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.hh.arome.BuildConfig;
import com.hh.arome.MyApplication;
import com.hh.arome.R;
import com.hh.arome.bean.AlipayUserInfoRequestBean;
import com.hh.arome.bean.AlipayUserInfoResultBean;
import com.hh.arome.bean.DeviceConfigRequestBean;
import com.hh.arome.bean.DeviceConfigResultBean;
import com.hh.arome.bean.HeartBeatRequestBean;
import com.hh.arome.bean.InvokeScanFaceBean;
import com.hh.arome.bean.LogcatAddRequestBean;
import com.hh.arome.bean.SimpleResultBean;
import com.hh.arome.bean.ampe.AmpeAppletRequestBean;
import com.hh.arome.bean.ampe.AmpeAppletResultBean;
import com.hh.arome.bean.ampe.AmpeActionDataBean;
import com.hh.arome.bean.face.StartReadyBpaasServiceBean;
import com.hh.arome.common.ConfigData;
import com.hh.arome.common.Constants;
import com.hh.arome.common.IAppLocalConfig;
import com.hh.arome.common.deviceui.BaseDeviceUI;
import com.hh.arome.common.deviceui.IDeviceUI;
import com.hh.arome.helper.ReadCardManager;
import com.hh.arome.helper.Serial.SerialPortFinder;
import com.hh.arome.mvp.contract.AlipayUserInfoContract;
import com.hh.arome.mvp.contract.DeviceConfigContract;
import com.hh.arome.mvp.contract.HeartbeatContract;
import com.hh.arome.mvp.contract.LogcatAddContract;
import com.hh.arome.mvp.presenter.AlipayUserInfoPresenter;
import com.hh.arome.mvp.presenter.DeviceConfigPresenter;
import com.hh.arome.mvp.presenter.HeartbeatPresenter;
import com.hh.arome.mvp.presenter.LogcatAddPresenter;
import com.hh.arome.ui.base.BaseHHActivity;
import com.hh.arome.utlis.DateUtil;
import com.hh.arome.utlis.device.DeviceUtils;
import com.hh.arome.utlis.device.FaceScenicUtile;
import com.hh.arome.utlis.log.AppLogUtils;
import com.hh.arome.utlis.log.LogType;
import com.hh.hhomc.IAidlInterface;
import com.hh.hhomc.AppMessageBean;
import com.hh.hhomc.IAidlCallBack;
import com.hjq.permissions.OnPermissionCallback;
import com.hjq.permissions.Permission;
import com.hjq.permissions.XXPermissions;
import com.silencefun.comtest.MyFunc;
import com.silencefun.comtest.SerialHelper;
import com.silencefun.comtest.been.ComBean;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.lang.ref.WeakReference;
import java.security.InvalidParameterException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;


import static com.hh.arome.common.Constants.Ampe.ACTION_DEVICE;
import static com.hh.arome.common.Constants.Ampe.ACTION_FACE;
import static com.hh.arome.common.Constants.Ampe.ACTION_IDCard;
import static com.hh.arome.common.Constants.Ampe.ACTION_INIT_FACE;
import static com.hh.arome.common.Constants.Ampe.ACTION_QR;
import static com.hh.arome.common.Constants.Ampe.ACTION_SCAN_FACE;
import static com.hh.arome.common.Constants.LogcatValue.LINE;
import static com.hh.arome.common.Constants.LogcatValue.LOG_NODE_APPLET;
import static com.hh.arome.common.Constants.LogcatValue.LOG_NODE_DEVICE;
import static com.hh.arome.common.Constants.LogcatValue.LOG_NODE_FACE;
import static com.hh.arome.common.Constants.LogcatValue.LOG_NODE_IDCARD;
import static com.hh.arome.common.Constants.LogcatValue.LOG_NODE_NET;
import static com.hh.arome.common.Constants.LogcatValue.LOG_NODE_NET_CONFIG_QUERY;
import static com.hh.arome.common.Constants.LogcatValue.LOG_NODE_NET_HEARTBEAT;
import static com.hh.arome.common.Constants.LogcatValue.LOG_NODE_QR;
import static com.hh.arome.common.Constants.LogcatValue.NET_ERROR;
import static com.hh.arome.common.Constants.LogcatValue.NET_LOGCAT;
import static com.hh.arome.common.Constants.LogcatValue.NODE;
import static com.hh.arome.common.Constants.LogcatValue.WARP;
import static com.hh.arome.common.Constants.SERVER_ACTION.CLOSE_APP;
import static com.hh.arome.common.Constants.Url.API_CONFIG_QUERY;
import static com.hh.arome.common.Constants.Value.CAMERA_BRAND;
import static com.hh.arome.common.Constants.Value.TIME_HEARTBEAT;
import static com.hh.arome.common.Constants.Value.TOKEN;


public class MainActivity extends BaseHHActivity implements DeviceConfigContract.View, HeartbeatContract.View, View.OnClickListener, LogcatAddContract.View, AlipayUserInfoContract.View {

    FaceScenicUtile faceScenicUtile;

    DeviceConfigPresenter mDeviceConfigPresenter;
    HeartbeatPresenter mHeartbeatPresenter;
    LogcatAddPresenter mLogcatAddPresenter;
    AlipayUserInfoPresenter mAlipayUserInfoPresenter;

    Button tv_exit, tv_scan, tv_sec, tv_idcard;
    Button tv_logcat, tv_error, tv_crash, tv_send_message;

    // aidl消息发送者，标识收到的消息来自哪个app
    String aidlSender = "HHArome";

    String localDeviceSN;

    Gson gson = new Gson();

    Handler mMainHandler = new Handler();

    @Override
    public int setLayout() {
        return R.layout.activity_main;
    }

    @Override
    protected void initView() {
        super.setHideTopBar();
//        faceScenicUtile = new FaceScenicUtile(this);//初始化下拉通知或底部导航配置
//        Config.setFaceScenicUtile(faceScenicUtile, false);


        String deviceDisplay = DeviceUtils.getDeviceDisplay();
        AppLogUtils.e("deviceDisplay=" + deviceDisplay);
        String androidVersion = DeviceUtils.getAndroidVersion();
        AppLogUtils.e("androidVersion=" + androidVersion);
        String deviceSN = DeviceUtils.getDeviceSN();
        AppLogUtils.e("deviceSN=" + deviceSN);


//        ArrayList<AppInfoBean> appList = AppUtils.getAppList(this);
//        for (AppInfoBean appInfoBean : appList) {
//            AppLogUtils.e(appInfoBean.appName+"   "+appInfoBean.getVersionName()+"   "+appInfoBean.packageName);
//        }

        tv_scan = findViewById(R.id.tv_scan);
        tv_exit = findViewById(R.id.tv_exit);
        tv_sec = findViewById(R.id.tv_sec);
        tv_idcard = findViewById(R.id.tv_idcard);

        tv_logcat = findViewById(R.id.tv_logcat);
        tv_error = findViewById(R.id.tv_error);
        tv_crash = findViewById(R.id.tv_crash);

        tv_send_message = findViewById(R.id.tv_send_message);

        tv_time = findViewById(R.id.tv_time);
        tv_net_no = findViewById(R.id.tv_net_no);
        iv_net_wifi = findViewById(R.id.iv_net_wifi);
        iv_net_flow = findViewById(R.id.iv_net_flow);
        iv_net_line = findViewById(R.id.iv_net_line);
        iv_setting = findViewById(R.id.iv_setting);

        tv_version = findViewById(R.id.tv_version);
        tv_sn = findViewById(R.id.tv_sn);
        tv_applet_name = findViewById(R.id.tv_applet_name);
        tv_enter_applet = findViewById(R.id.tv_enter_applet);

        tv_config_status = findViewById(R.id.tv_config_status);

        item_root = findViewById(R.id.item_root);
        iv_setting.setOnClickListener(this);
        tv_enter_applet.setOnClickListener(this);
    }

    public void setConfigStatusText(String text) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                tv_config_status.setText(text);
            }
        });

    }


    TextView tv_time, tv_net_no;
    ImageView iv_net_wifi, iv_net_flow, iv_net_line, iv_setting;
    TextView tv_version, tv_sn, tv_applet_name, tv_enter_applet, tv_config_status;
    RelativeLayout item_root;

    IAppLocalConfig localConfig;

    HeartBeatRequestBean heartBeatRequestBean;

    String netType;
    boolean isNetAvailable;


    private ConnectivityManager.NetworkCallback networkCallback;
    private ConnectivityManager connectivityManager;


    private class NetworkCallbackImpl extends ConnectivityManager.NetworkCallback {
        @Override
        public void onAvailable(Network network) {
            super.onAvailable(network);
            //
            AppLogUtils.e("网络--连接--onAvailable");

            isNetAvailable = true;
            netLogcatNum = 0;

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    getNetType();
                }
            });

        }

        @Override
        public void onLosing(Network network, int maxMsToLive) {
            super.onLosing(network, maxMsToLive);
            AppLogUtils.e("网络--onLosing");
        }

        @Override
        public void onLost(Network network) {
            super.onLost(network);
            AppLogUtils.e("网络--断开--onLost");

            isNetAvailable = false;

            runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    getNetType();
                }
            });
        }

        @Override
        public void onCapabilitiesChanged(Network network, NetworkCapabilities networkCapabilities) {
            super.onCapabilitiesChanged(network, networkCapabilities);
            AppLogUtils.e("网络-onCapabilitiesChanged");
        }

        @Override
        public void onLinkPropertiesChanged(Network network, LinkProperties linkProperties) {
            super.onLinkPropertiesChanged(network, linkProperties);
            AppLogUtils.e("网络-onLinkPropertiesChanged");
        }
    }

    IDeviceUI iDeviceUI;

    @Override
    protected void initData() {


//        String str1 = "１３８";
//        String str2 = "138";
//
//        AppLogUtils.e("encoding-str1-" + str1.length());
//        AppLogUtils.e("encoding-str2-" + str2.length());
//
//        String encoding = StringUtils.encoding(str1);
//        AppLogUtils.e("encoding-str1-" + encoding);
//        String encoding11 = StringUtils.encoding(str2);
//        AppLogUtils.e("encoding-str2-" + encoding11);


        localConfig = AppLocalConfigHandler.create(mContext.getApplicationContext(), IAppLocalConfig.class);


        iDeviceUI = BaseDeviceUI.getInstance().getDeviceUI();

        initNet();

//        getNetType();


        localDeviceSN = DeviceUtils.getDeviceSN();
        AppLogUtils.e("localDeviceSN:" + localDeviceSN);

        tv_version.setText("版本号：" + DeviceUtils.getAppVersionName(this));
        tv_sn.setText("SN号：" + localDeviceSN);


        // 权限
        requestPermissionsMethod();

//        // 网络请求
//        requestNetData();

        EventBus.getDefault().register(this);


        // 时间
        resh.mHandler.postDelayed(resh.runnableTime, 1000);// 每兩秒執行一次runnable.


        // 绑定aidl远程服务
        bindService();


        Intent intent = getIntent();
        if (intent != null) {
            boolean exist = intent.getBooleanExtra("IsExist", false);
            if (exist) {
                closeApp();
            }
        }

        // 删除日志
        AppLogUtils.deleteFileLog(LogType.Logcat, 7);
        AppLogUtils.deleteFileLog(LogType.Error, 7);
        AppLogUtils.deleteFileLog(LogType.Crash, 7);


    }

    private void initNet() {
        networkCallback = new NetworkCallbackImpl();
        NetworkRequest.Builder builder = new NetworkRequest.Builder();
        NetworkRequest request = builder.build();
        connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
        connectivityManager.registerNetworkCallback(request, networkCallback);


        tv_net_no.setVisibility(View.GONE);
        iv_net_wifi.setVisibility(View.GONE);
        iv_net_flow.setVisibility(View.GONE);
        iv_net_line.setVisibility(View.GONE);
    }

    private void requestNetData() {
        // 开始请求

        // 在线配置接口
        mDeviceConfigPresenter = new DeviceConfigPresenter(this);

        DeviceConfigRequestBean mDeviceConfigRequestBean = new DeviceConfigRequestBean();
        mDeviceConfigRequestBean.setSn(localDeviceSN);
        mDeviceConfigRequestBean.setToken(Constants.Value.TOKEN);
        mDeviceConfigPresenter.requestDeviceConfig(mDeviceConfigRequestBean);

        setConfigStatusText(netType + " 请求在线配置...");


        mLogcatAddPresenter = new LogcatAddPresenter(this);

        mAlipayUserInfoPresenter = new AlipayUserInfoPresenter(this);
    }

    private void getNetType() {

        tv_net_no.setVisibility(View.GONE);
        iv_net_wifi.setVisibility(View.GONE);
        iv_net_flow.setVisibility(View.GONE);
        iv_net_line.setVisibility(View.GONE);

        boolean isNetworkAvaiable = NetworkUtils.isNetworkAvaiable(getApplicationContext());
        if (isNetworkAvaiable) {

            netType = NetworkUtils.getNetType(getApplicationContext());

            AppLogUtils.e("netType--" + netType);
            if (StringUtils.isNotNull(netType)) {
                if (netType.contains("WIFI")) {
                    iv_net_wifi.setVisibility(View.VISIBLE);
                } else if (netType.contains("MOBILE")) {
                    iv_net_flow.setVisibility(View.VISIBLE);
                }
            }

            // 网络请求
            requestNetData();


        } else {
            tv_net_no.setVisibility(View.VISIBLE);
        }
    }


    @Override
    protected void initListener() {


        tv_exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AppLogUtils.e("tv_exit");
                closeApp();
            }
        });


        tv_scan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AppLogUtils.e(" Config.mSessionId:" + ConfigData.mSessionId);


                // 获取启动Bpaas刷脸的参数
                StartReadyBpaasServiceBean bpaasServiceBean = getStartReadyBpaasServiceBean();

                invokeScanFace(bpaasServiceBean);
            }
        });


        tv_idcard.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent intent = new Intent(MainActivity.this, IDCardScanActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(intent);

            }
        });


        tv_logcat.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!hasPermission) {
                    com.blankj.utilcode.util.ToastUtils.showShort("未获取到文件写入权限");
                    return;
                }
                AppLogUtils.saveLog(LogType.Logcat, "测试logcat日志");
            }
        });

        tv_error.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!hasPermission) {
                    com.blankj.utilcode.util.ToastUtils.showShort("未获取到文件写入权限");
                    return;
                }
                AppLogUtils.saveLog(LogType.Error, "测试error日志");
            }
        });


        tv_crash.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (!hasPermission) {
                    com.blankj.utilcode.util.ToastUtils.showShort("未获取到文件写入权限");
                    return;
                }
                TextView textView = null;
                textView.setText("执行后闪退记录日志");
            }
        });

        tv_send_message.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                sendAppInfoMessage();
            }
        });


//        tv_applet_name.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intent = new Intent(MainActivity.this, IDCardScanActivity.class);
//                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
//                startActivity(intent);
//            }
//        });


    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.iv_setting:

                startActivity(PasswordActivity.class);
                // 关闭当前，其余activity返回会重启MainActivity
                finish();

                break;
            case R.id.tv_enter_applet:
                if (deviceConfigBean != null) {

                    // 日志行数
                    String logLine = (new Throwable().getStackTrace())[0].toString();
                    // 日志节点
                    String logNodeTag = "点击进入小程序操作---";

                    // 开始保存本地日志
                    AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                            .append(LINE)
                            .append(logLine).append(WARP)
                            .append(NODE)
                            .append(logNodeTag)
                            .toString()
                    );

                    // 开始网络在线日志
                    LogcatAddRequestBean bean = new LogcatAddRequestBean();
                    bean.setLogType(NET_LOGCAT);
                    // 对应web端"日志标签"
                    bean.setLogTag(logLine + WARP + LOG_NODE_APPLET);
                    bean.setLogContent(logNodeTag);
                    requestLogcatAdd(bean);


                    initAndActive(deviceConfigBean);
                } else {
                    AppLogUtils.e("deviceConfigBean--null");
                }
                break;
        }
    }


    // 初始化ampe
    private void initAndActive(final DeviceConfigResultBean ampeConfigResultBean) {

        AppLogUtils.e("初始化小程序配置");
        setConfigStatusText("初始化小程序配置");


        // 主题参数配置
        Bundle themeConfig = new Bundle();
        // 不需要登录
        themeConfig.putBoolean("needLogin", false);
        //是否隐藏状态栏 默认false
        themeConfig.putBoolean("hideStatusBar", false);
        //是否隐藏导航栏 默认false
        themeConfig.putBoolean("hideNavigationBar", false);
        //是否隐藏标题栏胶囊按钮 默认false不隐藏。配置右上角三个圆点和X
        themeConfig.putBoolean("hideOptionMenu", true);
        //超时时间 单位秒，默认30秒 建议传大于10的值
//        themeConfig.putInt("timeOut", 30);
        themeConfig.putInt("operationTimeoutPeriod", 30);


//        // 初始化多窗口设置
//        final int[] rect = new int[]{0, 0, 1000, 1600};
//        //是否使用freeform打开小程序 默认false
//        themeConfig.putBoolean("enableFloatWindow", true);
//        //freeform窗口大小 需配合enableFloatWindow 值为true使用
//        themeConfig.putIntArray("windowBounds", rect);

//         配置黑名单 黑名单中的小程序可全屏显示
//        如果enableFloatWindow值为true，需要全屏显示的小程序配置到黑名单中可全屏显示
//        ArrayList<String> blackList = new ArrayList<>();
//        blackList.add("2021002163620647");
//        themeConfig.putStringArrayList("floatWindowBlacklist", blackList);
        //竖屏配置，若没有可以不配置
        Bundle portrait = new Bundle();
        //竖屏默认默认值是2 可参考https://opendocs.alipay.com/mini/00v8et?pathHash=8d2d3fa2#3.1%20%E5%90%AF%E5%8A%A8
        portrait.putInt("showType", 2);
        //默认750 小程序显示的宽度750就是按给定窗口的大小显示，如果是375则是给定窗口大小的一半显示
        portrait.putInt("launchWidth", 750);
        //横屏配置，若没有可以不配置
        Bundle landscape = new Bundle();
        //横屏默认值是123
        landscape.putInt("showType", 2);
        landscape.putInt("launchWidth", 750);

        themeConfig.putBundle("portrait", portrait);
        themeConfig.putBundle("landscape", landscape);


//        // 设置自定义titlebar资源加载路径
//        File resourcePath = new File(MainActivity.this.getExternalFilesDir(null), "cache");
//        File newFile = new File(resourcePath, "titlebarResPkg-debug.apk");
//        AppLogUtils.e("newFile--"+newFile.getAbsolutePath());
//        if (newFile.exists()) {
//            Uri contentUri = FileProvider.getUriForFile(MainActivity.this, "com.alipay.arome.aromedemo.fileprovider", newFile);
//            AppLogUtils.e("ampe---contentUri is " + contentUri);
//            MainActivity.this.grantUriPermission("com.alipay.arome.app", contentUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
//            themeConfig.putString("localAssetApkPath", contentUri.toString());
//            themeConfig.putString("localAssetPkgName", "com.example.titlebarResPkg");
//        }

        // 设备信息配置
        Bundle deviceConfig = new Bundle();
        //用于接收广播的应用包名
        deviceConfig.putString("packageName", getPackageName());
        deviceConfig.putBoolean("needLogin", false);

        final AromeInitOptions options = new AromeInitOptions.Builder()
                //0 手动登入登出 1 悬浮球头像露出，用户可登出 可选配置  2 提示超时退出通知
                .loginMode(2)
                //硬件名称 可选配置
                //.hardwareName("")
                .deviceConfig(deviceConfig)//设备信息配置，一般来说，如果不需要接收广播不需要该配置
                //全局主题参数配置，AromeLaunchRequest中的themeConfig是局部配置，影响范围为这一次启动小程序
                //局部配置优先级高于全局配置
                .themeConfig(themeConfig)
                .build();

        AromeActivateRequest activateRequest = new AromeActivateRequest();
        activateRequest.deviceId = ampeConfigResultBean.getSn();
        activateRequest.hostAppId = ampeConfigResultBean.getAmpeAppid();
        activateRequest.productId = Long.parseLong(ampeConfigResultBean.getProductId());//你自己的productId
        activateRequest.signature = ampeConfigResultBean.getSignature();

        // 日志开始----------------begin
        // 日志行数——对应web端"日志标签"
        String logLine = (new Throwable().getStackTrace())[0].toString();
        // 日志节点
        String logNode = "小程序初始化---入参---";
        // 日志内容
        StringBuilder logContentSb = new StringBuilder();
        logContentSb.append(logNode).append(WARP)
                .append("deviceId = ").append(ampeConfigResultBean.getSn()).append(WARP)
                .append("hostAppId = ").append(ampeConfigResultBean.getAmpeAppid()).append(WARP)
                .append("productId = ").append(ampeConfigResultBean.getProductId()).append(WARP)
                .append("signature = ").append(ampeConfigResultBean.getSignature());

        // 开始保存本地日志
        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                .append(LINE)
                .append(logLine).append(WARP)
                .append(NODE)
                .append(logContentSb)
                .toString()
        );

        // 开始网络在线日志
        LogcatAddRequestBean bean = new LogcatAddRequestBean();
        bean.setLogType(NET_LOGCAT);
        // 对应web端"日志标签"
        bean.setLogTag(logLine + WARP + LOG_NODE_APPLET);
        bean.setLogContent(logContentSb.toString());
        requestLogcatAdd(bean);
        // 日志开始----------------end

        AppLogUtils.e(logContentSb);

        AromeInit.initAndActivate(options, activateRequest, new AromeInit.Callback() {
            @Override
            public void postInit(boolean success, int errorCode, String errorMsg) {
                // 非主线程中

                // 日志开始----------------begin
                // 日志行数——对应web端"日志标签"
                String logLine = (new Throwable().getStackTrace())[0].toString();
                // 日志节点
                String logNode = "小程序初始化结果initAndActivate---";
                // 日志内容
                StringBuilder logContentSb = new StringBuilder();
                logContentSb.append(logNode).append(WARP)
                        .append("postInit result").append(WARP)
                        .append("success = ").append(success).append(WARP)
                        .append("errorCode = ").append(errorCode).append(WARP)
                        .append("errorMsg = ").append(errorMsg);

                // 开始保存本地日志
                AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                        .append(LINE)
                        .append(logLine).append(WARP)
                        .append(NODE)
                        .append(logContentSb)
                        .toString()
                );

                // 开始网络在线日志
                LogcatAddRequestBean bean = new LogcatAddRequestBean();
                bean.setLogType(NET_LOGCAT);
                // 对应web端"日志标签"
                bean.setLogTag(logLine + WARP + LOG_NODE_APPLET);
                bean.setLogContent(logContentSb.toString());
                requestLogcatAdd(bean);
                // 日志开始----------------end

                AppLogUtils.e(logContentSb);

                if (errorCode == 0) {
                    // 成功
                    appletId = ampeConfigResultBean.getMiniProgramAppid();

                    launchApplet(appletId);
                } else if (errorCode == 2002) {
                    // 可能是设备ampe未授权
                    setConfigStatusText("设备ampe未授权");
                } else if (errorCode == 3) {
                    // 检查引擎
                    setConfigStatusText("设备ampe启动失败--" + errorMsg);
                }


            }

            @Override
            public void serverDied() {

                // 日志开始----------------begin
                // 日志行数——对应web端"日志标签"
                String logLine = (new Throwable().getStackTrace())[0].toString();
                // 日志节点
                String logNode = "小程序初始化结果initAndActivate---";
                // 日志内容
                StringBuilder logContentSb = new StringBuilder();
                logContentSb.append(logNode).append(WARP)
                        .append("serverDied");

                // 开始保存本地日志
                AppLogUtils.saveLog(LogType.Error, new StringBuilder()
                        .append(LINE)
                        .append(logLine).append(WARP)
                        .append(NODE)
                        .append(logContentSb)
                        .toString()
                );

                // 开始网络在线日志
                LogcatAddRequestBean bean = new LogcatAddRequestBean();
                bean.setLogType(NET_ERROR);
                // 对应web端"日志标签"
                bean.setLogTag(logLine + WARP + LOG_NODE_APPLET);
                bean.setLogContent(logContentSb.toString());
                requestLogcatAdd(bean);
                // 日志开始----------------end

                AppLogUtils.e(logContentSb);

            }
        });

    }

    String appletId;
    boolean isLaunchApplet;

    // 注意还在子线程
    private void launchApplet(String appId) {
        setConfigStatusText("启动小程序...");

//        appId = "2021004124640172";
//        appId = "2021004108612349";

        // 日志开始----------------begin
        // 日志行数——对应web端"日志标签"
        String logLine = (new Throwable().getStackTrace())[0].toString();
        // 日志节点
        String logNode = "启动小程序launchApplet---";
        // 日志内容
        StringBuilder logContentSb = new StringBuilder();
        logContentSb.append(logNode).append(WARP)
                .append("appId = ").append(appId);

        // 开始保存本地日志
        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                .append(LINE)
                .append(logLine).append(WARP)
                .append(NODE)
                .append(logContentSb)
                .toString()
        );

        // 开始网络在线日志
        LogcatAddRequestBean bean = new LogcatAddRequestBean();
        bean.setLogType(NET_LOGCAT);
        // 对应web端"日志标签"
        bean.setLogTag(logLine + WARP + LOG_NODE_APPLET);
        bean.setLogContent(logContentSb.toString());
        requestLogcatAdd(bean);
        // 日志开始----------------end

        AppLogUtils.e(logContentSb);


        AromeLaunchAppRequest request = new AromeLaunchAppRequest();

        // 设备信息配置
        Bundle themeConfig = new Bundle();
        // 不需要登录
        themeConfig.putBoolean("needLogin", false);
        //支持指定displayId 如果不指定 直接在默认的屏幕显示
        //themeConfig.putInt("displayId", displayId);
        // 是否使用自定义的
        themeConfig.putBoolean("useCustomTitlebar", true);
        request.themeConfig = themeConfig;
        request.appId = appId;

        //如果需要黑白模式切换的逻辑 query需要传入 "openThemeSwitch=1"
        //不需要可以不传
//        request.query = "";
        // 江西就业之家
        request.query = "ampe=tzsw";
        //启动前是否关闭所有小程序，默认false，建议传true，减少性能开销
        request.closeAllApp = true;
        //注册硬件能力list
        // 只有注册硬件能力 AromeServiceInvoker.registerBridgeExtension才能收到回调
        request.extensionList = getExtensionList();
        //局部的配置只影响当前这一次启动，如果没有特殊需要可以不传
        //不传则采用初始化配置的全局配置


        // request.themeConfig = themeConfig;
        AromeServiceInvoker.invoke(request, new AromeServiceTask.Callback<AromeResponse>() {
            @Override
            public void onCallback(final AromeResponse aromeResponse) {
                // 此回调不在主线，如需要刷新UI 请自行切线程
                // {success=false, code=1001, message='token invalid!'}
                // {success=true, code=0, message='null'}
                AppLogUtils.e("launchApplet-- onCallback = " + aromeResponse.toString());

                int code = aromeResponse.code;


                if (code == 0 || code == 1000) {
                    isLaunchApplet = true;
                    setConfigStatusText("启动小程序成功");

                    // 防止多次点击，导致建立多个通道，信息也多次
//                    appletListen();
                } else {
                    if (code == 1001) {
                        isLaunchApplet = false;
                        setConfigStatusText("设备ampe未授权");
                    }
                }


                // 日志开始----------------begin
                // 日志行数——对应web端"日志标签"
                String logLine = (new Throwable().getStackTrace())[0].toString();
                // 日志节点
                String logNode = "启动小程序结果---invoke";
                // 日志内容
                StringBuilder logContentSb = new StringBuilder();
                logContentSb.append(logNode).append(WARP)
                        .append("code = ").append(code).append(WARP)
                        .append("aromeResponse = ").append(aromeResponse);

                // 开始保存本地日志
                AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                        .append(LINE)
                        .append(logLine).append(WARP)
                        .append(NODE)
                        .append(logContentSb)
                        .toString()
                );

                // 开始网络在线日志
                LogcatAddRequestBean bean = new LogcatAddRequestBean();
                bean.setLogType(NET_LOGCAT);
                // 对应web端"日志标签"
                bean.setLogTag(logLine + WARP + LOG_NODE_APPLET);
                bean.setLogContent(logContentSb.toString());
                requestLogcatAdd(bean);
                // 日志开始----------------end


            }
        });
    }

    // ampe通道名称
    private ArrayList<String> getExtensionList() {
        ArrayList<String> extensionList = new ArrayList<>();

        extensionList.add("HHCommunication");
        return extensionList;
    }


    public void exitApplet() {
        AppLogUtils.e("exitApplet");
        AromeExitAppRequest request = new AromeExitAppRequest();
        request.appId = appletId;
        AromeServiceInvoker.invoke(request, new AromeServiceTask.Callback<AromeExitAppResponse>() {
            @Override
            public void onCallback(final AromeExitAppResponse response) {
                AppLogUtils.e("exitApplet--response:" + response);

                startBPaaSServiceFlag = false;

                closeApp();

            }
        });
    }


    HashMap<String, AmpeActionDataBean> ampeActionMap = new HashMap<>();

    // 江西
    boolean isJxInitFace;
    // 通用版本
    boolean isInitFace;

    public void appletListen() {

        setConfigStatusText("小程序通道建立成功");
        AppLogUtils.e("appletListen");


        // 日志开始----------------begin
        // 日志行数——对应web端"日志标签"
        String logLine = (new Throwable().getStackTrace())[0].toString();
        // 日志节点
        String logNode = "小程序启动成功---通道建立开始监听---";
        // 日志内容
        StringBuilder logContentSb = new StringBuilder();
        logContentSb.append(logNode);

        // 开始保存本地日志
        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                .append(LINE)
                .append(logLine).append(WARP)
                .append(NODE)
                .append(logContentSb)
                .toString()
        );

        // 开始网络在线日志
        LogcatAddRequestBean bean = new LogcatAddRequestBean();
        bean.setLogType(NET_LOGCAT);
        // 对应web端"日志标签"
        bean.setLogTag(logLine + WARP + LOG_NODE_APPLET);
        bean.setLogContent(logContentSb.toString());
        requestLogcatAdd(bean);
        // 日志开始----------------end


        // 监听小程序发出来的获取硬件配置通知,通道建立
        AromeServiceInvoker.registerBridgeExtension(new AromeServiceInvoker.BridgeExtension() {
            @Override
            public void onCalled(String action, String params, AromeServiceInvoker.BridgeCallback bridgeCallback) {

                // 日志开始----------------begin
                // 日志行数——对应web端"日志标签"
                String logLine = (new Throwable().getStackTrace())[0].toString();
                // 日志节点
                String logNode = "小程序通道建立---入参---";
                // 日志内容
                StringBuilder logContentSb = new StringBuilder();
                logContentSb.append(logNode).append(WARP)
                        .append("onCalled").append(WARP)
                        .append("action = ").append(action).append(WARP)
                        .append("params = ").append(params);

                // 开始保存本地日志
                AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                        .append(LINE)
                        .append(logLine).append(WARP)
                        .append(NODE)
                        .append(logContentSb)
                        .toString()
                );

                // 开始网络在线日志
                LogcatAddRequestBean bean = new LogcatAddRequestBean();
                bean.setLogType(NET_LOGCAT);
                // 对应web端"日志标签"
                bean.setLogTag(logLine + WARP + LOG_NODE_APPLET);
                bean.setLogContent(logContentSb.toString());
                requestLogcatAdd(bean);
                // 日志开始----------------end


                AppLogUtils.e(logContentSb);

                AppLogUtils.e("action--" + action);
                AppLogUtils.e("小程序参数params--" + params);

                AmpeAppletRequestBean ampeAppletRequestBean = gson.fromJson(params, AmpeAppletRequestBean.class);


                if (ACTION_QR.equals(ampeAppletRequestBean.getAction())) { // 二维码

                    AmpeActionDataBean qrBean = new AmpeActionDataBean();
                    qrBean.setTaskId(ampeAppletRequestBean.getTaskId());
                    qrBean.setBridgeCallback(bridgeCallback);
                    qrBean.setEvent(ampeAppletRequestBean.getEvent());
                    ampeActionMap.put(ACTION_QR, qrBean);

                } else if (ACTION_IDCard.equals(ampeAppletRequestBean.getAction())) { // 身份证


                    AmpeActionDataBean idCardBean = new AmpeActionDataBean();
                    idCardBean.setTaskId(ampeAppletRequestBean.getTaskId());
                    idCardBean.setBridgeCallback(bridgeCallback);
                    idCardBean.setEvent(ampeAppletRequestBean.getEvent());
                    AmpeAppletRequestBean.ParamsDTO paramsDTO = ampeAppletRequestBean.getParams();
                    if (paramsDTO != null) {
                        String infoTypeStr = paramsDTO.getInfoType();
                        String[] paramsArray = infoTypeStr.split(",");
                        idCardBean.setParamsArray(paramsArray);
                    }
                    ampeActionMap.put(ACTION_IDCard, idCardBean);

                    // 跳转dialog样式的Activity页面去刷证
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            Intent intent = new Intent(MainActivity.this, IDCardScanActivity.class);
                            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                        }
                    }, 500); //延时10s执行run内代码


//                    startActivity(IDCardScanActivity.class);

//                    ReadCardManager.eid.readIDCard(IDOCRCardType.IDCARD, eidLinkReadCardCallBack, mResultListener);

                } else if (ACTION_INIT_FACE.equals(ampeAppletRequestBean.getAction())) { // 刷脸——初始化startBPass
                    AppLogUtils.e("ACTION_INIT_FACE");

                    AmpeActionDataBean faceBean = new AmpeActionDataBean();
                    faceBean.setTaskId(ampeAppletRequestBean.getTaskId());
                    faceBean.setBridgeCallback(bridgeCallback);
                    faceBean.setEvent(ampeAppletRequestBean.getEvent());
                    ampeActionMap.put(ACTION_INIT_FACE, faceBean);

                    AmpeAppletRequestBean.ParamsDTO paramsFace = ampeAppletRequestBean.getParams();
                    if (paramsFace != null) {
                        ConfigData.serviceId = paramsFace.getServiceId();
                        ConfigData.scope = paramsFace.getScope();
                        ConfigData.query = paramsFace.getQuery();
                    }
//                    startBPaaSServiceFlag = true;

                    isInitFace = true;

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            initAbcpFace();
                        }
                    });


//                    InnerApi.addIpcListener(mIpcListener);
//                    Handler handler = new Handler();
//                    handler.postDelayed(new Runnable() {
//                        @Override
//                        public void run() {
////                                Main_APPStuter.setText("SDK初始化成功");
//                            isAPPStuter = true;
//                            //启动核身服务
////                                startBpaasService(ConfigData.getDeviceConfigResultBean().getTrade(), ConfigData.isNeed1V1, ConfigData.getDeviceConfigResultBean().getGroupId(), 0, ConfigData.mSessionId,
////                                        ConfigData.getDeviceConfigResultBean().getAbcpAppId(), "scanFace", false);
//
//                            // startBpaasService0000
//                            // 获取启动Bpaas刷脸的参数
//                            StartReadyBpaasServiceBean bpaasServiceBean = getStartReadyBpaasServiceBean();
////                                //启动核身服务
//                            startZfbBpaasService(bpaasServiceBean);
//
//
//                        }
//                    }, 500); // 延时3s执行run内代码


                } else if (ACTION_FACE.equals(ampeAppletRequestBean.getAction())) { // 刷脸
                    AppLogUtils.e("ACTION_FACE");

                    AmpeActionDataBean faceBean = new AmpeActionDataBean();
                    faceBean.setTaskId(ampeAppletRequestBean.getTaskId());
                    faceBean.setBridgeCallback(bridgeCallback);
                    faceBean.setEvent(ampeAppletRequestBean.getEvent());
                    ampeActionMap.put(ACTION_FACE, faceBean);

                    AmpeAppletRequestBean.ParamsDTO paramsFace = ampeAppletRequestBean.getParams();

                    if (paramsFace != null) {
                        ConfigData.serviceId = paramsFace.getServiceId();
                        ConfigData.scope = paramsFace.getScope();
                        ConfigData.query = paramsFace.getQuery();
                    }

                    // 获取启动Bpaas刷脸的参数
                    StartReadyBpaasServiceBean bpaasServiceBean = getStartReadyBpaasServiceBean();
                    //启动核身服务
//                    startBpaasService(bpaasServiceBean);
                    // 唤起刷脸 2222
                    invokeScanFace(bpaasServiceBean);

                } else if (ACTION_SCAN_FACE.equals(ampeAppletRequestBean.getAction())) { // 刷脸-江西,初始化完后直接刷脸
                    AppLogUtils.e("ACTION_SCAN_FACE");

                    AmpeActionDataBean faceBean = new AmpeActionDataBean();
                    faceBean.setTaskId(ampeAppletRequestBean.getTaskId());
                    faceBean.setBridgeCallback(bridgeCallback);
                    faceBean.setEvent(ampeAppletRequestBean.getEvent());
                    ampeActionMap.put(ACTION_SCAN_FACE, faceBean);

                    AmpeAppletRequestBean.ParamsDTO paramsFace = ampeAppletRequestBean.getParams();

                    if (paramsFace != null) {
//                        ConfigData.serviceId = paramsFace.getServiceId();
//                        ConfigData.scope = paramsFace.getScope();
//                        ConfigData.query = paramsFace.getQuery();

                        AmpeAppletRequestBean.ParamsDTO.ExtInfo extInfoBean = paramsFace.getExtInfo();
                        if (extInfoBean != null) {
                            String scopes = extInfoBean.getScopes();
                            String merchantAppId = extInfoBean.getMerchantAppId();

                            if (StringUtils.isNotNull(scopes)) {
                                ConfigData.scope = scopes;
                            }

//                            if (StringUtils.isNotNull(merchantAppId)) {
//                                ConfigData.machineAppId = merchantAppId;
//                            }

                        }
                    }

                    // 获取启动Bpaas刷脸的参数
                    StartReadyBpaasServiceBean bpaasServiceBean = getStartReadyBpaasServiceBean();


                    if (!isJxInitFace) {
                        isJxInitFace = true;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                ToastUtils.showShortToast("刷脸页面初始化...");
                                initAbcpFace();
                            }
                        });
                    } else {

                        //启动核身服务
//                    startBpaasService(bpaasServiceBean);
                        // 唤起刷脸 2222
                        invokeScanFace(bpaasServiceBean);

                    }


                } else if (ACTION_DEVICE.equals(ampeAppletRequestBean.getAction())) { // 设备信息

                    AmpeActionDataBean deviceInfoBean = new AmpeActionDataBean();
                    deviceInfoBean.setTaskId(ampeAppletRequestBean.getTaskId());
                    deviceInfoBean.setBridgeCallback(bridgeCallback);
                    deviceInfoBean.setEvent(ampeAppletRequestBean.getEvent());
                    ampeActionMap.put(ACTION_DEVICE, deviceInfoBean);

                    getDeviceInfo(ampeAppletRequestBean.getEvent(), ampeAppletRequestBean.getTaskId(), bridgeCallback);
                }

            }
        });


    }


    boolean isinvokeScanFaceFirst;


    //判断activity是否在最上层
//    @Override
//    public void onWindowFocusChanged(boolean hasFocus) {
//        super.onWindowFocusChanged(hasFocus);
//        if (!hasFocus) {
//            Config.setFaceScenicUtile(faceScenicUtile, true);
//        } else {
//            Config.setFaceScenicUtile(faceScenicUtile, false);
//        }
//    }


    // BPaaSApi启动与否的标识
    private boolean isAPPStuter = true;

    private String CardOrCode = "face";


    private Handler timeHandler = new Handler();
    private Runnable heartBeatRunnable = new Runnable() {
        @Override
        public void run() {
            if (!ConfigData.taskStatus.equals("complete")) {
                CardOrCode = "face";
                ConfigData.taskStatus = "wait";
            }
            AppLogUtils.e("-----------------重启核点服务");
//            LocalremoveTouchView();
//            removeTouchView();

//            startBpaasService(ConfigData.getDeviceConfigResultBean().getTrade()trade, ConfigData.isNeed1V1, ConfigData.getDeviceConfigResultBean().getGroupId(), 0, ConfigData.mSessionId,
//                    ConfigData.machineAppId, "scanFace", false);
//            startBpaasService(ConfigData.getDeviceConfigResultBean().getTrade(), ConfigData.isNeed1V1, ConfigData.getDeviceConfigResultBean().getGroupId(), 0, ConfigData.mSessionId,
//                    ConfigData.getDeviceConfigResultBean().getAbcpAppId(), "scanFace", false);


            // 获取启动Bpaas刷脸的参数
            StartReadyBpaasServiceBean bpaasServiceBean = getStartReadyBpaasServiceBean();
            //启动核身服务
            startZfbBpaasService(bpaasServiceBean);

        }
    };


    RefreshPage resh = new RefreshPage();

    // 在线设备配置
    DeviceConfigResultBean deviceConfigBean;

    // 0000
    @Override
    public void showDeviceConfigData(DeviceConfigResultBean resultBean) {
        if (resultBean == null) {
            AppLogUtils.e("DeviceConfigResultBean--null，从本地中开始获取数据");
            DeviceConfigResultBean deviceConfigDataFromLocal = getDeviceConfigDataFromLocal();

            if (deviceConfigDataFromLocal == null) {
                AppLogUtils.e("从本地数据deviceConfigBean == null,return");
                return;
            } else {
                AppLogUtils.e("从本地数据deviceConfigBean有值");
                resultBean = deviceConfigDataFromLocal;
            }

        }

        // 日志开始----------------begin
        // 日志行数——对应web端"日志标签"
        String logLine = (new Throwable().getStackTrace())[0].toString();
        // 日志节点
        String logNode = "拉取在线配置结果---";
        // 日志内容
        StringBuilder logContentSb = new StringBuilder();
        logContentSb.append(logNode).append(WARP)
                .append("resultBean = ").append(resultBean.toString());

        // 开始保存本地日志
        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                .append(LINE)
                .append(logLine).append(WARP)
                .append(NODE)
                .append(logContentSb)
                .toString()
        );

        // 开始网络在线日志
        LogcatAddRequestBean bean = new LogcatAddRequestBean();
        bean.setLogType(NET_LOGCAT);
        // 对应web端"日志标签"
        bean.setLogTag(logLine + WARP + LOG_NODE_NET_CONFIG_QUERY);
        bean.setLogContent(logContentSb.toString());
        requestLogcatAdd(bean);
        // 日志开始----------------end


        setConfigStatusText("拉取在线配置成功");

        deviceConfigBean = resultBean;

        // 保存-内存
        ConfigData.setDeviceConfigResultBean(deviceConfigBean);
        // 保存-sp
        String deviceConfigBeanStr = gson.toJson(deviceConfigBean);
        localConfig.setDeviceConfigResultBeanStr(deviceConfigBeanStr);


        // 小程序通道
        appletListen();


        // 刷脸配置
        boolean useAlipayFace = deviceConfigBean.isUseAlipayFace();
        AppLogUtils.e("useAlipayFace = " + useAlipayFace);
        if (useAlipayFace) {
            // 刷脸初始化
//            initAbcpFace();
        }

        // 二维码配置
        boolean useQrcode = deviceConfigBean.isUseQrcode();
        AppLogUtils.e("useQrcode = " + useQrcode);
        if (useQrcode) {
            /**
             * 刷二维码用
             * 开启串口
             */
            GetSeria();
        }

        boolean useIdcard = deviceConfigBean.isUseIdcard();
        AppLogUtils.e("useIdcard = " + useIdcard);
        if (useIdcard) {
            // 身份证
            initIDCard();
        }

        // 小程序启动配置
        tv_enter_applet.setVisibility(View.GONE);
        tv_applet_name.setVisibility(View.GONE);
        boolean automaticEnterApplet = resultBean.isAutomaticEnterApplet();
        AppLogUtils.e("小程序启动automaticEnterApplet--" + automaticEnterApplet);
        if (automaticEnterApplet) {
            // 直接进入小程序
            // 初始化ampe   1111
            initAndActive(resultBean);
            // 如果未打开，那就是error1, no implement
        } else {
            // 展示按钮
            tv_enter_applet.setVisibility(View.VISIBLE);
            tv_applet_name.setVisibility(View.VISIBLE);
            tv_applet_name.setText(deviceConfigBean.getAppName());
        }

        // 禁止下拉通知栏 false-不启用(默认) true-启用
        boolean forbidPullDown = deviceConfigBean.isForbidPullDown();
        AppLogUtils.e("下拉通知栏forbidPullDown--" + forbidPullDown);
        if (forbidPullDown) {
            iDeviceUI.hideNotification(mActivity);
        } else {
            iDeviceUI.showNotification(mActivity);
        }

        // 隐藏底部导航栏 false-不启用(默认) true-启用
        boolean hideNavigationBar = deviceConfigBean.isHideNavigationBar();
        AppLogUtils.e("底部导航栏hideNavigationBar--" + hideNavigationBar);
        if (hideNavigationBar) {
            iDeviceUI.hideNavigationBar(mActivity);
        } else {
            iDeviceUI.showNavigationBar(mActivity);
        }


        boolean mirror = deviceConfigBean.isMirror();
        AppLogUtils.e("mirror--" + mirror);
        boolean displayMirror = deviceConfigBean.isDisplayMirror();
        AppLogUtils.e("displayMirror--" + displayMirror);

        // 主页图片
        if (StringUtils.isNotNull(deviceConfigBean.getHomePageUrl())) {
            GlideUtils.loadRelativeLayout(MainActivity.this, deviceConfigBean.getHomePageUrl(), item_root);
        }

        // 启动页图片
        localConfig.setSplashImageUrl(deviceConfigBean.getStartPageUrl());


        // app自启动
        boolean autoLaunch = deviceConfigBean.isAutoLaunch();
        AppLogUtils.e("autoLaunch--" + autoLaunch);
        localConfig.setAutoApp(autoLaunch);


        // 设备心跳
        mHeartbeatPresenter = new HeartbeatPresenter(this);
        heartBeatRequestBean = new HeartBeatRequestBean();
        heartBeatRequestBean.setBizAppApkName(DeviceUtils.getAppPackageName(this));
        heartBeatRequestBean.setBizAppVersion(DeviceUtils.getAppVersionName(this));
        heartBeatRequestBean.setSn(localDeviceSN);
        mHeartbeatPresenter.requestHeartbeat(heartBeatRequestBean);

        // 设备在线心跳
        resh.mHandler.postDelayed(resh.runnableHeartbeat, TIME_HEARTBEAT);


    }

    private DeviceConfigResultBean getDeviceConfigDataFromLocal() {
        String deviceConfigResultBeanStr = localConfig.getDeviceConfigResultBeanStr("");
        if (StringUtils.isNotNull(deviceConfigResultBeanStr)) {
            deviceConfigBean = gson.fromJson(deviceConfigResultBeanStr, DeviceConfigResultBean.class);
            return deviceConfigBean;
        }
        return null;
    }


    @Override
    public void showLoading() {

    }

    @Override
    public void dismissLoading() {

    }

    @Override
    public void showError(String msg) {
//        ToastUtils.showLongToast(msg + "");

        // 日志开始----------------begin
        // 日志行数——对应web端"日志标签"
//        String logLine = (new Throwable().getStackTrace())[0].toString();
//        // 日志节点
//        String logNode = "网络请求结果异常---";
//        // 日志内容
//        StringBuilder logContentSb = new StringBuilder();
//        logContentSb.append(logNode).append(WARP)
//                .append("msg = ").append(msg);
//
//        // 开始保存本地日志
//        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
//                .append(LINE)
//                .append(logLine).append(WARP)
//                .append(NODE)
//                .append(logContentSb)
//                .toString()
//        );
//
//        // 开始网络在线日志
//        LogcatAddRequestBean bean = new LogcatAddRequestBean();
//        bean.setLogType(NET_LOGCAT);
//        // 对应web端"日志标签"
//        bean.setLogTag(logLine + WARP + LOG_NODE_NET);
//        bean.setLogContent(logContentSb.toString());
//        requestLogcatAdd(bean);
        // 日志开始----------------end

    }

    @Override
    public void showError(String url, String msg) {

//        setConfigStatusText(msg + "");

        netLogcatSave(url, msg);

        if (url.contains(API_CONFIG_QUERY)) {
            DeviceConfigResultBean deviceConfigDataFromLocal = getDeviceConfigDataFromLocal();
            if (deviceConfigDataFromLocal != null) {
                showDeviceConfigData(deviceConfigDataFromLocal);
            }
        }

    }

    // 写入无网络日志次数
    int netLogcatNum;


    private void netLogcatSave(String url, String msg) {

        // 防止无网络时，一直写入日志和请求在线日志
        if (netLogcatNum > 3) {
            return;
        }

        netLogcatNum++;
        // 日志开始----------------begin
        // 日志行数——对应web端"日志标签"
        String logLine = (new Throwable().getStackTrace())[0].toString();
        // 日志节点
        String logNode = "网络请求结果异常---";
        // 日志内容
        StringBuilder logContentSb = new StringBuilder();
        logContentSb.append(logNode).append(WARP)
                .append("url = ").append(url).append(WARP)
                .append("msg = ").append(msg);

        // 开始保存本地日志
        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                .append(LINE)
                .append(logLine).append(WARP)
                .append(NODE)
                .append(logContentSb)
                .toString()
        );

        // 开始网络在线日志
        LogcatAddRequestBean bean = new LogcatAddRequestBean();
        bean.setLogType(NET_LOGCAT);
        // 对应web端"日志标签"
        bean.setLogTag(logLine + WARP + LOG_NODE_NET);
        bean.setLogContent(logContentSb.toString());
        requestLogcatAdd(bean);
        // 日志开始----------------end
    }

    @Override
    public void showHeartbeatResult(SimpleResultBean resultBean) {

        String heartbeatUrl = "";
        if (deviceConfigBean != null && deviceConfigBean.getHeartTrackingUrl() != null) {
            heartbeatUrl = deviceConfigBean.getHeartTrackingUrl();
        }

        // 日志开始----------------begin
        // 日志行数——对应web端"日志标签"
        String logLine = (new Throwable().getStackTrace())[0].toString();
        // 日志节点
        String logNode = "设备心跳---";
        // 日志内容
        StringBuilder logContentSb = new StringBuilder();
        logContentSb.append(logNode).append(WARP)
                .append("url = ").append(heartbeatUrl).append(WARP)
                .append("msg = ").append("成功");

        // 开始保存本地日志
        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                .append(LINE)
                .append(logLine).append(WARP)
                .append(NODE)
                .append(logContentSb)
                .toString()
        );

        // 开始网络在线日志
        LogcatAddRequestBean bean = new LogcatAddRequestBean();
        bean.setLogType(NET_LOGCAT);
        // 对应web端"日志标签"
        bean.setLogTag(logLine + WARP + LOG_NODE_NET_HEARTBEAT);
        bean.setLogContent(logContentSb.toString());
        requestLogcatAdd(bean);
        // 日志开始----------------end
    }

    // 在线日志
    public void requestLogcatAdd(LogcatAddRequestBean bean) {

        if (mLogcatAddPresenter == null) {
            mLogcatAddPresenter = new LogcatAddPresenter(this);
        }

        bean.setToken(TOKEN);
        bean.setSn(DeviceUtils.getDeviceSN());

        if (isNetAvailable) {
            mLogcatAddPresenter.requestLogcatAdd(bean);
        }

    }


    @Override
    public void showLogcatAddResult(SimpleResultBean resultBean) {

    }


    // 11111
    @Override
    public void showAlipayUserInfoResult(AlipayUserInfoResultBean alipayUserInfoBeanData) {


//        AlipayUserInfoResultBean.DataDTO alipayUserInfoBeanData = resultBean.getData();
        String userName = alipayUserInfoBeanData.getUserName();
        String certNo = alipayUserInfoBeanData.getCertNo();
        AppLogUtils.e("handleMessage---userName:" + userName);
        ConfigData.taskStatus = "wait";

//                    ToastUtils.showLongToast("刷脸成功:" + userName + "  " + certNo);

        AmpeActionDataBean ampeActionDataBean = ampeActionMap.get(ACTION_FACE);
        AromeServiceInvoker.BridgeCallback bridgeCallback = ampeActionDataBean.getBridgeCallback();

        AmpeAppletResultBean bean = new AmpeAppletResultBean();
        bean.setAction(ACTION_FACE);
        bean.setEvent(ampeActionDataBean.getEvent());
        bean.setTaskId(ampeActionDataBean.getTaskId());
        bean.setSuccess(true);
        bean.setMessage("成功");


        AmpeAppletResultBean.Data dataBean = new AmpeAppletResultBean.Data();
        dataBean.setIdNum(alipayUserInfoBeanData.getCertNo());
        dataBean.setName(alipayUserInfoBeanData.getUserName());
        dataBean.setUserId(alipayUserInfoBeanData.getUserId());
        dataBean.setMobile(alipayUserInfoBeanData.getMobile());
        dataBean.setAvatar(alipayUserInfoBeanData.getAvatar());

        bean.setData(dataBean);

        // 回传处理结果给小程序
        try {
            JsonObject jsonObject = gson.toJsonTree(bean).getAsJsonObject();

            if (bridgeCallback != null) {
                bridgeCallback.callback(jsonObject.toString());
            }

            // 日志开始----------------begin
            // 日志行数——对应web端"日志标签"
            String logLine = (new Throwable().getStackTrace())[0].toString();
            // 日志节点
            String logNode = "ACTION_FACE--刷脸--用户三要素--回传处理结果给小程序--";
            // 日志内容
            StringBuilder logContentSb = new StringBuilder();
            logContentSb.append(logNode).append(WARP)
                    .append("jsonObject = ").append(jsonObject);

            // 开始保存本地日志
            AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                    .append(LINE)
                    .append(logLine).append(WARP)
                    .append(NODE)
                    .append(logContentSb)
                    .toString()
            );

            // 开始网络在线日志
            LogcatAddRequestBean logBean = new LogcatAddRequestBean();
            logBean.setLogType(NET_LOGCAT);
            logBean.setLogTag(logLine + WARP + LOG_NODE_APPLET + LOG_NODE_FACE);
            logBean.setLogContent(logContentSb.toString());
            requestLogcatAdd(logBean);
            // 日志开始----------------end

            // 打印编译器输出日志
            AppLogUtils.e(logContentSb);


        } catch (Throwable t) {
            AppLogUtils.e("onCalled--t" + t);
        }


        // 重新唤起刷脸
        invokeResume();


    }


    class RefreshPage {
        Handler mHandler = new Handler();
        Runnable runnableTime = new Runnable() {
            @Override
            public void run() {
                // 设置最新时间
                tv_time.setText(DateUtil.getTime("yyyy.MM.dd HH:mm:ss") + " " + DateUtil.getWeekOfDate(new Date()));
                // 接着发送刷新任务
                mHandler.postDelayed(runnableTime, 1000);
            }
        };


        Runnable runnableHeartbeat = new Runnable() {
            @Override
            public void run() {
                mHandler.postDelayed(runnableHeartbeat, TIME_HEARTBEAT);
                mHeartbeatPresenter.requestHeartbeat(heartBeatRequestBean);
            }
        };

    }


    private final IpcListener mIpcListener = new IpcListener() {
        @Override
        public void onConnected(IpcChannel ipcChannel) {
            //启动核身服务
//            startBpaasService(ConfigD.trade, true, Config.GroupID, 0, Config.mSessionId,
//                    Config.machineAppId, "scanFace", false);
//            startBpaasService(ConfigData.getDeviceConfigResultBean().getTrade(), true, ConfigData.getDeviceConfigResultBean().getGroupId(), 0, ConfigData.mSessionId,
//                    ConfigData.getDeviceConfigResultBean().getAbcpAppId(), "scanFace", false);


            // 获取启动Bpaas刷脸的参数
            StartReadyBpaasServiceBean bpaasServiceBean = getStartReadyBpaasServiceBean();
            //启动核身服务
            startZfbBpaasService(bpaasServiceBean);


        }

        @Override
        public void onDisconnected(IpcChannel ipcChannel) {
        }

        @Override
        public void onConnectionFailed(IpcChannel ipcChannel) {
        }
    };


    String bPassErrorMessage = "";

    private void initAbcpFace() {
        Bundle extInfo = new Bundle();
        extInfo.putLong(BPaaSApi.KEY_EXT_TIME_OUT, 2 * 60 * 600);

        // test1
//        extInfo.putString("scopes", "auth_user,order_service");

        // MachineAppId 对应 abcpAppId

        // 日志开始----------------begin
        // 日志行数——对应web端"日志标签"
        String logLine = (new Throwable().getStackTrace())[0].toString();
        // 日志节点
        String logNode = "abcp--BPaaSApi--刷脸初始化入参---";
        // 日志内容
        StringBuilder logContentSb = new StringBuilder();
        logContentSb.append(logNode).append(WARP)
                .append("APP_ID = ").append(ConfigData.getDeviceConfigResultBean().getAbcpAppId()).append(WARP)
                .append("APP_VERION = ").append(ConfigData.appVersionBPaaS).append(WARP)
                .append("extInfo = ").append(new Gson().toJson(extInfo));

        // 开始保存本地日志
        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                .append(LINE)
                .append(logLine).append(WARP)
                .append(NODE)
                .append(logContentSb)
                .toString()
        );

        // 开始网络在线日志
        LogcatAddRequestBean bean = new LogcatAddRequestBean();
        bean.setLogType(NET_LOGCAT);
        // 对应web端"日志标签"
        bean.setLogTag(logLine + WARP + LOG_NODE_FACE);
        bean.setLogContent(logContentSb.toString());
        requestLogcatAdd(bean);
        // 日志开始----------------end


        AppLogUtils.e(logContentSb);

        BPaaSApi.getInstance().init(MyApplication.getContext(), ConfigData.getDeviceConfigResultBean().getAbcpAppId(), ConfigData.appVersionBPaaS, extInfo,
                new BPaaSInitCallback() {
                    @Override
                    public void onSuccess() {

                        // 日志开始----------------begin
                        // 日志行数——对应web端"日志标签"
                        String logLine = (new Throwable().getStackTrace())[0].toString();
                        // 日志节点
                        String logNode = "BPaaSApi--init---onSuccess--刷脸初始化成功---";
                        // 日志内容
                        StringBuilder logContentSb = new StringBuilder();
                        logContentSb.append(logNode).append(WARP);

                        // 开始保存本地日志
                        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                                .append(LINE)
                                .append(logLine).append(WARP)
                                .append(NODE)
                                .append(logContentSb)
                                .toString()
                        );

                        // 开始网络在线日志
                        LogcatAddRequestBean bean = new LogcatAddRequestBean();
                        bean.setLogType(NET_LOGCAT);
                        // 对应web端"日志标签"
                        bean.setLogTag(logLine + WARP + LOG_NODE_FACE);
                        bean.setLogContent(logContentSb.toString());
                        requestLogcatAdd(bean);
                        // 日志开始----------------end

                        AppLogUtils.e(logContentSb);

                        setConfigStatusText("BPaaSApi--刷脸初始化成功");

                        //添加IpcListener,用于监听与刷脸smile的连接,便于业务自愈
                        InnerApi.addIpcListener(mIpcListener);
                        Handler handler = new Handler();
                        String finalMSessionId1 = ConfigData.mSessionId;
                        handler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
//                                Main_APPStuter.setText("SDK初始化成功");
                                isAPPStuter = true;
                                //启动核身服务
//                                startBpaasService(ConfigData.getDeviceConfigResultBean().getTrade(), ConfigData.isNeed1V1, ConfigData.getDeviceConfigResultBean().getGroupId(), 0, ConfigData.mSessionId,
//                                        ConfigData.getDeviceConfigResultBean().getAbcpAppId(), "scanFace", false);

                                // startBpaasService00
                                // 获取启动Bpaas刷脸的参数
                                StartReadyBpaasServiceBean bpaasServiceBean = getStartReadyBpaasServiceBean();
                                //启动核身服务
                                startZfbBpaasService(bpaasServiceBean);


                            }
                        }, 500); // 延时3s执行run内代码


                    }

                    @Override
                    public void onFail(String errorMessage) {
                        // E69003
                        AppLogUtils.e("BPaaSApi--init--onFail--errorMessage = " + errorMessage);

                        bPassErrorMessage = errorMessage;


                        // 日志开始----------------begin
                        // 日志行数——对应web端"日志标签"
                        String logLine = (new Throwable().getStackTrace())[0].toString();
                        // 日志节点
                        String logNode = "BPaaSApi--刷脸初始化失败---";
                        // 日志内容
                        StringBuilder logContentSb = new StringBuilder();
                        logContentSb.append(logNode).append(WARP)
                                .append("onFail---").append(WARP)
                                .append("errorMessage = ").append(errorMessage);

                        // 开始保存本地日志
                        AppLogUtils.saveLog(LogType.Error, new StringBuilder()
                                .append(LINE)
                                .append(logLine).append(WARP)
                                .append(NODE)
                                .append(logContentSb)
                                .toString()
                        );

                        // 开始网络在线日志
                        LogcatAddRequestBean bean = new LogcatAddRequestBean();
                        bean.setLogType(NET_ERROR);
                        // 对应web端"日志标签"
                        bean.setLogTag(logLine + WARP + LOG_NODE_FACE);
                        bean.setLogContent(logContentSb.toString());
                        requestLogcatAdd(bean);
                        // 日志开始----------------end


                    }
                });

        // 超过2秒不报fail，就认为初始化成功
        mMainHandler.postDelayed(new Runnable() {
            @Override
            public void run() {

//                AppLogUtils.e("startBPaaSServiceFlag = " + startBPaaSServiceFlag);
//                if (startBPaaSServiceFlag) {


                if (isInitFace) {
                    AmpeActionDataBean ampeActionDataBean = ampeActionMap.get(ACTION_INIT_FACE);
                    AromeServiceInvoker.BridgeCallback bridgeCallback = ampeActionDataBean.getBridgeCallback();

                    AmpeAppletResultBean initFaceBean = new AmpeAppletResultBean();
                    initFaceBean.setAction(ACTION_INIT_FACE);
                    initFaceBean.setEvent(ampeActionDataBean.getEvent());
                    initFaceBean.setTaskId(ampeActionDataBean.getTaskId());

                    if (StringUtils.isNull(bPassErrorMessage)) {
                        initFaceBean.setSuccess(true);
                        initFaceBean.setMessage("成功");
                    } else {
                        initFaceBean.setSuccess(false);
                        initFaceBean.setMessage(bPassErrorMessage);
                    }

                    AmpeAppletResultBean.Data dataBean = new AmpeAppletResultBean.Data();
                    initFaceBean.setData(dataBean);

                    // 回传处理结果给小程序
                    try {
                        JsonObject jsonObject = gson.toJsonTree(initFaceBean).getAsJsonObject();

                        if (bridgeCallback != null) {
                            bridgeCallback.callback(jsonObject.toString());
                        }

                        startBPaaSServiceFlag = false;

                        // 日志开始----------------begin
                        // 日志行数——对应web端"日志标签"
                        String logLineInitFace = (new Throwable().getStackTrace())[0].toString();
                        // 日志节点
                        String logNodeInitFace = "ACTION_INIT_FACE--刷脸--startBPaaSService--";
                        // 日志内容
                        StringBuilder logContentSbInitFace = new StringBuilder();
                        logContentSbInitFace.append(logNodeInitFace).append(WARP)
                                .append("jsonObject = ").append(jsonObject);

                        // 开始保存本地日志
                        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                                .append(LINE)
                                .append(logLineInitFace).append(WARP)
                                .append(NODE)
                                .append(logContentSbInitFace)
                                .toString()
                        );

                        // 开始网络在线日志
                        LogcatAddRequestBean logBeanInitFace = new LogcatAddRequestBean();
                        logBeanInitFace.setLogType(NET_LOGCAT);
                        logBeanInitFace.setLogTag(logLine + WARP + LOG_NODE_APPLET + LOG_NODE_FACE);
                        logBeanInitFace.setLogContent(logContentSbInitFace.toString());
                        requestLogcatAdd(logBeanInitFace);
                        // 日志开始----------------end

                        // 打印编译器输出日志
                        AppLogUtils.e(logContentSbInitFace);


                    } catch (Throwable t) {
                        AppLogUtils.e("onCalled--t" + t);
                    }
                } else if (isJxInitFace) {
                    AppLogUtils.e("isJxInitFace");
                    // 江西，初始化完后直接刷脸
                    StartReadyBpaasServiceBean bpaasServiceBean = getStartReadyBpaasServiceBean();
                    invokeScanFace(bpaasServiceBean);
                }


            }
        }, 2000);


    }

    private StartReadyBpaasServiceBean getStartReadyBpaasServiceBean() {
        DeviceConfigResultBean deviceConfigResultBean = ConfigData.getDeviceConfigResultBean();
        if (deviceConfigResultBean == null) {
            deviceConfigResultBean = new DeviceConfigResultBean();
        }

        StartReadyBpaasServiceBean bpaasServiceBean = new StartReadyBpaasServiceBean();
        bpaasServiceBean.setTrade(deviceConfigResultBean.getTrade());
        bpaasServiceBean.setNeed1v1(ConfigData.isNeed1V1);
        bpaasServiceBean.setCheckWay(ConfigData.checkWay);

        bpaasServiceBean.setMerchantAppId(deviceConfigResultBean.getServiceAppId());
//        bpaasServiceBean.setMerchantAppId("2021004108612349");


        bpaasServiceBean.setmSessionId(ConfigData.mSessionId);

        bpaasServiceBean.setServiceId(ConfigData.serviceId);
        bpaasServiceBean.setQuery(ConfigData.query);
        bpaasServiceBean.setScope(ConfigData.scope);
        AppLogUtils.e("ConfigData.scopes = " + ConfigData.scope);


        return bpaasServiceBean;
    }

    String mSessionId;


    boolean startBPaaSServiceFlag;

//    public void startBpaasService(String trade, boolean need1v1, String groupId, int scanFaceCheckWay, String mSessionId
//            , String machineAppId, String checkWay, boolean OnlyBPaas) {

    public void startZfbBpaasService(StartReadyBpaasServiceBean bpaasServiceBean) {

        AppLogUtils.e("BPaaSApi--startBpaasService");
//        AppLogUtils.e("BPaaSApi--startBpaasService--machineAppId = " + ConfigData.getDeviceConfigResultBean().getAbcpAppId());
//        AppLogUtils.e("BPaaSApi--startBpaasService--trade = " + bpaasServiceBean.getTrade());
        AppLogUtils.e("BPaaSApi--startBpaasService--bpaasServiceBean = " + bpaasServiceBean.toString());

//        if (mSessionId != null || (!mSessionId.equals(""))) {
////            stopBpaasService(mSessionId, faceScenicUtile);
//            return;
//        }

        Bundle params = new Bundle();
        params.putString("trade", bpaasServiceBean.getTrade());
        params.putBoolean("need1v1", bpaasServiceBean.isNeed1v1());
        params.putString("checkWay", bpaasServiceBean.getCheckWay());

        //这里 xxxxx 需替换成 isv 自己的需要授权的 merchantAppId
        params.putString("merchantAppId", bpaasServiceBean.getMerchantAppId());

        // 江西的参数-------begin

        try {
            JSONObject extInfo = new JSONObject();
            String serviceId = bpaasServiceBean.getServiceId();
            AppLogUtils.e("serviceId = " + serviceId);
            if (StringUtils.isNotNull(serviceId)) {
                extInfo.put("serviceId", serviceId);
            }

            String query = bpaasServiceBean.getQuery();
            AppLogUtils.e("query = " + query);
            if (StringUtils.isNotNull(query)) {
                extInfo.put("query", query);
            }

            String scope = bpaasServiceBean.getScope();
            AppLogUtils.e("scope = " + scope);
            if (StringUtils.isNotNull(scope)) {
                extInfo.put("scope", scope);
            }

            // 注意，如果字符串之间有空格，会导致invoke刷脸失败1001
//            extInfo.put("scope", "auth_user, order_service");
//            extInfo.put("scope", "auth_user,order_service");

            params.putString("extInfo", extInfo.toString());
            AppLogUtils.e("extInfo = " + extInfo.toString());

        } catch (JSONException e) {
            AppLogUtils.e("extInfo -- e = " + e.toString());
            e.printStackTrace();
        }
        // 江西的参数-------end


//        try {
//            extInfo.put("scope", "auth_user,order_service");
////            extInfo.put("scope", "auth_user,yingpin");
////            extInfo.put("scope", bpaasServiceBean.getScope());
//            params.putString("extInfo", extInfo.toString());
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }

        String cameraBrand = ConfigData.getDeviceConfigResultBean().getCameraBrand();
        AppLogUtils.e("cameraBrand=" + cameraBrand);
        if (CAMERA_BRAND.equals(cameraBrand)) {
            AppLogUtils.e("是马里奥的，不配置zolozConfig");
        } else {
            AppLogUtils.e("非马里奥的，开始配置zolozConfig");
            //各设备 zolozConfig 参数，参考 zolozConfig
            try {
                params.putString("zolozConfig", getHardWareConfig());
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }


        params.putLong(BPaaSApi.KEY_BPAAS_IPC_TIME_OUT, -1L);

        AppLogUtils.e("BPaaSApi--准备startBpaasService");
        AppLogUtils.e("BPaaSApi--准备startBpaasService--params：" + params.toString());

        // 日志开始----------------begin
        // 日志行数——对应web端"日志标签"
        String logLine = (new Throwable().getStackTrace())[0].toString();
        // 日志节点
        String logNode = "startBpaasService入参---";
        // 日志内容
        StringBuilder logContentSb = new StringBuilder();
        logContentSb.append(logNode).append(WARP)
                .append("params = ").append(params.toString()).append(WARP)
                .append("StartBpaasServiceBean = ").append(bpaasServiceBean.toString())
        ;

        // 开始保存本地日志
        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                .append(LINE)
                .append(logLine).append(WARP)
                .append(NODE)
                .append(logContentSb)
                .toString()
        );

        // 开始网络在线日志
        LogcatAddRequestBean bean = new LogcatAddRequestBean();
        bean.setLogType(NET_LOGCAT);
        // 对应web端"日志标签"
        bean.setLogTag(logLine + WARP + LOG_NODE_FACE);
        bean.setLogContent(logContentSb.toString());
        requestLogcatAdd(bean);
        // 日志开始----------------end

        //
        AppLogUtils.e(logContentSb);


        String finalMSessionId = ConfigData.mSessionId;
        mSessionId = BPaaSApi.getInstance().startBPaaSService(ConfigData.getDeviceConfigResultBean().getAbcpAppId(),
                "BPaasVerifyID", params, new BPaaSCallback() {
                    @Override
                    public void onResponse(BPaaSResponse bPaaSResponse) {

                        AppLogUtils.e("BPaaSApi--startBpaasService--onResponse = " + bPaaSResponse);
                        // {code=1000, subCode='E00000', subMsg='成功(E00000)', mResult='Bundle[mParcelledData.dataSize=124]', extInfo={}}
                        // code=1001, subCode='E69009', subMsg='未初始化成功，请先初始化(E69009)  注意检测getHardWareConfig
                        // {code=1001, subCode='E60001', subMsg='flow eval error', mResult='null', extInfo={}}

                        int code = bPaaSResponse.getCode();

                        AppLogUtils.e("BPaaSApi--startBpaasService--onResponse--Code = " + code);


                        // 日志开始----------------begin
                        // 日志行数——对应web端"日志标签"
                        String logLine = (new Throwable().getStackTrace())[0].toString();
                        // 日志节点
                        String logNode = "startBpaasService结果onResponse---";
                        // 日志内容
                        StringBuilder logContentSb = new StringBuilder();
                        logContentSb.append(logNode).append(WARP)
                                .append("code = ").append(code).append(WARP)
                                .append("onResponse = ").append(bPaaSResponse);

                        // 开始保存本地日志
                        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                                .append(LINE)
                                .append(logLine).append(WARP)
                                .append(NODE)
                                .append(logContentSb)
                                .toString()
                        );

                        // 开始网络在线日志
                        LogcatAddRequestBean bean = new LogcatAddRequestBean();
                        bean.setLogType(NET_LOGCAT);
                        // 对应web端"日志标签"
                        bean.setLogTag(logLine + WARP + LOG_NODE_FACE);
                        bean.setLogContent(logContentSb.toString());
                        requestLogcatAdd(bean);
                        // 日志开始----------------end


                        // 1000表示超时（已经刷脸成功拿到其他信息，但是还没有做其他处理，导致20s超时）
                        // 1004smile异常
                        if (code == 1004) {
                            //重新启动核点服务
                            startZfbBpaasService(bpaasServiceBean);
                        }


                    }

                    @Override
                    public void onEvent(String bPaasVerifyID, String resultStr, Bundle bundle) {

                        // 刷脸成功返回的数据
                        AppLogUtils.e("BPaaSApi--startBpaasService--onEvent,bPaasVerifyID: " + bPaasVerifyID + ",resultStr:" + resultStr + ",bundle = " + new Gson().toJson(bundle));

                        AppLogUtils.e("BPaaSApi--startBpaasService--onEvent,resultStr: " + resultStr);


                        // 日志开始----------------begin
                        // 日志行数——对应web端"日志标签"
                        String logLine = (new Throwable().getStackTrace())[0].toString();
                        // 日志节点
                        String logNode = LOG_NODE_FACE + "startBpaasService结果onEvent--刷脸返回数据---";
                        // 日志内容
                        StringBuilder logContentSb = new StringBuilder();
                        logContentSb.append(logNode).append(WARP)
                                .append("onEvent = ").append(WARP)
                                .append("resultStr = ").append(resultStr).append(WARP)
                                .append("bPaasVerifyID = ").append(bPaasVerifyID).append(WARP)
                                .append("bundle = ").append(new Gson().toJson(bundle));

                        // 开始保存本地日志
                        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                                .append(LINE)
                                .append(logLine).append(WARP)
                                .append(NODE)
                                .append(logContentSb)
                                .toString()
                        );

                        // 开始网络在线日志
                        LogcatAddRequestBean bean = new LogcatAddRequestBean();
                        bean.setLogType(NET_LOGCAT);
                        // 对应web端"日志标签"
                        bean.setLogTag(logLine + WARP + LOG_NODE_FACE);
                        bean.setLogContent(logContentSb.toString());
                        requestLogcatAdd(bean);
                        // 日志开始----------------end


                        // {"alipayUid":"","code":2006,"extInfo":"{\"authCode\":\"\"}","ftoken":"fp11d8fef76c02372e78fe3169cbde9ch72","isvResult":true,"subCode":"Z1208","subMessage":"抱歉，无法认出你(Z1208)","vid":""}

                        timeHandler.removeCallbacks(heartBeatRunnable);//结束核点超时的保底机制

                        // 判断扫脸是否已结束
//                        if (ConfigData.taskStatus.equals("complete")) {
//                            return;
//                        }

                        ConfigData.setFaceScenicUtile(faceScenicUtile, false);

                        // 将resultStr转成json
                        InvokeScanFaceBean invokeScanFaceBean = new Gson().fromJson(resultStr, InvokeScanFaceBean.class);

                        AppLogUtils.e("invokeScanFaceBean.getCode() = " + invokeScanFaceBean.getCode());

                        if (invokeScanFaceBean.getCode() == 1000) {

                            // 刷脸
                            if (CardOrCode.equals("face")) {

                                // String userInfoTestData = "{\"vid\":\"\",\"code\":1000,\"isvResult\":true,\"subCode\":\"\",\"ftoken\":\"fp174ad54ffa1d5e6a532583d5017e12h84\",\"sn\":\"224F010T01400827\",\"subMessage\":\"\",\"alipayUid\":\"2088612116677214\",\"extInfo\":\"{\\\"authCode\\\":\\\"87ac7d355f1b4eeba2d4080bb427FX21\\\"}\"}\n";

                                // 重新唤起
                                invokeResume();

                                // 根据配置是否请求用户信息三要素
                                boolean appGetUserInfo = deviceConfigBean.isAppGetUserInfo();
                                AppLogUtils.e("appGetUserInfo = " + appGetUserInfo);
                                if (appGetUserInfo) {
                                    // 获取三要素
                                    AlipayUserInfoRequestBean alipayUserInfoRequestBean = gson.fromJson(resultStr, AlipayUserInfoRequestBean.class);
                                    alipayUserInfoRequestBean.setSn(DeviceUtils.getDeviceSN());
                                    if (mAlipayUserInfoPresenter == null) {
                                        mAlipayUserInfoPresenter = new AlipayUserInfoPresenter(MainActivity.this);
                                    }
                                    mAlipayUserInfoPresenter.requestAlipayUserInfo(alipayUserInfoRequestBean);


                                    // 日志开始保存----------------begin
                                    // 日志行数——对应web端"日志标签"
                                    String logLineUserInfo = (new Throwable().getStackTrace())[0].toString();
                                    // 日志节点
                                    String logNodeUserInfo = "用户信息三要素---入参---";
                                    // 日志内容
                                    StringBuilder logContentSbUserInfo = new StringBuilder();
                                    logContentSbUserInfo.append(logNodeUserInfo).append(WARP)
                                            .append("alipayUserInfoRequestBean = ").append(alipayUserInfoRequestBean.toString());

                                    // 开始保存本地日志
                                    AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                                            .append(LINE)
                                            .append(logLineUserInfo).append(WARP)
                                            .append(NODE)
                                            .append(logContentSbUserInfo)
                                            .toString()
                                    );

                                    // 开始网络在线日志
                                    LogcatAddRequestBean logBeanUserInfo = new LogcatAddRequestBean();
                                    logBeanUserInfo.setLogType(NET_LOGCAT);
                                    // 对应web端"日志标签"
                                    logBeanUserInfo.setLogTag(logLineUserInfo + WARP + LOG_NODE_FACE);
                                    logBeanUserInfo.setLogContent(logContentSbUserInfo.toString());
                                    requestLogcatAdd(logBeanUserInfo);
                                    // 日志开始保存----------------end

                                    // 打印编译器输出日志
                                    AppLogUtils.e(logContentSbUserInfo);

                                } else {
                                    // 不获取，直接返回支付宝刷脸结果

                                    AmpeActionDataBean ampeActionDataBean = null;
                                    if (isInitFace) {
                                        AppLogUtils.e("BPaaSApi--startBpaasService--onEvent--isInitFace");
                                        ampeActionDataBean = ampeActionMap.get(ACTION_FACE);
                                    } else if (isJxInitFace) {
                                        AppLogUtils.e("BPaaSApi--startBpaasService--onEvent--isJxInitFace");
                                        ampeActionDataBean = ampeActionMap.get(ACTION_SCAN_FACE);
                                    }
                                    AromeServiceInvoker.BridgeCallback bridgeCallback = ampeActionDataBean.getBridgeCallback();

                                    AmpeAppletResultBean ampeAppletResultBean = new AmpeAppletResultBean();
                                    ampeAppletResultBean.setAction(ACTION_FACE);
                                    ampeAppletResultBean.setEvent(ampeActionDataBean.getEvent());
                                    ampeAppletResultBean.setTaskId(ampeActionDataBean.getTaskId());
                                    ampeAppletResultBean.setSuccess(true);
                                    ampeAppletResultBean.setMessage("成功");


                                    AmpeAppletResultBean.Data dataBean = gson.fromJson(resultStr, AmpeAppletResultBean.Data.class);

                                    ampeAppletResultBean.setData(dataBean);

                                    // 回传处理结果给小程序
                                    try {
                                        JsonObject jsonObject = gson.toJsonTree(ampeAppletResultBean).getAsJsonObject();

                                        if (bridgeCallback != null) {
                                            bridgeCallback.callback(jsonObject.toString());
                                        }


                                        // 日志开始----------------begin
                                        // 日志行数——对应web端"日志标签"
                                        String logLine11 = (new Throwable().getStackTrace())[0].toString();
                                        // 日志节点
                                        String logNode11 = "ACTION_FACE--刷脸--支付宝结果--回传处理结果给小程序--";
                                        // 日志内容
                                        StringBuilder logContentSb11 = new StringBuilder();
                                        logContentSb11.append(logNode11).append(WARP)
                                                .append("jsonObject = ").append(jsonObject).append(WARP)
                                                .append("appGetUserInfo = ").append(appGetUserInfo);

                                        // 开始保存本地日志
                                        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                                                .append(LINE)
                                                .append(logLine11).append(WARP)
                                                .append(NODE)
                                                .append(logContentSb11)
                                                .toString()
                                        );

                                        // 开始网络在线日志
                                        LogcatAddRequestBean bean11 = new LogcatAddRequestBean();
                                        bean11.setLogType(NET_LOGCAT);
                                        // 对应web端"日志标签"
                                        bean11.setLogTag(logLine11 + WARP + LOG_NODE_APPLET + LOG_NODE_FACE);
                                        bean11.setLogContent(logContentSb11.toString());
                                        requestLogcatAdd(bean11);
                                        // 日志开始----------------end

                                        // 打印编译器输出日志
                                        AppLogUtils.e(logContentSb11);


                                    } catch (Throwable t) {
                                        AppLogUtils.e("onCalled--t" + t);
                                    }


                                }


//                                bean.setSn("224F010T01400827");
////                                bean.setSn(DeviceUtils.getDeviceSN());
//
//                                String userInfoTestData = gson.toJson(bean);
//
//
//                                new Thread(new Runnable() {
//                                    @Override
//                                    public void run() {
//                                        requestUserThreeInfo(userInfoTestData);
//                                    }
//                                }).start();


                                //
                                ConfigData.taskStatus = "complete";

                            }


                        } else {

                            // 非1000

                            AmpeActionDataBean ampeActionDataBean = ampeActionMap.get(ACTION_FACE);

                            AromeServiceInvoker.BridgeCallback bridgeCallback = ampeActionDataBean.getBridgeCallback();

                            AmpeAppletResultBean ampeAppletResultBean = new AmpeAppletResultBean();
                            ampeAppletResultBean.setAction(ACTION_FACE);
                            ampeAppletResultBean.setEvent(ampeActionDataBean.getEvent());
                            ampeAppletResultBean.setTaskId(ampeActionDataBean.getTaskId());
                            ampeAppletResultBean.setSuccess(false);
                            ampeAppletResultBean.setMessage(resultStr);

                            // 回传处理结果给小程序
                            try {
                                JsonObject jsonObject = gson.toJsonTree(ampeAppletResultBean).getAsJsonObject();

                                if (bridgeCallback != null) {
                                    bridgeCallback.callback(jsonObject.toString());
                                }

                                // 日志开始----------------begin
                                // 日志行数——对应web端"日志标签"
                                String logLine11 = (new Throwable().getStackTrace())[0].toString();
                                // 日志节点
                                String logNode11 = "ACTION_FACE--刷脸--异常--支付宝结果--回传处理结果给小程序--";
                                // 日志内容
                                StringBuilder logContentSb11 = new StringBuilder();
                                logContentSb11.append(logNode11).append(WARP)
                                        .append("jsonObject = ").append(jsonObject).append(WARP);

                                // 开始保存本地日志
                                AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                                        .append(LINE)
                                        .append(logLine11).append(WARP)
                                        .append(NODE)
                                        .append(logContentSb11)
                                        .toString()
                                );

                                // 开始网络在线日志
                                LogcatAddRequestBean bean11 = new LogcatAddRequestBean();
                                bean11.setLogType(NET_LOGCAT);
                                // 对应web端"日志标签"
                                bean11.setLogTag(logLine11 + WARP + LOG_NODE_APPLET + LOG_NODE_FACE);
                                bean11.setLogContent(logContentSb11.toString());
                                requestLogcatAdd(bean11);
                                // 日志开始----------------end

                                // 打印编译器输出日志
                                AppLogUtils.e(logContentSb11);


                            } catch (Throwable t) {
                                AppLogUtils.e("onCalled--t" + t);
                            }


                            if (invokeScanFaceBean.getCode() == 1001) {
                                //

                            } else if (invokeScanFaceBean.getCode() == 2006) {
                                // 无法认出

                            }

                        }


                    }
                });

        ConfigData.mSessionId = mSessionId;
        AppLogUtils.e("startBpaasService--mSessionId = " + mSessionId);


    }


    OkHttpClient client = new OkHttpClient().newBuilder().build();
    public static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");


    String alipayUserInfoUrl = "https://ldb-permit.hz-hanghui.com:8088/hanghui/outapi/alipayApi/faceAuth/getAlipayUserInfo";

    private Handler nethandler = new NetHandler(Looper.myLooper(), this);


    public final static int USER_INFO_SUCCESS = 100;

    class NetHandler extends Handler {
        WeakReference<Activity> mainActivityWeakReference;

        //构造函数传入外部的this
        public NetHandler(@NonNull Looper looper, Activity mainActivity) {
            super(looper);
            //构建一个弱引用对象
            mainActivityWeakReference = new WeakReference<Activity>(mainActivity);
        }

        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);

            //判断活动是否还存在，如果不存在则结束
            Activity activity = mainActivityWeakReference.get();
            if (activity == null) {
                return;
            }

            switch (msg.what) {
                case USER_INFO_SUCCESS:
                    String s = (String) msg.obj;

                    AlipayUserInfoResultBean alipayUserInfoResultBean = gson.fromJson(s, AlipayUserInfoResultBean.class);


                    break;
            }
        }
    }


    // 根据authcode获取用户三要素
    private void requestUserThreeInfo(String userInfoTestData) {


        RequestBody requestBody = RequestBody.create(JSON, userInfoTestData);

        Request request = new Request.Builder().url(alipayUserInfoUrl).post(requestBody).build();
        Response response = null;
        client.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                Gson json = new Gson();
                String toJson = response.body().string();

                try {
                    AppLogUtils.e("三要素--toJson:" + toJson);
                    /**
                     * {
                     * 	"errcode": "0",
                     * 	"errmsg": "成功",
                     * 	"data": {
                     * 		"userId": "2088612116677214",
                     * 		"certNo": "",
                     * 		"mobile": "",
                     * 		"userName": "",
                     * 		"personPictures": null,
                     * 		"avatar": "https://tfs.alipayobjects.com/images/partner/TB1HRIDcIRCDuNjm2EsXXadrFX",
                     * 		"photoBase64": null
                     *        }
                     * }
                     */
                    org.json.JSONObject jsonObject1 = new org.json.JSONObject(toJson);
                    if (jsonObject1.getString("errcode").equals("0")) {
                        org.json.JSONObject responseOrder = jsonObject1.getJSONObject("data");
                        Message msg = Message.obtain();
                        msg.obj = toJson;
                        msg.what = USER_INFO_SUCCESS;
                        nethandler.sendMessage(msg);

                    } else {
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }

            }
        });


    }


    //设备 zolozConfig 参数
//    private String getHardWareConfig() throws JSONException {
//        JSONObject zolozConfig = new JSONObject();
//        zolozConfig.put("cameraID", 0);
//        zolozConfig.put("supCameraID", 1);
//        zolozConfig.put("toygerPowerMode", 0);
//        zolozConfig.put("minIod", 0.02);
////        zolozConfig.put("algorithmAngle", ConfigData.algorithmAngle);
////        zolozConfig.put("supAlgorithmAngle", ConfigData.supAlgorithmAngle);
////        zolozConfig.put("isDisplayMirror", ConfigData.isDisplayMirror);   //false
//        zolozConfig.put("algorithmAngle", 270);
//        zolozConfig.put("supAlgorithmAngle",270);
//        zolozConfig.put("isDisplayMirror",true);   //false
//        zolozConfig.put("supIsDisplayMirror", false);  //false
//        zolozConfig.put("supIsMirror", false);      //false
////        zolozConfig.put("isMirror", ConfigData.isMirror);          //true
////        zolozConfig.put("displayAngle", ConfigData.displayAngle);
//        zolozConfig.put("isMirror", true);          //true
//        zolozConfig.put("displayAngle", 90);
//        zolozConfig.put("supDisplayAngle", 90);
//        return zolozConfig.toString();
//    }


    // K8
    public String getHardWareConfig() throws JSONException {

        org.json.JSONObject zolozConfig = new JSONObject();
        zolozConfig.put("cameraID", 0); // 相机camera id 一般为0为colorCamera, 1为IrCamera
        zolozConfig.put("supCameraID", 1);  // 用于ir相机camera id，不设置的话自动用colorCameraId加1
        zolozConfig.put("toygerPowerMode", 0);
        zolozConfig.put("minIod", 0.02);
        zolozConfig.put("supIsMirror", false);  // 用于ir摄像头帧数据是否镜像
        zolozConfig.put("supIsDisplayMirror", false);    // 用于ir摄像头预览是否镜像
        zolozConfig.put("supDisplayAngle", 0);  // 用于ir摄像头预览角度，不设置的话保持和color的一致

        if (deviceConfigBean == null) {
            // 日志开始----------------begin
            // 日志行数——对应web端"日志标签"
            String logLine = (new Throwable().getStackTrace())[0].toString();
            // 日志节点
            String logNode = "摄像头配置错误---zolozConfig---getHardWareConfig---";
            // 日志内容
            StringBuilder logContentSb = new StringBuilder();
            logContentSb.append(logNode).append(WARP)
                    .append("deviceConfigBean == null，开始用默认值");

            // 开始保存本地日志
            AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                    .append(LINE)
                    .append(logLine).append(WARP)
                    .append(NODE)
                    .append(logContentSb)
                    .toString()
            );

            // 开始网络在线日志
            LogcatAddRequestBean bean = new LogcatAddRequestBean();
            bean.setLogType(NET_LOGCAT);
            // 对应web端"日志标签"
            bean.setLogTag(logLine + WARP + LOG_NODE_FACE);
            bean.setLogContent(logContentSb.toString());
            requestLogcatAdd(bean);
            // 日志开始----------------end

            // 打印编译器输出日志
            AppLogUtils.e(logContentSb);

            // 设置k8默认值
            zolozConfig.put("algorithmAngle", 90);  // 送算法的图像角度
            zolozConfig.put("supAlgorithmAngle", 90);   // 用于ir摄像头算法角度
            zolozConfig.put("displayAngle", 0);    // 预览角度
            zolozConfig.put("isDisplayMirror", true);   // 预览的图像是否需要镜像  后面的摄像头背景 false头像移动向左，摄像头里也是向左
            zolozConfig.put("isMirror", false);  // 送算法图像是否镜像   小圆圈里的

        } else {
            zolozConfig.put("algorithmAngle", deviceConfigBean.getAlgorithmAngle());  // 送算法的图像角度
            zolozConfig.put("supAlgorithmAngle", deviceConfigBean.getSupAlgorithmAngle());   // 用于ir摄像头算法角度
            zolozConfig.put("displayAngle", deviceConfigBean.getDisplayAngle());    // 预览角度
            zolozConfig.put("isDisplayMirror", deviceConfigBean.isDisplayMirror());   // 预览的图像是否需要镜像 后面的摄像头背景  false头像移动向左，摄像头里也是向左
            zolozConfig.put("isMirror", deviceConfigBean.isMirror());  // 送算法图像是否镜像  小圆圈里的
        }


        // 日志开始----------------begin
        // 日志行数——对应web端"日志标签"
        String logLine = (new Throwable().getStackTrace())[0].toString();
        // 日志节点
        String logNode = "摄像头配置---zolozConfig---getHardWareConfig---";
        // 日志内容
        StringBuilder logContentSb = new StringBuilder();
        logContentSb.append(logNode).append(WARP)
                .append("zolozConfig = ").append(zolozConfig.toString());

        // 开始保存本地日志
        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                .append(LINE)
                .append(logLine).append(WARP)
                .append(NODE)
                .append(logContentSb)
                .toString()
        );

        // 开始网络在线日志
        LogcatAddRequestBean bean = new LogcatAddRequestBean();
        bean.setLogType(NET_LOGCAT);
        // 对应web端"日志标签"
        bean.setLogTag(logLine + WARP + LOG_NODE_FACE);
        bean.setLogContent(logContentSb.toString());
        requestLogcatAdd(bean);
        // 日志开始----------------end

        // 打印编译器输出日志
        AppLogUtils.e(logContentSb);

        return zolozConfig.toString();
    }


    // ------------------身份证
    private void initIDCard() {
        ReadCardManager.initEid(getApplicationContext());
        ReadCardManager.eid.setGetDataFromSdk(true);

        // 日志开始----------------begin
        // 日志行数——对应web端"日志标签"
        String logLine = (new Throwable().getStackTrace())[0].toString();
        // 日志节点
        String logNode = "在线身份证--开始初始化---";
        // 日志内容
        StringBuilder logContentSb = new StringBuilder();
        logContentSb.append(logNode).append(WARP);

        // 开始保存本地日志
        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                .append(LINE)
                .append(logLine).append(WARP)
                .append(NODE)
                .append(logContentSb)
                .toString()
        );

        // 开始网络在线日志
        LogcatAddRequestBean bean = new LogcatAddRequestBean();
        bean.setLogType(NET_LOGCAT);
        // 对应web端"日志标签"
        bean.setLogTag(logLine + WARP + LOG_NODE_IDCARD);
        bean.setLogContent(logContentSb.toString());
        requestLogcatAdd(bean);
        // 日志开始----------------end


    }


    public static String toHexString(byte[] b) {
        String bstr = "";
        try {
            for (int i = 0; i < b.length; i++) {
                String hex = Integer.toHexString(b[i] & 0xFF);
                if (hex.length() == 1) {
                    hex = '0' + hex;
                }
                bstr = bstr + hex.toUpperCase();
            }
        } catch (Exception e) {
        }
        return bstr;
    }


    /**
     * 转16进制字符串
     *
     * @param data 数据
     * @return 16进制字符串
     */
    public static String bytesToHex(byte[] data) {
        StringBuilder sb = new StringBuilder();
        String stmp;
        for (int n = 0; n < data.length; n++) {
            stmp = (Integer.toHexString(data[n] & 0xFF));
            if (stmp.length() == 1)
                sb.append("0");
            sb.append(stmp);
        }
        return sb.toString().toUpperCase(Locale.CHINA);
    }


    @Override
    protected void onDestroy() {

        onDestroyUnregister();

        super.onDestroy();


    }

    private void onDestroyUnregister() {

        if (ReadCardManager.eid != null) {
            ReadCardManager.eid.release();
        }

        //解除注册
        if (null != iAidlInterface && iAidlInterface.asBinder().isBinderAlive()) {
            try {
                iAidlInterface.unregisterCallBack(iAidlCallBack);
            } catch (RemoteException e) {
                e.printStackTrace();
            }
        }
        //解除绑定服务
        if (null != serviceConnection) {
            unbindService(serviceConnection);
        }

        EventBus.getDefault().unregister(this);


        if (resh.mHandler != null) {
            resh.mHandler.removeCallbacksAndMessages(null);
            resh.mHandler = null;
        }


        if (mDeviceConfigPresenter != null) {
            mDeviceConfigPresenter = null;
        }

        if (mHeartbeatPresenter != null) {
            mHeartbeatPresenter = null;
        }

        if (mAlipayUserInfoPresenter != null) {
            mAlipayUserInfoPresenter = null;
        }

        if (connectivityManager != null) {
            // 网络监听
            connectivityManager.unregisterNetworkCallback(networkCallback);
        }

        startBPaaSServiceFlag = false;


    }


    // 接收IDCardScanActivity页面返回的结果
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void receiveIDCardResult(AmpeAppletResultBean resultBean) {
        AppLogUtils.e("receiveIDCardResult--bean" + resultBean.toString());
        // ACTION_IDCard--回传处理结果给小程序

        AmpeActionDataBean ampeActionDataBean = ampeActionMap.get(ACTION_IDCard);
        AromeServiceInvoker.BridgeCallback bridgeCallback = ampeActionDataBean.getBridgeCallback();

        AmpeAppletResultBean bean = new AmpeAppletResultBean();
        bean.setAction(ACTION_IDCard);
        bean.setEvent(ampeActionDataBean.getEvent());
        bean.setTaskId(ampeActionDataBean.getTaskId());
        bean.setSuccess(true);
        bean.setMessage("成功");

        AmpeAppletResultBean.Data dataBean = new AmpeAppletResultBean.Data();
        AmpeAppletResultBean.Data identityBean = resultBean.getData();

        // 可能会有空格，去除
        String name = identityBean.getName().replace(" ", "");
        String address = identityBean.getAddress();

//        String address = identityBean.getAddress().replace("\r", "");
//        AppLogUtils.e("address--" + address);
//        String address1 = identityBean.getAddress().replace("\n", "");
//        AppLogUtils.e("address1--" + address1);
//        String s = StringUtils.removeSpace(identityBean.getAddress(), ' ');
//        AppLogUtils.e("s--" + s);


//        try {
//            byte[] utf8 = identityBean.getAddress().getBytes("UTF-8");
//            String n = new String(utf8, "UTF-8");
//            AppLogUtils.e("n--" + n);
//        } catch (UnsupportedEncodingException e) {
//            e.printStackTrace();
//        }


//        String s12= "１３８";
//        String s13= "138";


        String[] paramsArray = ampeActionDataBean.getParamsArray();
//        AppLogUtils.e("paramsArray--" + paramsArray.toString());
//        String[] paramsArray = new String[]{"base", "other"};
//        String[] paramsArray = new String[]{};
        if (paramsArray != null && paramsArray.length > 0) {
            for (int i = 0; i < paramsArray.length; i++) {

                String param = paramsArray[i];

                if (param.equals("base")) {
                    dataBean.setIdNum(identityBean.getIdNum());
                    dataBean.setName(name);
                } else if (param.equals("photo")) {
                    dataBean.setPhotoBase64(identityBean.getPhotoBase64());
                } else if (param.equals("other")) {
                    dataBean.setSigningOrganization(identityBean.getSigningOrganization());
                    dataBean.setAddress(address);
                    dataBean.setNation(identityBean.getNation());
                    dataBean.setSex(identityBean.getSex());
                    dataBean.setBeginTime(identityBean.getBeginTime());
                    dataBean.setEndTime(identityBean.getEndTime());
                    dataBean.setBirthDate(identityBean.getBirthDate());
                }
            }

            bean.setData(dataBean);

        } else {
            dataBean.setIdNum(identityBean.getIdNum());
            dataBean.setName(name);

            dataBean.setSigningOrganization(identityBean.getSigningOrganization());
            dataBean.setAddress(address);
            dataBean.setNation(identityBean.getNation());
            dataBean.setSex(identityBean.getSex());
            dataBean.setBeginTime(identityBean.getBeginTime());
            dataBean.setEndTime(identityBean.getEndTime());
            dataBean.setBirthDate(identityBean.getBirthDate());
            dataBean.setPhotoBase64(identityBean.getPhotoBase64());

            bean.setData(dataBean);
        }


        // 回传处理结果给小程序
        try {
            JsonObject jsonObject = gson.toJsonTree(bean).getAsJsonObject();

            if (bridgeCallback != null) {
                bridgeCallback.callback(jsonObject.toString());
            } else {
                AppLogUtils.e("bridgeCallback--null");
            }

            // 日志开始----------------begin
            // 日志行数——对应web端"日志标签"
            String logLine = (new Throwable().getStackTrace())[0].toString();
            // 日志节点
            String logNode = "ACTION_IDCard--刷身份证--回传处理结果给小程序--";
            // 日志内容
            StringBuilder logContentSb = new StringBuilder();
            logContentSb.append(logNode).append(WARP)
                    .append("jsonObject = ").append(jsonObject);

            // 开始保存本地日志
            AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                    .append(LINE)
                    .append(logLine).append(WARP)
                    .append(NODE)
                    .append(logContentSb)
                    .toString()
            );

            // 开始网络在线日志
            LogcatAddRequestBean logBean = new LogcatAddRequestBean();
            logBean.setLogType(NET_LOGCAT);
            // 对应web端"日志标签"
            logBean.setLogTag(logLine + WARP + LOG_NODE_APPLET + LOG_NODE_IDCARD);
            logBean.setLogContent(logContentSb.toString());
            requestLogcatAdd(logBean);
            // 日志开始----------------end

            // 打印编译器输出日志
            AppLogUtils.e(logContentSb);


        } catch (Throwable t) {
            AppLogUtils.e("onCalled--t" + t);
        }

    }


    // --------------------------------二维码


    SerialControl ComA;//4个串口
    boolean isDispQueue = true;//设置标识，判断是否继续执行接收二维码返回数据线程

    private void GetSeria() {


        // 日志开始----------------begin
        // 日志行数——对应web端"日志标签"
        String logLine = (new Throwable().getStackTrace())[0].toString();
        // 日志节点
        String logNode = "二维码---初始化---开始打开串口";
        // 日志内容
        StringBuilder logContentSb = new StringBuilder();
        logContentSb.append(logNode).append(WARP);

        // 开始保存本地日志
        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                .append(LINE)
                .append(logLine).append(WARP)
                .append(NODE)
                .append(logContentSb)
                .toString()
        );

        // 开始网络在线日志
        LogcatAddRequestBean logBean = new LogcatAddRequestBean();
        logBean.setLogType(NET_LOGCAT);
        logBean.setLogTag(logLine + WARP + LOG_NODE_QR);
        logBean.setLogContent(logContentSb.toString());
        requestLogcatAdd(logBean);
        // 日志开始----------------end


        isDispQueue = true;
        ComA = new SerialControl();
        String pat = "";
        if (Build.MODEL.indexOf("F2") != -1) {
            pat = "/dev/ttyACM0";
        } else if (Build.MODEL.indexOf("TPS980") != -1) {
            pat = "/dev/ttyS0";
        } else if (Build.MODEL.indexOf("K8") != -1) {
            pat = "/dev/ttyACM0";
        } else {
            String[] DevicesPath = new SerialPortFinder().getAllDevicesPath();
            AppLogUtils.e("-------GetSeria串口-----" + new Gson().toJson(DevicesPath));
            boolean isACM = false;
            for (int i = 0; i < DevicesPath.length; i++) {
                if (DevicesPath[i].indexOf("/dev/ttyACM") != -1) {
                    isACM = true;
                    continue;
                }
            }
            if (isACM) {
                for (int i = 0; i < DevicesPath.length; i++) {
                    if (DevicesPath[i].indexOf("ttyACM") != -1) {
                        pat = DevicesPath[i];
                        return;
                    }
                }
            } else {
                AppLogUtils.e("-----------未能找到对应串口，串口连接失败  ");

                // 日志开始----------------begin
                // 日志行数——对应web端"日志标签"
                String logLine22 = (new Throwable().getStackTrace())[0].toString();
                // 日志节点
                String logNode22 = "二维码---初始化---打开串口失败---未能找到对应串口";
                // 日志内容
                StringBuilder logContentSb22 = new StringBuilder();
                logContentSb22.append(logNode22).append(WARP);

                // 开始保存本地日志
                AppLogUtils.saveLog(LogType.Error, new StringBuilder()
                        .append(LINE)
                        .append(logLine22).append(WARP)
                        .append(NODE)
                        .append(logContentSb22)
                        .toString()
                );

                // 开始网络在线日志
                LogcatAddRequestBean bean22 = new LogcatAddRequestBean();
                bean22.setLogType(NET_ERROR);
                // // 对应web端"日志标签"
                bean22.setLogTag(logLine22 + WARP + LOG_NODE_QR);
                bean22.setLogContent(logContentSb22.toString());
                requestLogcatAdd(bean22);
                // 日志开始----------------end


                return;
            }
        }
        AppLogUtils.e("--------------pat串口路径  " + pat);


        // 日志开始----------------begin
        // 日志行数——对应web端"日志标签"
        String logLine11 = (new Throwable().getStackTrace())[0].toString();
        // 日志节点
        String logNode11 = "二维码---初始化---打开串口成功";
        // 日志内容
        StringBuilder logContentSb11 = new StringBuilder();
        logContentSb11.append(logNode11).append(WARP)
                .append("串口路径 = ").append(pat);

        // 开始保存本地日志
        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                .append(LINE)
                .append(logLine11).append(WARP)
                .append(NODE)
                .append(logContentSb11)
                .toString()
        );

        // 开始网络在线日志
        LogcatAddRequestBean logBean11 = new LogcatAddRequestBean();
        logBean11.setLogType(NET_LOGCAT);
        logBean11.setLogTag(logLine11 + WARP + LOG_NODE_QR);
        logBean11.setLogContent(logContentSb11.toString());
        requestLogcatAdd(logBean11);
        // 日志开始----------------end


        // 设置串口路径
        ComA.setPort(pat);
        // 数据位，停止位，校验位
        ComA.setN81("8", "1", "N");
        //setN81(String idataBits, String istopBits, String cparity) {
        // 波特率
        ComA.setBaudRate("9600");
        OpenComPort(ComA);

        sPort = pat;
        dataBits = 8;
        stopBits = 1;
        parity = 'N';
        iBaudRate = 9600;
    }


    String sPort;
    int iBaudRate;
    int dataBits;
    int stopBits;
    char parity;

    public void OpenComPort(SerialHelper ComPort) {
        try {
            ComPort.open();
        } catch (SecurityException e) {
            AppLogUtils.e("-----------打开串口失败:没有串口读/写权限");

            // 日志开始----------------begin
            // 日志行数——对应web端"日志标签"
            String logLine = (new Throwable().getStackTrace())[0].toString();
            // 日志节点
            String logNode = "二维码---初始化---打开串口失败:没有串口读/写权限";
            // 日志内容
            StringBuilder logContentSb = new StringBuilder();
            logContentSb.append(logNode).append(WARP);

            // 开始保存本地日志
            AppLogUtils.saveLog(LogType.Error, new StringBuilder()
                    .append(LINE)
                    .append(logLine).append(WARP)
                    .append(NODE)
                    .append(logContentSb)
                    .toString()
            );

            // 开始网络在线日志
            LogcatAddRequestBean bean = new LogcatAddRequestBean();
            bean.setLogType(NET_ERROR);
            // 对应web端"日志标签"
            bean.setLogTag(logLine + WARP + LOG_NODE_QR);
            bean.setLogContent(logContentSb.toString());
            requestLogcatAdd(bean);
            // 日志开始----------------end


        } catch (IOException e) {
            AppLogUtils.e("-----------打开串口失败:未知错误");

            // 日志开始----------------begin
            // 日志行数——对应web端"日志标签"
            String logLine = (new Throwable().getStackTrace())[0].toString();
            // 日志节点
            String logNode = "二维码---初始化---打开串口失败:未知错误";
            // 日志内容
            StringBuilder logContentSb = new StringBuilder();
            logContentSb.append(logNode).append(WARP);

            // 开始保存本地日志
            AppLogUtils.saveLog(LogType.Error, new StringBuilder()
                    .append(LINE)
                    .append(logLine).append(WARP)
                    .append(NODE)
                    .append(logContentSb)
                    .toString()
            );

            // 开始网络在线日志
            LogcatAddRequestBean bean = new LogcatAddRequestBean();
            bean.setLogType(NET_ERROR);
            // 对应web端"日志标签"
            bean.setLogTag(logLine + WARP + LOG_NODE_QR);
            bean.setLogContent(logContentSb.toString());
            requestLogcatAdd(bean);
            // 日志开始----------------end

        } catch (InvalidParameterException e) {
            AppLogUtils.e("-----------打开串口失败:参数错误");

            // 日志开始----------------begin
            // 日志行数——对应web端"日志标签"
            String logLine = (new Throwable().getStackTrace())[0].toString();
            // 日志节点
            String logNode = "二维码---初始化---打开串口失败:参数错误";
            // 日志内容
            StringBuilder logContentSb = new StringBuilder();
            logContentSb.append(logNode).append(WARP);

            // 开始保存本地日志
            AppLogUtils.saveLog(LogType.Error, new StringBuilder()
                    .append(LINE)
                    .append(logLine).append(WARP)
                    .append(NODE)
                    .append(logContentSb)
                    .toString()
            );

            // 开始网络在线日志
            LogcatAddRequestBean bean = new LogcatAddRequestBean();
            bean.setLogType(NET_ERROR);
            // 对应web端"日志标签"
            bean.setLogTag(logLine + WARP + LOG_NODE_QR);
            bean.setLogContent(logContentSb.toString());
            requestLogcatAdd(bean);
            // 日志开始----------------end

        }
    }

    private List<ComBean> QueueList = new ArrayList();

    public class SerialControl extends SerialHelper {
        public SerialControl() {
        }

        @Override
        protected void onDataReceived(final ComBean ComRecData) {
            AppLogUtils.e("-----------数据处理 bRec  " + new Gson().toJson(ComRecData.bRec));
            QueueList.add(ComRecData);
            AppLogUtils.e("-------MyFunc  " + MyFunc.ByteArrToHex(ComRecData.bRec));

            // 日志开始----------------begin
            // 日志行数——对应web端"日志标签"
            String logLine = (new Throwable().getStackTrace())[0].toString();
            // 日志节点
            String logNode = LOG_NODE_QR + "结果";
            // 日志内容
            StringBuilder logContentSb = new StringBuilder();
            logContentSb.append(logNode).append(WARP)
                    .append("原始数据 = ").append(new Gson().toJson(ComRecData.bRec)).append(WARP)
                    .append("原始数据MyFunc转换 = ").append(MyFunc.ByteArrToHex(ComRecData.bRec));

            // 开始保存本地日志
            AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                    .append(LINE)
                    .append(logLine).append(WARP)
                    .append(NODE)
                    .append(logContentSb)
                    .toString()
            );

            // 开始网络在线日志
            LogcatAddRequestBean bean = new LogcatAddRequestBean();
            bean.setLogType(NET_LOGCAT);
            bean.setLogTag(logLine + WARP + LOG_NODE_QR);
            bean.setLogContent(logContentSb.toString());
            requestLogcatAdd(bean);
            // 日志开始----------------end


        }

        //尝试进行转换
        @Override
        protected void DoQueue() {
            if (QueueList.size() > 0) {
//                for (int i = 0; i < QueueList.size(); i++) {
//                    qrData = qrData + new String(QueueList.get(i).bRec);
//                }
//                AppLogUtils.e("-----------SerialControl二维码结果  " + qrData);
                qrData = new String(QueueList.get(0).bRec);
                AppLogUtils.e("-----------SerialControl二维码结果bRec  " + qrData);

                // 日志开始----------------begin
                // 日志行数——对应web端"日志标签"
                String logLine = (new Throwable().getStackTrace())[0].toString();
                // 日志节点
                String logNode = LOG_NODE_QR + "结果";
                // 日志内容
                StringBuilder logContentSb = new StringBuilder();
                logContentSb.append(logNode).append(WARP)
                        .append("转换后的数据qrData = ").append(qrData);

                // 开始保存本地日志
                AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                        .append(LINE)
                        .append(logLine).append(WARP)
                        .append(NODE)
                        .append(logContentSb)
                        .toString()
                );

                // 开始网络在线日志
                LogcatAddRequestBean bean = new LogcatAddRequestBean();
                bean.setLogType(NET_LOGCAT);
                // 对应web端"日志标签"
                bean.setLogTag(logLine + WARP + LOG_NODE_QR);
                bean.setLogContent(logContentSb.toString());
                requestLogcatAdd(bean);
                // 日志开始----------------end


                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {

                        AmpeActionDataBean ampeActionDataBean = ampeActionMap.get(ACTION_QR);
                        AromeServiceInvoker.BridgeCallback bridgeCallback = null;
                        try {
                            bridgeCallback = ampeActionDataBean.getBridgeCallback();
                        } catch (NullPointerException e) {
                            e.printStackTrace();
                        }

                        AmpeAppletResultBean bean = new AmpeAppletResultBean();
                        bean.setAction(ACTION_QR);
                        bean.setEvent(ampeActionDataBean.getEvent());
                        bean.setTaskId(ampeActionDataBean.getTaskId());
                        bean.setSuccess(true);
                        bean.setMessage("成功");

                        AmpeAppletResultBean.Data dataBean = new AmpeAppletResultBean.Data();
                        dataBean.setQrCode(qrData);
                        bean.setData(dataBean);

                        // 回传处理结果给小程序
                        try {
                            JsonObject jsonObject = gson.toJsonTree(bean).getAsJsonObject();
                            if (bridgeCallback != null) {
                                bridgeCallback.callback(jsonObject.toString());
                            }

                            // 日志开始----------------begin
                            // 日志行数——对应web端"日志标签"
                            String logLine = (new Throwable().getStackTrace())[0].toString();
                            // 日志节点
                            String logNode = "ACTION_QR--二维码--回传处理结果给小程序";
                            // 日志内容
                            StringBuilder logContentSb = new StringBuilder();
                            logContentSb.append(logNode).append(WARP)
                                    .append("jsonObject = ").append(jsonObject);

                            // 开始保存本地日志
                            AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                                    .append(LINE)
                                    .append(logLine).append(WARP)
                                    .append(NODE)
                                    .append(logContentSb)
                                    .toString()
                            );

                            // 开始网络在线日志
                            LogcatAddRequestBean logBean = new LogcatAddRequestBean();
                            logBean.setLogType(NET_LOGCAT);
                            // 对应web端"日志标签"
                            logBean.setLogTag(logLine + WARP + LOG_NODE_APPLET + LOG_NODE_QR);
                            logBean.setLogContent(logContentSb.toString());
                            requestLogcatAdd(logBean);
                            // 日志开始----------------end

                            // 打印编译器输出日志
                            AppLogUtils.e(logContentSb);

                        } catch (Throwable t) {
                            AppLogUtils.e("onCalled--t" + t);
                        }

                    }
                });

//                GetSeria();


//                ToastUtils.showLongToast("SerialControl二维码结果  " + qrData);

//                RecHandler.postDelayed(RecRunnable, 0);
                QueueList.clear();
            }
        }
    }


    public String qrData = "";


    public void getDeviceInfo(String event, String taskId, AromeServiceInvoker.BridgeCallback bridgeCallback) {


        AmpeAppletResultBean bean = new AmpeAppletResultBean();
        bean.setAction(ACTION_DEVICE);
        bean.setEvent(event);
        bean.setTaskId(taskId);
        bean.setSuccess(true);
        bean.setMessage("成功");

        AmpeAppletResultBean.Data dataBean = new AmpeAppletResultBean.Data();
        // sn
        dataBean.setSn(DeviceUtils.getDeviceSN());
        // 设备型号
        dataBean.setDeviceModel(DeviceUtils.getDeviceModel());
        // IP
        dataBean.setDeviceIP(DeviceUtils.getDeviceIP());
        // 设备固件号
        dataBean.setdeviceDisplay(DeviceUtils.getDeviceDisplay());
        // app版本号
        dataBean.setAppVersion(DeviceUtils.getAppVersionCode(mActivity) + "");
        // android版本
        dataBean.setAndroidVersion(DeviceUtils.getAndroidVersion());
        // 设置data
        bean.setData(dataBean);
        AppLogUtils.e("bean:" + bean.toString());

        // 回传处理结果给小程序
        try {
            JsonObject jsonObject = gson.toJsonTree(bean).getAsJsonObject();
            if (bridgeCallback != null) {
                bridgeCallback.callback(jsonObject.toString());
            }

            // 日志开始----------------begin
            // 日志行数——对应web端"日志标签"
            String logLine = (new Throwable().getStackTrace())[0].toString();
            // 日志节点
            String logNode = "ACTION_DEVICE--设备信息--回传处理结果给小程序--";
            // 日志内容
            StringBuilder logContentSb = new StringBuilder();
            logContentSb.append(logNode).append(WARP)
                    .append("jsonObject = ").append(jsonObject);

            // 开始保存本地日志
            AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                    .append(LINE)
                    .append(logLine).append(WARP)
                    .append(NODE)
                    .append(logContentSb)
                    .toString()
            );

            // 开始网络在线日志
            LogcatAddRequestBean logBean = new LogcatAddRequestBean();
            logBean.setLogType(NET_LOGCAT);
            // 对应web端"日志标签"
            logBean.setLogTag(logLine + WARP + LOG_NODE_APPLET + LOG_NODE_DEVICE);
            logBean.setLogContent(logContentSb.toString());
            requestLogcatAdd(logBean);
            // 日志开始----------------end

            // 打印编译器输出日志
            AppLogUtils.e(logContentSb);

        } catch (Throwable t) {
            AppLogUtils.e("onCalled--t" + t);
        }


    }


    // ------------------------OMC相关的操作
    // 关闭app
    private void closeApp() {
        AppLogUtils.e("closeApp");
        finish();
        android.os.Process.killProcess(android.os.Process.myPid());
        System.exit(0);
    }

    // 重启设备
    private void restartDevice() {

        try {
            // posutil
            ShellUtils.execCommand("reboot", true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    // 调用刷脸服务
    public void invokeScanFace(StartReadyBpaasServiceBean bpaasServiceBean) {
        CardOrCode = "face";
//        if (Config.taskStatus.equals("doing") || Config.taskStatus.equals("wait")) {
        ConfigData.setFaceScenicUtile(faceScenicUtile, true);
        Map<String, Object> params = new HashMap<>();


        // test3   都放开注释，仅展示订单的
//        JSONObject extInfo = new JSONObject();
//        try {
//            extInfo.put("scope", "auth_user,order_service");
//            params.put("extInfo", extInfo.toString());
//        } catch (JSONException e) {
//            e.printStackTrace();
//        }
//        params.put("scope", "auth_user,order_service");

//        params.put("checkWay", bpaasServiceBean.getCheckWay());
        params.put("checkWay", ConfigData.checkWay);


        // 江西的参数-------begin
//        String serviceId = bpaasServiceBean.getServiceId();
//        AppLogUtils.e("serviceId = " + serviceId);
//        if (StringUtils.isNotNull(serviceId)) {
//            params.put("serviceId", serviceId);
//        }
//
//        String query = bpaasServiceBean.getQuery();
//        AppLogUtils.e("query = " + query);
//        if (StringUtils.isNotNull(query)) {
//            params.put("query", query);
//        }
//
//        String scopes = bpaasServiceBean.getScopes();
//        AppLogUtils.e("scopes = " + scopes);
//        if (StringUtils.isNotNull(scopes)) {
//            params.put("scopes", scopes);
//        }
        // 江西的参数-------end


        invoke(params, ConfigData.mSessionId);
//        }
    }

    public void invoke(Map<String, Object> params, String mSessionId) {
        AppLogUtils.e("invoke -- params = " + params.toString());
        AppLogUtils.e("invoke -- mSessionId = " + mSessionId);
        // 初始化Bpaas服务前先判断mSessionId
        if (mSessionId == null) {
            AppLogUtils.e("invoke, mSessionId is null");
            return;
        }
        if (params == null) {
            params = new HashMap<>();
        }

        AppLogUtils.e("invoke -- params = " + params.toString());

        params.put(BPaaSApi.KEY_BPAAS_IPC_TIME_OUT, -1L);
        BPaaSApi.getInstance().invoke(ConfigData.getDeviceConfigResultBean().getAbcpAppId(),
                "BPaasVerifyID", params, mSessionId, new BPaaSCallback() {
                    @Override
                    public void onResponse(BPaaSResponse bPaaSResponse) {
                        // 非主线程
                        AppLogUtils.e("---调用刷脸invoke onResponse = " + new Gson().toJson(bPaaSResponse) + "-----CardOrCode = " + CardOrCode);

                        int code = bPaaSResponse.getCode();

                        // 日志开始----------------begin
                        // 日志行数——对应web端"日志标签"
                        String logLine = (new Throwable().getStackTrace())[0].toString();
                        // 日志节点
                        String logNode = "刷脸invoke---onResponse---";
                        // 日志内容
                        StringBuilder logContentSb = new StringBuilder();
                        logContentSb.append(logNode).append(WARP)
                                .append("code = ").append(code).append(WARP)
                                .append("bPaaSResponse = ").append(bPaaSResponse);

                        // 开始保存本地日志
                        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                                .append(LINE)
                                .append(logLine).append(WARP)
                                .append(NODE)
                                .append(logContentSb)
                                .toString()
                        );

                        // 开始网络在线日志
                        LogcatAddRequestBean bean = new LogcatAddRequestBean();
                        bean.setLogType(NET_LOGCAT);
                        // 对应web端"日志标签"
                        bean.setLogTag(logLine + WARP + LOG_NODE_FACE);
                        bean.setLogContent(logContentSb.toString());
                        requestLogcatAdd(bean);
                        // 日志开始----------------end


                        if (code == 1000) {
                            if (ConfigData.taskStatus.equals("complete") || (!CardOrCode.equals("QrCard") &&
                                    !CardOrCode.equals("Card"))) {
                                return;
                            }

                            timeHandler.removeCallbacks(heartBeatRunnable);//结束核点超时的保底机制
                            ConfigData.taskStatus = "complete";

//                            SetFederatedPlatformsBean setFederatedPlatformsBean = Config.getSetFederatedPlatformsBean();
//                            setMyFederatedPlatforms(setFederatedPlatformsBean,
//                                    setFederatedPlatformsBean.getData().get(0).getName(),
//                                    setFederatedPlatformsBean.getData().get(0).getCardid(),
//                                    setFederatedPlatformsBean.getData().get(0).getPhone());
                        } else if (code == 1001) {
                            ToastUtils.showLongToast(bPaaSResponse.getSubMsg());
//                            LocalremoveTouchView();
                        }
                    }

                    @Override
                    public void onEvent(String id, String resultStr, Bundle bundle) {
                        AppLogUtils.e("---调用刷脸invoke--onEvent--id = " + id + "----resultStr = " + resultStr + "-- bundle = " + new Gson().toJson(bundle));
                        // {"alipayUid":"","code":1001,"extInfo":"{\"authCode\":\"\"}","isvResult":true,"subCode":"Z6136","subMessage":"没有认出你，请再试一次(Z6136)","vid":""}null
                        // {"alipayUid":"2088612116677214","code":1000,"extInfo":"{\"authCode\":\"b34a132e7650445eb9b254d5dd7dDD21\"}","ftoken":"fp103df6a4e88e2611591822c46101e3h91","isvResult":true,"subCode":"","subMessage":"","vid":""}-- bundle = null

                        // 日志开始----------------begin
                        // 日志行数——对应web端"日志标签"
                        String logLine = (new Throwable().getStackTrace())[0].toString();
                        // 日志节点
                        String logNode = "刷脸invoke---onEvent---";
                        // 日志内容
                        StringBuilder logContentSb = new StringBuilder();
                        logContentSb.append(logNode).append(WARP)
                                .append("id = ").append(id).append(WARP)
                                .append("resultStr = ").append(resultStr).append(WARP)
                                .append("bundle = ").append(new Gson().toJson(bundle));

                        // 开始保存本地日志
                        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                                .append(LINE)
                                .append(logLine).append(WARP)
                                .append(NODE)
                                .append(logContentSb)
                                .toString()
                        );

                        // 开始网络在线日志
                        LogcatAddRequestBean bean = new LogcatAddRequestBean();
                        bean.setLogType(NET_LOGCAT);
                        // 对应web端"日志标签"
                        bean.setLogTag(logLine + WARP + LOG_NODE_FACE);
                        bean.setLogContent(logContentSb.toString());
                        requestLogcatAdd(bean);
                        // 日志开始----------------end

                        // 将resultStr转成json
                        InvokeScanFaceBean invokeScanFaceBean = new Gson().fromJson(resultStr, InvokeScanFaceBean.class);

                        if (invokeScanFaceBean.getCode() == 1000) {

                            // 刷脸
                            if (CardOrCode.equals("face")) {

                                // String userInfoTestData = "{\"vid\":\"\",\"code\":1000,\"isvResult\":true,\"subCode\":\"\",\"ftoken\":\"fp174ad54ffa1d5e6a532583d5017e12h84\",\"sn\":\"224F010T01400827\",\"subMessage\":\"\",\"alipayUid\":\"2088612116677214\",\"extInfo\":\"{\\\"authCode\\\":\\\"87ac7d355f1b4eeba2d4080bb427FX21\\\"}\"}\n";

                                // 重新唤起
                                invokeResume();

                                // 根据配置是否请求用户信息三要素
                                boolean appGetUserInfo = deviceConfigBean.isAppGetUserInfo();
                                AppLogUtils.e("appGetUserInfo = " + appGetUserInfo);
                                if (appGetUserInfo) {
                                    // 获取三要素
                                    AlipayUserInfoRequestBean alipayUserInfoRequestBean = gson.fromJson(resultStr, AlipayUserInfoRequestBean.class);
                                    alipayUserInfoRequestBean.setSn(DeviceUtils.getDeviceSN());
                                    if (mAlipayUserInfoPresenter == null) {
                                        mAlipayUserInfoPresenter = new AlipayUserInfoPresenter(MainActivity.this);
                                    }
                                    mAlipayUserInfoPresenter.requestAlipayUserInfo(alipayUserInfoRequestBean);


                                    // 日志开始保存----------------begin
                                    // 日志行数——对应web端"日志标签"
                                    String logLineUserInfo = (new Throwable().getStackTrace())[0].toString();
                                    // 日志节点
                                    String logNodeUserInfo = "用户信息三要素---入参---";
                                    // 日志内容
                                    StringBuilder logContentSbUserInfo = new StringBuilder();
                                    logContentSbUserInfo.append(logNodeUserInfo).append(WARP)
                                            .append("alipayUserInfoRequestBean = ").append(alipayUserInfoRequestBean.toString());

                                    // 开始保存本地日志
                                    AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                                            .append(LINE)
                                            .append(logLineUserInfo).append(WARP)
                                            .append(NODE)
                                            .append(logContentSbUserInfo)
                                            .toString()
                                    );

                                    // 开始网络在线日志
                                    LogcatAddRequestBean logBeanUserInfo = new LogcatAddRequestBean();
                                    logBeanUserInfo.setLogType(NET_LOGCAT);
                                    // 对应web端"日志标签"
                                    logBeanUserInfo.setLogTag(logLineUserInfo + WARP + LOG_NODE_FACE);
                                    logBeanUserInfo.setLogContent(logContentSbUserInfo.toString());
                                    requestLogcatAdd(logBeanUserInfo);
                                    // 日志开始保存----------------end

                                    // 打印编译器输出日志
                                    AppLogUtils.e(logContentSbUserInfo);

                                } else {
                                    // 不获取，直接返回支付宝刷脸结果
                                    AmpeActionDataBean ampeActionDataBean = ampeActionMap.get(ACTION_FACE);

                                    AromeServiceInvoker.BridgeCallback bridgeCallback = ampeActionDataBean.getBridgeCallback();

                                    AmpeAppletResultBean ampeAppletResultBean = new AmpeAppletResultBean();
                                    ampeAppletResultBean.setAction(ACTION_FACE);
                                    ampeAppletResultBean.setEvent(ampeActionDataBean.getEvent());
                                    ampeAppletResultBean.setTaskId(ampeActionDataBean.getTaskId());
                                    ampeAppletResultBean.setSuccess(true);
                                    ampeAppletResultBean.setMessage("成功");


                                    AmpeAppletResultBean.Data dataBean = gson.fromJson(resultStr, AmpeAppletResultBean.Data.class);

                                    ampeAppletResultBean.setData(dataBean);

                                    // 回传处理结果给小程序
                                    try {
                                        JsonObject jsonObject = gson.toJsonTree(ampeAppletResultBean).getAsJsonObject();

                                        if (bridgeCallback != null) {
                                            bridgeCallback.callback(jsonObject.toString());
                                        }


                                        // 日志开始----------------begin
                                        // 日志行数——对应web端"日志标签"
                                        String logLine11 = (new Throwable().getStackTrace())[0].toString();
                                        // 日志节点
                                        String logNode11 = "ACTION_FACE--刷脸--支付宝结果--回传处理结果给小程序--";
                                        // 日志内容
                                        StringBuilder logContentSb11 = new StringBuilder();
                                        logContentSb11.append(logNode11).append(WARP)
                                                .append("jsonObject = ").append(jsonObject).append(WARP)
                                                .append("appGetUserInfo = ").append(appGetUserInfo);

                                        // 开始保存本地日志
                                        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                                                .append(LINE)
                                                .append(logLine11).append(WARP)
                                                .append(NODE)
                                                .append(logContentSb11)
                                                .toString()
                                        );

                                        // 开始网络在线日志
                                        LogcatAddRequestBean bean11 = new LogcatAddRequestBean();
                                        bean11.setLogType(NET_LOGCAT);
                                        // 对应web端"日志标签"
                                        bean11.setLogTag(logLine11 + WARP + LOG_NODE_APPLET + LOG_NODE_FACE);
                                        bean11.setLogContent(logContentSb11.toString());
                                        requestLogcatAdd(bean11);
                                        // 日志开始----------------end

                                        // 打印编译器输出日志
                                        AppLogUtils.e(logContentSb11);


                                    } catch (Throwable t) {
                                        AppLogUtils.e("onCalled--t" + t);
                                    }


                                }


                                //
                                ConfigData.taskStatus = "complete";

                            }


                        } else {

                            // 非1000

                            AmpeActionDataBean ampeActionDataBean = ampeActionMap.get(ACTION_FACE);

                            AromeServiceInvoker.BridgeCallback bridgeCallback = ampeActionDataBean.getBridgeCallback();

                            AmpeAppletResultBean ampeAppletResultBean = new AmpeAppletResultBean();
                            ampeAppletResultBean.setAction(ACTION_FACE);
                            ampeAppletResultBean.setEvent(ampeActionDataBean.getEvent());
                            ampeAppletResultBean.setTaskId(ampeActionDataBean.getTaskId());
                            ampeAppletResultBean.setSuccess(false);
                            ampeAppletResultBean.setMessage(resultStr);

                            // 回传处理结果给小程序
                            try {
                                JsonObject jsonObject = gson.toJsonTree(ampeAppletResultBean).getAsJsonObject();

                                if (bridgeCallback != null) {
                                    bridgeCallback.callback(jsonObject.toString());
                                }

                                // 日志开始----------------begin
                                // 日志行数——对应web端"日志标签"
                                String logLine11 = (new Throwable().getStackTrace())[0].toString();
                                // 日志节点
                                String logNode11 = "ACTION_FACE--刷脸--异常--支付宝结果--回传处理结果给小程序--";
                                // 日志内容
                                StringBuilder logContentSb11 = new StringBuilder();
                                logContentSb11.append(logNode11).append(WARP)
                                        .append("jsonObject = ").append(jsonObject).append(WARP);

                                // 开始保存本地日志
                                AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                                        .append(LINE)
                                        .append(logLine11).append(WARP)
                                        .append(NODE)
                                        .append(logContentSb11)
                                        .toString()
                                );

                                // 开始网络在线日志
                                LogcatAddRequestBean bean11 = new LogcatAddRequestBean();
                                bean11.setLogType(NET_LOGCAT);
                                // 对应web端"日志标签"
                                bean11.setLogTag(logLine11 + WARP + LOG_NODE_APPLET + LOG_NODE_FACE);
                                bean11.setLogContent(logContentSb11.toString());
                                requestLogcatAdd(bean11);
                                // 日志开始----------------end

                                // 打印编译器输出日志
                                AppLogUtils.e(logContentSb11);


                            } catch (Throwable t) {
                                AppLogUtils.e("onCalled--t" + t);
                            }


                            if (invokeScanFaceBean.getCode() == 1001) {
                                //

                            } else if (invokeScanFaceBean.getCode() == 2006) {
                                // 无法认出

                            }

                        }


                    }
                });
    }


    // 重新唤起刷脸
    public void invokeResume() {
        Map<String, Object> params = new HashMap<>();
        params.put("action", "resume");

        // 日志开始----------------begin
        // 日志行数——对应web端"日志标签"
        String logLine = (new Throwable().getStackTrace())[0].toString();
        // 日志节点
        String logNode = LOG_NODE_FACE + "invokeResume---重新唤起刷脸---";
        // 日志内容
        StringBuilder logContentSb = new StringBuilder();
        logContentSb.append(logNode).append(WARP)
                .append("params = ").append(params.toString());

        // 开始保存本地日志
        AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                .append(LINE)
                .append(logLine).append(WARP)
                .append(NODE)
                .append(logContentSb)
                .toString()
        );

        // 开始网络在线日志
        LogcatAddRequestBean bean = new LogcatAddRequestBean();
        bean.setLogType(NET_LOGCAT);
        // 对应web端"日志标签"
        bean.setLogTag(logLine + WARP + LOG_NODE_FACE);
        bean.setLogContent(logContentSb.toString());
        requestLogcatAdd(bean);
        // 日志开始----------------end


        //参见 3.2.5
        invoke(params, ConfigData.mSessionId);
    }


    boolean hasPermission;


    /**
     * 请求权限
     */
    private void requestPermissionsMethod() {
        XXPermissions.with(this)
                // 申请多个权限
                .permission(Permission.MANAGE_EXTERNAL_STORAGE)
                // 设置权限请求拦截器（局部设置）
                //.interceptor(new PermissionInterceptor())
                // 设置不触发错误检测机制（局部设置）
                //.unchecked()
                .request(new OnPermissionCallback() {

                    @Override
                    public void onGranted(List<String> permissions, boolean all) {
                        hasPermission = true;
                    }

                    @Override
                    public void onDenied(List<String> permissions, boolean never) {
                    }
                });
    }


    // ----------aidl 消息互通-----------
    private void bindService() {

        AppLogUtils.e("bindService");
        Intent intent = new Intent();
        // 对应服务端AndroidManifest.xml配置service action:name
        String ACTION = "com.hh.hhomc.services.AidlService";
        intent.setAction(ACTION);
        // 对应服务端AndroidManifest.xml package,可能会是测试包，注意打印对应服务端app包名，不然会连不上
        intent.setPackage(BuildConfig.AIDL_SERVER_APP_PACKAGE_NAME);
        bindService(intent, serviceConnection, BIND_AUTO_CREATE);

    }

    IAidlInterface iAidlInterface;

    private ServiceConnection serviceConnection = new ServiceConnection() {
        @Override
        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
            AppLogUtils.e("onServiceConnected");
            iAidlInterface = IAidlInterface.Stub.asInterface(iBinder);
            AppLogUtils.e("onServiceConnected--iAidlInterface--" + iAidlInterface);
            try {
                iAidlInterface.asBinder().linkToDeath(mDeathRecipient, 0);
                iAidlInterface.registerCallBack(iAidlCallBack);


                // 日志开始----------------begin
                // 日志行数——对应web端"日志标签"
                String logLine = (new Throwable().getStackTrace())[0].toString();
                // 日志节点
                String logNode = "AIDL---消息通道成功---";
                // 日志内容
                StringBuilder logContentSb = new StringBuilder();
                logContentSb.append(logNode).append(WARP)
                        .append("sn = ").append(DeviceUtils.getDeviceSN()).append(WARP)
                        .append("包名 = ").append(DeviceUtils.getAppPackageName(mActivity)).append(WARP)
                        .append("版本号 = ").append(DeviceUtils.getAppVersionName(mActivity));

                // 开始保存本地日志
                AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                        .append(LINE)
                        .append(logLine).append(WARP)
                        .append(NODE)
                        .append(logContentSb)
                        .toString()
                );

                // 开始网络在线日志
                LogcatAddRequestBean bean = new LogcatAddRequestBean();
                bean.setLogType(NET_LOGCAT);
                // 对应web端"日志标签"
                bean.setLogTag(logLine + WARP + LOG_NODE_DEVICE);
                bean.setLogContent(logContentSb.toString());
                requestLogcatAdd(bean);
                // 日志开始----------------end


                // 发送消息
//                sendAppInfoMessage();

                // 发送消息
//                if (iAidlInterface != null) {
//                    AppMessageBean sendBean = new AppMessageBean();
//                    sendBean.setBusinessAppPackageName(DeviceUtils.getAppPackageName(mActivity));
//                    sendBean.setBusinessAppVersionName(DeviceUtils.getAppVersionName(mActivity));
//                    iAidlInterface.setAppMessageBean(sendBean);
//                    AppLogUtils.e("发送消息");
//                }


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

        @Override
        public void onServiceDisconnected(ComponentName componentName) {

        }
    };

    private IBinder.DeathRecipient mDeathRecipient = new IBinder.DeathRecipient() {
        //当承载IBinder的进程消失时接收回调的接口
        @Override
        public void binderDied() {
            if (null == iAidlInterface) {
                return;
            }
            iAidlInterface.asBinder().unlinkToDeath(mDeathRecipient, 0);
            iAidlInterface = null;
            //断线重来逻辑
        }
    };

    private IAidlCallBack iAidlCallBack = new IAidlCallBack.Stub() {
        @Override
        public void onMessageSuccess(AppMessageBean appMessageBean) throws RemoteException {
            AppLogUtils.e("IAidlCallBack---getAppMessageBean" + appMessageBean.toString());


            // 接受消息
//            AppMessageBean getBean = iAidlInterface.getAppMessageBean();
            if (appMessageBean != null) {
                AppLogUtils.e("接受消息");
                String op = appMessageBean.getOp();
                if (CLOSE_APP.equals(op)) {
                    AppLogUtils.e("接受消息CLOSE_APP");

                    // 日志开始----------------begin
                    // 日志行数——对应web端"日志标签"
                    String logLine = (new Throwable().getStackTrace())[0].toString();
                    // 日志节点
                    String logNode = "iAidlCallBack--接受消息--CLOSE_APP---";
                    // 日志内容
                    StringBuilder logContentSb = new StringBuilder();
                    logContentSb.append(logNode).append(WARP)
                            .append("sn = ").append(DeviceUtils.getDeviceSN()).append(WARP)
                            .append("包名 = ").append(DeviceUtils.getAppPackageName(mActivity)).append(WARP)
                            .append("版本号 = ").append(DeviceUtils.getAppVersionName(mActivity));

                    // 开始保存本地日志
                    AppLogUtils.saveLog(LogType.Logcat, new StringBuilder()
                            .append(LINE)
                            .append(logLine).append(WARP)
                            .append(NODE)
                            .append(logContentSb)
                            .toString()
                    );

                    // 开始网络在线日志
                    LogcatAddRequestBean bean = new LogcatAddRequestBean();
                    bean.setLogType(NET_LOGCAT);
                    // 对应web端"日志标签"
                    bean.setLogTag(logLine + WARP + LOG_NODE_DEVICE);
                    bean.setLogContent(logContentSb.toString());
                    requestLogcatAdd(bean);
                    // 日志开始----------------end


//                    onDestroyUnregister();

//                    AppMessageBean bean = new AppMessageBean();
//                    bean.setOp(CLOSE_APP);
//                    bean.setSender(aidlSender);
//                    iAidlInterface.setAppMessageBean(bean);

//                    new Handler().postDelayed(new Runnable() {
//                        @Override
//                        public void run() {
                    // 上面的代码放开任意一段，都会导致无法关闭app

                    if (isLaunchApplet) {
                        exitApplet();
                    } else {
                        closeApp();
                    }


//                        }
//                    }, 1500); //延时10s执行run内代码


                }
            }


        }


//        @Override
//        public void setAppMessageBean(AppMessageBean appMessageBean) throws RemoteException {
//            AppLogUtils.e("IAidlCallBack---setAppMessageBean");
//            // 接受消息
//            AppMessageBean getBean = iAidlInterface.getAppMessageBean();
//            if (getBean != null) {
//                AppLogUtils.e("接受消息");
//                String businessAppPackageName = getBean.getBusinessAppPackageName();
//                String businessAppVersionName = getBean.getBusinessAppVersionName();
//                String op = getBean.getOp();
//
//                AppLogUtils.e("接受消息----businessAppPackageName  " + businessAppPackageName);
//                AppLogUtils.e("接受消息----businessAppVersionName  " + businessAppVersionName);
//                AppLogUtils.e("接受消息----op  " + op);
//
//                closeApp();
//
//            }
//        }
//
//        @Override
//        public AppMessageBean getAppMessageBean() throws RemoteException {
//            AppLogUtils.e("IAidlCallBack---getAppMessageBean");
//            // 接受消息
//            AppMessageBean getBean = iAidlInterface.getAppMessageBean();
//            if (getBean != null) {
//                AppLogUtils.e("接受消息");
//                String businessAppPackageName = getBean.getBusinessAppPackageName();
//                String businessAppVersionName = getBean.getBusinessAppVersionName();
//
//                AppLogUtils.e("接受消息----businessAppPackageName  " + businessAppPackageName);
//                AppLogUtils.e("接受消息----businessAppVersionName  " + businessAppVersionName);
//            }
//
//
//            return getBean;
//        }

    };


    private void sendAppInfoMessage() {
        // 发送消息
        if (iAidlInterface != null) {
            try {


                String appPackageName = DeviceUtils.getAppPackageName(mActivity);
                String appVersionName = DeviceUtils.getAppVersionName(mActivity);

                AppLogUtils.e("appPackageName--" + appPackageName);
                AppLogUtils.e("appVersionName--" + appVersionName);

                AppMessageBean sendBean = new AppMessageBean();
                sendBean.setBusinessAppPackageName(appPackageName + "");
                sendBean.setBusinessAppVersionName(appVersionName + "");
                sendBean.setSender(aidlSender);
                sendBean.setSender(DeviceUtils.getDeviceSN());

                iAidlInterface.setAppMessageBean(sendBean);
            } catch (RemoteException e) {
                e.printStackTrace();
            } catch (NullPointerException e) {
                AppLogUtils.e("发送消息--NullPointerException");
                e.printStackTrace();
            }
            AppLogUtils.e("发送消息");
        } else {
            AppLogUtils.e("发送消息---iAidlInterface");
        }
    }


    // onDestroy注意aidl解绑


}