重构Config以及优化CoreService各种配置变量初始化代码。
authorsnickersun <scy@incartech.cn>
Tue, 20 Apr 2021 03:18:35 +0000 (11:18 +0800)
committersnickersun <scy@incartech.cn>
Tue, 20 Apr 2021 03:18:35 +0000 (11:18 +0800)
添加Json Config文件的支持。暂时只支持几种变量在Config中配置。

app/release/output.json [deleted file]
app/src/main/java/com/enqualcomm/support/Config.java
app/src/main/java/com/enqualcomm/support/CoreService.java

diff --git a/app/release/output.json b/app/release/output.json
deleted file mode 100644 (file)
index 3e6cc5a..0000000
+++ /dev/null
@@ -1 +0,0 @@
-[{"outputType":{"type":"APK"},"apkData":{"type":"MAIN","splits":[],"versionCode":774,"versionName":"2104062040","enabled":true,"outputFile":"ICSer_V774_2104062040_release.apk","fullName":"release","baseName":"release"},"path":"ICSer_V774_2104062040_release.apk","properties":{}}]
\ No newline at end of file
index a050f5c..7a28bd1 100644 (file)
@@ -3,6 +3,7 @@ package com.enqualcomm.support;
 import android.content.Context;
 import android.provider.Settings;
 import android.text.TextUtils;
+import android.util.JsonReader;
 
 import com.enqualcomm.support.bean.ICLocation;
 import com.enqualcomm.support.bean.Runtime;
@@ -18,8 +19,20 @@ import com.ic.protocols.protocolAPIHelper;
 import org.json.JSONException;
 import org.json.JSONStringer;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
+import java.io.StringReader;
 import java.util.HashMap;
+import java.util.List;
 
