app/src/main/java/safeluck/drive/evaluation/MainActivity.java
@@ -9,6 +9,7 @@
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
@@ -24,12 +25,16 @@
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;
import androidx.work.Data;
import androidx.work.OneTimeWorkRequest;
import androidx.work.WorkManager;
import me.yokeyword.fragmentation.SupportActivity;
import safeluck.drive.evaluation.DB.appstatusdb.AppStatus;
import safeluck.drive.evaluation.DB.appstatusdb.AppStatusViewModel;
import safeluck.drive.evaluation.DB.rtktb.RTKConfig;
import safeluck.drive.evaluation.DB.rtktb.RTKConfigUpdateWorker;
import safeluck.drive.evaluation.DB.rtktb.RTKConfigViewModel;
import safeluck.drive.evaluation.DB.signalConfigdb.SignalConfigViewModel;
import safeluck.drive.evaluation.bean.ExamPlatformData;
@@ -38,6 +43,7 @@
import safeluck.drive.evaluation.cEventCenter.ICEventListener;
import safeluck.drive.evaluation.fragment.HomeFragment;
import com.anyun.exam.lib.AYSdk;
import com.anyun.im_lib.listener.IMSConnectStatusCallback;
import com.google.gson.Gson;
import com.safeluck.aykj.utils.BytesUtils;
@@ -45,6 +51,7 @@
import org.json.JSONException;
import org.json.JSONObject;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executors;
@@ -61,6 +68,7 @@
import safeluck.drive.evaluation.util.PermissionManager;
import safeluck.drive.evaluation.util.SPUtils;
import safeluck.drive.evaluation.util.Utils;
import safeluck.drive.evaluation.viewmodels.AuthMapViewmodel;
import safeluck.drive.evaluation.viewmodels.ExamPlatformModel;
import safeluck.drive.evaluation.viewmodels.TimeViewModel;
@@ -84,7 +92,7 @@
    public View viewtitle;
    private ScheduledExecutorService scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();
   private AuthMapViewmodel authMapViewmodel;
    private ICEventListener icEventListener = new ICEventListener() {
        @Override
        public void onCEvent(String topic, int msgCode, int resultCode, Object obj) {
@@ -111,6 +119,7 @@
                    try {
                        JSONObject jsonObject = new JSONObject((String) obj);
                        int bleStatus = jsonObject.getInt("bluetooth_stauts");
                        String mac = jsonObject.getString("bluetooth_addr");
                        String des ="蓝牙关闭";
                        switch (bleStatus){
                            case 0:
@@ -123,7 +132,9 @@
                                des ="蓝牙未连接";
                                break;
                            case 3:
                                authMapViewmodel.setAuthValue(3);
                                des ="蓝牙连接";
                                SPUtils.put(getApplicationContext(),SPUtils.BLUETOOTH_MAC,mac);
                                break;
                        }
                        tv_ble_status.setText(des);
@@ -138,8 +149,7 @@
        }
    };
    private List<SignalConfigRemote> signalConfiglist = new ArrayList<>();
    private int permissionCount = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
@@ -194,7 +204,21 @@
            }
        });
        authMapViewmodel = ViewModelProviders.of(this).get(AuthMapViewmodel.class);
        authMapViewmodel.getAuthValue().observe(this, new Observer<Integer>() {
            @Override
            public void onChanged(Integer integer) {
                Log.i(TAG,"AuthMapViewmodel auth="+integer);
                if (integer.intValue() == Constant.BLUETOOTH_CONNECT){
                    MyLog.i(TAG,"Bluetooth connected,auth permission and sn != null");
                    String sn = ExamPlatformData.getInstance().getMcuSN();
                    MyLog.i(TAG,"权限允许,获得到的sn="+sn);
                    Data data = new Data.Builder().putString(safeluck.drive.evaluation.DB.Constant.RTK_CONFIG_UPDATE_JSON,sn).build();
                    OneTimeWorkRequest rtkConfigUpdateWorker= new OneTimeWorkRequest.Builder(RTKConfigUpdateWorker.class).setInputData(data).build();
                    WorkManager.getInstance(getApplicationContext()).enqueue(rtkConfigUpdateWorker);
                }
            }
        });
        // TODO
        //  进行tcp连接
        final String userId = "100002";
@@ -254,6 +278,16 @@
            @Override
            public void authorized(int requestCode) {
                Log.d(TAG, "requestCode = " + requestCode);
                permissionCount++;
                if (permissionCount == PERMISSIONS.length){
                    ExamPlatformData.getInstance().setCanWriteSD(true);
                    //只要app不销毁(重启)只会请求一次,但是确保PERMISSIONS最后一个元素是writeSD
                    CThreadPoolExecutor.runInBackground(()->{
                        MyLog.i(TAG,"权限允许,开始发送配置参数");
                        sendJudgeArgs();
                    });
                }
            }
            @Override
@@ -288,7 +322,36 @@
    }
    private void sendJudgeArgs() {
        FileUtil.createdirs(getApplicationContext());
        File dir = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+File.separator+getPackageName());
        List<String> names = ExamPlatformData.getRulesettingFilesName();
        for (int i = 0; i < names.size(); i++) {
            File settFile = new File(dir,names.get(i));
            if (settFile.exists() ){
                Log.i(TAG,settFile.getName()+"存在不复制");
            }else{
                Log.i(TAG,settFile.getName()+"不存在,复制...");
                FileUtil.copyAssertFileToSD(getApplicationContext(),names.get(i));
            }
        }
        if (dir.exists()){
            File[] files = dir.listFiles();
            for (int i = 0; i < files.length; i++) {
                Log.i(TAG,files[i].getName());
                if (names.contains(files[i].getName())){
                    byte[] buffer = FileUtil.readFile(files[i].getAbsolutePath());
                    AYSdk.getInstance().sendCmd(Constant.ID_judge_args,new String(buffer).trim());
                }else{
                }
            }
        }
    }
    @Override
    protected void onDestroy() {
        super.onDestroy();