+import chestnut.Interface.json.Json;
+
+import static com.enqualcomm.support.bean.ICLocation.CUSTOM_MOD8_GPS;
+import static com.enqualcomm.support.bean.ICLocation.NORMAL_MOD;
+import static com.enqualcomm.support.bean.Runtime.AlarmType.ALARM_LOWBATTERY;
 import static com.enqualcomm.support.utils.Util.getSystemProperties;
 
 public class Config {
@@ -44,15 +57,16 @@ public class Config {
     public static final String DefaultLogFtpUser = "ftpuser";
     public static final String DefaultLogFtpPWD = "iclog";
 
+    public static String DefaultHttpLogServerUrl = "http://icfota.snicker.com.cn:8089/UploadFile.jsp";
 
-    public static final String DefaultWiFiSSID = "Xplay6";
-    public static final String DefaultWiFiPWD = "87654321";
-    public static final String DefaultWiFiEncryptType = "psk";
+    public static String DefaultWiFiSSID = "icwifi20210417";
+    public static String DefaultWiFiPWD = "87654321";
+    public static String DefaultWiFiEncryptType = "psk";
 
     public static final int GPSLocationTimeoutInSeconds = 50;
     public static final int WiFiLocationTimeoutInSeconds = 12;
 
-    public static final boolean sendSOSAtOnce = Util.getSystemProperties("persist.sys.sos_at_once", "false").equals("true");
+    public static boolean sendSOSAtOnce = false;
     public static String c43_branch_name = "none";
     public static String custom_name = "none";
 
@@ -90,52 +104,21 @@ public class Config {
      * 1  代表扫描beacon后,直接把扫描结果上报即可。
      **/
 
-    public static boolean UsePolingCheckWeared = false;
-
-    static {
-        disableWiFiScan = Util.getSystemProperties("persist.sys.disableWiFiLocation", "false").equals("true");
-        disableWristTemp = Util.getSystemProperties("persist.sys.disableWristTemp", "false").equals("true");
-        BLEScanProtocol = Util.getSystemPropertiesInt("persist.sys.BLEScanProtocol", 0);
-        UsePolingCheckWeared = Util.getSystemProperties("persist.sys.PolingCheckAnti", "false").equals("true");
-    }
-
-    private static String make() {
-        try {
-            return (new JSONStringer()).object()
-                    .key("cmd").value("Init")
-                    .key("sw_version").value("eiot_V1.0.0")
-                    .key("protocol_version").value("2.0")
-                    .key("product").value(2L)
-                    .key("swReleaseNo").value(sw_release_no)
-                    .endObject().toString();
-        } catch (JSONException jSONException) {
-            jSONException.printStackTrace();
-            return "";
-        }
-    }
-
-    public static String toJson() {
-        if (TextUtils.isEmpty(json))
-            json = make();
-        return json;
-    }
-
-
     public final static boolean isL03Tracker = getIsL03tracker();
     public final static boolean upload_logs_via_ftp = false;
     final static String KeyProtocolServerIP = "ProtocolServerIP";
     final static String KeyProtocolServerHOST = "ProtocolServerHOST";
     final static String KeyProtocolServerPort = "ProtoclServerPort";
-    ;
-    final static String KeyLogServerIP = "LogServerIP";
-    final static String KeyLogServerPort = "LogServerPort";
+
+    final static String KeyLogServerUrl = "LogServerUrl";
+
     final static String KeyFotaServerUrl = "FotaServerUrl";
 
 
     final static String KeyPpgTestCycle = "PPGTestCycle";
     final static String KeyLocationCycle = "LocationCycle";
     final static String KeyLocationMode = "LocationMode";
-    ;
+
 
     final static String KeyAlarmCycle = "HeartBeatCycle";
 
@@ -174,6 +157,268 @@ public class Config {
 
     final static String KeyLastUnReadMessage = "UnreadMsg";
 
+    private static HashMap<Integer, Boolean> AlarmConfiglist;
+    static final boolean doJsonTest=false;  //测试Jason文件标志
+    static String JsonConfigFilePath="/system/etc/protocol_config.json"; // Config文件路径
+
+    public static int  DefaultLocationMode=CUSTOM_MOD8_GPS;
+    public static int DefaultLocationCycle=60*60;
+    public static int DefaultPPGTestCycle=60;
+    public static int DefaultTemperatureTestCycle=60*60;
+
+    public static int DefaultWifiStatus=0; //0 close , 1 open, 2 open and connect using default wifi
+
+    static {
+        AlarmConfiglist = new HashMap<Integer, Boolean>();
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_SOS.ordinal(), true);
+        AlarmConfiglist.put(ALARM_LOWBATTERY.ordinal(), true);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_ANTIOFF.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_WEARED.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_CUTOFF.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_FALL.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_ABNORMAL_HEART_RATE.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_HEART_RATE_HIGH.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_HEART_RATE_LOW.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPH_HIGH.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPH_LOW.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPL_HIGH.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPL_LOW.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_SEDENTARY.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_LOCK_WATCH.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_TEMP_HIGH.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_TEMP_LOW.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_POWER_OFF.ordinal(), true);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_ESCAPE.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_NONE.ordinal(), false);
+        AlarmConfiglist.put(Runtime.AlarmType.ALARM_REMOVE_SOS.ordinal(), true);
+
+        disableWiFiScan = Util.getSystemProperties("persist.sys.disableWiFiLocation", "false").equals("true");
+        disableWristTemp = Util.getSystemProperties("persist.sys.disableWristTemp", "false").equals("true");
+        BLEScanProtocol = Util.getSystemPropertiesInt("persist.sys.BLEScanProtocol", 0);
+        JsonConfigFilePath = Util.getSystemProperties("persist.sys.JsonConfigFilePath", "/system/etc/protocol_config.json");
+        sendSOSAtOnce = Util.getSystemProperties("persist.sys.sos_at_once", "false").equals("true");
+
+
+        do_broadCast_message = Util.getSystemProperties("persist.sys.doBroadcastMSG","false").equals("true");
+
+        noPPGSensor = (ICJniUtils.isPPGavailable() == 0);
+        noTempSensor = (ICJniUtils.isTemperatureDevAvailable() == 0);
+
+        //默认关闭NTP
+        disable_ntp_server = Util.getSystemProperties("persist.sys.disableNTP", "false").equals("true");
+
+        c43_branch_name = Util.getSystemProperties("persist.sys.c43.branch");
+
+        try {
+            DefaultWifiStatus = Integer.valueOf(Util.getSystemProperties("persist.sys.DefaultWifiStatus","0"));
+        }catch (Exception e){
+            ICLogger.e(e.getMessage(),e);
+        }
+
+        if ((c43_branch_name.equals("l03")) || (c43_branch_name.equals("l05"))) {
+            noPushTxtNotifyDialog = true;
+            noSMSNotifyDialog = true;
+            noVoiceNotifyDialog = true;
+            noTempSensor = true;
+            if (c43_branch_name.equals("l05")) {
+                SOSNoNeedDial = true;//采用新写的SOS,协议只需要发送消息,无需控制拨号。
+                noPPGSensor = false;
+            } else {
+                noPPGSensor = true;
+            }
+        }
+        custom_name = Util.getSystemProperties("persist.sys.customname");
+        ICLogger.i("get CUSTOMNAME " + custom_name);
+
+        if (custom_name.equals("H88") || custom_name.equals("H88A") ) {
+            ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true);
+            DefaultLocationMode=CUSTOM_MOD8_GPS;
+            DefaultLocationCycle=60*60;
+            DefaultPPGTestCycle=60;
+            DefaultTemperatureTestCycle=60*60;
+
+            noPushTxtNotifyDialog = true;
+            noSMSNotifyDialog = false;
+            noVoiceNotifyDialog = false;
+            noPPGSensor = false;
+            noTempSensor = false;
+            needBroadcastAntiAlarm = false;
+
+        } else if (Config.custom_name.equals("l004")) {
+            ConfigAlarm(Runtime.AlarmType.ALARM_CUTOFF, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_LOCK_WATCH, true);
+            DefaultLocationMode=CUSTOM_MOD8_GPS;
+            DefaultLocationCycle=10*60;
+            DefaultPPGTestCycle=0;
+            DefaultTemperatureTestCycle=0;
+
+            noPushTxtNotifyDialog = true;
+            noSMSNotifyDialog = true;
+            noVoiceNotifyDialog = true;
+            needBroadcastAntiAlarm = false;
+            needBroadcastCutoffAlarm = true;
+            needAllwaysAlarmCutOff = false;
+            needAllwaysAlarmFenceOut = false;
+            needTemperature_abnormal_alarm = false;
+            noPPGSensor = false;
+            noTempSensor = false;
+            L004_BroadCastActionStrip = true;
+
+        } else if (custom_name.equals("YQ") || custom_name.equals("YQ_EN")) {
+            ConfigAlarm(Runtime.AlarmType.ALARM_CUTOFF, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_LOCK_WATCH, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_UNREADMSG, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_MSGREAD, true);
+            DefaultLocationMode=NORMAL_MOD;
+            DefaultLocationCycle=15*60;
+            DefaultPPGTestCycle=0;
+            DefaultTemperatureTestCycle=0;
+
+            noPushTxtNotifyDialog = false;
+            noSMSNotifyDialog = true;
+            noVoiceNotifyDialog = true;
+            noBroadCastPushTxtNotify = true;
+            noBroadCastSMSNotify = true;
+            needBroadcastAntiAlarm = false;
+            needBroadcastCutoffAlarm = true;
+            needAllwaysAlarmCutOff = true;
+            needAllwaysAlarmFenceOut = true;
+            needTemperature_abnormal_alarm = true;
+            noPushTxtReadReply = false;//A9需要阅读反馈
+            noPPGSensor = false;
+            noTempSensor = false;
+            A9_noBroadCastActionStrip = true;
+        } else if (custom_name.equals("AK")) {
+
+            ConfigAlarm(Runtime.AlarmType.ALARM_SOS, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_LOWBATTERY, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true);
+            enableSleep = true;
+            DefaultLocationMode=NORMAL_MOD;
+            DefaultLocationCycle=900;
+            DefaultPPGTestCycle=0;
+            DefaultTemperatureTestCycle=0;
+
+            noPushTxtNotifyDialog = true;
+            noSMSNotifyDialog = true;
+            noVoiceNotifyDialog = true;
+            noPPGSensor = false;
+            noTempSensor = true;
+            SOSNoNeedDial = true; //采用新写的SOS,协议只需要发送消息,无需控制拨号。
+
+        } else if (custom_name.equals("YT")) {
+
+            ConfigAlarm(Runtime.AlarmType.ALARM_SOS, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_LOWBATTERY, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true);
+            enableSleep = true;
+
+            DefaultLocationMode=NORMAL_MOD;
+            DefaultLocationCycle=900;
+            DefaultPPGTestCycle=0;
+            DefaultTemperatureTestCycle=0;
+
+            noPushTxtNotifyDialog = false;
+            noSMSNotifyDialog = false;
+            noVoiceNotifyDialog = false;
+            noPPGSensor = false;
+            noTempSensor = true;
+
+        } else if (custom_name.equals("SGL")) { //C5项目
+            ConfigAlarm(Runtime.AlarmType.ALARM_ESCAPE, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_CUTOFF, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_LOCK_WATCH, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true);
+            ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true);
+            forceMoveCheck = false; //对定位不进行运动检测。
+
+            DefaultLocationMode=CUSTOM_MOD8_GPS;
+            DefaultLocationCycle=5 * 60;
+            DefaultPPGTestCycle=0;
+            DefaultTemperatureTestCycle=0;
+
+            noPushTxtNotifyDialog = false;
+            noSMSNotifyDialog = false;
+            noVoiceNotifyDialog = true;
+            needBroadcastAntiAlarm = false;
+            needBroadcastCutoffAlarm = true;
+            needAllwaysAlarmCutOff = true;
+            needAllwaysAlarmFenceOut = false;
+            needTemperature_abnormal_alarm = false;
+            noPPGSensor = false;
+            noTempSensor = false;
+            C5_noBroadCastActionStrip = true;
+
+        } else if (Config.custom_name.equals("L02") || Config.custom_name.equals("L03") || Config.custom_name.equals("L05")) { //L02
+            Config.forceMoveCheck = false; //即爱对gps不进行运动检测,此变量专门为了给其他协议进行强制运动检测用的。
+            DefaultLocationMode=NORMAL_MOD;
+            DefaultLocationCycle=900;
+            DefaultPPGTestCycle=0;
+            DefaultTemperatureTestCycle=0;
+            noPushTxtReadReply = false;//即爱需要阅读反馈
+            noBroadCastPushTxtNotify = true;
+        } else if (Config.custom_name.equals("VitracK") || Config.custom_name.equals("wtsrui")) {
+
+            Config.ConfigAlarm(Runtime.AlarmType.ALARM_SOS, true);
+            Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOWBATTERY, true);
+            Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true);
+            Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true);
+            enableSleep = false;
+            DefaultLocationMode=CUSTOM_MOD8_GPS;
+            DefaultLocationCycle=15 * 60;
+            DefaultPPGTestCycle=15;
+            DefaultTemperatureTestCycle=15 * 60;
+
+        } else {
+
+            DefaultLocationMode=NORMAL_MOD;
+            DefaultLocationCycle=900;
+            DefaultPPGTestCycle=0;
+            DefaultTemperatureTestCycle=0;
+            noBroadCastPushTxtNotify = true;
+        }
+    }
+
+    static void load_config_fromfile(){
+        try {
+            JsonReader jsonReader=null;
+            if(doJsonTest) {
+                String jsonString = (new JSONStringer())
+                        .object().key("pversion").value("V0.2.3").key("value").value("eiot_V1.0.0").key("protocol_version").value("2.0").key("product").value(String.valueOf(2L)).key("swReleaseNo").value(String.valueOf(sw_release_no)).endObject()
+                        .toString();
+                ICLogger.d("json String "+jsonString);
+                jsonReader = new JsonReader(new StringReader(jsonString));
+            }else {
+                File jsonFile=new File(JsonConfigFilePath);
+                ICLogger.d("json file "+JsonConfigFilePath+(jsonFile.exists()?" exist":" not exist"));
+                jsonReader = new JsonReader(new FileReader(jsonFile));
+            }
+            jsonReader.beginObject();
+            while (jsonReader.hasNext()) {
+                String name = jsonReader.nextName();
+                String value = jsonReader.nextString();
+                setConfigValue(name,value);
+            }
+            jsonReader.endObject();
+
+            jsonReader.close();
+        } catch (FileNotFoundException e) {
+            e.printStackTrace();
+        } catch (IOException e) {
+            e.printStackTrace();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+    }
 
     public static void setDurationOfVibration(Context context, int cycle) {
         SharPreferenceUtil.setPrefInt(context, KEYDurationOfVibration, cycle);
@@ -350,22 +595,14 @@ public class Config {
         return SharPreferenceUtil.getPrefInt(context, "ConfigInitFlag", 0);
     }
 
-    public static void setLogServerIP(Context context, String serverIP, int serverPort) {
-
-        SharPreferenceUtil.setPrefString(context, KeyLogServerIP, serverIP);
-        SharPreferenceUtil.setPrefInt(context, KeyLogServerPort, serverPort);
-
-    }
-
-    public static String getLogServerIP(Context context) {
-        return SharPreferenceUtil.getPrefString(context, KeyLogServerIP, "http://icfota.snicker.com.cn:8089/UploadFile.jsp");
+    public static void setHttpLogServerUrl(Context context, String serverurl) {
+        SharPreferenceUtil.setPrefString(context, KeyLogServerUrl, serverurl);
     }
 
-    public static int getLogServerPort(Context context) {
-        return SharPreferenceUtil.getPrefInt(context, KeyLogServerPort, 8089);
+    public static String getHttpLogServerUrl(Context context) {
+        return SharPreferenceUtil.getPrefString(context, KeyLogServerUrl, DefaultHttpLogServerUrl);
     }
 
-
     public static void setPPGTestCycle(Context context, int cycle_ninutes) {
         SharPreferenceUtil.setPrefInt(context, KeyPpgTestCycle, cycle_ninutes);
     }
@@ -480,100 +717,6 @@ public class Config {
 
     public static void LoadMessageConfigs() {
 
-        String tmp = Util.getSystemProperties("persist.sys.doBroadcastMSG");
-        boolean ret = false;
-        if (tmp.equals("true"))
-            ret = true;
-
-        do_broadCast_message = ret;
-
-        noPPGSensor = (ICJniUtils.isPPGavailable() == 0);
-        noTempSensor = (ICJniUtils.isTemperatureDevAvailable() == 0);
-
-        //默认关闭NTP
-        disable_ntp_server = Util.getSystemProperties("persist.sys.disableNTP", "false").equals("true");
-
-        c43_branch_name = Util.getSystemProperties("persist.sys.c43.branch");
-
-        if ((c43_branch_name.equals("l03")) || (c43_branch_name.equals("l05"))) {
-            noPushTxtNotifyDialog = true;
-            noSMSNotifyDialog = true;
-            noVoiceNotifyDialog = true;
-            noTempSensor = true;
-            if (c43_branch_name.equals("l05")) {
-                SOSNoNeedDial = true;//采用新写的SOS,协议只需要发送消息,无需控制拨号。
-                noPPGSensor = false;
-            } else {
-                noPPGSensor = true;
-            }
-        }
-        custom_name = Util.getSystemProperties("persist.sys.customname");
-        ICLogger.i("get CUSTOMNAME " + custom_name);
-        if (custom_name.equals("H88") || custom_name.equals("H88A")) {
-            noPushTxtNotifyDialog = true;
-            noSMSNotifyDialog = false;
-            noVoiceNotifyDialog = false;
-            noPPGSensor = false;
-            noTempSensor = false;
-            needBroadcastAntiAlarm = false;
-        } else if ((custom_name.equals("AK"))) {
-            noPushTxtNotifyDialog = true;
-            noSMSNotifyDialog = true;
-            noVoiceNotifyDialog = true;
-            noPPGSensor = false;
-            noTempSensor = true;
-            SOSNoNeedDial = true; //采用新写的SOS,协议只需要发送消息,无需控制拨号。
-        } else if ((custom_name.equals("YT"))) {
-            noPushTxtNotifyDialog = false;
-            noSMSNotifyDialog = false;
-            noVoiceNotifyDialog = false;
-            noPPGSensor = false;
-            noTempSensor = true;
-        } else if ((custom_name.equals("l004"))) {
-            noPushTxtNotifyDialog = true;
-            noSMSNotifyDialog = true;
-            noVoiceNotifyDialog = true;
-            needBroadcastAntiAlarm = false;
-            needBroadcastCutoffAlarm = true;
-            needAllwaysAlarmCutOff = false;
-            needAllwaysAlarmFenceOut = false;
-            needTemperature_abnormal_alarm = false;
-            noPPGSensor = false;
-            noTempSensor = false;
-            L004_BroadCastActionStrip = true;
-        } else if (custom_name.equals("YQ") || custom_name.equals("YQ_EN")) { //A9-YQ
-            noPushTxtNotifyDialog = false;
-            noSMSNotifyDialog = true;
-            noVoiceNotifyDialog = true;
-            noBroadCastPushTxtNotify = true;
-            noBroadCastSMSNotify = true;
-            needBroadcastAntiAlarm = false;
-            needBroadcastCutoffAlarm = true;
-            needAllwaysAlarmCutOff = true;
-            needAllwaysAlarmFenceOut = true;
-            needTemperature_abnormal_alarm = true;
-            noPushTxtReadReply = false;//A9需要阅读反馈
-            noPPGSensor = false;
-            noTempSensor = false;
-            A9_noBroadCastActionStrip = true;
-        } else if (custom_name.equals("SGL")) {
-            noPushTxtNotifyDialog = false;
-            noSMSNotifyDialog = false;
-            noVoiceNotifyDialog = true;
-            needBroadcastAntiAlarm = false;
-            needBroadcastCutoffAlarm = true;
-            needAllwaysAlarmCutOff = true;
-            needAllwaysAlarmFenceOut = false;
-            needTemperature_abnormal_alarm = false;
-            noPPGSensor = false;
-            noTempSensor = false;
-            C5_noBroadCastActionStrip = true;
-        } else if (custom_name.equals("L02")) {
-            noPushTxtReadReply = false;//即爱需要阅读反馈
-            noBroadCastPushTxtNotify = true;
-        } else {
-            noBroadCastPushTxtNotify = true;
-        }
 
 
     }
@@ -827,33 +970,7 @@ public class Config {
         }
     }
 
-    private static HashMap<Integer, Boolean> AlarmConfiglist;
 
-    static {
-        AlarmConfiglist = new HashMap<Integer, Boolean>();
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_SOS.ordinal(), true);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_LOWBATTERY.ordinal(), true);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_ANTIOFF.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_WEARED.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_CUTOFF.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_FALL.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_ABNORMAL_HEART_RATE.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_HEART_RATE_HIGH.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_HEART_RATE_LOW.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPH_HIGH.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPH_LOW.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPL_HIGH.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_BPL_LOW.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_SEDENTARY.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_LOCK_WATCH.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_TEMP_HIGH.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_TEMP_LOW.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_POWER_OFF.ordinal(), true);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_ESCAPE.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_NONE.ordinal(), false);
-        AlarmConfiglist.put(Runtime.AlarmType.ALARM_REMOVE_SOS.ordinal(), true);
-    }
 
     public static boolean isAlarmTypeEnabled(Runtime.AlarmType alarmType) {
 
@@ -871,5 +988,42 @@ public class Config {
         } else
             return false;
     }
+
+
+    public static void setConfigValue(String key,String value){
+        ICLogger.d("( "+key+" , "+value+")");
+
+        try {
+            if (key.trim().equals("AlarmConfig")) {
+                String[] alarmlist = value.split(",");
+                for (String al : alarmlist) {
+                    try {
+                        AlarmConfiglist.put(Runtime.AlarmType.valueOf(al).ordinal(), Boolean.valueOf(value));
+                    } catch (Exception e) {
+                        ICLogger.e(e.getMessage(),e);
+                    }
+                }
+            } else if (key.trim().equals("disableWiFiScan")) {
+                disableWiFiScan=Boolean.valueOf(value);
+            } else if (key.trim().equals("disableWristTemp")) {
+                disableWristTemp=Boolean.valueOf(value);
+            } else if (key.trim().equals("BLEScanProtocol")) {
+                BLEScanProtocol=Integer.valueOf(value);
+            } else if (key.trim().equals("UsePolingCheckWeared")) {
+
+/*
+*
+    public static String DefaultHttpLogServerUrl = "http://icfota.snicker.com.cn:8089/UploadFile.jsp";
+
+    public static String DefaultWiFiSSID = "icwifi20210417";
+    public static String DefaultWiFiPWD = "87654321";
+    public static String DefaultWiFiEncryptType = "psk";
+* */
+            }
+        }catch (Exception e){
+            ICLogger.e(e.getMessage(),e);
+        }
+    }
+
 }
 
index 8ca7752..8519cd3 100644 (file)
@@ -678,147 +678,24 @@ public class CoreService extends Service {
 
 
         //初始化消息相关配置
-        Config.LoadMessageConfigs();
-
-        if (Config.custom_name.equals("H88")) {
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true);
-            if (Config.getConfigInitFlag(this) == 0) {
-                Config.setLocationMode(this, CUSTOM_MOD8_GPS);
-                Config.setLocationCycle(this, 60 * 60);
-                Config.setPPGTestCycle(this, 60);
-                Config.setTemperatureTestCycle(runtime, 60 * 60);
-                Config.setConfigInitFlag(this, 1);
+        if (Config.custom_name.equals("YT")) {
+            int contactcount = runtime.getDbHelper().getContactCount(getContentResolver());
+            ICLogger.i("=====Contact count " + contactcount);
+            if (contactcount == 0) { //如果没有SOS
+                ICLogger.i("=====add hotline 96885 ");
+                ArrayList<Contact> contactArray = new ArrayList<Contact>();
+                contactArray.add(new Contact(Contact.CATEGORY_CALL, this.getResources().getString(R.string.hotline), "96885"));
+                runtime.getDbHelper().saveContacts(contactArray, false, false, false, false, false, true);
             }
-        } else if (Config.custom_name.equals("l004")) {
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_CUTOFF, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOCK_WATCH, true);
-
-            if (Config.getConfigInitFlag(this) == 0) {
-                Config.setLocationMode(this, CUSTOM_MOD8_GPS);
-                Config.setLocationCycle(this, 10 * 60);
-                Config.setPPGTestCycle(this, 0);
-                Config.setTemperatureTestCycle(runtime, 0);
-                Config.setConfigInitFlag(this, 1);
-
-            }
-        } else if (Config.custom_name.equals("YQ") || Config.custom_name.equals("YQ_EN")) {
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_CUTOFF, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOCK_WATCH, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_UNREADMSG, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_MSGREAD, true);
-
-            if (Config.getConfigInitFlag(this) == 0) {
-                Config.setLocationMode(this, NORMAL_MOD);
-                Config.setLocationCycle(this, 15 * 60);
-                Config.setPPGTestCycle(this, 0);
-                Config.setTemperatureTestCycle(runtime, 0);
-                Config.setConfigInitFlag(this, 1);
-
-            }
-        } else if (Config.custom_name.equals("AK")) {
-
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_SOS, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOWBATTERY, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true);
-            Config.enableSleep = true;
-
-            if (Config.getConfigInitFlag(this) == 0) {
-                Config.setPPGTestCycle(this, 0);
-                Config.setTemperatureTestCycle(runtime, 0);
-                Config.setConfigInitFlag(this, 1);
-
-//                int contactcount=runtime.getDbHelper().getContactCount(getContentResolver());
-//                ICLogger.i("=====Contact count "+contactcount);
-//                if(contactcount==0){ //如果没有SOS
-//                    ICLogger.i("=====add SOS 07522312120 ");
-//                    ArrayList<Contact> contactArray=new ArrayList<Contact>();
-//                    contactArray.add(new Contact(Contact.CATEGORY_SOS, "sos1", "07522312120"));
-//                    runtime.getDbHelper().saveContacts(contactArray,false,false,false,false,false,true);
-//                }
-            }
-        } else if (Config.custom_name.equals("YT")) {
-
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_SOS, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOWBATTERY, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true);
-            Config.enableSleep = true;
-
-            if (Config.getConfigInitFlag(this) == 0) {
-                Config.setPPGTestCycle(this, 0);
-                Config.setTemperatureTestCycle(runtime, 0);
-                Config.setConfigInitFlag(this, 1);
-
-                int contactcount = runtime.getDbHelper().getContactCount(getContentResolver());
-                ICLogger.i("=====Contact count " + contactcount);
-                if (contactcount == 0) { //如果没有SOS
-                    ICLogger.i("=====add hotline 96885 ");
-                    ArrayList<Contact> contactArray = new ArrayList<Contact>();
-                    contactArray.add(new Contact(Contact.CATEGORY_CALL, this.getResources().getString(R.string.hotline), "96885"));
-                    runtime.getDbHelper().saveContacts(contactArray, false, false, false, false, false, true);
-                }
-            }
-        } else if (Config.custom_name.equals("SGL")) { //C5项目
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_ESCAPE, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_CUTOFF, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_ILLEGAL_CUTOFF, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOCK_WATCH, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true);
-            Config.forceMoveCheck = false; //对定位不进行运动检测。
-            if (Config.getConfigInitFlag(this) == 0) {
-                Config.setLocationMode(this, CUSTOM_MOD8_GPS);
-//                Config.setLocationMode(this, CUSTOM_MOD8_WIFI);
-                Config.setLocationCycle(this, 5 * 60);
-                Config.setPPGTestCycle(this, 0);
-                Config.setTemperatureTestCycle(runtime, 0);
-                Config.setConfigInitFlag(this, 1);
-
-//                int contactcount=runtime.getDbHelper().getContactCount(getContentResolver());
-//                ICLogger.i("=====Contact count "+contactcount);
-//                if(contactcount==0){ //如果没有SOS
-//                    ICLogger.i("=====add SOS 07522312120 ");
-//                    ArrayList<Contact> contactArray=new ArrayList<Contact>();
-//                    contactArray.add(new Contact(Contact.CATEGORY_SOS, "sos1", "07522312120"));
-//                    runtime.getDbHelper().saveContacts(contactArray,false,false,false,false,false,true);
-//                }
-            }
-        } else if (Config.custom_name.equals("L02") || Config.custom_name.equals("L03") || Config.custom_name.equals("L05")) { //L02
-            Config.forceMoveCheck = false; //即爱对gps不进行运动检测,此变量专门为了给其他协议进行强制运动检测用的。
-            if (Config.getConfigInitFlag(this) == 0) {
-                Config.setPPGTestCycle(this, 0);
-                Config.setTemperatureTestCycle(runtime, 0);
-                Config.setConfigInitFlag(this, 1);
-            }
-
-        } else if (Config.custom_name.equals("VitracK") || Config.custom_name.equals("wtsrui")) {
-
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_SOS, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_LOWBATTERY, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_WEARED, true);
-            Config.ConfigAlarm(Runtime.AlarmType.ALARM_ANTIOFF, true);
-            Config.enableSleep = false;
-            if (Config.getConfigInitFlag(this) == 0) {
-                Config.setLocationMode(this, CUSTOM_MOD8_GPS);
-                Config.setLocationCycle(this, 15 * 60);
-                Config.setPPGTestCycle(this, 15);
-                Config.setTemperatureTestCycle(runtime, 15 * 60);
-                Config.setConfigInitFlag(this, 1);
-            }
-
-        } else {
+        }
 
-            if (Config.getConfigInitFlag(this) == 0) {
-                Config.setPPGTestCycle(this, 0);
-                Config.setTemperatureTestCycle(runtime, 0);
-                Config.setConfigInitFlag(this, 1);
-            }
+        if (Config.getConfigInitFlag(this) == 0) {
+            Config.load_config_fromfile();
+            Config.setLocationMode(this, Config.DefaultLocationMode);
+            Config.setLocationCycle(this, Config.DefaultLocationCycle);
+            Config.setPPGTestCycle(this,Config.DefaultPPGTestCycle);
+            Config.setTemperatureTestCycle(runtime, Config.DefaultTemperatureTestCycle);
+            Config.setConfigInitFlag(this, 1);
         }
 
         Config.dumpAlarmConfig();
@@ -1211,7 +1088,12 @@ public class CoreService extends Service {
                 //这里就是为了省电,如果wifi开启,且屏幕关闭,则wifi也关闭 ,还有获取wifi消息的时候也和它有关
                 if (Util.isConnectWifi((this.runtime.getContextProxy()).context) && !screenon) {
                     is_wifi_network_ok = true; //如果wifi开启的,则记录wifi状态为开启,以后屏幕开启时,再根据此变量决定是否打开wifi
-                    Util.turnOffWifiForSleep((this.runtime.getContextProxy()).context, this.runtime);
+                    String isUserOpen = Util.getSystemProperties("persist.sys.ic.wifi_enable", "false");
+                    ICLogger.d("is open by user == > " + isUserOpen);
+                    if ("false".equals(isUserOpen)) {
+                        //用户手动打开的,那么就不关闭wifi了
+                        Util.turnOffWifiForSleep((this.runtime.getContextProxy()).context, this.runtime);
+                    }
                 }
 //                setAlarm(alarmCycle);
 //                if (Config.LOG_TOFILE) FileOutputUtil.fileOutput(runtime.getCacheDir(), "alarmCycle", "ALARM alarmCycle");